mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-16 13:06:40 +00:00
cmd/evm/internal/t8ntool, core/rawdb: fix RLP iterator error handling (#33820)
This fixes two cases where `Iterator.Err()` was misused. The method will only return an error after `Next()` has returned false, so it makes no sense to check for the error within the loop itself.
This commit is contained in:
parent
341907cdb8
commit
3011d83e6f
2 changed files with 7 additions and 6 deletions
|
|
@ -115,9 +115,6 @@ func Transaction(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
var results []result
|
var results []result
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
if err := it.Err(); err != nil {
|
|
||||||
return NewError(ErrorIO, err)
|
|
||||||
}
|
|
||||||
var tx types.Transaction
|
var tx types.Transaction
|
||||||
err := rlp.DecodeBytes(it.Value(), &tx)
|
err := rlp.DecodeBytes(it.Value(), &tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -188,6 +185,10 @@ func Transaction(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
results = append(results, r)
|
results = append(results, r)
|
||||||
}
|
}
|
||||||
|
if err := it.Err(); err != nil {
|
||||||
|
return NewError(ErrorIO, err)
|
||||||
|
}
|
||||||
|
|
||||||
out, err := json.MarshalIndent(results, "", " ")
|
out, err := json.MarshalIndent(results, "", " ")
|
||||||
fmt.Println(string(out))
|
fmt.Println(string(out))
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -147,9 +147,6 @@ func findTxInBlockBody(blockbody rlp.RawValue, target common.Hash) (*types.Trans
|
||||||
}
|
}
|
||||||
txIndex := uint64(0)
|
txIndex := uint64(0)
|
||||||
for iter.Next() {
|
for iter.Next() {
|
||||||
if iter.Err() != nil {
|
|
||||||
return nil, 0, iter.Err()
|
|
||||||
}
|
|
||||||
// The preimage for the hash calculation of legacy transactions
|
// The preimage for the hash calculation of legacy transactions
|
||||||
// is just their RLP encoding. For typed (EIP-2718) transactions,
|
// is just their RLP encoding. For typed (EIP-2718) transactions,
|
||||||
// which are encoded as byte arrays, the preimage is the content of
|
// which are encoded as byte arrays, the preimage is the content of
|
||||||
|
|
@ -171,6 +168,9 @@ func findTxInBlockBody(blockbody rlp.RawValue, target common.Hash) (*types.Trans
|
||||||
}
|
}
|
||||||
txIndex++
|
txIndex++
|
||||||
}
|
}
|
||||||
|
if iter.Err() != nil {
|
||||||
|
return nil, 0, iter.Err()
|
||||||
|
}
|
||||||
return nil, 0, errors.New("transaction not found")
|
return nil, 0, errors.New("transaction not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue