feat: add StateNetworkVersion to mpool API

This commit is contained in:
Aayush 2022-09-21 11:49:24 -04:00
parent 9e94dc5550
commit 347d92b29c
2 changed files with 19 additions and 10 deletions

View File

@ -624,11 +624,11 @@ func (mp *MessagePool) addLocal(ctx context.Context, m *types.SignedMessage) err
// sufficiently. // sufficiently.
// For non local messages, if the message cannot be included in the next 20 blocks it returns // For non local messages, if the message cannot be included in the next 20 blocks it returns
// a (soft) validation error. // a (soft) validation error.
func (mp *MessagePool) verifyMsgBeforeAdd(m *types.SignedMessage, curTs *types.TipSet, local bool) (bool, error) { func (mp *MessagePool) verifyMsgBeforeAdd(ctx context.Context, m *types.SignedMessage, curTs *types.TipSet, local bool) (bool, error) {
epoch := curTs.Height() + 1 epoch := curTs.Height() + 1
minGas := vm.PricelistByEpoch(epoch).OnChainMessage(m.ChainLength()) minGas := vm.PricelistByEpoch(epoch).OnChainMessage(m.ChainLength())
if err := m.VMMessage().ValidForBlockInclusion(minGas.Total(), build.NewestNetworkVersion); err != nil { if err := m.VMMessage().ValidForBlockInclusion(minGas.Total(), mp.api.StateNetworkVersion(ctx, epoch)); err != nil {
return false, xerrors.Errorf("message will not be included in a block: %w", err) return false, xerrors.Errorf("message will not be included in a block: %w", err)
} }
@ -671,7 +671,7 @@ func (mp *MessagePool) Push(ctx context.Context, m *types.SignedMessage) (cid.Ci
done := metrics.Timer(ctx, metrics.MpoolPushDuration) done := metrics.Timer(ctx, metrics.MpoolPushDuration)
defer done() defer done()
err := mp.checkMessage(m) err := mp.checkMessage(ctx, m)
if err != nil { if err != nil {
return cid.Undef, err return cid.Undef, err
} }
@ -705,14 +705,14 @@ func (mp *MessagePool) Push(ctx context.Context, m *types.SignedMessage) (cid.Ci
return m.Cid(), nil return m.Cid(), nil
} }
func (mp *MessagePool) checkMessage(m *types.SignedMessage) error { func (mp *MessagePool) checkMessage(ctx context.Context, m *types.SignedMessage) error {
// big messages are bad, anti DOS // big messages are bad, anti DOS
if m.Size() > MaxMessageSize { if m.Size() > MaxMessageSize {
return xerrors.Errorf("mpool message too large (%dB): %w", m.Size(), ErrMessageTooBig) return xerrors.Errorf("mpool message too large (%dB): %w", m.Size(), ErrMessageTooBig)
} }
// Perform syntactic validation, minGas=0 as we check the actual mingas before we add it // Perform syntactic validation, minGas=0 as we check the actual mingas before we add it
if err := m.Message.ValidForBlockInclusion(0, build.NewestNetworkVersion); err != nil { if err := m.Message.ValidForBlockInclusion(0, mp.api.StateNetworkVersion(ctx, mp.curTs.Height())); err != nil {
return xerrors.Errorf("message not valid for block inclusion: %w", err) return xerrors.Errorf("message not valid for block inclusion: %w", err)
} }
@ -740,7 +740,7 @@ func (mp *MessagePool) Add(ctx context.Context, m *types.SignedMessage) error {
done := metrics.Timer(ctx, metrics.MpoolAddDuration) done := metrics.Timer(ctx, metrics.MpoolAddDuration)
defer done() defer done()
err := mp.checkMessage(m) err := mp.checkMessage(ctx, m)
if err != nil { if err != nil {
return err return err
} }
@ -845,7 +845,7 @@ func (mp *MessagePool) addTs(ctx context.Context, m *types.SignedMessage, curTs
mp.lk.Lock() mp.lk.Lock()
defer mp.lk.Unlock() defer mp.lk.Unlock()
publish, err := mp.verifyMsgBeforeAdd(m, curTs, local) publish, err := mp.verifyMsgBeforeAdd(ctx, m, curTs, local)
if err != nil { if err != nil {
return false, err return false, err
} }
@ -870,7 +870,7 @@ func (mp *MessagePool) addTs(ctx context.Context, m *types.SignedMessage, curTs
} }
func (mp *MessagePool) addLoaded(ctx context.Context, m *types.SignedMessage) error { func (mp *MessagePool) addLoaded(ctx context.Context, m *types.SignedMessage) error {
err := mp.checkMessage(m) err := mp.checkMessage(ctx, m)
if err != nil { if err != nil {
return err return err
} }
@ -890,7 +890,7 @@ func (mp *MessagePool) addLoaded(ctx context.Context, m *types.SignedMessage) er
return xerrors.Errorf("minimum expected nonce is %d: %w", snonce, ErrNonceTooLow) return xerrors.Errorf("minimum expected nonce is %d: %w", snonce, ErrNonceTooLow)
} }
_, err = mp.verifyMsgBeforeAdd(m, curTs, true) _, err = mp.verifyMsgBeforeAdd(ctx, m, curTs, true)
if err != nil { if err != nil {
return err return err
} }
@ -1060,7 +1060,7 @@ func (mp *MessagePool) getStateBalance(ctx context.Context, addr address.Address
// - extra strict add checks are used when adding the messages to the msgSet // - extra strict add checks are used when adding the messages to the msgSet
// that means: no nonce gaps, at most 10 pending messages for the actor // that means: no nonce gaps, at most 10 pending messages for the actor
func (mp *MessagePool) PushUntrusted(ctx context.Context, m *types.SignedMessage) (cid.Cid, error) { func (mp *MessagePool) PushUntrusted(ctx context.Context, m *types.SignedMessage) (cid.Cid, error) {
err := mp.checkMessage(m) err := mp.checkMessage(ctx, m)
if err != nil { if err != nil {
return cid.Undef, err return cid.Undef, err
} }

View File

@ -4,6 +4,10 @@ import (
"context" "context"
"time" "time"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/network"
"github.com/ipfs/go-cid" "github.com/ipfs/go-cid"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -28,6 +32,7 @@ type Provider interface {
PubSubPublish(string, []byte) error PubSubPublish(string, []byte) error
GetActorAfter(address.Address, *types.TipSet) (*types.Actor, error) GetActorAfter(address.Address, *types.TipSet) (*types.Actor, error)
StateAccountKeyAtFinality(context.Context, address.Address, *types.TipSet) (address.Address, error) StateAccountKeyAtFinality(context.Context, address.Address, *types.TipSet) (address.Address, error)
StateNetworkVersion(context.Context, abi.ChainEpoch) network.Version
MessagesForBlock(context.Context, *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) MessagesForBlock(context.Context, *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error)
MessagesForTipset(context.Context, *types.TipSet) ([]types.ChainMsg, error) MessagesForTipset(context.Context, *types.TipSet) ([]types.ChainMsg, error)
LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) LoadTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error)
@ -104,6 +109,10 @@ func (mpp *mpoolProvider) StateAccountKeyAtFinality(ctx context.Context, addr ad
return mpp.sm.ResolveToKeyAddressAtFinality(ctx, addr, ts) return mpp.sm.ResolveToKeyAddressAtFinality(ctx, addr, ts)
} }
func (mpp *mpoolProvider) StateNetworkVersion(ctx context.Context, height abi.ChainEpoch) network.Version {
return mpp.sm.GetNetworkVersion(ctx, height)
}
func (mpp *mpoolProvider) MessagesForBlock(ctx context.Context, h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) { func (mpp *mpoolProvider) MessagesForBlock(ctx context.Context, h *types.BlockHeader) ([]*types.Message, []*types.SignedMessage, error) {
return mpp.sm.ChainStore().MessagesForBlock(ctx, h) return mpp.sm.ChainStore().MessagesForBlock(ctx, h)
} }