Skip to content

Commit 05aec15

Browse files
debug_traceBlockByHash: reject non-canonical hash (#9616)
for #8721
1 parent 3de29a0 commit 05aec15

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

turbo/jsonrpc/tracing.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,19 @@ func (api *PrivateDebugAPIImpl) traceBlock(ctx context.Context, blockNrOrHash rp
4343
return err
4444
}
4545
defer tx.Rollback()
46-
var (
47-
block *types.Block
48-
number rpc.BlockNumber
49-
numberOk bool
50-
hash common.Hash
51-
hashOk bool
52-
)
53-
if number, numberOk = blockNrOrHash.Number(); numberOk {
54-
block, err = api.blockByRPCNumber(number, tx)
55-
} else if hash, hashOk = blockNrOrHash.Hash(); hashOk {
56-
block, err = api.blockByHashWithSenders(tx, hash)
57-
} else {
58-
return fmt.Errorf("invalid arguments; neither block nor hash specified")
59-
}
6046

47+
blockNumber, hash, _, err := rpchelper.GetCanonicalBlockNumber(blockNrOrHash, tx, api.filters)
48+
if err != nil {
49+
stream.WriteNil()
50+
return err
51+
}
52+
block, err := api.blockWithSenders(tx, hash, blockNumber)
6153
if err != nil {
6254
stream.WriteNil()
6355
return err
6456
}
65-
6657
if block == nil {
67-
if numberOk {
68-
return fmt.Errorf("invalid arguments; block with number %d not found", number)
69-
}
58+
stream.WriteNil()
7059
return fmt.Errorf("invalid arguments; block with hash %x not found", hash)
7160
}
7261

0 commit comments

Comments
 (0)