Merge remote-tracking branch 'upstream/master'

This commit is contained in:
LLLeon 2017-10-16 12:53:28 +08:00
commit 93f84c879f
6 changed files with 55 additions and 36 deletions

View file

@ -1 +1 @@
1.7.2 1.7.3

View file

@ -102,7 +102,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
header.Cap *= 4 header.Cap *= 4
cache := *(*[]byte)(unsafe.Pointer(&header)) 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)) size := uint64(len(cache))
rows := int(size) / hashBytes rows := int(size) / hashBytes
@ -187,7 +187,7 @@ func fnvHash(mix []uint32, data []uint32) {
// generateDatasetItem combines data from 256 pseudorandomly selected cache nodes, // generateDatasetItem combines data from 256 pseudorandomly selected cache nodes,
// and hashes that to compute a single dataset node. // and hashes that to compute a single dataset node.
func generateDatasetItem(cache []uint32, index uint32, keccak512 hasher) []byte { 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) rows := uint32(len(cache) / hashWords)
// Initialize the mix // 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 // hashimoto aggregates data from the full dataset in order to produce our final
// value for a particular header hash and nonce. // value for a particular header hash and nonce.
func hashimoto(hash []byte, nonce uint64, size uint64, lookup func(index uint32) []uint32) ([]byte, []byte) { 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) rows := uint32(size / mixBytes)
// Combine header+nonce into a 64 byte seed // Combine header+nonce into a 64 byte seed

View file

@ -147,12 +147,12 @@ func TestTransactionPriceNonceSort(t *testing.T) {
txset := NewTransactionsByPriceAndNonce(signer, groups) txset := NewTransactionsByPriceAndNonce(signer, groups)
txs := Transactions{} txs := Transactions{}
for { for tx := txset.Peek(); tx != nil; tx = txset.Peek() {
if tx := txset.Peek(); tx != nil {
txs = append(txs, tx) txs = append(txs, tx)
txset.Shift() txset.Shift()
} }
break if len(txs) != 25*25 {
t.Errorf("expected %d transactions, found %d", 25*25, len(txs))
} }
for i, txi := range txs { for i, txi := range txs {
fromi, _ := Sender(signer, txi) fromi, _ := Sender(signer, txi)

View file

@ -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] 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 { if !operation.valid {
return nil, fmt.Errorf("invalid opcode 0x%x", int(op)) 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 { if err := operation.validateStack(stack); err != nil {
return nil, err 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 var memorySize uint64
// calculate the new memory size and expand the memory to fit // calculate the new memory size and expand the memory to fit

View file

@ -23,7 +23,7 @@ import (
const ( const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 7 // Minor version component of the current release VersionMinor = 7 // Minor version component of the current release
VersionPatch = 2 // Patch 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 VersionMeta = "unstable" // Version metadata to append to the version string
) )

View file

@ -22,6 +22,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/big"
"math/rand" "math/rand"
"os" "os"
"reflect" "reflect"
@ -30,7 +31,9 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
) )
func init() { func init() {
@ -505,8 +508,6 @@ func BenchmarkGet(b *testing.B) { benchGet(b, false) }
func BenchmarkGetDB(b *testing.B) { benchGet(b, true) } func BenchmarkGetDB(b *testing.B) { benchGet(b, true) }
func BenchmarkUpdateBE(b *testing.B) { benchUpdate(b, binary.BigEndian) } func BenchmarkUpdateBE(b *testing.B) { benchUpdate(b, binary.BigEndian) }
func BenchmarkUpdateLE(b *testing.B) { benchUpdate(b, binary.LittleEndian) } 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 const benchElemCount = 20000
@ -549,19 +550,40 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
return trie return trie
} }
func benchHash(b *testing.B, e binary.ByteOrder) { // Benchmarks the trie hashing. Since the trie caches the result of any operation,
trie := newEmpty() // we cannot use b.N as the number of hashing rouns, since all rounds apart from
k := make([]byte, 32) // the first one will be NOOP. As such, we'll use b.N as the number of account to
for i := 0; i < benchElemCount; i++ { // insert into the trie before measuring the hashing.
e.PutUint64(k, uint64(i)) func BenchmarkHash(b *testing.B) {
trie.Update(k, k) // Make the random benchmark deterministic
} random := rand.New(rand.NewSource(0))
b.ResetTimer() // Create a realistic account trie to hash
for i := 0; i < b.N; i++ { addresses := make([][20]byte, b.N)
trie.Hash() 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) { func tempDB() (string, Database) {
dir, err := ioutil.TempDir("", "trie-bench") dir, err := ioutil.TempDir("", "trie-bench")