mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
fix: Update transaction validation logic in ethclient (#1435)
- Declare zeroAddress as a constant - If there is only one transaction in the block and the header's txHash is `EmptyTxsHash`, it indicates a state-sync transaction. No error handling is required in this case.
This commit is contained in:
parent
d1219ff6d4
commit
51af82cca1
2 changed files with 11 additions and 1 deletions
|
|
@ -8,6 +8,10 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
zeroAddress = "0x0000000000000000000000000000000000000000"
|
||||||
|
)
|
||||||
|
|
||||||
// GetRootHash returns the merkle root of the block headers
|
// GetRootHash returns the merkle root of the block headers
|
||||||
func (ec *Client) GetRootHash(ctx context.Context, startBlockNumber uint64, endBlockNumber uint64) (string, error) {
|
func (ec *Client) GetRootHash(ctx context.Context, startBlockNumber uint64, endBlockNumber uint64) (string, error) {
|
||||||
var rootHash string
|
var rootHash string
|
||||||
|
|
|
||||||
|
|
@ -163,8 +163,14 @@ func (ec *Client) getBlock(ctx context.Context, method string, args ...interface
|
||||||
return nil, errors.New("server returned empty uncle list but block header indicates uncles")
|
return nil, errors.New("server returned empty uncle list but block header indicates uncles")
|
||||||
}
|
}
|
||||||
if head.TxHash == types.EmptyTxsHash && len(body.Transactions) > 0 {
|
if head.TxHash == types.EmptyTxsHash && len(body.Transactions) > 0 {
|
||||||
|
// If there is only one transaction in the block and the header's txHash is `EmptyTxsHash`,
|
||||||
|
// it indicates a state-sync transaction. No error handling is required in this case.
|
||||||
|
tx := body.Transactions[0]
|
||||||
|
if (tx.From != nil && *tx.From != common.HexToAddress(zeroAddress)) ||
|
||||||
|
(tx.tx.To() != nil && *tx.tx.To() != common.HexToAddress(zeroAddress)) {
|
||||||
return nil, errors.New("server returned non-empty transaction list but block header indicates no transactions")
|
return nil, errors.New("server returned non-empty transaction list but block header indicates no transactions")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if head.TxHash != types.EmptyTxsHash && len(body.Transactions) == 0 {
|
if head.TxHash != types.EmptyTxsHash && len(body.Transactions) == 0 {
|
||||||
return nil, errors.New("server returned empty transaction list but block header indicates transactions")
|
return nil, errors.New("server returned empty transaction list but block header indicates transactions")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue