aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/geth/main.go2
-rw-r--r--core/block_processor.go2
-rw-r--r--crypto/key_store_passphrase.go13
-rw-r--r--eth/downloader/downloader.go2
-rw-r--r--miner/worker.go10
-rw-r--r--p2p/discover/udp.go46
-rw-r--r--p2p/discover/udp_test.go25
7 files changed, 70 insertions, 30 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index b4d7feed1..725f04efe 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -563,7 +563,7 @@ func upgradeDb(ctx *cli.Context) {
bcVersion = core.BlockChainVersion
}
- filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("2006-01-02_15:04:05"))
+ filename := fmt.Sprintf("blockchain_%d_%s.chain", bcVersion, time.Now().Format("20060102_150405"))
exportFile := filepath.Join(ctx.GlobalString(utils.DataDirFlag.Name), filename)
err = utils.ExportChain(ethereum.ChainManager(), exportFile)
diff --git a/core/block_processor.go b/core/block_processor.go
index af47069ad..059c442cc 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -197,7 +197,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
// There can be at most two uncles
if len(block.Uncles()) > 2 {
- return nil, ValidationError("Block can only contain one uncle (contained %v)", len(block.Uncles()))
+ return nil, ValidationError("Block can only contain maximum 2 uncles (contained %v)", len(block.Uncles()))
}
receipts, err := sm.TransitionState(state, parent, block, false)
diff --git a/crypto/key_store_passphrase.go b/crypto/key_store_passphrase.go
index d9a5a81f9..782f92bf1 100644
--- a/crypto/key_store_passphrase.go
+++ b/crypto/key_store_passphrase.go
@@ -28,21 +28,22 @@ the private key is encrypted and on disk uses another JSON encoding.
Cryptography:
-1. Encryption key is first 16 bytes of SHA3-256 of first 16 bytes of
- scrypt derived key from user passphrase. Scrypt parameters
+1. Encryption key is first 16 bytes of scrypt derived key
+ from user passphrase. Scrypt parameters
(work factors) [1][2] are defined as constants below.
2. Scrypt salt is 32 random bytes from CSPRNG.
- It's stored in plain next to ciphertext in key file.
-3. MAC is SHA3-256 of concatenation of ciphertext and last 16 bytes of scrypt derived key.
+ It's stored in plain next in the key file.
+3. MAC is SHA3-256 of concatenation of ciphertext and
+ last 16 bytes of scrypt derived key.
4. Plaintext is the EC private key bytes.
5. Encryption algo is AES 128 CBC [3][4]
6. CBC IV is 16 random bytes from CSPRNG.
- It's stored in plain next to ciphertext in key file.
+ It's stored in plain next in the key file.
7. Plaintext padding is PKCS #7 [5][6]
Encoding:
-1. On disk, the ciphertext, MAC, salt and IV are encoded in a nested JSON object.
+1. On disk, the ciphertext, MAC, salt and IV are encoded in a JSON object.
cat a key file to see the structure.
2. byte arrays are base64 JSON strings.
3. The EC private key bytes are in uncompressed form [7].
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 5850ea13a..85de78ebf 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -280,7 +280,7 @@ out:
// already fetched hash list. This can't guarantee 100% correctness but does
// a fair job. This is always either correct or false incorrect.
for _, peer := range d.peers.AllPeers() {
- if d.queue.Has(peer.head) && !attemptedPeers[p.id] {
+ if d.queue.Has(peer.head) && !attemptedPeers[peer.id] {
p = peer
break
}
diff --git a/miner/worker.go b/miner/worker.go
index f737be507..c70ded434 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -45,7 +45,8 @@ type environment struct {
state *state.StateDB // apply state changes here
coinbase *state.StateObject // the miner's account
block *types.Block // the new block
- family *set.Set // family set (used for checking uncles)
+ ancestors *set.Set // ancestor set (used for checking uncle parent validity)
+ family *set.Set // family set (used for checking uncle invalidity)
uncles *set.Set // uncle set
remove *set.Set // tx which will be removed
tcount int // tx count in cycle
@@ -62,6 +63,7 @@ func env(block *types.Block, eth core.Backend) *environment {
totalUsedGas: new(big.Int),
state: state,
block: block,
+ ancestors: set.New(),
family: set.New(),
uncles: set.New(),
coinbase: state.GetOrNewStateObject(block.Coinbase()),
@@ -265,7 +267,11 @@ func (self *worker) makeCurrent() {
current := env(block, self.eth)
for _, ancestor := range self.chain.GetAncestors(block, 7) {
+ for _, uncle := range ancestor.Uncles() {
+ current.family.Add(uncle.Hash())
+ }
current.family.Add(ancestor.Hash())
+ current.ancestors.Add(ancestor.Hash())
}
accounts, _ := self.eth.AccountManager().Accounts()
// Keep track of transactions which return errors so they can be removed
@@ -363,7 +369,7 @@ func (self *worker) commitUncle(uncle *types.Header) error {
}
self.current.uncles.Add(uncle.Hash())
- if !self.current.family.Has(uncle.ParentHash) {
+ if !self.current.ancestors.Has(uncle.ParentHash) {
return core.UncleError(fmt.Sprintf("Uncle's parent unknown (%x)", uncle.ParentHash[0:4]))
}
diff --git a/p2p/discover/udp.go b/p2p/discover/udp.go
index 1213c12c8..539ccd460 100644
--- a/p2p/discover/udp.go
+++ b/p2p/discover/udp.go
@@ -363,7 +363,31 @@ const (
headSize = macSize + sigSize // space of packet frame data
)
-var headSpace = make([]byte, headSize)
+var (
+ headSpace = make([]byte, headSize)
+
+ // Neighbors responses are sent across multiple packets to
+ // stay below the 1280 byte limit. We compute the maximum number
+ // of entries by stuffing a packet until it grows too large.
+ maxNeighbors int
+)
+
+func init() {
+ p := neighbors{Expiration: ^uint64(0)}
+ maxSizeNode := rpcNode{IP: make(net.IP, 16), UDP: ^uint16(0), TCP: ^uint16(0)}
+ for n := 0; ; n++ {
+ p.Nodes = append(p.Nodes, maxSizeNode)
+ size, _, err := rlp.EncodeToReader(p)
+ if err != nil {
+ // If this ever happens, it will be caught by the unit tests.
+ panic("cannot encode: " + err.Error())
+ }
+ if headSize+size+1 >= 1280 {
+ maxNeighbors = n
+ break
+ }
+ }
+}
func (t *udp) send(toaddr *net.UDPAddr, ptype byte, req interface{}) error {
packet, err := encodePacket(t.priv, ptype, req)
@@ -402,7 +426,10 @@ func encodePacket(priv *ecdsa.PrivateKey, ptype byte, req interface{}) ([]byte,
// readLoop runs in its own goroutine. it handles incoming UDP packets.
func (t *udp) readLoop() {
defer t.conn.Close()
- buf := make([]byte, 4096) // TODO: good buffer size
+ // Discovery packets are defined to be no larger than 1280 bytes.
+ // Packets larger than this size will be cut at the end and treated
+ // as invalid because their hash won't match.
+ buf := make([]byte, 1280)
for {
nbytes, from, err := t.conn.ReadFromUDP(buf)
if err != nil {
@@ -504,15 +531,16 @@ func (req *findnode) handle(t *udp, from *net.UDPAddr, fromID NodeID, mac []byte
closest := t.closest(target, bucketSize).entries
t.mutex.Unlock()
- // TODO: this conversion could use a cached version of the slice
- closestrpc := make([]rpcNode, len(closest))
+ p := neighbors{Expiration: uint64(time.Now().Add(expiration).Unix())}
+ // Send neighbors in chunks with at most maxNeighbors per packet
+ // to stay below the 1280 byte limit.
for i, n := range closest {
- closestrpc[i] = nodeToRPC(n)
+ p.Nodes = append(p.Nodes, nodeToRPC(n))
+ if len(p.Nodes) == maxNeighbors || i == len(closest)-1 {
+ t.send(from, neighborsPacket, p)
+ p.Nodes = p.Nodes[:0]
+ }
}
- t.send(from, neighborsPacket, neighbors{
- Nodes: closestrpc,
- Expiration: uint64(time.Now().Add(expiration).Unix()),
- })
return nil
}
diff --git a/p2p/discover/udp_test.go b/p2p/discover/udp_test.go
index f175835a8..11fa31d7c 100644
--- a/p2p/discover/udp_test.go
+++ b/p2p/discover/udp_test.go
@@ -163,17 +163,22 @@ func TestUDP_findnode(t *testing.T) {
))
// check that closest neighbors are returned.
test.packetIn(nil, findnodePacket, &findnode{Target: testTarget, Expiration: futureExp})
- test.waitPacketOut(func(p *neighbors) {
- expected := test.table.closest(targetHash, bucketSize)
- if len(p.Nodes) != bucketSize {
- t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize)
- }
- for i := range p.Nodes {
- if p.Nodes[i].ID != expected.entries[i].ID {
- t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, p.Nodes[i], expected.entries[i])
+ expected := test.table.closest(targetHash, bucketSize)
+
+ waitNeighbors := func(want []*Node) {
+ test.waitPacketOut(func(p *neighbors) {
+ if len(p.Nodes) != len(want) {
+ t.Errorf("wrong number of results: got %d, want %d", len(p.Nodes), bucketSize)
}
- }
- })
+ for i := range p.Nodes {
+ if p.Nodes[i].ID != want[i].ID {
+ t.Errorf("result mismatch at %d:\n got: %v\n want: %v", i, p.Nodes[i], expected.entries[i])
+ }
+ }
+ })
+ }
+ waitNeighbors(expected.entries[:maxNeighbors])
+ waitNeighbors(expected.entries[maxNeighbors:])
}
func TestUDP_findnodeMultiReply(t *testing.T) {