Skip to content

Commit 8003997

Browse files
authored
fix(eth): make trace_filter resilient to null rounds (#12702)
1 parent c0ec481 commit 8003997

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# UNRELEASED
44

5+
## Bug Fixes
6+
7+
- Make `EthTraceFilter` / `trace_filter` skip null rounds instead of erroring. ([filecoin-project/lotus#12702](https://github.com/filecoin-project/lotus/pull/12702))
8+
59
# UNRELEASED v1.31.0
610

711
See https://github.com/filecoin-project/lotus/blob/release/v1.31.0/CHANGELOG.md

itests/eth_transactions_test.go

+27-3
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ func TestTraceFilter(t *testing.T) {
761761
blockTime := 100 * time.Millisecond
762762
client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC())
763763

764-
ens.InterconnectAll().BeginMining(blockTime)
764+
bms := ens.InterconnectAll().BeginMining(blockTime)
765765

766766
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
767767
defer cancel()
@@ -844,7 +844,7 @@ func TestTraceFilter(t *testing.T) {
844844
require.NotNil(t, tracesAddressFilter)
845845
require.NotEmpty(t, tracesAddressFilter)
846846

847-
//we should only get our contract deploy transaction
847+
// we should only get our contract deploy transaction
848848
require.Len(t, tracesAddressFilter, 1)
849849
require.Equal(t, 1, tracesAddressFilter[0].TransactionPosition)
850850
require.Equal(t, hash, tracesAddressFilter[0].TransactionHash)
@@ -864,8 +864,32 @@ func TestTraceFilter(t *testing.T) {
864864
require.NotNil(t, traces)
865865
require.NotEmpty(t, traces)
866866

867-
//we should only get the last two results from the first trace query
867+
// we should only get the last two results from the first trace query
868868
require.Len(t, tracesAfterCount, 2)
869869
require.Equal(t, traces[1].TransactionHash, tracesAfterCount[0].TransactionHash)
870870
require.Equal(t, traces[2].TransactionHash, tracesAfterCount[1].TransactionHash)
871+
872+
// make sure we have null rounds in the chain
873+
bms[0].InjectNulls(2)
874+
ch, err := client.ChainNotify(ctx)
875+
require.NoError(t, err)
876+
hc := <-ch // current
877+
require.Equal(t, store.HCCurrent, hc[0].Type)
878+
beforeNullHeight := hc[0].Val.Height()
879+
hc = <-ch // wait for next block
880+
require.Equal(t, store.HCApply, hc[0].Type)
881+
afterNullHeight := hc[0].Val.Height()
882+
require.Greater(t, afterNullHeight, beforeNullHeight+1)
883+
hc = <-ch // one more, so "latest" points to the block after nulls
884+
require.Equal(t, store.HCApply, hc[0].Type)
885+
886+
// define filter criteria that spans a null round so it has to at lest consider it
887+
toBlock = "latest"
888+
filter = ethtypes.EthTraceFilterCriteria{
889+
FromBlock: &fromBlock,
890+
ToBlock: &toBlock,
891+
}
892+
traces, err = client.EthTraceFilter(ctx, filter)
893+
require.NoError(t, err)
894+
require.Len(t, traces, 3) // still the same traces as before
871895
}

node/impl/full/eth.go

+3
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,9 @@ func (a *EthModule) EthTraceFilter(ctx context.Context, filter ethtypes.EthTrace
13641364
for blkNum := fromBlock; blkNum <= toBlock; blkNum++ {
13651365
blockTraces, err := a.EthTraceBlock(ctx, strconv.FormatUint(uint64(blkNum), 10))
13661366
if err != nil {
1367+
if errors.Is(err, &api.ErrNullRound{}) {
1368+
continue
1369+
}
13671370
return nil, xerrors.Errorf("cannot get trace for block %d: %w", blkNum, err)
13681371
}
13691372

0 commit comments

Comments
 (0)