Skip to content

Commit

Permalink
fix: EthAPI: Make newEthBlockFromFilecoinTipSet faster and correct
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Mar 2, 2023
1 parent dbbcf4b commit ae3aeb4
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1792,18 +1792,27 @@ func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTx

block := ethtypes.NewEthBlock(len(msgs) > 0)

// this seems to be a very expensive way to get gasUsed of the block. may need to find an efficient way to do it
gasUsed := int64(0)
for txIdx, msg := range msgs {
msgLookup, err := sa.StateSearchMsg(ctx, types.EmptyTSK, msg.Cid(), api.LookbackNoLimit, false)
if err != nil || msgLookup == nil {
return ethtypes.EthBlock{}, nil
compOutput, err := sa.StateCompute(ctx, ts.Height(), nil, ts.Key())
if err != nil {
return ethtypes.EthBlock{}, xerrors.Errorf("failed to compute state: %w", err)
}

for txIdx, msg := range compOutput.Trace {
// skip system messages like reward application and cron
if msg.Msg.From == builtintypes.SystemActorAddr {
continue
}
gasUsed += msgLookup.Receipt.GasUsed

tx, err := newEthTxFromMessageLookup(ctx, msgLookup, txIdx, cs, sa)
gasUsed += msg.MsgRct.GasUsed
tx, err := newEthTxFromMessageLookup(ctx, &api.MsgLookup{
Message: msg.MsgCid,
Receipt: *msg.MsgRct,
TipSet: ts.Key(),
Height: ts.Height(),
}, txIdx, cs, sa)
if err != nil {
return ethtypes.EthBlock{}, nil
return ethtypes.EthBlock{}, xerrors.Errorf("failed to convert msg to ethTx")
}

if fullTxInfo {
Expand Down

0 comments on commit ae3aeb4

Please sign in to comment.