lotus/chain/events/utils.go

50 lines
1.3 KiB
Go
Raw Permalink Normal View History

2019-11-19 21:27:25 +00:00
package events
import (
"context"
2019-11-20 16:36:37 +00:00
"golang.org/x/xerrors"
2022-06-14 15:00:51 +00:00
"github.com/filecoin-project/lotus/chain/stmgr"
2019-11-19 21:27:25 +00:00
"github.com/filecoin-project/lotus/chain/types"
)
2021-08-04 00:10:30 +00:00
func (me *messageEvents) CheckMsg(smsg types.ChainMsg, hnd MsgHandler) CheckFunc {
2019-11-24 16:35:50 +00:00
msg := smsg.VMMessage()
2021-08-04 00:10:30 +00:00
return func(ctx context.Context, ts *types.TipSet) (done bool, more bool, err error) {
fa, err := me.cs.StateGetActor(ctx, msg.From, ts.Key())
2019-11-19 21:27:25 +00:00
if err != nil {
return false, true, err
}
2019-11-24 19:16:34 +00:00
// >= because actor nonce is actually the next nonce that is expected to appear on chain
if msg.Nonce >= fa.Nonce {
2019-11-24 16:35:50 +00:00
return false, true, nil
}
2019-11-19 21:27:25 +00:00
2021-08-04 00:10:30 +00:00
ml, err := me.cs.StateSearchMsg(ctx, ts.Key(), msg.Cid(), stmgr.LookbackNoLimit, true)
2019-11-19 21:27:25 +00:00
if err != nil {
2019-11-24 16:35:50 +00:00
return false, true, xerrors.Errorf("getting receipt in CheckMsg: %w", err)
2019-11-19 21:27:25 +00:00
}
2021-04-05 17:56:53 +00:00
if ml == nil {
more, err = hnd(msg, nil, ts, ts.Height())
} else {
more, err = hnd(msg, &ml.Receipt, ts, ts.Height())
}
2019-11-19 21:27:25 +00:00
2019-11-24 16:35:50 +00:00
return true, more, err
2019-11-19 21:27:25 +00:00
}
}
func (me *messageEvents) MatchMsg(inmsg *types.Message) MsgMatchFunc {
return func(msg *types.Message) (matched bool, err error) {
2019-11-20 16:36:37 +00:00
if msg.From == inmsg.From && msg.Nonce == inmsg.Nonce && !inmsg.Equals(msg) {
return false, xerrors.Errorf("matching msg %s from %s, nonce %d: got duplicate origin/nonce msg %d", inmsg.Cid(), inmsg.From, inmsg.Nonce, msg.Nonce)
2019-11-20 16:36:37 +00:00
}
return inmsg.Equals(msg), nil
2019-11-19 21:27:25 +00:00
}
}