Skip to content

Commit 0c99868

Browse files
authored
cmd/devp2p, eth/protocols/eth: fix tests + make sanity checks earlier (#22749)
1 parent d9c9ee5 commit 0c99868

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎cmd/devp2p/internal/ethtest/eth66_suite.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ func (s *Suite) TestNewPooledTxs_66(t *utesting.T) {
483483
t.Fatalf("unexpected number of txs requested: wanted %d, got %d", len(hashes), len(msg))
484484
}
485485
return
486-
case *NewPooledTransactionHashes:
487-
// ignore propagated txs from old tests
486+
case *NewPooledTransactionHashes, *NewBlock, *NewBlockHashes:
487+
// ignore propagated txs and blocks from old tests
488488
continue
489489
default:
490490
t.Fatalf("unexpected %s", pretty.Sdump(msg))

‎cmd/devp2p/internal/ethtest/large.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func largeHeader() *types.Header {
7070
GasUsed: 0,
7171
Coinbase: common.Address{},
7272
GasLimit: 0,
73-
UncleHash: randHash(),
73+
UncleHash: types.EmptyUncleHash,
7474
Time: 1337,
7575
ParentHash: randHash(),
7676
Root: randHash(),

‎cmd/devp2p/internal/ethtest/suite_test.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ethtest
1919
import (
2020
"os"
2121
"testing"
22+
"time"
2223

2324
"github.com/ethereum/go-ethereum/eth"
2425
"github.com/ethereum/go-ethereum/eth/ethconfig"
@@ -87,8 +88,15 @@ func setupGeth(stack *node.Node) error {
8788
}
8889

8990
backend, err := eth.New(stack, &ethconfig.Config{
90-
Genesis: &chain.genesis,
91-
NetworkId: chain.genesis.Config.ChainID.Uint64(), // 19763
91+
Genesis: &chain.genesis,
92+
NetworkId: chain.genesis.Config.ChainID.Uint64(), // 19763
93+
DatabaseCache: 10,
94+
TrieCleanCache: 10,
95+
TrieCleanCacheJournal: "",
96+
TrieCleanCacheRejournal: 60 * time.Minute,
97+
TrieDirtyCache: 16,
98+
TrieTimeout: 60 * time.Minute,
99+
SnapshotCache: 10,
92100
})
93101
if err != nil {
94102
return err

‎eth/protocols/eth/handlers.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ func handleNewBlock(backend Backend, msg Decoder, peer *Peer) error {
292292
if err := msg.Decode(ann); err != nil {
293293
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
294294
}
295+
if err := ann.sanityCheck(); err != nil {
296+
return err
297+
}
295298
if hash := types.CalcUncleHash(ann.Block.Uncles()); hash != ann.Block.UncleHash() {
296299
log.Warn("Propagated block has invalid uncles", "have", hash, "exp", ann.Block.UncleHash())
297300
return nil // TODO(karalabe): return error eventually, but wait a few releases
@@ -300,9 +303,6 @@ func handleNewBlock(backend Backend, msg Decoder, peer *Peer) error {
300303
log.Warn("Propagated block has invalid body", "have", hash, "exp", ann.Block.TxHash())
301304
return nil // TODO(karalabe): return error eventually, but wait a few releases
302305
}
303-
if err := ann.sanityCheck(); err != nil {
304-
return err
305-
}
306306
ann.Block.ReceivedAt = msg.Time()
307307
ann.Block.ReceivedFrom = peer
308308

0 commit comments

Comments
 (0)