Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events): load actor from tipset state, not parent state #11945

Draft
wants to merge 1 commit into
base: masih/events-index-by-id
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 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,46 @@ 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)
}
// Because we collect events after the tipset is processed, a call to TipSetState should't have
// to execute the tipset to get the state root, so we shouldn't have to worry about avoiding
// expensive migrations here.
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
Loading