5f157affdd
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
80 lines
1.8 KiB
Go
80 lines
1.8 KiB
Go
package messagepool
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
"github.com/ipfs/go-datastore"
|
|
)
|
|
|
|
var (
|
|
ReplaceByFeeRatioDefault = 1.25
|
|
MemPoolSizeLimitHiDefault = 30000
|
|
MemPoolSizeLimitLoDefault = 20000
|
|
PruneCooldownDefault = time.Minute
|
|
GasLimitOverestimation = 1.25
|
|
|
|
ConfigKey = datastore.NewKey("/mpool/config")
|
|
)
|
|
|
|
func loadConfig(ds dtypes.MetadataDS) (*types.MpoolConfig, error) {
|
|
haveCfg, err := ds.Has(ConfigKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if !haveCfg {
|
|
return DefaultConfig(), nil
|
|
}
|
|
|
|
cfgBytes, err := ds.Get(ConfigKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cfg := new(types.MpoolConfig)
|
|
err = json.Unmarshal(cfgBytes, cfg)
|
|
if cfg.GasLimitOverestimation == 0 {
|
|
// TODO: remove in next reset
|
|
cfg.GasLimitOverestimation = GasLimitOverestimation
|
|
}
|
|
return cfg, err
|
|
}
|
|
|
|
func saveConfig(cfg *types.MpoolConfig, ds dtypes.MetadataDS) error {
|
|
cfgBytes, err := json.Marshal(cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return ds.Put(ConfigKey, cfgBytes)
|
|
}
|
|
|
|
func (mp *MessagePool) GetConfig() *types.MpoolConfig {
|
|
mp.cfgLk.Lock()
|
|
defer mp.cfgLk.Unlock()
|
|
return mp.cfg.Clone()
|
|
}
|
|
|
|
func (mp *MessagePool) SetConfig(cfg *types.MpoolConfig) {
|
|
cfg = cfg.Clone()
|
|
mp.cfgLk.Lock()
|
|
mp.cfg = cfg
|
|
mp.rbfNum = types.NewInt(uint64((cfg.ReplaceByFeeRatio - 1) * RbfDenom))
|
|
err := saveConfig(cfg, mp.ds)
|
|
if err != nil {
|
|
log.Warnf("error persisting mpool config: %s", err)
|
|
}
|
|
mp.cfgLk.Unlock()
|
|
}
|
|
|
|
func DefaultConfig() *types.MpoolConfig {
|
|
return &types.MpoolConfig{
|
|
SizeLimitHigh: MemPoolSizeLimitHiDefault,
|
|
SizeLimitLow: MemPoolSizeLimitLoDefault,
|
|
ReplaceByFeeRatio: ReplaceByFeeRatioDefault,
|
|
PruneCooldown: PruneCooldownDefault,
|
|
GasLimitOverestimation: GasLimitOverestimation,
|
|
}
|
|
}
|