Use current ntwk version in mpool message check

This commit is contained in:
ZenGround0 2021-07-20 12:02:52 -04:00
parent 9fc4a25bd1
commit ed844c5283
3 changed files with 50 additions and 22 deletions

View File

@ -11,7 +11,6 @@ import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/api" "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/types"
"github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/chain/vm"
) )
@ -107,6 +106,8 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message,
curTs := mp.curTs curTs := mp.curTs
mp.curTsLk.Unlock() mp.curTsLk.Unlock()
epoch := curTs.Height()
var baseFee big.Int var baseFee big.Int
if len(curTs.Blocks()) > 0 { if len(curTs.Blocks()) > 0 {
baseFee = curTs.Blocks()[0].ParentBaseFee baseFee = curTs.Blocks()[0].ParentBaseFee
@ -257,8 +258,14 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message,
Code: api.CheckStatusMessageValidity, Code: api.CheckStatusMessageValidity,
}, },
} }
nv, err := mp.getNtwkVersion(epoch)
if err := m.ValidForBlockInclusion(0, build.NewestNetworkVersion); err != nil { 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.OK = false
check.Err = fmt.Sprintf("syntactically invalid message: %s", err.Error()) check.Err = fmt.Sprintf("syntactically invalid message: %s", err.Error())
} else { } else {
@ -274,7 +281,7 @@ func (mp *MessagePool) checkMessages(ctx context.Context, msgs []*types.Message,
// gas checks // gas checks
// 4. Min Gas // 4. Min Gas
minGas := vm.PricelistByVersion(build.NewestNetworkVersion).OnChainMessage(m.ChainLength()) minGas := vm.PricelistByVersion(nv).OnChainMessage(m.ChainLength())
check = api.MessageCheckStatus{ check = api.MessageCheckStatus{
Cid: m.Cid(), Cid: m.Cid(),

View File

@ -14,6 +14,7 @@ import (
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/network"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
@ -29,6 +30,7 @@ import (
"github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build" "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/store"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/chain/vm"
@ -147,6 +149,8 @@ type MessagePool struct {
minGasPrice types.BigInt minGasPrice types.BigInt
getNtwkVersion func(abi.ChainEpoch) (network.Version, error)
currentSize int currentSize int
// pruneTrigger is a channel used to trigger a mempool pruning // pruneTrigger is a channel used to trigger a mempool pruning
@ -362,6 +366,10 @@ func New(api Provider, ds dtypes.MetadataDS, netName dtypes.NetworkName, j journ
if j == nil { if j == nil {
j = journal.NilJournal() j = journal.NilJournal()
} }
us := stmgr.DefaultUpgradeSchedule()
if err := us.Validate(); err != nil {
return nil, err
}
mp := &MessagePool{ mp := &MessagePool{
ds: ds, ds: ds,
@ -373,6 +381,7 @@ func New(api Provider, ds dtypes.MetadataDS, netName dtypes.NetworkName, j journ
pending: make(map[address.Address]*msgSet), pending: make(map[address.Address]*msgSet),
keyCache: make(map[address.Address]address.Address), keyCache: make(map[address.Address]address.Address),
minGasPrice: types.NewInt(0), minGasPrice: types.NewInt(0),
getNtwkVersion: us.GetNtwkVersion,
pruneTrigger: make(chan struct{}, 1), pruneTrigger: make(chan struct{}, 1),
pruneCooldown: make(chan struct{}, 1), pruneCooldown: make(chan struct{}, 1),
blsSigCache: cache, blsSigCache: cache,

View File

@ -296,6 +296,18 @@ func (us UpgradeSchedule) Validate() error {
return nil 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) { func (sm *StateManager) handleStateForks(ctx context.Context, root cid.Cid, height abi.ChainEpoch, cb ExecMonitor, ts *types.TipSet) (cid.Cid, error) {
retCid := root retCid := root
var err error var err error