Do not compute message index as traces should be in message execution order

This commit is contained in:
Fridrik Asmundsson 2023-08-22 14:32:59 +00:00
parent a1b890c8c7
commit ef7bcfec06
2 changed files with 8 additions and 12 deletions

View File

@ -229,7 +229,7 @@ func BuildTraces(traces *[]*Trace, parent *Trace, addr []int, et types.Execution
return nil 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{} tmp := &bytes.Buffer{}
// first write data to tmp buffer to get the size // first write data to tmp buffer to get the size

View File

@ -857,23 +857,19 @@ func (a *EthModule) TraceBlock(ctx context.Context, blkNum string) ([]*ethtypes.
} }
allTraces := make([]*ethtypes.TraceBlock, 0, len(trace)) allTraces := make([]*ethtypes.TraceBlock, 0, len(trace))
msgIdx := 0
for _, ir := range trace { for _, ir := range trace {
// ignore messages from system actor // ignore messages from system actor
if ir.Msg.From == builtinactors.SystemActorAddr { if ir.Msg.From == builtinactors.SystemActorAddr {
continue continue
} }
idx := -1 // as we include TransactionPosition in the results, lets do sanity checking that the
for msgIdx, msg := range msgs { // traces are indeed in the message execution order
if ir.Msg.From == msg.Message.From { if ir.Msg.Cid() != msgs[msgIdx].Message.Cid() {
idx = msgIdx return nil, xerrors.Errorf("traces are not in message execution order")
break
}
}
if idx == -1 {
log.Warnf("cannot resolve message index for cid: %s", ir.MsgCid)
continue
} }
msgIdx++
txHash, err := a.EthGetTransactionHashByCid(ctx, ir.MsgCid) txHash, err := a.EthGetTransactionHashByCid(ctx, ir.MsgCid)
if err != nil { if err != nil {
@ -897,7 +893,7 @@ func (a *EthModule) TraceBlock(ctx context.Context, blkNum string) ([]*ethtypes.
BlockHash: blkHash, BlockHash: blkHash,
BlockNumber: int64(ts.Height()), BlockNumber: int64(ts.Height()),
TransactionHash: *txHash, TransactionHash: *txHash,
TransactionPosition: idx, TransactionPosition: msgIdx,
}) })
} }