From 510f01545e90d10fafb702fe078bb437d78b9752 Mon Sep 17 00:00:00 2001 From: Rod Vagg Date: Tue, 30 Apr 2024 15:38:38 +1000 Subject: [PATCH] fix(events): load actor from tipset state, not parent state --- chain/events/filter/index.go | 6 +++++- node/impl/full/eth_events.go | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/chain/events/filter/index.go b/chain/events/filter/index.go index 2f2e6dca333..ef015313f59 100644 --- a/chain/events/filter/index.go +++ b/chain/events/filter/index.go @@ -362,6 +362,10 @@ func (ei *EventIndex) migrateToVersion4(ctx context.Context) error { } } + if _, err = tx.Exec("INSERT OR IGNORE INTO _meta (version) VALUES (4)"); err != nil { + return xerrors.Errorf("increment _meta version: %w", err) + } + err = tx.Commit() if err != nil { return xerrors.Errorf("commit transaction: %w", err) @@ -502,7 +506,7 @@ func (ei *EventIndex) migrateToVersion5(ctx context.Context, chainStore *store.C } // Increment the schema version in _meta table to 4. - if _, err = tx.Exec("INSERT OR IGNORE INTO _meta (version) VALUES (4)"); err != nil { + if _, err = tx.Exec("INSERT OR IGNORE INTO _meta (version) VALUES (5)"); err != nil { return xerrors.Errorf("increment _meta version: %w", err) } diff --git a/node/impl/full/eth_events.go b/node/impl/full/eth_events.go index e6917738cc7..369b0e1f60c 100644 --- a/node/impl/full/eth_events.go +++ b/node/impl/full/eth_events.go @@ -97,7 +97,7 @@ func ethLogFromEvent(entries []types.EventEntry) (data []byte, topics []ethtypes func ethFilterResultFromEvents(ctx context.Context, evs []*filter.CollectedEvent, sa StateAPI) (*ethtypes.EthFilterResult, error) { res := ðtypes.EthFilterResult{} for _, ev := range evs { - log := ethtypes.EthLog{ + ethlog := ethtypes.EthLog{ Removed: ev.Reverted, LogIndex: ethtypes.EthUint64(ev.EventIdx), TransactionIndex: ethtypes.EthUint64(ev.MsgIdx), @@ -108,7 +108,7 @@ func ethFilterResultFromEvents(ctx context.Context, evs []*filter.CollectedEvent ok bool ) - log.Data, log.Topics, ok = ethLogFromEvent(ev.Entries) + ethlog.Data, ethlog.Topics, ok = ethLogFromEvent(ev.Entries) if !ok { continue } @@ -118,22 +118,30 @@ func ethFilterResultFromEvents(ctx context.Context, evs []*filter.CollectedEvent return nil, xerrors.Errorf("emitter to addr: %w", err) } - actor, err := sa.StateGetActor(ctx, emitterAddr, ev.TipSetKey) + ts, err := sa.Chain.GetTipSetFromKey(ctx, ev.TipSetKey) + if err != nil { + return nil, xerrors.Errorf("loading tipset: %w", err) + } + stateRoot, _, err := sa.StateManager.TipSetState(ctx, ts) + if err != nil { + return nil, xerrors.Errorf("loading tipset state: %w", err) + } + actor, err := sa.StateManager.LoadActorRaw(ctx, emitterAddr, stateRoot) if err != nil { return nil, xerrors.Errorf("state get actor: %w", err) } if actor == nil && actor.Address == nil { return nil, xerrors.New("state get actor: nil") } - log.Address, err = ethtypes.EthAddressFromFilecoinAddress(*actor.Address) + ethlog.Address, err = ethtypes.EthAddressFromFilecoinAddress(*actor.Address) if err != nil { return nil, xerrors.Errorf("eth addr from fil: %w", err) } - log.TransactionHash, err = ethTxHashFromMessageCid(ctx, ev.MsgCid, sa) + ethlog.TransactionHash, err = ethTxHashFromMessageCid(ctx, ev.MsgCid, sa) if err != nil { return nil, err } - if log.TransactionHash == ethtypes.EmptyEthHash { + if ethlog.TransactionHash == ethtypes.EmptyEthHash { // We've garbage collected the message, ignore the events and continue. continue } @@ -141,12 +149,12 @@ func ethFilterResultFromEvents(ctx context.Context, evs []*filter.CollectedEvent if err != nil { return nil, err } - log.BlockHash, err = ethtypes.EthHashFromCid(c) + ethlog.BlockHash, err = ethtypes.EthHashFromCid(c) if err != nil { return nil, err } - res.Results = append(res.Results, log) + res.Results = append(res.Results, ethlog) } return res, nil