cmd/devp2p, eth/protocols/eth: fix tests + make sanity checks earlier (#22749)
This commit is contained in:
parent
d9c9ee5ac9
commit
0c99868416
@ -483,8 +483,8 @@ func (s *Suite) TestNewPooledTxs_66(t *utesting.T) {
|
|||||||
t.Fatalf("unexpected number of txs requested: wanted %d, got %d", len(hashes), len(msg))
|
t.Fatalf("unexpected number of txs requested: wanted %d, got %d", len(hashes), len(msg))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
case *NewPooledTransactionHashes:
|
case *NewPooledTransactionHashes, *NewBlock, *NewBlockHashes:
|
||||||
// ignore propagated txs from old tests
|
// ignore propagated txs and blocks from old tests
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unexpected %s", pretty.Sdump(msg))
|
t.Fatalf("unexpected %s", pretty.Sdump(msg))
|
||||||
|
@ -70,7 +70,7 @@ func largeHeader() *types.Header {
|
|||||||
GasUsed: 0,
|
GasUsed: 0,
|
||||||
Coinbase: common.Address{},
|
Coinbase: common.Address{},
|
||||||
GasLimit: 0,
|
GasLimit: 0,
|
||||||
UncleHash: randHash(),
|
UncleHash: types.EmptyUncleHash,
|
||||||
Time: 1337,
|
Time: 1337,
|
||||||
ParentHash: randHash(),
|
ParentHash: randHash(),
|
||||||
Root: randHash(),
|
Root: randHash(),
|
||||||
|
@ -19,6 +19,7 @@ package ethtest
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
"github.com/ethereum/go-ethereum/eth/ethconfig"
|
||||||
@ -87,8 +88,15 @@ func setupGeth(stack *node.Node) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
backend, err := eth.New(stack, ðconfig.Config{
|
backend, err := eth.New(stack, ðconfig.Config{
|
||||||
Genesis: &chain.genesis,
|
Genesis: &chain.genesis,
|
||||||
NetworkId: chain.genesis.Config.ChainID.Uint64(), // 19763
|
NetworkId: chain.genesis.Config.ChainID.Uint64(), // 19763
|
||||||
|
DatabaseCache: 10,
|
||||||
|
TrieCleanCache: 10,
|
||||||
|
TrieCleanCacheJournal: "",
|
||||||
|
TrieCleanCacheRejournal: 60 * time.Minute,
|
||||||
|
TrieDirtyCache: 16,
|
||||||
|
TrieTimeout: 60 * time.Minute,
|
||||||
|
SnapshotCache: 10,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -292,6 +292,9 @@ func handleNewBlock(backend Backend, msg Decoder, peer *Peer) error {
|
|||||||
if err := msg.Decode(ann); err != nil {
|
if err := msg.Decode(ann); err != nil {
|
||||||
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
|
return fmt.Errorf("%w: message %v: %v", errDecode, msg, err)
|
||||||
}
|
}
|
||||||
|
if err := ann.sanityCheck(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if hash := types.CalcUncleHash(ann.Block.Uncles()); hash != ann.Block.UncleHash() {
|
if hash := types.CalcUncleHash(ann.Block.Uncles()); hash != ann.Block.UncleHash() {
|
||||||
log.Warn("Propagated block has invalid uncles", "have", hash, "exp", ann.Block.UncleHash())
|
log.Warn("Propagated block has invalid uncles", "have", hash, "exp", ann.Block.UncleHash())
|
||||||
return nil // TODO(karalabe): return error eventually, but wait a few releases
|
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 {
|
|||||||
log.Warn("Propagated block has invalid body", "have", hash, "exp", ann.Block.TxHash())
|
log.Warn("Propagated block has invalid body", "have", hash, "exp", ann.Block.TxHash())
|
||||||
return nil // TODO(karalabe): return error eventually, but wait a few releases
|
return nil // TODO(karalabe): return error eventually, but wait a few releases
|
||||||
}
|
}
|
||||||
if err := ann.sanityCheck(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ann.Block.ReceivedAt = msg.Time()
|
ann.Block.ReceivedAt = msg.Time()
|
||||||
ann.Block.ReceivedFrom = peer
|
ann.Block.ReceivedFrom = peer
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user