aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/block_processor.go4
-rw-r--r--core/chain_manager.go4
-rw-r--r--core/transaction_pool.go6
-rw-r--r--core/types/transaction.go31
-rw-r--r--crypto/crypto.go16
-rw-r--r--crypto/sha3/keccakf.go563
-rw-r--r--crypto/sha3/sha3.go19
-rw-r--r--eth/backend.go2
-rw-r--r--eth/downloader/downloader.go14
-rw-r--r--eth/downloader/downloader_test.go22
-rw-r--r--eth/downloader/peer.go50
-rw-r--r--eth/downloader/queue.go10
-rw-r--r--eth/downloader/queue_test.go31
-rw-r--r--tests/block_test.go1
-rw-r--r--tests/files/BlockTests/bcBruncleTest.json265
15 files changed, 783 insertions, 255 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index ca205ee86..a3ad383d0 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -364,8 +364,8 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
return UncleError("uncle[%d](%x) is ancestor", i, hash[:4])
}
- if !ancestors.Has(uncle.ParentHash) {
- return UncleError("uncle[%d](%x)'s parent unknown (%x)", i, hash[:4], uncle.ParentHash[0:4])
+ if !ancestors.Has(uncle.ParentHash) || uncle.ParentHash == parent.Hash() {
+ return UncleError("uncle[%d](%x)'s parent is not ancestor (%x)", i, hash[:4], uncle.ParentHash[0:4])
}
if err := sm.ValidateHeader(uncle, ancestorHeaders[uncle.ParentHash], true); err != nil {
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 3e8ef6fd8..088ca8d5b 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -522,9 +522,9 @@ type queueEvent struct {
}
func (self *ChainManager) procFutureBlocks() {
- blocks := make([]*types.Block, len(self.futureBlocks.blocks))
+ blocks := []*types.Block{}
self.futureBlocks.Each(func(i int, block *types.Block) {
- blocks[i] = block
+ blocks = append(blocks, block)
})
types.BlockBy(types.Number).Sort(blocks)
diff --git a/core/transaction_pool.go b/core/transaction_pool.go
index c896488d1..ee6360614 100644
--- a/core/transaction_pool.go
+++ b/core/transaction_pool.go
@@ -112,12 +112,6 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
return ErrInvalidSender
}
- // Validate curve param
- v, _, _ := tx.Curve()
- if v > 28 || v < 27 {
- return fmt.Errorf("tx.v != (28 || 27) => %v", v)
- }
-
if !pool.currentState().HasAccount(from) {
return ErrNonExistentAccount
}
diff --git a/core/types/transaction.go b/core/types/transaction.go
index d8dcd7424..3d6d31ae7 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -8,7 +8,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp"
@@ -93,9 +92,9 @@ func (self *Transaction) SetNonce(AccountNonce uint64) {
}
func (self *Transaction) From() (common.Address, error) {
- pubkey := self.PublicKey()
- if len(pubkey) == 0 || pubkey[0] != 4 {
- return common.Address{}, errors.New("invalid public key")
+ pubkey, err := self.PublicKey()
+ if err != nil {
+ return common.Address{}, err
}
var addr common.Address
@@ -110,34 +109,34 @@ func (tx *Transaction) To() *common.Address {
return tx.Recipient
}
-func (tx *Transaction) Curve() (v byte, r []byte, s []byte) {
+func (tx *Transaction) GetSignatureValues() (v byte, r []byte, s []byte) {
v = byte(tx.V)
r = common.LeftPadBytes(tx.R.Bytes(), 32)
s = common.LeftPadBytes(tx.S.Bytes(), 32)
return
}
-func (tx *Transaction) Signature(key []byte) []byte {
- hash := tx.Hash()
- sig, _ := secp256k1.Sign(hash[:], key)
- return sig
-}
+func (tx *Transaction) PublicKey() ([]byte, error) {
+ if !crypto.ValidateSignatureValues(tx.V, tx.R, tx.S) {
+ return nil, errors.New("invalid v, r, s values")
+ }
-func (tx *Transaction) PublicKey() []byte {
hash := tx.Hash()
- v, r, s := tx.Curve()
+ v, r, s := tx.GetSignatureValues()
sig := append(r, s...)
sig = append(sig, v-27)
- //pubkey := crypto.Ecrecover(append(hash[:], sig...))
- //pubkey, _ := secp256k1.RecoverPubkey(hash[:], sig)
p, err := crypto.SigToPub(hash[:], sig)
if err != nil {
glog.V(logger.Error).Infof("Could not get pubkey from signature: ", err)
- return nil
+ return nil, err
}
+
pubkey := crypto.FromECDSAPub(p)
- return pubkey
+ if len(pubkey) == 0 || pubkey[0] != 4 {
+ return nil, errors.New("invalid public key")
+ }
+ return pubkey, nil
}
func (tx *Transaction) SetSignatureValues(sig []byte) error {
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 4bbd62f7f..9aef44863 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -10,6 +10,7 @@ import (
"fmt"
"io"
"io/ioutil"
+ "math/big"
"os"
"encoding/hex"
@@ -26,9 +27,12 @@ import (
"golang.org/x/crypto/ripemd160"
)
+var secp256k1n *big.Int
+
func init() {
// specify the params for the s256 curve
ecies.AddParamsForCurve(S256(), ecies.ECIES_AES128_SHA256)
+ secp256k1n = common.String2Big("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141")
}
func Sha3(data ...[]byte) []byte {
@@ -151,6 +155,18 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
return ecdsa.GenerateKey(S256(), rand.Reader)
}
+func ValidateSignatureValues(v byte, r, s *big.Int) bool {
+ vint := uint32(v)
+ if r.Cmp(common.Big0) == 0 || s.Cmp(common.Big0) == 0 {
+ return false
+ }
+ if r.Cmp(secp256k1n) < 0 && s.Cmp(secp256k1n) < 0 && (vint == 27 || vint == 28) {
+ return true
+ } else {
+ return false
+ }
+}
+
func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
s, err := Ecrecover(hash, sig)
if err != nil {
diff --git a/crypto/sha3/keccakf.go b/crypto/sha3/keccakf.go
index 3baf13ba3..13e7058fa 100644
--- a/crypto/sha3/keccakf.go
+++ b/crypto/sha3/keccakf.go
@@ -1,171 +1,410 @@
-// Copyright 2013 The Go Authors. All rights reserved.
+// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package sha3
-// This file implements the core Keccak permutation function necessary for computing SHA3.
-// This is implemented in a separate file to allow for replacement by an optimized implementation.
-// Nothing in this package is exported.
-// For the detailed specification, refer to the Keccak web site (http://keccak.noekeon.org/).
-
// rc stores the round constants for use in the ι step.
-var rc = [...]uint64{
- 0x0000000000000001,
- 0x0000000000008082,
- 0x800000000000808A,
- 0x8000000080008000,
- 0x000000000000808B,
- 0x0000000080000001,
- 0x8000000080008081,
- 0x8000000000008009,
- 0x000000000000008A,
- 0x0000000000000088,
- 0x0000000080008009,
- 0x000000008000000A,
- 0x000000008000808B,
- 0x800000000000008B,
- 0x8000000000008089,
- 0x8000000000008003,
- 0x8000000000008002,
- 0x8000000000000080,
- 0x000000000000800A,
- 0x800000008000000A,
- 0x8000000080008081,
- 0x8000000000008080,
- 0x0000000080000001,
- 0x8000000080008008,
+var rc = [24]uint64{
+ 0x0000000000000001,
+ 0x0000000000008082,
+ 0x800000000000808A,
+ 0x8000000080008000,
+ 0x000000000000808B,
+ 0x0000000080000001,
+ 0x8000000080008081,
+ 0x8000000000008009,
+ 0x000000000000008A,
+ 0x0000000000000088,
+ 0x0000000080008009,
+ 0x000000008000000A,
+ 0x000000008000808B,
+ 0x800000000000008B,
+ 0x8000000000008089,
+ 0x8000000000008003,
+ 0x8000000000008002,
+ 0x8000000000000080,
+ 0x000000000000800A,
+ 0x800000008000000A,
+ 0x8000000080008081,
+ 0x8000000000008080,
+ 0x0000000080000001,
+ 0x8000000080008008,
}
-// ro_xx represent the rotation offsets for use in the χ step.
-// Defining them as const instead of in an array allows the compiler to insert constant shifts.
-const (
- ro_00 = 0
- ro_01 = 36
- ro_02 = 3
- ro_03 = 41
- ro_04 = 18
- ro_05 = 1
- ro_06 = 44
- ro_07 = 10
- ro_08 = 45
- ro_09 = 2
- ro_10 = 62
- ro_11 = 6
- ro_12 = 43
- ro_13 = 15
- ro_14 = 61
- ro_15 = 28
- ro_16 = 55
- ro_17 = 25
- ro_18 = 21
- ro_19 = 56
- ro_20 = 27
- ro_21 = 20
- ro_22 = 39
- ro_23 = 8
- ro_24 = 14
-)
-
-// keccakF computes the complete Keccak-f function consisting of 24 rounds with a different
-// constant (rc) in each round. This implementation fully unrolls the round function to avoid
-// inner loops, as well as pre-calculating shift offsets.
-func (d *digest) keccakF() {
- for _, roundConstant := range rc {
- // θ step
- d.c[0] = d.a[0] ^ d.a[5] ^ d.a[10] ^ d.a[15] ^ d.a[20]
- d.c[1] = d.a[1] ^ d.a[6] ^ d.a[11] ^ d.a[16] ^ d.a[21]
- d.c[2] = d.a[2] ^ d.a[7] ^ d.a[12] ^ d.a[17] ^ d.a[22]
- d.c[3] = d.a[3] ^ d.a[8] ^ d.a[13] ^ d.a[18] ^ d.a[23]
- d.c[4] = d.a[4] ^ d.a[9] ^ d.a[14] ^ d.a[19] ^ d.a[24]
-
- d.d[0] = d.c[4] ^ (d.c[1]<<1 ^ d.c[1]>>63)
- d.d[1] = d.c[0] ^ (d.c[2]<<1 ^ d.c[2]>>63)
- d.d[2] = d.c[1] ^ (d.c[3]<<1 ^ d.c[3]>>63)
- d.d[3] = d.c[2] ^ (d.c[4]<<1 ^ d.c[4]>>63)
- d.d[4] = d.c[3] ^ (d.c[0]<<1 ^ d.c[0]>>63)
-
- d.a[0] ^= d.d[0]
- d.a[1] ^= d.d[1]
- d.a[2] ^= d.d[2]
- d.a[3] ^= d.d[3]
- d.a[4] ^= d.d[4]
- d.a[5] ^= d.d[0]
- d.a[6] ^= d.d[1]
- d.a[7] ^= d.d[2]
- d.a[8] ^= d.d[3]
- d.a[9] ^= d.d[4]
- d.a[10] ^= d.d[0]
- d.a[11] ^= d.d[1]
- d.a[12] ^= d.d[2]
- d.a[13] ^= d.d[3]
- d.a[14] ^= d.d[4]
- d.a[15] ^= d.d[0]
- d.a[16] ^= d.d[1]
- d.a[17] ^= d.d[2]
- d.a[18] ^= d.d[3]
- d.a[19] ^= d.d[4]
- d.a[20] ^= d.d[0]
- d.a[21] ^= d.d[1]
- d.a[22] ^= d.d[2]
- d.a[23] ^= d.d[3]
- d.a[24] ^= d.d[4]
-
- // ρ and π steps
- d.b[0] = d.a[0]
- d.b[1] = d.a[6]<<ro_06 ^ d.a[6]>>(64-ro_06)
- d.b[2] = d.a[12]<<ro_12 ^ d.a[12]>>(64-ro_12)
- d.b[3] = d.a[18]<<ro_18 ^ d.a[18]>>(64-ro_18)
- d.b[4] = d.a[24]<<ro_24 ^ d.a[24]>>(64-ro_24)
- d.b[5] = d.a[3]<<ro_15 ^ d.a[3]>>(64-ro_15)
- d.b[6] = d.a[9]<<ro_21 ^ d.a[9]>>(64-ro_21)
- d.b[7] = d.a[10]<<ro_02 ^ d.a[10]>>(64-ro_02)
- d.b[8] = d.a[16]<<ro_08 ^ d.a[16]>>(64-ro_08)
- d.b[9] = d.a[22]<<ro_14 ^ d.a[22]>>(64-ro_14)
- d.b[10] = d.a[1]<<ro_05 ^ d.a[1]>>(64-ro_05)
- d.b[11] = d.a[7]<<ro_11 ^ d.a[7]>>(64-ro_11)
- d.b[12] = d.a[13]<<ro_17 ^ d.a[13]>>(64-ro_17)
- d.b[13] = d.a[19]<<ro_23 ^ d.a[19]>>(64-ro_23)
- d.b[14] = d.a[20]<<ro_04 ^ d.a[20]>>(64-ro_04)
- d.b[15] = d.a[4]<<ro_20 ^ d.a[4]>>(64-ro_20)
- d.b[16] = d.a[5]<<ro_01 ^ d.a[5]>>(64-ro_01)
- d.b[17] = d.a[11]<<ro_07 ^ d.a[11]>>(64-ro_07)
- d.b[18] = d.a[17]<<ro_13 ^ d.a[17]>>(64-ro_13)
- d.b[19] = d.a[23]<<ro_19 ^ d.a[23]>>(64-ro_19)
- d.b[20] = d.a[2]<<ro_10 ^ d.a[2]>>(64-ro_10)
- d.b[21] = d.a[8]<<ro_16 ^ d.a[8]>>(64-ro_16)
- d.b[22] = d.a[14]<<ro_22 ^ d.a[14]>>(64-ro_22)
- d.b[23] = d.a[15]<<ro_03 ^ d.a[15]>>(64-ro_03)
- d.b[24] = d.a[21]<<ro_09 ^ d.a[21]>>(64-ro_09)
-
- // χ step
- d.a[0] = d.b[0] ^ (^d.b[1] & d.b[2])
- d.a[1] = d.b[1] ^ (^d.b[2] & d.b[3])
- d.a[2] = d.b[2] ^ (^d.b[3] & d.b[4])
- d.a[3] = d.b[3] ^ (^d.b[4] & d.b[0])
- d.a[4] = d.b[4] ^ (^d.b[0] & d.b[1])
- d.a[5] = d.b[5] ^ (^d.b[6] & d.b[7])
- d.a[6] = d.b[6] ^ (^d.b[7] & d.b[8])
- d.a[7] = d.b[7] ^ (^d.b[8] & d.b[9])
- d.a[8] = d.b[8] ^ (^d.b[9] & d.b[5])
- d.a[9] = d.b[9] ^ (^d.b[5] & d.b[6])
- d.a[10] = d.b[10] ^ (^d.b[11] & d.b[12])
- d.a[11] = d.b[11] ^ (^d.b[12] & d.b[13])
- d.a[12] = d.b[12] ^ (^d.b[13] & d.b[14])
- d.a[13] = d.b[13] ^ (^d.b[14] & d.b[10])
- d.a[14] = d.b[14] ^ (^d.b[10] & d.b[11])
- d.a[15] = d.b[15] ^ (^d.b[16] & d.b[17])
- d.a[16] = d.b[16] ^ (^d.b[17] & d.b[18])
- d.a[17] = d.b[17] ^ (^d.b[18] & d.b[19])
- d.a[18] = d.b[18] ^ (^d.b[19] & d.b[15])
- d.a[19] = d.b[19] ^ (^d.b[15] & d.b[16])
- d.a[20] = d.b[20] ^ (^d.b[21] & d.b[22])
- d.a[21] = d.b[21] ^ (^d.b[22] & d.b[23])
- d.a[22] = d.b[22] ^ (^d.b[23] & d.b[24])
- d.a[23] = d.b[23] ^ (^d.b[24] & d.b[20])
- d.a[24] = d.b[24] ^ (^d.b[20] & d.b[21])
-
- // ι step
- d.a[0] ^= roundConstant
- }
+// keccakF1600 applies the Keccak permutation to a 1600b-wide
+// state represented as a slice of 25 uint64s.
+func keccakF1600(a *[25]uint64) {
+ // Implementation translated from Keccak-inplace.c
+ // in the keccak reference code.
+ var t, bc0, bc1, bc2, bc3, bc4, d0, d1, d2, d3, d4 uint64
+
+ for i := 0; i < 24; i += 4 {
+ // Combines the 5 steps in each round into 2 steps.
+ // Unrolls 4 rounds per loop and spreads some steps across rounds.
+
+ // Round 1
+ bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
+ bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
+ bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
+ bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
+ bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
+ d0 = bc4 ^ (bc1<<1 | bc1>>63)
+ d1 = bc0 ^ (bc2<<1 | bc2>>63)
+ d2 = bc1 ^ (bc3<<1 | bc3>>63)
+ d3 = bc2 ^ (bc4<<1 | bc4>>63)
+ d4 = bc3 ^ (bc0<<1 | bc0>>63)
+
+ bc0 = a[0] ^ d0
+ t = a[6] ^ d1
+ bc1 = t<<44 | t>>(64-44)
+ t = a[12] ^ d2
+ bc2 = t<<43 | t>>(64-43)
+ t = a[18] ^ d3
+ bc3 = t<<21 | t>>(64-21)
+ t = a[24] ^ d4
+ bc4 = t<<14 | t>>(64-14)
+ a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i]
+ a[6] = bc1 ^ (bc3 &^ bc2)
+ a[12] = bc2 ^ (bc4 &^ bc3)
+ a[18] = bc3 ^ (bc0 &^ bc4)
+ a[24] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[10] ^ d0
+ bc2 = t<<3 | t>>(64-3)
+ t = a[16] ^ d1
+ bc3 = t<<45 | t>>(64-45)
+ t = a[22] ^ d2
+ bc4 = t<<61 | t>>(64-61)
+ t = a[3] ^ d3
+ bc0 = t<<28 | t>>(64-28)
+ t = a[9] ^ d4
+ bc1 = t<<20 | t>>(64-20)
+ a[10] = bc0 ^ (bc2 &^ bc1)
+ a[16] = bc1 ^ (bc3 &^ bc2)
+ a[22] = bc2 ^ (bc4 &^ bc3)
+ a[3] = bc3 ^ (bc0 &^ bc4)
+ a[9] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[20] ^ d0
+ bc4 = t<<18 | t>>(64-18)
+ t = a[1] ^ d1
+ bc0 = t<<1 | t>>(64-1)
+ t = a[7] ^ d2
+ bc1 = t<<6 | t>>(64-6)
+ t = a[13] ^ d3
+ bc2 = t<<25 | t>>(64-25)
+ t = a[19] ^ d4
+ bc3 = t<<8 | t>>(64-8)
+ a[20] = bc0 ^ (bc2 &^ bc1)
+ a[1] = bc1 ^ (bc3 &^ bc2)
+ a[7] = bc2 ^ (bc4 &^ bc3)
+ a[13] = bc3 ^ (bc0 &^ bc4)
+ a[19] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[5] ^ d0
+ bc1 = t<<36 | t>>(64-36)
+ t = a[11] ^ d1
+ bc2 = t<<10 | t>>(64-10)
+ t = a[17] ^ d2
+ bc3 = t<<15 | t>>(64-15)
+ t = a[23] ^ d3
+ bc4 = t<<56 | t>>(64-56)
+ t = a[4] ^ d4
+ bc0 = t<<27 | t>>(64-27)
+ a[5] = bc0 ^ (bc2 &^ bc1)
+ a[11] = bc1 ^ (bc3 &^ bc2)
+ a[17] = bc2 ^ (bc4 &^ bc3)
+ a[23] = bc3 ^ (bc0 &^ bc4)
+ a[4] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[15] ^ d0
+ bc3 = t<<41 | t>>(64-41)
+ t = a[21] ^ d1
+ bc4 = t<<2 | t>>(64-2)
+ t = a[2] ^ d2
+ bc0 = t<<62 | t>>(64-62)
+ t = a[8] ^ d3
+ bc1 = t<<55 | t>>(64-55)
+ t = a[14] ^ d4
+ bc2 = t<<39 | t>>(64-39)
+ a[15] = bc0 ^ (bc2 &^ bc1)
+ a[21] = bc1 ^ (bc3 &^ bc2)
+ a[2] = bc2 ^ (bc4 &^ bc3)
+ a[8] = bc3 ^ (bc0 &^ bc4)
+ a[14] = bc4 ^ (bc1 &^ bc0)
+
+ // Round 2
+ bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
+ bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
+ bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
+ bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
+ bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
+ d0 = bc4 ^ (bc1<<1 | bc1>>63)
+ d1 = bc0 ^ (bc2<<1 | bc2>>63)
+ d2 = bc1 ^ (bc3<<1 | bc3>>63)
+ d3 = bc2 ^ (bc4<<1 | bc4>>63)
+ d4 = bc3 ^ (bc0<<1 | bc0>>63)
+
+ bc0 = a[0] ^ d0
+ t = a[16] ^ d1
+ bc1 = t<<44 | t>>(64-44)
+ t = a[7] ^ d2
+ bc2 = t<<43 | t>>(64-43)
+ t = a[23] ^ d3
+ bc3 = t<<21 | t>>(64-21)
+ t = a[14] ^ d4
+ bc4 = t<<14 | t>>(64-14)
+ a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+1]
+ a[16] = bc1 ^ (bc3 &^ bc2)
+ a[7] = bc2 ^ (bc4 &^ bc3)
+ a[23] = bc3 ^ (bc0 &^ bc4)
+ a[14] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[20] ^ d0
+ bc2 = t<<3 | t>>(64-3)
+ t = a[11] ^ d1
+ bc3 = t<<45 | t>>(64-45)
+ t = a[2] ^ d2
+ bc4 = t<<61 | t>>(64-61)
+ t = a[18] ^ d3
+ bc0 = t<<28 | t>>(64-28)
+ t = a[9] ^ d4
+ bc1 = t<<20 | t>>(64-20)
+ a[20] = bc0 ^ (bc2 &^ bc1)
+ a[11] = bc1 ^ (bc3 &^ bc2)
+ a[2] = bc2 ^ (bc4 &^ bc3)
+ a[18] = bc3 ^ (bc0 &^ bc4)
+ a[9] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[15] ^ d0
+ bc4 = t<<18 | t>>(64-18)
+ t = a[6] ^ d1
+ bc0 = t<<1 | t>>(64-1)
+ t = a[22] ^ d2
+ bc1 = t<<6 | t>>(64-6)
+ t = a[13] ^ d3
+ bc2 = t<<25 | t>>(64-25)
+ t = a[4] ^ d4
+ bc3 = t<<8 | t>>(64-8)
+ a[15] = bc0 ^ (bc2 &^ bc1)
+ a[6] = bc1 ^ (bc3 &^ bc2)
+ a[22] = bc2 ^ (bc4 &^ bc3)
+ a[13] = bc3 ^ (bc0 &^ bc4)
+ a[4] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[10] ^ d0
+ bc1 = t<<36 | t>>(64-36)
+ t = a[1] ^ d1
+ bc2 = t<<10 | t>>(64-10)
+ t = a[17] ^ d2
+ bc3 = t<<15 | t>>(64-15)
+ t = a[8] ^ d3
+ bc4 = t<<56 | t>>(64-56)
+ t = a[24] ^ d4
+ bc0 = t<<27 | t>>(64-27)
+ a[10] = bc0 ^ (bc2 &^ bc1)
+ a[1] = bc1 ^ (bc3 &^ bc2)
+ a[17] = bc2 ^ (bc4 &^ bc3)
+ a[8] = bc3 ^ (bc0 &^ bc4)
+ a[24] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[5] ^ d0
+ bc3 = t<<41 | t>>(64-41)
+ t = a[21] ^ d1
+ bc4 = t<<2 | t>>(64-2)
+ t = a[12] ^ d2
+ bc0 = t<<62 | t>>(64-62)
+ t = a[3] ^ d3
+ bc1 = t<<55 | t>>(64-55)
+ t = a[19] ^ d4
+ bc2 = t<<39 | t>>(64-39)
+ a[5] = bc0 ^ (bc2 &^ bc1)
+ a[21] = bc1 ^ (bc3 &^ bc2)
+ a[12] = bc2 ^ (bc4 &^ bc3)
+ a[3] = bc3 ^ (bc0 &^ bc4)
+ a[19] = bc4 ^ (bc1 &^ bc0)
+
+ // Round 3
+ bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
+ bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
+ bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
+ bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
+ bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
+ d0 = bc4 ^ (bc1<<1 | bc1>>63)
+ d1 = bc0 ^ (bc2<<1 | bc2>>63)
+ d2 = bc1 ^ (bc3<<1 | bc3>>63)
+ d3 = bc2 ^ (bc4<<1 | bc4>>63)
+ d4 = bc3 ^ (bc0<<1 | bc0>>63)
+
+ bc0 = a[0] ^ d0
+ t = a[11] ^ d1
+ bc1 = t<<44 | t>>(64-44)
+ t = a[22] ^ d2
+ bc2 = t<<43 | t>>(64-43)
+ t = a[8] ^ d3
+ bc3 = t<<21 | t>>(64-21)
+ t = a[19] ^ d4
+ bc4 = t<<14 | t>>(64-14)
+ a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+2]
+ a[11] = bc1 ^ (bc3 &^ bc2)
+ a[22] = bc2 ^ (bc4 &^ bc3)
+ a[8] = bc3 ^ (bc0 &^ bc4)
+ a[19] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[15] ^ d0
+ bc2 = t<<3 | t>>(64-3)
+ t = a[1] ^ d1
+ bc3 = t<<45 | t>>(64-45)
+ t = a[12] ^ d2
+ bc4 = t<<61 | t>>(64-61)
+ t = a[23] ^ d3
+ bc0 = t<<28 | t>>(64-28)
+ t = a[9] ^ d4
+ bc1 = t<<20 | t>>(64-20)
+ a[15] = bc0 ^ (bc2 &^ bc1)
+ a[1] = bc1 ^ (bc3 &^ bc2)
+ a[12] = bc2 ^ (bc4 &^ bc3)
+ a[23] = bc3 ^ (bc0 &^ bc4)
+ a[9] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[5] ^ d0
+ bc4 = t<<18 | t>>(64-18)
+ t = a[16] ^ d1
+ bc0 = t<<1 | t>>(64-1)
+ t = a[2] ^ d2
+ bc1 = t<<6 | t>>(64-6)
+ t = a[13] ^ d3
+ bc2 = t<<25 | t>>(64-25)
+ t = a[24] ^ d4
+ bc3 = t<<8 | t>>(64-8)
+ a[5] = bc0 ^ (bc2 &^ bc1)
+ a[16] = bc1 ^ (bc3 &^ bc2)
+ a[2] = bc2 ^ (bc4 &^ bc3)
+ a[13] = bc3 ^ (bc0 &^ bc4)
+ a[24] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[20] ^ d0
+ bc1 = t<<36 | t>>(64-36)
+ t = a[6] ^ d1
+ bc2 = t<<10 | t>>(64-10)
+ t = a[17] ^ d2
+ bc3 = t<<15 | t>>(64-15)
+ t = a[3] ^ d3
+ bc4 = t<<56 | t>>(64-56)
+ t = a[14] ^ d4
+ bc0 = t<<27 | t>>(64-27)
+ a[20] = bc0 ^ (bc2 &^ bc1)
+ a[6] = bc1 ^ (bc3 &^ bc2)
+ a[17] = bc2 ^ (bc4 &^ bc3)
+ a[3] = bc3 ^ (bc0 &^ bc4)
+ a[14] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[10] ^ d0
+ bc3 = t<<41 | t>>(64-41)
+ t = a[21] ^ d1
+ bc4 = t<<2 | t>>(64-2)
+ t = a[7] ^ d2
+ bc0 = t<<62 | t>>(64-62)
+ t = a[18] ^ d3
+ bc1 = t<<55 | t>>(64-55)
+ t = a[4] ^ d4
+ bc2 = t<<39 | t>>(64-39)
+ a[10] = bc0 ^ (bc2 &^ bc1)
+ a[21] = bc1 ^ (bc3 &^ bc2)
+ a[7] = bc2 ^ (bc4 &^ bc3)
+ a[18] = bc3 ^ (bc0 &^ bc4)
+ a[4] = bc4 ^ (bc1 &^ bc0)
+
+ // Round 4
+ bc0 = a[0] ^ a[5] ^ a[10] ^ a[15] ^ a[20]
+ bc1 = a[1] ^ a[6] ^ a[11] ^ a[16] ^ a[21]
+ bc2 = a[2] ^ a[7] ^ a[12] ^ a[17] ^ a[22]
+ bc3 = a[3] ^ a[8] ^ a[13] ^ a[18] ^ a[23]
+ bc4 = a[4] ^ a[9] ^ a[14] ^ a[19] ^ a[24]
+ d0 = bc4 ^ (bc1<<1 | bc1>>63)
+ d1 = bc0 ^ (bc2<<1 | bc2>>63)
+ d2 = bc1 ^ (bc3<<1 | bc3>>63)
+ d3 = bc2 ^ (bc4<<1 | bc4>>63)
+ d4 = bc3 ^ (bc0<<1 | bc0>>63)
+
+ bc0 = a[0] ^ d0
+ t = a[1] ^ d1
+ bc1 = t<<44 | t>>(64-44)
+ t = a[2] ^ d2
+ bc2 = t<<43 | t>>(64-43)
+ t = a[3] ^ d3
+ bc3 = t<<21 | t>>(64-21)
+ t = a[4] ^ d4
+ bc4 = t<<14 | t>>(64-14)
+ a[0] = bc0 ^ (bc2 &^ bc1) ^ rc[i+3]
+ a[1] = bc1 ^ (bc3 &^ bc2)
+ a[2] = bc2 ^ (bc4 &^ bc3)
+ a[3] = bc3 ^ (bc0 &^ bc4)
+ a[4] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[5] ^ d0
+ bc2 = t<<3 | t>>(64-3)
+ t = a[6] ^ d1
+ bc3 = t<<45 | t>>(64-45)
+ t = a[7] ^ d2
+ bc4 = t<<61 | t>>(64-61)
+ t = a[8] ^ d3
+ bc0 = t<<28 | t>>(64-28)
+ t = a[9] ^ d4
+ bc1 = t<<20 | t>>(64-20)
+ a[5] = bc0 ^ (bc2 &^ bc1)
+ a[6] = bc1 ^ (bc3 &^ bc2)
+ a[7] = bc2 ^ (bc4 &^ bc3)
+ a[8] = bc3 ^ (bc0 &^ bc4)
+ a[9] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[10] ^ d0
+ bc4 = t<<18 | t>>(64-18)
+ t = a[11] ^ d1
+ bc0 = t<<1 | t>>(64-1)
+ t = a[12] ^ d2
+ bc1 = t<<6 | t>>(64-6)
+ t = a[13] ^ d3
+ bc2 = t<<25 | t>>(64-25)
+ t = a[14] ^ d4
+ bc3 = t<<8 | t>>(64-8)
+ a[10] = bc0 ^ (bc2 &^ bc1)
+ a[11] = bc1 ^ (bc3 &^ bc2)
+ a[12] = bc2 ^ (bc4 &^ bc3)
+ a[13] = bc3 ^ (bc0 &^ bc4)
+ a[14] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[15] ^ d0
+ bc1 = t<<36 | t>>(64-36)
+ t = a[16] ^ d1
+ bc2 = t<<10 | t>>(64-10)
+ t = a[17] ^ d2
+ bc3 = t<<15 | t>>(64-15)
+ t = a[18] ^ d3
+ bc4 = t<<56 | t>>(64-56)
+ t = a[19] ^ d4
+ bc0 = t<<27 | t>>(64-27)
+ a[15] = bc0 ^ (bc2 &^ bc1)
+ a[16] = bc1 ^ (bc3 &^ bc2)
+ a[17] = bc2 ^ (bc4 &^ bc3)
+ a[18] = bc3 ^ (bc0 &^ bc4)
+ a[19] = bc4 ^ (bc1 &^ bc0)
+
+ t = a[20] ^ d0
+ bc3 = t<<41 | t>>(64-41)
+ t = a[21] ^ d1
+ bc4 = t<<2 | t>>(64-2)
+ t = a[22] ^ d2
+ bc0 = t<<62 | t>>(64-62)
+ t = a[23] ^ d3
+ bc1 = t<<55 | t>>(64-55)
+ t = a[24] ^ d4
+ bc2 = t<<39 | t>>(64-39)
+ a[20] = bc0 ^ (bc2 &^ bc1)
+ a[21] = bc1 ^ (bc3 &^ bc2)
+ a[22] = bc2 ^ (bc4 &^ bc3)
+ a[23] = bc3 ^ (bc0 &^ bc4)
+ a[24] = bc4 ^ (bc1 &^ bc0)
+ }
}
diff --git a/crypto/sha3/sha3.go b/crypto/sha3/sha3.go
index 22df0ef11..6b058ae4d 100644
--- a/crypto/sha3/sha3.go
+++ b/crypto/sha3/sha3.go
@@ -38,13 +38,10 @@ const stateSize = laneSize * numLanes
// O(2^{outputSize/2}) computations (the birthday lower bound). Future standards may modify the
// capacity/outputSize ratio to allow for more output with lower cryptographic security.
type digest struct {
- a [numLanes]uint64 // main state of the hash
- b [numLanes]uint64 // intermediate states
- c [sliceSize]uint64 // intermediate states
- d [sliceSize]uint64 // intermediate states
- outputSize int // desired output size in bytes
- capacity int // number of bytes to leave untouched during squeeze/absorb
- absorbed int // number of bytes absorbed thus far
+ a [numLanes]uint64 // main state of the hash
+ outputSize int // desired output size in bytes
+ capacity int // number of bytes to leave untouched during squeeze/absorb
+ absorbed int // number of bytes absorbed thus far
}
// minInt returns the lesser of two integer arguments, to simplify the absorption routine.
@@ -116,7 +113,7 @@ func (d *digest) Write(p []byte) (int, error) {
// For every rate() bytes absorbed, the state must be permuted via the F Function.
if (d.absorbed)%d.rate() == 0 {
- d.keccakF()
+ keccakF1600(&d.a)
}
}
@@ -134,7 +131,7 @@ func (d *digest) Write(p []byte) (int, error) {
d.absorbed += (lastLane - firstLane) * laneSize
// For every rate() bytes absorbed, the state must be permuted via the F Function.
if (d.absorbed)%d.rate() == 0 {
- d.keccakF()
+ keccakF1600(&d.a)
}
offset = 0
@@ -167,7 +164,7 @@ func (d *digest) pad() {
// finalize prepares the hash to output data by padding and one final permutation of the state.
func (d *digest) finalize() {
d.pad()
- d.keccakF()
+ keccakF1600(&d.a)
}
// squeeze outputs an arbitrary number of bytes from the hash state.
@@ -192,7 +189,7 @@ func (d *digest) squeeze(in []byte, toSqueeze int) []byte {
out = out[laneSize:]
}
if len(out) > 0 {
- d.keccakF()
+ keccakF1600(&d.a)
}
}
return in[:len(in)+toSqueeze] // Re-slice in case we wrote extra data.
diff --git a/eth/backend.go b/eth/backend.go
index 18e214d44..98939b1fa 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -45,7 +45,7 @@ var (
defaultBootNodes = []*discover.Node{
// ETH/DEV Go Bootnodes
discover.MustParseNode("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@52.16.188.185:30303"),
- discover.MustParseNode("enode://7f25d3eab333a6b98a8b5ed68d962bb22c876ffcd5561fca54e3c2ef27f754df6f7fd7c9b74cc919067abac154fb8e1f8385505954f161ae440abc355855e034@54.207.93.166:30303"),
+ discover.MustParseNode("enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303"),
// ETH/DEV cpp-ethereum (poc-9.ethdev.com)
discover.MustParseNode("enode://487611428e6c99a11a9795a6abe7b529e81315ca6aad66e2a2fc76e3adf263faba0d35466c2f8f68d561dbefa8878d4df5f1f2ddb1fbeab7f42ffb8cd328bd4a@5.1.83.226:30303"),
}
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 85531ce15..f52a97610 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -27,9 +27,10 @@ const (
)
var (
- blockTTL = 5 * time.Second // Time it takes for a block request to time out
- crossCheckCycle = time.Second // Period after which to check for expired cross checks
- minDesiredPeerCount = 5 // Amount of peers desired to start syncing
+ blockSoftTTL = 3 * time.Second // Request completion threshold for increasing or decreasing a peer's bandwidth
+ blockHardTTL = 3 * blockSoftTTL // Maximum time allowance before a block request is considered expired
+ crossCheckCycle = time.Second // Period after which to check for expired cross checks
+ minDesiredPeerCount = 5 // Amount of peers desired to start syncing
)
var (
@@ -324,7 +325,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
glog.V(logger.Detail).Infof("Cross checking (%s) with %x/%x", active.id, origin, parent)
d.checks[origin] = &crossCheck{
- expire: time.Now().Add(blockTTL),
+ expire: time.Now().Add(blockSoftTTL),
parent: parent,
}
active.getBlocks([]common.Hash{origin})
@@ -429,6 +430,7 @@ out:
// Peer did deliver, but some blocks were off, penalize
glog.V(logger.Debug).Infof("Failed delivery for peer %s: %v\n", blockPack.peerId, err)
peer.Demote()
+ peer.SetIdle()
break
}
if glog.V(logger.Debug) && len(blockPack.blocks) > 0 {
@@ -444,7 +446,7 @@ out:
// that badly or poorly behave are removed from the peer set (not banned).
// Bad peers are excluded from the available peer set and therefor won't be
// reused. XXX We could re-introduce peers after X time.
- badPeers := d.queue.Expire(blockTTL)
+ badPeers := d.queue.Expire(blockHardTTL)
for _, pid := range badPeers {
// XXX We could make use of a reputation system here ranking peers
// in their performance
@@ -475,7 +477,7 @@ out:
}
// Get a possible chunk. If nil is returned no chunk
// could be returned due to no hashes available.
- request := d.queue.Reserve(peer, MaxBlockFetch)
+ request := d.queue.Reserve(peer)
if request == nil {
continue
}
diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go
index 66be1ca18..ef94ddbab 100644
--- a/eth/downloader/downloader_test.go
+++ b/eth/downloader/downloader_test.go
@@ -191,7 +191,7 @@ func (dl *downloadTester) badBlocksPeer(id string, td *big.Int, hash common.Hash
func TestDownload(t *testing.T) {
minDesiredPeerCount = 4
- blockTTL = 1 * time.Second
+ blockHardTTL = 1 * time.Second
targetBlocks := 1000
hashes := createHashes(0, targetBlocks)
@@ -240,7 +240,7 @@ func TestMissing(t *testing.T) {
func TestTaking(t *testing.T) {
minDesiredPeerCount = 4
- blockTTL = 1 * time.Second
+ blockHardTTL = 1 * time.Second
targetBlocks := 1000
hashes := createHashes(0, targetBlocks)
@@ -281,7 +281,7 @@ func TestInactiveDownloader(t *testing.T) {
func TestCancel(t *testing.T) {
minDesiredPeerCount = 4
- blockTTL = 1 * time.Second
+ blockHardTTL = 1 * time.Second
targetBlocks := 1000
hashes := createHashes(0, targetBlocks)
@@ -307,7 +307,7 @@ func TestCancel(t *testing.T) {
func TestThrottling(t *testing.T) {
minDesiredPeerCount = 4
- blockTTL = 1 * time.Second
+ blockHardTTL = 1 * time.Second
targetBlocks := 16 * blockCacheLimit
hashes := createHashes(0, targetBlocks)
@@ -461,7 +461,7 @@ func TestInvalidHashOrderAttack(t *testing.T) {
// Tests that if a malicious peer makes up a random hash chain and tries to push
// indefinitely, it actually gets caught with it.
func TestMadeupHashChainAttack(t *testing.T) {
- blockTTL = 100 * time.Millisecond
+ blockSoftTTL = 100 * time.Millisecond
crossCheckCycle = 25 * time.Millisecond
// Create a long chain of hashes without backing blocks
@@ -495,10 +495,10 @@ func TestMadeupHashChainDrippingAttack(t *testing.T) {
// Tests that if a malicious peer makes up a random block chain, and tried to
// push indefinitely, it actually gets caught with it.
func TestMadeupBlockChainAttack(t *testing.T) {
- defaultBlockTTL := blockTTL
+ defaultBlockTTL := blockSoftTTL
defaultCrossCheckCycle := crossCheckCycle
- blockTTL = 100 * time.Millisecond
+ blockSoftTTL = 100 * time.Millisecond
crossCheckCycle = 25 * time.Millisecond
// Create a long chain of blocks and simulate an invalid chain by dropping every second
@@ -516,7 +516,7 @@ func TestMadeupBlockChainAttack(t *testing.T) {
t.Fatalf("synchronisation error mismatch: have %v, want %v", err, ErrCrossCheckFailed)
}
// Ensure that a valid chain can still pass sync
- blockTTL = defaultBlockTTL
+ blockSoftTTL = defaultBlockTTL
crossCheckCycle = defaultCrossCheckCycle
tester.hashes = hashes
@@ -530,10 +530,10 @@ func TestMadeupBlockChainAttack(t *testing.T) {
// attacker make up a valid hashes for random blocks, but also forges the block
// parents to point to existing hashes.
func TestMadeupParentBlockChainAttack(t *testing.T) {
- defaultBlockTTL := blockTTL
+ defaultBlockTTL := blockSoftTTL
defaultCrossCheckCycle := crossCheckCycle
- blockTTL = 100 * time.Millisecond
+ blockSoftTTL = 100 * time.Millisecond
crossCheckCycle = 25 * time.Millisecond
// Create a long chain of blocks and simulate an invalid chain by dropping every second
@@ -550,7 +550,7 @@ func TestMadeupParentBlockChainAttack(t *testing.T) {
t.Fatalf("synchronisation error mismatch: have %v, want %v", err, ErrCrossCheckFailed)
}
// Ensure that a valid chain can still pass sync
- blockTTL = defaultBlockTTL
+ blockSoftTTL = defaultBlockTTL
crossCheckCycle = defaultCrossCheckCycle
tester.blocks = blocks
diff --git a/eth/downloader/peer.go b/eth/downloader/peer.go
index 4abae8d5e..8ef017df7 100644
--- a/eth/downloader/peer.go
+++ b/eth/downloader/peer.go
@@ -5,10 +5,14 @@ package downloader
import (
"errors"
+ "math"
"sync"
"sync/atomic"
+ "time"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"gopkg.in/fatih/set.v0"
)
@@ -27,14 +31,15 @@ type peer struct {
head common.Hash // Hash of the peers latest known block
idle int32 // Current activity state of the peer (idle = 0, active = 1)
- rep int32 // Simple peer reputation (not used currently)
+ rep int32 // Simple peer reputation
- mu sync.RWMutex
+ capacity int32 // Number of blocks allowed to fetch per request
+ started time.Time // Time instance when the last fetch was started
- ignored *set.Set
+ ignored *set.Set // Set of hashes not to request (didn't have previously)
- getHashes hashFetcherFn
- getBlocks blockFetcherFn
+ getHashes hashFetcherFn // Method to retrieve a batch of hashes (mockable for testing)
+ getBlocks blockFetcherFn // Method to retrieve a batch of blocks (mockable for testing)
}
// newPeer create a new downloader peer, with specific hash and block retrieval
@@ -43,6 +48,7 @@ func newPeer(id string, head common.Hash, getHashes hashFetcherFn, getBlocks blo
return &peer{
id: id,
head: head,
+ capacity: 1,
getHashes: getHashes,
getBlocks: getBlocks,
ignored: set.New(),
@@ -52,6 +58,7 @@ func newPeer(id string, head common.Hash, getHashes hashFetcherFn, getBlocks blo
// Reset clears the internal state of a peer entity.
func (p *peer) Reset() {
atomic.StoreInt32(&p.idle, 0)
+ atomic.StoreInt32(&p.capacity, 1)
p.ignored.Clear()
}
@@ -61,6 +68,8 @@ func (p *peer) Fetch(request *fetchRequest) error {
if !atomic.CompareAndSwapInt32(&p.idle, 0, 1) {
return errAlreadyFetching
}
+ p.started = time.Now()
+
// Convert the hash set to a retrievable slice
hashes := make([]common.Hash, 0, len(request.Hashes))
for hash, _ := range request.Hashes {
@@ -72,10 +81,41 @@ func (p *peer) Fetch(request *fetchRequest) error {
}
// SetIdle sets the peer to idle, allowing it to execute new retrieval requests.
+// Its block retrieval allowance will also be updated either up- or downwards,
+// depending on whether the previous fetch completed in time or not.
func (p *peer) SetIdle() {
+ // Update the peer's download allowance based on previous performance
+ scale := 2.0
+ if time.Since(p.started) > blockSoftTTL {
+ scale = 0.5
+ }
+ for {
+ // Calculate the new download bandwidth allowance
+ prev := atomic.LoadInt32(&p.capacity)
+ next := int32(math.Max(1, math.Min(MaxBlockFetch, float64(prev)*scale)))
+
+ // Try to update the old value
+ if atomic.CompareAndSwapInt32(&p.capacity, prev, next) {
+ // If we're having problems at 1 capacity, try to find better peers
+ if next == 1 {
+ p.Demote()
+ }
+ if prev != next {
+ glog.V(logger.Detail).Infof("%s: changing block download capacity from %d to %d", p.id, prev, next)
+ }
+ break
+ }
+ }
+ // Set the peer to idle to allow further block requests
atomic.StoreInt32(&p.idle, 0)
}
+// Capacity retrieves the peers block download allowance based on its previously
+// discovered bandwidth capacity.
+func (p *peer) Capacity() int {
+ return int(atomic.LoadInt32(&p.capacity))
+}
+
// Promote increases the peer's reputation.
func (p *peer) Promote() {
atomic.AddInt32(&p.rep, 1)
diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go
index 7ea400dc4..69d91512a 100644
--- a/eth/downloader/queue.go
+++ b/eth/downloader/queue.go
@@ -203,7 +203,7 @@ func (q *queue) TakeBlocks() []*Block {
// Reserve reserves a set of hashes for the given peer, skipping any previously
// failed download.
-func (q *queue) Reserve(p *peer, max int) *fetchRequest {
+func (q *queue) Reserve(p *peer) *fetchRequest {
q.lock.Lock()
defer q.lock.Unlock()
@@ -215,11 +215,17 @@ func (q *queue) Reserve(p *peer, max int) *fetchRequest {
if _, ok := q.pendPool[p.id]; ok {
return nil
}
+ // Calculate an upper limit on the hashes we might fetch (i.e. throttling)
+ space := len(q.blockCache) - len(q.blockPool)
+ for _, request := range q.pendPool {
+ space -= len(request.Hashes)
+ }
// Retrieve a batch of hashes, skipping previously failed ones
send := make(map[common.Hash]int)
skip := make(map[common.Hash]int)
- for len(send) < max && !q.hashQueue.Empty() {
+ capacity := p.Capacity()
+ for len(send) < space && len(send) < capacity && !q.hashQueue.Empty() {
hash, priority := q.hashQueue.Pop()
if p.ignored.Has(hash) {
skip[hash.(common.Hash)] = int(priority)
diff --git a/eth/downloader/queue_test.go b/eth/downloader/queue_test.go
index b1f3591f3..ee6141f71 100644
--- a/eth/downloader/queue_test.go
+++ b/eth/downloader/queue_test.go
@@ -1,8 +1,6 @@
package downloader
import (
- "testing"
-
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"gopkg.in/fatih/set.v0"
@@ -30,32 +28,3 @@ func createBlocksFromHashSet(hashes *set.Set) []*types.Block {
return blocks
}
-
-func TestChunking(t *testing.T) {
- queue := newQueue()
- peer1 := newPeer("peer1", common.Hash{}, nil, nil)
- peer2 := newPeer("peer2", common.Hash{}, nil, nil)
-
- // 99 + 1 (1 == known genesis hash)
- hashes := createHashes(0, 99)
- queue.Insert(hashes)
-
- chunk1 := queue.Reserve(peer1, 99)
- if chunk1 == nil {
- t.Errorf("chunk1 is nil")
- t.FailNow()
- }
- chunk2 := queue.Reserve(peer2, 99)
- if chunk2 == nil {
- t.Errorf("chunk2 is nil")
- t.FailNow()
- }
-
- if len(chunk1.Hashes) != 99 {
- t.Error("expected chunk1 hashes to be 99, got", len(chunk1.Hashes))
- }
-
- if len(chunk2.Hashes) != 1 {
- t.Error("expected chunk1 hashes to be 1, got", len(chunk2.Hashes))
- }
-}
diff --git a/tests/block_test.go b/tests/block_test.go
index f5dfac017..8191d56a2 100644
--- a/tests/block_test.go
+++ b/tests/block_test.go
@@ -18,6 +18,7 @@ func TestBcValidBlockTests(t *testing.T) {
func TestBcUncleTests(t *testing.T) {
runBlockTestsInFile("files/BlockTests/bcUncleTest.json", []string{}, t)
+ runBlockTestsInFile("files/BlockTests/bcBruncleTest.json", []string{}, t)
}
func TestBcUncleHeaderValidityTests(t *testing.T) {
diff --git a/tests/files/BlockTests/bcBruncleTest.json b/tests/files/BlockTests/bcBruncleTest.json
new file mode 100644
index 000000000..788e5d418
--- /dev/null
+++ b/tests/files/BlockTests/bcBruncleTest.json
@@ -0,0 +1,265 @@
+{
+ "UncleIsBrother" : {
+ "blocks" : [
+ {
+ "blockHeader" : {
+ "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
+ "difficulty" : "0x020000",
+ "extraData" : "0x",
+ "gasLimit" : "0x2fefd8",
+ "gasUsed" : "0x5208",
+ "hash" : "b33b222d72b0ac4de8c6a85132ca00d082c858f5d8cd38faaec880bf01948868",
+ "mixHash" : "4429011a33e2fa9143440b2b3ec09203daaf899201db66fa5e269b17b88de65d",
+ "nonce" : "5df16caa8f38b720",
+ "number" : "0x01",
+ "parentHash" : "12762bcfc4e3a39bc07c594da011f7a1298de685d04fb78281fb808e24d2e922",
+ "receiptTrie" : "e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313",
+ "stateRoot" : "2c15e8b5cb6cf880faa558c76c02a591e181ef2c4450ad92e53ae6c21093dc70",
+ "timestamp" : "0x556cb4da",
+ "transactionsTrie" : "aa2cd9b3cb075451f4e5ba70792741f966d065b3e900f9338af5e61a992b107c",
+ "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
+ },
+ "rlp" : "0xf90261f901f9a012762bcfc4e3a39bc07c594da011f7a1298de685d04fb78281fb808e24d2e922a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a02c15e8b5cb6cf880faa558c76c02a591e181ef2c4450ad92e53ae6c21093dc70a0aa2cd9b3cb075451f4e5ba70792741f966d065b3e900f9338af5e61a992b107ca0e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd882520884556cb4da80a04429011a33e2fa9143440b2b3ec09203daaf899201db66fa5e269b17b88de65d885df16caa8f38b720f862f86080018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0f569d8483892e3d35d84c69db9404e951a8dbd94f4d74dafa2bb47a53d1bec02a0e32607cfa73b4b2af5c08970edb3bba3aade4c05e54d65735f923d7a4c2f5c9bc0",
+ "transactions" : [
+ {
+ "data" : "0x",
+ "gasLimit" : "0x04cb2f",
+ "gasPrice" : "0x01",
+ "nonce" : "0x00",
+ "r" : "0xf569d8483892e3d35d84c69db9404e951a8dbd94f4d74dafa2bb47a53d1bec02",
+ "s" : "0xe32607cfa73b4b2af5c08970edb3bba3aade4c05e54d65735f923d7a4c2f5c9b",
+ "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
+ "v" : "0x1b",
+ "value" : "0x0a"
+ }
+ ],
+ "uncleHeaders" : [
+ ]
+ },
+ {
+ "blockHeader" : {
+ "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
+ "difficulty" : "0x020040",
+ "extraData" : "0x",
+ "gasLimit" : "0x2fefd8",
+ "gasUsed" : "0x5208",
+ "hash" : "5a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7e",
+ "mixHash" : "bad21f7ba41f2e18257ac63c74596d6a24e530cbe2f8ac16e00e5603b90b5879",
+ "nonce" : "e3ba58fa89603930",
+ "number" : "0x02",
+ "parentHash" : "b33b222d72b0ac4de8c6a85132ca00d082c858f5d8cd38faaec880bf01948868",
+ "receiptTrie" : "5a750181d80a2b69fac54c1b2f7a37ebc4666ea5320e25db6603b90958686b27",
+ "stateRoot" : "a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fe",
+ "timestamp" : "0x556cb4dc",
+ "transactionsTrie" : "87ac5f6dad44a1d936ac91c7adc1af1432c4de558437c28a0310cad080618788",
+ "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
+ },
+ "rlp" : "0xf90261f901f9a0b33b222d72b0ac4de8c6a85132ca00d082c858f5d8cd38faaec880bf01948868a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fea087ac5f6dad44a1d936ac91c7adc1af1432c4de558437c28a0310cad080618788a05a750181d80a2b69fac54c1b2f7a37ebc4666ea5320e25db6603b90958686b27b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302004002832fefd882520884556cb4dc80a0bad21f7ba41f2e18257ac63c74596d6a24e530cbe2f8ac16e00e5603b90b587988e3ba58fa89603930f862f86001018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba01efcde76a5247d3d54a0a6ba2c41c92eb947d217521eb2bd9336354353d99795a075bb5a9e0cb47db96c827e4e0c813bf0df09e402cbf637c8d6ca904abd0b9b90c0",
+ "transactions" : [
+ {
+ "data" : "0x",
+ "gasLimit" : "0x04cb2f",
+ "gasPrice" : "0x01",
+ "nonce" : "0x01",
+ "r" : "0x1efcde76a5247d3d54a0a6ba2c41c92eb947d217521eb2bd9336354353d99795",
+ "s" : "0x75bb5a9e0cb47db96c827e4e0c813bf0df09e402cbf637c8d6ca904abd0b9b90",
+ "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
+ "v" : "0x1b",
+ "value" : "0x0a"
+ }
+ ],
+ "uncleHeaders" : [
+ ]
+ },
+ {
+ "rlp" : "0xf903f8f901f7a05a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7ea0252fa1b79fd960f83f1e9ec4770a29596996326eb34fd0e91d5e74e79db6c05b948888f1f195afa192cfee860698584c030f4c9db1a0a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefd88084556cb4e280a000f430211f20f7885d46f98cdb697e40a4e8c685b654101ab878ec0bb526ebb588feff31c8314b072ac0f901faf901f7a05a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794acde5374fce5edbc8e2a8697c15331677e6ebf0ba0a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefd88084556cb4de80a059be7526b162cde243feac643a5c8ffc455c6f77fa1fa912961893687b65017188e049f43874907e7c"
+ }
+ ],
+ "genesisBlockHeader" : {
+ "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
+ "difficulty" : "0x020000",
+ "extraData" : "0x42",
+ "gasLimit" : "0x2fefd8",
+ "gasUsed" : "0x00",
+ "hash" : "12762bcfc4e3a39bc07c594da011f7a1298de685d04fb78281fb808e24d2e922",
+ "mixHash" : "72ac0702fd9563f986d604eecd03931452e716b7915e1d81babf77747eb631af",
+ "nonce" : "efe914e72f8823a7",
+ "number" : "0x00",
+ "parentHash" : "0000000000000000000000000000000000000000000000000000000000000000",
+ "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
+ "stateRoot" : "7dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1",
+ "timestamp" : "0x54c98c81",
+ "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
+ "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
+ },
+ "genesisRLP" : "0xf901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a07dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a072ac0702fd9563f986d604eecd03931452e716b7915e1d81babf77747eb631af88efe914e72f8823a7c0c0",
+ "lastblockhash" : "5a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7e",
+ "postState" : {
+ "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
+ "balance" : "0x14",
+ "code" : "0x",
+ "nonce" : "0x00",
+ "storage" : {
+ }
+ },
+ "8888f1f195afa192cfee860698584c030f4c9db1" : {
+ "balance" : "0x29a2241af62ca410",
+ "code" : "0x",
+ "nonce" : "0x00",
+ "storage" : {
+ }
+ },
+ "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
+ "balance" : "0x09184e71fbdc",
+ "code" : "0x",
+ "nonce" : "0x02",
+ "storage" : {
+ }
+ }
+ },
+ "pre" : {
+ "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
+ "balance" : "0x09184e72a000",
+ "code" : "0x",
+ "nonce" : "0x00",
+ "storage" : {
+ }
+ }
+ }
+ },
+
+ "UncleIsBrother2" : {
+ "blocks" : [
+ {
+ "blockHeader" : {
+ "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
+ "difficulty" : "0x020000",
+ "extraData" : "0x",
+ "gasLimit" : "0x2fefd8",
+ "gasUsed" : "0x5208",
+ "hash" : "b33b222d72b0ac4de8c6a85132ca00d082c858f5d8cd38faaec880bf01948868",
+ "mixHash" : "4429011a33e2fa9143440b2b3ec09203daaf899201db66fa5e269b17b88de65d",
+ "nonce" : "5df16caa8f38b720",
+ "number" : "0x01",
+ "parentHash" : "12762bcfc4e3a39bc07c594da011f7a1298de685d04fb78281fb808e24d2e922",
+ "receiptTrie" : "e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313",
+ "stateRoot" : "2c15e8b5cb6cf880faa558c76c02a591e181ef2c4450ad92e53ae6c21093dc70",
+ "timestamp" : "0x556cb4da",
+ "transactionsTrie" : "aa2cd9b3cb075451f4e5ba70792741f966d065b3e900f9338af5e61a992b107c",
+ "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
+ },
+ "rlp" : "0xf90261f901f9a012762bcfc4e3a39bc07c594da011f7a1298de685d04fb78281fb808e24d2e922a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a02c15e8b5cb6cf880faa558c76c02a591e181ef2c4450ad92e53ae6c21093dc70a0aa2cd9b3cb075451f4e5ba70792741f966d065b3e900f9338af5e61a992b107ca0e9244cf7503b79c03d3a099e07a80d2dbc77bb0b502d8a89d51ac0d68dd31313b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd882520884556cb4da80a04429011a33e2fa9143440b2b3ec09203daaf899201db66fa5e269b17b88de65d885df16caa8f38b720f862f86080018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba0f569d8483892e3d35d84c69db9404e951a8dbd94f4d74dafa2bb47a53d1bec02a0e32607cfa73b4b2af5c08970edb3bba3aade4c05e54d65735f923d7a4c2f5c9bc0",
+ "transactions" : [
+ {
+ "data" : "0x",
+ "gasLimit" : "0x04cb2f",
+ "gasPrice" : "0x01",
+ "nonce" : "0x00",
+ "r" : "0xf569d8483892e3d35d84c69db9404e951a8dbd94f4d74dafa2bb47a53d1bec02",
+ "s" : "0xe32607cfa73b4b2af5c08970edb3bba3aade4c05e54d65735f923d7a4c2f5c9b",
+ "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
+ "v" : "0x1b",
+ "value" : "0x0a"
+ }
+ ],
+ "uncleHeaders" : [
+ ]
+ },
+ {
+ "blockHeader" : {
+ "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
+ "difficulty" : "0x020040",
+ "extraData" : "0x",
+ "gasLimit" : "0x2fefd8",
+ "gasUsed" : "0x5208",
+ "hash" : "5a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7e",
+ "mixHash" : "bad21f7ba41f2e18257ac63c74596d6a24e530cbe2f8ac16e00e5603b90b5879",
+ "nonce" : "e3ba58fa89603930",
+ "number" : "0x02",
+ "parentHash" : "b33b222d72b0ac4de8c6a85132ca00d082c858f5d8cd38faaec880bf01948868",
+ "receiptTrie" : "5a750181d80a2b69fac54c1b2f7a37ebc4666ea5320e25db6603b90958686b27",
+ "stateRoot" : "a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fe",
+ "timestamp" : "0x556cb4dc",
+ "transactionsTrie" : "87ac5f6dad44a1d936ac91c7adc1af1432c4de558437c28a0310cad080618788",
+ "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
+ },
+ "rlp" : "0xf90261f901f9a0b33b222d72b0ac4de8c6a85132ca00d082c858f5d8cd38faaec880bf01948868a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0a2a5e3d96e902272adb58e90c364f7b92684c539e0ded77356cf33d966f917fea087ac5f6dad44a1d936ac91c7adc1af1432c4de558437c28a0310cad080618788a05a750181d80a2b69fac54c1b2f7a37ebc4666ea5320e25db6603b90958686b27b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302004002832fefd882520884556cb4dc80a0bad21f7ba41f2e18257ac63c74596d6a24e530cbe2f8ac16e00e5603b90b587988e3ba58fa89603930f862f86001018304cb2f94095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba01efcde76a5247d3d54a0a6ba2c41c92eb947d217521eb2bd9336354353d99795a075bb5a9e0cb47db96c827e4e0c813bf0df09e402cbf637c8d6ca904abd0b9b90c0",
+ "transactions" : [
+ {
+ "data" : "0x",
+ "gasLimit" : "0x04cb2f",
+ "gasPrice" : "0x01",
+ "nonce" : "0x01",
+ "r" : "0x1efcde76a5247d3d54a0a6ba2c41c92eb947d217521eb2bd9336354353d99795",
+ "s" : "0x75bb5a9e0cb47db96c827e4e0c813bf0df09e402cbf637c8d6ca904abd0b9b90",
+ "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87",
+ "v" : "0x1b",
+ "value" : "0x0a"
+ }
+ ],
+ "uncleHeaders" : [
+ ]
+ },
+ {
+ "rlp" : "0xf903f8f901f7a05a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7ea0252fa1b79fd960f83f1e9ec4770a29596996326eb34fd0e91d5e74e79db6c05b948888f1f195afa192cfee860698584c030f4c9db1a01b8bf4ebfcd765992f945d162f677e5b5655b464121f9c057163cae9119fc3e9a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefd88084556cb4e280a000f430211f20f7885d46f98cdb697e40a4e8c685b654101ab878ec0bb526ebb588feff31c8314b072ac0f901faf901f7a05a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794acde5374fce5edbc8e2a8697c15331677e6ebf0ba01b8bf4ebfcd765992f945d162f677e5b5655b464121f9c057163cae9119fc3e9a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefd88084556cb4de80a059be7526b162cde243feac643a5c8ffc455c6f77fa1fa912961893687b65017188e049f43874907e7c"
+ }
+ ],
+ "genesisBlockHeader" : {
+ "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "coinbase" : "8888f1f195afa192cfee860698584c030f4c9db1",
+ "difficulty" : "0x020000",
+ "extraData" : "0x42",
+ "gasLimit" : "0x2fefd8",
+ "gasUsed" : "0x00",
+ "hash" : "12762bcfc4e3a39bc07c594da011f7a1298de685d04fb78281fb808e24d2e922",
+ "mixHash" : "72ac0702fd9563f986d604eecd03931452e716b7915e1d81babf77747eb631af",
+ "nonce" : "efe914e72f8823a7",
+ "number" : "0x00",
+ "parentHash" : "0000000000000000000000000000000000000000000000000000000000000000",
+ "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
+ "stateRoot" : "7dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1",
+ "timestamp" : "0x54c98c81",
+ "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
+ "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
+ },
+ "genesisRLP" : "0xf901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a07dba07d6b448a186e9612e5f737d1c909dce473e53199901a302c00646d523c1a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808454c98c8142a072ac0702fd9563f986d604eecd03931452e716b7915e1d81babf77747eb631af88efe914e72f8823a7c0c0",
+ "lastblockhash" : "5a9cba116901d3e11fa9d93ef421c83762912e348625d3d2f559a661d4455d7e",
+ "postState" : {
+ "095e7baea6a6c7c4c2dfeb977efac326af552d87" : {
+ "balance" : "0x14",
+ "code" : "0x",
+ "nonce" : "0x00",
+ "storage" : {
+ }
+ },
+ "8888f1f195afa192cfee860698584c030f4c9db1" : {
+ "balance" : "0x29a2241af62ca410",
+ "code" : "0x",
+ "nonce" : "0x00",
+ "storage" : {
+ }
+ },
+ "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
+ "balance" : "0x09184e71fbdc",
+ "code" : "0x",
+ "nonce" : "0x02",
+ "storage" : {
+ }
+ }
+ },
+ "pre" : {
+ "a94f5374fce5edbc8e2a8697c15331677e6ebf0b" : {
+ "balance" : "0x09184e72a000",
+ "code" : "0x",
+ "nonce" : "0x00",
+ "storage" : {
+ }
+ }
+ }
+ }
+}