From ed844c5283a86463432852ade65a756a701fba04 Mon Sep 17 00:00:00 2001 From: ZenGround0 Date: Tue, 20 Jul 2021 12:02:52 -0400 Subject: [PATCH] Use current ntwk version in mpool message check --- chain/messagepool/check.go | 15 ++++++++--- chain/messagepool/messagepool.go | 45 +++++++++++++++++++------------- chain/stmgr/forks.go | 12 +++++++++ 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/chain/messagepool/check.go b/chain/messagepool/check.go index c36b7d0a7..9a55c283c 100644 --- a/chain/messagepool/check.go +++ b/chain/messagepool/check.go @@ -11,7 +11,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" ) @@ -107,6 +106,8 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, curTs := mp.curTs mp.curTsLk.Unlock() + epoch := curTs.Height() + var baseFee big.Int if len(curTs.Blocks()) > 0 { baseFee = curTs.Blocks()[0].ParentBaseFee @@ -257,8 +258,14 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, Code: api.CheckStatusMessageValidity, }, } - - if err := m.ValidForBlockInclusion(0, build.NewestNetworkVersion); err != nil { + nv, err := mp.getNtwkVersion(epoch) + if err != nil { + check.OK = false + check.Err = fmt.Sprintf("error retrieving network version: %s", err.Error()) + } else { + check.OK = true + } + if err := m.ValidForBlockInclusion(0, nv); err != nil { check.OK = false check.Err = fmt.Sprintf("syntactically invalid message: %s", err.Error()) } else { @@ -274,7 +281,7 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message, // gas checks // 4. Min Gas - minGas := vm.PricelistByVersion(build.NewestNetworkVersion).OnChainMessage(m.ChainLength()) + minGas := vm.PricelistByVersion(nv).OnChainMessage(m.ChainLength()) check = api.MessageCheckStatus{ Cid: m.Cid(), diff --git a/chain/messagepool/messagepool.go b/chain/messagepool/messagepool.go index 9e17b2ff2..2307a4f39 100644 --- a/chain/messagepool/messagepool.go +++ b/chain/messagepool/messagepool.go @@ -14,6 +14,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/go-state-types/network" "github.com/hashicorp/go-multierror" lru "github.com/hashicorp/golang-lru" "github.com/ipfs/go-cid" @@ -29,6 +30,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" @@ -147,6 +149,8 @@ type MessagePool struct { minGasPrice types.BigInt + getNtwkVersion func(abi.ChainEpoch) (network.Version, error) + currentSize int // pruneTrigger is a channel used to trigger a mempool pruning @@ -362,26 +366,31 @@ func New(api Provider, ds dtypes.MetadataDS, netName dtypes.NetworkName, j journ if j == nil { j = journal.NilJournal() } + us := stmgr.DefaultUpgradeSchedule() + if err := us.Validate(); err != nil { + return nil, err + } mp := &MessagePool{ - ds: ds, - addSema: make(chan struct{}, 1), - closer: make(chan struct{}), - repubTk: build.Clock.Ticker(RepublishInterval), - repubTrigger: make(chan struct{}, 1), - localAddrs: make(map[address.Address]struct{}), - pending: make(map[address.Address]*msgSet), - keyCache: make(map[address.Address]address.Address), - minGasPrice: types.NewInt(0), - pruneTrigger: make(chan struct{}, 1), - pruneCooldown: make(chan struct{}, 1), - blsSigCache: cache, - sigValCache: verifcache, - changes: lps.New(50), - localMsgs: namespace.Wrap(ds, datastore.NewKey(localMsgsDs)), - api: api, - netName: netName, - cfg: cfg, + ds: ds, + addSema: make(chan struct{}, 1), + closer: make(chan struct{}), + repubTk: build.Clock.Ticker(RepublishInterval), + repubTrigger: make(chan struct{}, 1), + localAddrs: make(map[address.Address]struct{}), + pending: make(map[address.Address]*msgSet), + keyCache: make(map[address.Address]address.Address), + minGasPrice: types.NewInt(0), + getNtwkVersion: us.GetNtwkVersion, + pruneTrigger: make(chan struct{}, 1), + pruneCooldown: make(chan struct{}, 1), + blsSigCache: cache, + sigValCache: verifcache, + changes: lps.New(50), + localMsgs: namespace.Wrap(ds, datastore.NewKey(localMsgsDs)), + api: api, + netName: netName, + cfg: cfg, evtTypes: [...]journal.EventType{ evtTypeMpoolAdd: j.RegisterEventType("mpool", "add"), evtTypeMpoolRemove: j.RegisterEventType("mpool", "remove"), diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index c4fe5108e..56618172c 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -296,6 +296,18 @@ func (us UpgradeSchedule) Validate() error { return nil } +func (us UpgradeSchedule) GetNtwkVersion(e abi.ChainEpoch) (network.Version, error) { + // Traverse from newest to oldest returning upgrade active during epoch e + for i := len(us) - 1; i >= 0; i-- { + u := us[i] + // u.Height is the last epoch before u.Network becomes the active version + if u.Height < e { + return u.Network, nil + } + } + return network.Version0, xerrors.Errorf("Epoch %d has no defined network version") +} + func (sm *StateManager) handleStateForks(ctx context.Context, root cid.Cid, height abi.ChainEpoch, cb ExecMonitor, ts *types.TipSet) (cid.Cid, error) { retCid := root var err error