aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-06-25 20:47:56 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-06-30 00:51:48 +0800
commitd0bb90c69e5572417128fdb8188f53cc45f76002 (patch)
treea2d566c3be0e45d1b0d66fb304d684fe5911e5ad
parent992dc74efdab530b716828e6f4a8468d27db41f0 (diff)
downloaddexon-d0bb90c69e5572417128fdb8188f53cc45f76002.tar
dexon-d0bb90c69e5572417128fdb8188f53cc45f76002.tar.gz
dexon-d0bb90c69e5572417128fdb8188f53cc45f76002.tar.bz2
dexon-d0bb90c69e5572417128fdb8188f53cc45f76002.tar.lz
dexon-d0bb90c69e5572417128fdb8188f53cc45f76002.tar.xz
dexon-d0bb90c69e5572417128fdb8188f53cc45f76002.tar.zst
dexon-d0bb90c69e5572417128fdb8188f53cc45f76002.zip
core: generate benchmark keys only once
-rw-r--r--core/bench_test.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/core/bench_test.go b/core/bench_test.go
index bba5cce5f..6d851febd 100644
--- a/core/bench_test.go
+++ b/core/bench_test.go
@@ -72,16 +72,24 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
}
}
+var (
+ ringKeys = make([]*ecdsa.PrivateKey, 1000)
+ ringAddrs = make([]common.Address, len(ringKeys))
+)
+
+func init() {
+ ringKeys[0] = benchRootKey
+ ringAddrs[0] = benchRootAddr
+ for i := 1; i < len(ringKeys); i++ {
+ ringKeys[i], _ = crypto.GenerateKey()
+ ringAddrs[i] = crypto.PubkeyToAddress(ringKeys[i].PublicKey)
+ }
+}
+
// genTxRing returns a block generator that sends ether in a ring
// among n accounts. This is creates n entries in the state database
// and fills the blocks with many small transactions.
func genTxRing(naccounts int) func(int, *BlockGen) {
- keys := make([]*ecdsa.PrivateKey, naccounts)
- keys[0] = benchRootKey
- for i := 1; i < naccounts; i++ {
- keys[i], _ = crypto.GenerateKey()
- }
-
from := 0
return func(i int, gen *BlockGen) {
gas := CalcGasLimit(gen.PrevBlock(i - 1))
@@ -91,9 +99,15 @@ func genTxRing(naccounts int) func(int, *BlockGen) {
break
}
to := (from + 1) % naccounts
- fromaddr := crypto.PubkeyToAddress(keys[from].PublicKey)
- toaddr := crypto.PubkeyToAddress(keys[to].PublicKey)
- tx, _ := types.NewTransaction(gen.TxNonce(fromaddr), toaddr, benchRootFunds, params.TxGas, nil, nil).SignECDSA(keys[from])
+ tx := types.NewTransaction(
+ gen.TxNonce(ringAddrs[from]),
+ ringAddrs[to],
+ benchRootFunds,
+ params.TxGas,
+ nil,
+ nil,
+ )
+ tx, _ = tx.SignECDSA(ringKeys[from])
gen.AddTx(tx)
from = to
}