From ef7bcfec067284e86c11b9879d41ecaff5f67552 Mon Sep 17 00:00:00 2001 From: Fridrik Asmundsson Date: Tue, 22 Aug 2023 14:32:59 +0000 Subject: [PATCH] Do not compute message index as traces should be in message execution order --- chain/types/ethtypes/eth_trace.go | 2 +- node/impl/full/eth.go | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/chain/types/ethtypes/eth_trace.go b/chain/types/ethtypes/eth_trace.go index 66fb860b6..14f7e3332 100644 --- a/chain/types/ethtypes/eth_trace.go +++ b/chain/types/ethtypes/eth_trace.go @@ -229,7 +229,7 @@ func BuildTraces(traces *[]*Trace, parent *Trace, addr []int, et types.Execution return nil } -func writePadded[T any](w io.Writer, data T, size int) error { +func writePadded(w io.Writer, data any, size int) error { tmp := &bytes.Buffer{} // first write data to tmp buffer to get the size diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index 0d983d803..25796e864 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -857,23 +857,19 @@ func (a *EthModule) TraceBlock(ctx context.Context, blkNum string) ([]*ethtypes. } allTraces := make([]*ethtypes.TraceBlock, 0, len(trace)) + msgIdx := 0 for _, ir := range trace { // ignore messages from system actor if ir.Msg.From == builtinactors.SystemActorAddr { continue } - idx := -1 - for msgIdx, msg := range msgs { - if ir.Msg.From == msg.Message.From { - idx = msgIdx - break - } - } - if idx == -1 { - log.Warnf("cannot resolve message index for cid: %s", ir.MsgCid) - continue + // as we include TransactionPosition in the results, lets do sanity checking that the + // traces are indeed in the message execution order + if ir.Msg.Cid() != msgs[msgIdx].Message.Cid() { + return nil, xerrors.Errorf("traces are not in message execution order") } + msgIdx++ txHash, err := a.EthGetTransactionHashByCid(ctx, ir.MsgCid) if err != nil { @@ -897,7 +893,7 @@ func (a *EthModule) TraceBlock(ctx context.Context, blkNum string) ([]*ethtypes. BlockHash: blkHash, BlockNumber: int64(ts.Height()), TransactionHash: *txHash, - TransactionPosition: idx, + TransactionPosition: msgIdx, }) }