From c599b78f62cda1ab91117b966f88f79fe4778f4f Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Wed, 11 Oct 2017 11:35:44 +0100 Subject: [PATCH 1/6] core/types: fix test for TransactionsByPriceAndNonce --- core/types/transaction_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core/types/transaction_test.go b/core/types/transaction_test.go index 30ecb84ddb..82d74e3b34 100644 --- a/core/types/transaction_test.go +++ b/core/types/transaction_test.go @@ -147,12 +147,12 @@ func TestTransactionPriceNonceSort(t *testing.T) { txset := NewTransactionsByPriceAndNonce(signer, groups) txs := Transactions{} - for { - if tx := txset.Peek(); tx != nil { - txs = append(txs, tx) - txset.Shift() - } - break + for tx := txset.Peek(); tx != nil; tx = txset.Peek() { + txs = append(txs, tx) + txset.Shift() + } + if len(txs) != 25*25 { + t.Errorf("expected %d transactions, found %d", 25*25, len(txs)) } for i, txi := range txs { fromi, _ := Sender(signer, txi) From 2e83c82f80f104e8073ec4a80c51800e10b37496 Mon Sep 17 00:00:00 2001 From: Ernesto del Toro Date: Fri, 13 Oct 2017 01:13:52 -0400 Subject: [PATCH 2/6] ethash: fix typo --- consensus/ethash/algorithm.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/consensus/ethash/algorithm.go b/consensus/ethash/algorithm.go index a737bc636b..76f19252fa 100644 --- a/consensus/ethash/algorithm.go +++ b/consensus/ethash/algorithm.go @@ -102,7 +102,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) { header.Cap *= 4 cache := *(*[]byte)(unsafe.Pointer(&header)) - // Calculate the number of thoretical rows (we'll store in one buffer nonetheless) + // Calculate the number of theoretical rows (we'll store in one buffer nonetheless) size := uint64(len(cache)) rows := int(size) / hashBytes @@ -187,7 +187,7 @@ func fnvHash(mix []uint32, data []uint32) { // generateDatasetItem combines data from 256 pseudorandomly selected cache nodes, // and hashes that to compute a single dataset node. func generateDatasetItem(cache []uint32, index uint32, keccak512 hasher) []byte { - // Calculate the number of thoretical rows (we use one buffer nonetheless) + // Calculate the number of theoretical rows (we use one buffer nonetheless) rows := uint32(len(cache) / hashWords) // Initialize the mix @@ -287,7 +287,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) { // hashimoto aggregates data from the full dataset in order to produce our final // value for a particular header hash and nonce. func hashimoto(hash []byte, nonce uint64, size uint64, lookup func(index uint32) []uint32) ([]byte, []byte) { - // Calculate the number of thoretical rows (we use one buffer nonetheless) + // Calculate the number of theoretical rows (we use one buffer nonetheless) rows := uint32(size / mixBytes) // Combine header+nonce into a 64 byte seed From a5fcaa55ac12a1861f13ab0096db1afecbc15904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 13 Oct 2017 11:10:02 +0300 Subject: [PATCH 3/6] trie: make hasher benchmark meaningful post-caches --- trie/trie_test.go | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/trie/trie_test.go b/trie/trie_test.go index 1c90950703..1e28c3bc48 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -22,6 +22,7 @@ import ( "errors" "fmt" "io/ioutil" + "math/big" "math/rand" "os" "reflect" @@ -30,7 +31,9 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/rlp" ) func init() { @@ -505,8 +508,6 @@ func BenchmarkGet(b *testing.B) { benchGet(b, false) } func BenchmarkGetDB(b *testing.B) { benchGet(b, true) } func BenchmarkUpdateBE(b *testing.B) { benchUpdate(b, binary.BigEndian) } func BenchmarkUpdateLE(b *testing.B) { benchUpdate(b, binary.LittleEndian) } -func BenchmarkHashBE(b *testing.B) { benchHash(b, binary.BigEndian) } -func BenchmarkHashLE(b *testing.B) { benchHash(b, binary.LittleEndian) } const benchElemCount = 20000 @@ -549,18 +550,39 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie { return trie } -func benchHash(b *testing.B, e binary.ByteOrder) { - trie := newEmpty() - k := make([]byte, 32) - for i := 0; i < benchElemCount; i++ { - e.PutUint64(k, uint64(i)) - trie.Update(k, k) - } +// Benchmarks the trie hashing. Since the trie caches the result of any operation, +// we cannot use b.N as the number of hashing rouns, since all rounds apart from +// the first one will be NOOP. As such, we'll use b.N as the number of account to +// insert into the trie before measuring the hashing. +func BenchmarkHash(b *testing.B) { + // Make the random benchmark deterministic + random := rand.New(rand.NewSource(0)) - b.ResetTimer() - for i := 0; i < b.N; i++ { - trie.Hash() + // Create a realistic account trie to hash + addresses := make([][20]byte, b.N) + for i := 0; i < len(addresses); i++ { + for j := 0; j < len(addresses[i]); j++ { + addresses[i][j] = byte(random.Intn(256)) + } } + accounts := make([][]byte, len(addresses)) + for i := 0; i < len(accounts); i++ { + var ( + nonce = uint64(random.Int63()) + balance = new(big.Int).Rand(random, new(big.Int).Exp(common.Big2, common.Big256, nil)) + root = emptyRoot + code = crypto.Keccak256(nil) + ) + accounts[i], _ = rlp.EncodeToBytes([]interface{}{nonce, balance, root, code}) + } + // Insert the accounts into the trie and hash it + trie := newEmpty() + for i := 0; i < len(addresses); i++ { + trie.Update(crypto.Keccak256(addresses[i][:]), accounts[i]) + } + b.ResetTimer() + b.ReportAllocs() + trie.Hash() } func tempDB() (string, Database) { From a91e6822349b6daa30a311f75b7d824739e5823d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Sat, 14 Oct 2017 15:42:48 +0300 Subject: [PATCH 4/6] core/vm: check opcode stack before readonly enforcement --- core/vm/interpreter.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 94b922c797..516438509f 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -138,10 +138,10 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret pc = uint64(0) // program counter cost uint64 // copies used by tracer - stackCopy = newstack() // stackCopy needed for Tracer since stack is mutated by 63/64 gas rule - pcCopy uint64 // needed for the deferred Tracer - gasCopy uint64 // for Tracer to log gas remaining before execution - logged bool // deferred Tracer should ignore already logged steps + stackCopy = newstack() // stackCopy needed for Tracer since stack is mutated by 63/64 gas rule + pcCopy uint64 // needed for the deferred Tracer + gasCopy uint64 // for Tracer to log gas remaining before execution + logged bool // deferred Tracer should ignore already logged steps ) contract.Input = input @@ -169,22 +169,19 @@ func (in *Interpreter) Run(snapshot int, contract *Contract, input []byte) (ret } } - // get the operation from the jump table matching the opcode + // Get the operation from the jump table matching the opcode and validate the + // stack and make sure there enough stack items available to perform the operation operation := in.cfg.JumpTable[op] - if err := in.enforceRestrictions(op, operation, stack); err != nil { - return nil, err - } - - // if the op is invalid abort the process and return an error if !operation.valid { return nil, fmt.Errorf("invalid opcode 0x%x", int(op)) } - - // validate the stack and make sure there enough stack items available - // to perform the operation if err := operation.validateStack(stack); err != nil { return nil, err } + // If the operation is valid, enforce and write restrictions + if err := in.enforceRestrictions(op, operation, stack); err != nil { + return nil, err + } var memorySize uint64 // calculate the new memory size and expand the memory to fit From 1db4ecdc0b9e828ff65777fb466fc7c1d04e0de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Sat, 14 Oct 2017 15:58:53 +0300 Subject: [PATCH 5/6] params: bump to 1.7.2 stable --- params/version.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/params/version.go b/params/version.go index 1abbae98a3..bde6d7b371 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 7 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release - VersionMeta = "unstable" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 7 // Minor version component of the current release + VersionPatch = 2 // Patch version component of the current release + VersionMeta = "stable" // Version metadata to append to the version string ) // Version holds the textual version string. From e9295163aa25479e817efee4aac23eaeb7554bba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Sat, 14 Oct 2017 16:00:46 +0300 Subject: [PATCH 6/6] VERSION, params: start 1.7.3 release cycle --- VERSION | 2 +- params/version.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index f8a696c8dc..661e7aeadf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.2 +1.7.3 diff --git a/params/version.go b/params/version.go index bde6d7b371..40d4591625 100644 --- a/params/version.go +++ b/params/version.go @@ -21,10 +21,10 @@ import ( ) const ( - VersionMajor = 1 // Major version component of the current release - VersionMinor = 7 // Minor version component of the current release - VersionPatch = 2 // Patch version component of the current release - VersionMeta = "stable" // Version metadata to append to the version string + VersionMajor = 1 // Major version component of the current release + VersionMinor = 7 // Minor version component of the current release + VersionPatch = 3 // Patch version component of the current release + VersionMeta = "unstable" // Version metadata to append to the version string ) // Version holds the textual version string.