Documentation
¶
Index ¶
Constants ¶
const ( MAX_REFRESH_INTERVAL = 60 * time.Minute MAX_RATES_PAGE = 100 )
const (
// At this point, always return congestion as 100%
MAX_CONGESTION_RATIO = 1.5
)
Variables ¶
This section is empty.
Functions ¶
func CalculateCongestion ¶
* The algorithm for calculating congestion is as follows:
1) Compute the average number of messages per minute, excluding the current minute which may be incomplete 2) Take the greater of: the current minute's rate, the previous minute's rate, or the preceding 4 minute average 3) Compute the ratio of the max rate to the target rate 4) If the ratio is less than or equal to 1, return 0 5) If the ratio is greater than MAX_CONGESTION_RATIO, return 100 6) Otherwise, return the congestion as an exponential function of the ratio *
Types ¶
type ContractRatesFetcher ¶
type ContractRatesFetcher struct {
// contains filtered or unexported fields
}
ContractRatesFetcher pulls all the rates from the RatesManager contract and stores them in a sorted set to find the appropriate rate for a given timestamp
func NewContractRatesFetcher ¶
func NewContractRatesFetcher( ctx context.Context, ethclient bind.ContractCaller, logger *zap.Logger, options config.ContractsOptions, ) (*ContractRatesFetcher, error)
NewContractRatesFetcher creates a new ContractRatesFetcher using the provided eth client
func (*ContractRatesFetcher) GetRates ¶
func (c *ContractRatesFetcher) GetRates(timestamp time.Time) (*Rates, error)
func (*ContractRatesFetcher) Start ¶
func (c *ContractRatesFetcher) Start() error
Start the ContractRatesFetcher and begin fetching rates from the smart contract periodically.
type FeeCalculator ¶
type FeeCalculator struct {
// contains filtered or unexported fields
}
func NewFeeCalculator ¶
func NewFeeCalculator(ratesFetcher IRatesFetcher) *FeeCalculator
func (*FeeCalculator) CalculateBaseFee ¶
func (c *FeeCalculator) CalculateBaseFee( messageTime time.Time, messageSize int64, storageDurationDays uint32, ) (currency.PicoDollar, error)
func (*FeeCalculator) CalculateCongestionFee ¶
type FixedRatesFetcher ¶
type FixedRatesFetcher struct {
// contains filtered or unexported fields
}
A fixed fee schedule that doesn't rely on the blockchain. Used primarily for testing, and until we have fees onchain.
func NewFixedRatesFetcher ¶
func NewFixedRatesFetcher(rates *Rates) *FixedRatesFetcher
type IFeeCalculator ¶
type IRatesFetcher ¶
The RatesFetcher is responsible for loading the rates for a given message time. This allows us to roll out new rates over time, and apply them to messages consistently.
type Rates ¶
type Rates struct {
MessageFee currency.PicoDollar // The flat per-message fee
StorageFee currency.PicoDollar // The fee per byte-day of storage
CongestionFee currency.PicoDollar // The fee per unit of congestion
TargetRatePerMinute uint64 // The target rate per minute for each node
}
Rates contain the cost for each fee component at a given message time. Values in the rates struct are denominated in USD PicoDollars