good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 95f720ff authored by Felix Lange's avatar Felix Lange Committed by GitHub
Browse files

cmd/devp2p/internal/ethtest: update test chain (#21742)

The old one was wrong in two ways: the first block in chain.rlp was the
genesis block, and the genesis difficulty was below minimum difficulty.

This also contains some other fixes to the test.
parent 6487c002
Branches
Tags
No related merge requests found
...@@ -124,13 +124,22 @@ func (c *Chain) GetHeaders(req GetBlockHeaders) (BlockHeaders, error) { ...@@ -124,13 +124,22 @@ func (c *Chain) GetHeaders(req GetBlockHeaders) (BlockHeaders, error) {
// loadChain takes the given chain.rlp file, and decodes and returns // loadChain takes the given chain.rlp file, and decodes and returns
// the blocks from the file. // the blocks from the file.
func loadChain(chainfile string, genesis string) (*Chain, error) { func loadChain(chainfile string, genesis string) (*Chain, error) {
// Open the file handle and potentially unwrap the gzip stream chainConfig, err := ioutil.ReadFile(genesis)
if err != nil {
return nil, err
}
var gen core.Genesis
if err := json.Unmarshal(chainConfig, &gen); err != nil {
return nil, err
}
gblock := gen.ToBlock(nil)
// Load chain.rlp.
fh, err := os.Open(chainfile) fh, err := os.Open(chainfile)
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer fh.Close() defer fh.Close()
var reader io.Reader = fh var reader io.Reader = fh
if strings.HasSuffix(chainfile, ".gz") { if strings.HasSuffix(chainfile, ".gz") {
if reader, err = gzip.NewReader(reader); err != nil { if reader, err = gzip.NewReader(reader); err != nil {
...@@ -138,29 +147,21 @@ func loadChain(chainfile string, genesis string) (*Chain, error) { ...@@ -138,29 +147,21 @@ func loadChain(chainfile string, genesis string) (*Chain, error) {
} }
} }
stream := rlp.NewStream(reader, 0) stream := rlp.NewStream(reader, 0)
var blocks []*types.Block var blocks = make([]*types.Block, 1)
blocks[0] = gblock
for i := 0; ; i++ { for i := 0; ; i++ {
var b types.Block var b types.Block
if err := stream.Decode(&b); err == io.EOF { if err := stream.Decode(&b); err == io.EOF {
break break
} else if err != nil { } else if err != nil {
return nil, fmt.Errorf("at block %d: %v", i, err) return nil, fmt.Errorf("at block index %d: %v", i, err)
}
blocks = append(blocks, &b)
} }
if b.NumberU64() != uint64(i+1) {
// Open the file handle and potentially unwrap the gzip stream return nil, fmt.Errorf("block at index %d has wrong number %d", i, b.NumberU64())
chainConfig, err := ioutil.ReadFile(genesis)
if err != nil {
return nil, err
} }
var gen core.Genesis blocks = append(blocks, &b)
if err := json.Unmarshal(chainConfig, &gen); err != nil {
return nil, err
} }
return &Chain{ c := &Chain{blocks: blocks, chainConfig: gen.Config}
blocks: blocks, return c, nil
chainConfig: gen.Config,
}, nil
} }
No preview for this file type
{ {
"config": { "config": {
"chainId": 1, "chainId": 19763,
"homesteadBlock": 0, "homesteadBlock": 0,
"eip150Block": 0, "eip150Block": 0,
"eip155Block": 0, "eip155Block": 0,
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
"nonce": "0xdeadbeefdeadbeef", "nonce": "0xdeadbeefdeadbeef",
"timestamp": "0x0", "timestamp": "0x0",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x8000000", "gasLimit": "0x80000000",
"difficulty": "0x10", "difficulty": "0x20000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000", "coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { "alloc": {
"71562b71999873db5b286df957af199ec94617f7": { "71562b71999873db5b286df957af199ec94617f7": {
"balance": "0xf4240" "balance": "0xffffffff"
} }
}, },
"number": "0x0", "number": "0x0",
......
...@@ -242,12 +242,14 @@ func (c *Conn) Write(msg Message) error { ...@@ -242,12 +242,14 @@ func (c *Conn) Write(msg Message) error {
} }
_, err = c.Conn.Write(uint64(msg.Code()), payload) _, err = c.Conn.Write(uint64(msg.Code()), payload)
return err return err
} }
// handshake checks to make sure a `HELLO` is received. // handshake checks to make sure a `HELLO` is received.
func (c *Conn) handshake(t *utesting.T) Message { func (c *Conn) handshake(t *utesting.T) Message {
// write protoHandshake to client defer c.SetDeadline(time.Time{})
c.SetDeadline(time.Now().Add(10 * time.Second))
// write hello to client
pub0 := crypto.FromECDSAPub(&c.ourKey.PublicKey)[1:] pub0 := crypto.FromECDSAPub(&c.ourKey.PublicKey)[1:]
ourHandshake := &Hello{ ourHandshake := &Hello{
Version: 5, Version: 5,
...@@ -260,14 +262,13 @@ func (c *Conn) handshake(t *utesting.T) Message { ...@@ -260,14 +262,13 @@ func (c *Conn) handshake(t *utesting.T) Message {
if err := c.Write(ourHandshake); err != nil { if err := c.Write(ourHandshake); err != nil {
t.Fatalf("could not write to connection: %v", err) t.Fatalf("could not write to connection: %v", err)
} }
// read protoHandshake from client // read hello from client
switch msg := c.Read().(type) { switch msg := c.Read().(type) {
case *Hello: case *Hello:
// set snappy if version is at least 5 // set snappy if version is at least 5
if msg.Version >= 5 { if msg.Version >= 5 {
c.SetSnappy(true) c.SetSnappy(true)
} }
c.negotiateEthProtocol(msg.Caps) c.negotiateEthProtocol(msg.Caps)
if c.ethProtocolVersion == 0 { if c.ethProtocolVersion == 0 {
t.Fatalf("unexpected eth protocol version") t.Fatalf("unexpected eth protocol version")
...@@ -297,9 +298,11 @@ func (c *Conn) negotiateEthProtocol(caps []p2p.Cap) { ...@@ -297,9 +298,11 @@ func (c *Conn) negotiateEthProtocol(caps []p2p.Cap) {
// statusExchange performs a `Status` message exchange with the given // statusExchange performs a `Status` message exchange with the given
// node. // node.
func (c *Conn) statusExchange(t *utesting.T, chain *Chain) Message { func (c *Conn) statusExchange(t *utesting.T, chain *Chain) Message {
defer c.SetDeadline(time.Time{})
c.SetDeadline(time.Now().Add(20 * time.Second))
// read status message from client // read status message from client
var message Message var message Message
loop: loop:
for { for {
switch msg := c.Read().(type) { switch msg := c.Read().(type) {
...@@ -331,7 +334,7 @@ loop: ...@@ -331,7 +334,7 @@ loop:
// write status message to client // write status message to client
status := Status{ status := Status{
ProtocolVersion: uint32(c.ethProtocolVersion), ProtocolVersion: uint32(c.ethProtocolVersion),
NetworkID: 1, NetworkID: chain.chainConfig.ChainID.Uint64(),
TD: chain.TD(chain.Len()), TD: chain.TD(chain.Len()),
Head: chain.blocks[chain.Len()-1].Hash(), Head: chain.blocks[chain.Len()-1].Hash(),
Genesis: chain.blocks[0].Hash(), Genesis: chain.blocks[0].Hash(),
...@@ -347,12 +350,15 @@ loop: ...@@ -347,12 +350,15 @@ loop:
// waitForBlock waits for confirmation from the client that it has // waitForBlock waits for confirmation from the client that it has
// imported the given block. // imported the given block.
func (c *Conn) waitForBlock(block *types.Block) error { func (c *Conn) waitForBlock(block *types.Block) error {
defer c.SetReadDeadline(time.Time{})
timeout := time.Now().Add(20 * time.Second)
c.SetReadDeadline(timeout)
for { for {
req := &GetBlockHeaders{Origin: hashOrNumber{Hash: block.Hash()}, Amount: 1} req := &GetBlockHeaders{Origin: hashOrNumber{Hash: block.Hash()}, Amount: 1}
if err := c.Write(req); err != nil { if err := c.Write(req); err != nil {
return err return err
} }
switch msg := c.Read().(type) { switch msg := c.Read().(type) {
case *BlockHeaders: case *BlockHeaders:
if len(*msg) > 0 { if len(*msg) > 0 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment