Skip to content

Commit

Permalink
fix(events): load actor from tipset state, not parent state
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Apr 30, 2024
1 parent 9abe818 commit 510f015
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion chain/events/filter/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
24 changes: 16 additions & 8 deletions node/impl/full/eth_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := &ethtypes.EthFilterResult{}
for _, ev := range evs {
log := ethtypes.EthLog{
ethlog := ethtypes.EthLog{
Removed: ev.Reverted,
LogIndex: ethtypes.EthUint64(ev.EventIdx),
TransactionIndex: ethtypes.EthUint64(ev.MsgIdx),
Expand All @@ -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
}
Expand All @@ -118,35 +118,43 @@ 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
}
c, err := ev.TipSetKey.Cid()
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
Expand Down

0 comments on commit 510f015

Please sign in to comment.