Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
8c31d289
Unverified
Commit
8c31d289
authored
Apr 07, 2018
by
Martin Holst Swende
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: add blockchain benchmarks
parent
14c9215d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
111 additions
and
0 deletions
+111
-0
blockchain_test.go
core/blockchain_test.go
+111
-0
No files found.
core/blockchain_test.go
View file @
8c31d289
...
...
@@ -1338,3 +1338,114 @@ func TestLargeReorgTrieGC(t *testing.T) {
}
}
}
// Benchmarks large blocks with value transfers to non-existing accounts
func
benchmarkLargeNumberOfValueToNonexisting
(
b
*
testing
.
B
,
numTxs
,
numBlocks
int
,
recipientFn
func
(
uint64
)
common
.
Address
,
dataFn
func
(
uint64
)
[]
byte
)
{
var
(
signer
=
types
.
HomesteadSigner
{}
testBankKey
,
_
=
crypto
.
HexToECDSA
(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
)
testBankAddress
=
crypto
.
PubkeyToAddress
(
testBankKey
.
PublicKey
)
bankFunds
=
big
.
NewInt
(
100000000000000000
)
gspec
=
Genesis
{
Config
:
params
.
TestChainConfig
,
Alloc
:
GenesisAlloc
{
testBankAddress
:
{
Balance
:
bankFunds
},
common
.
HexToAddress
(
"0xc0de"
)
:
{
Code
:
[]
byte
{
0x60
,
0x01
,
0x50
},
Balance
:
big
.
NewInt
(
0
),
},
// push 1, pop
},
GasLimit
:
100e6
,
// 100 M
}
)
// Generate the original common chain segment and the two competing forks
engine
:=
ethash
.
NewFaker
()
db
,
_
:=
ethdb
.
NewMemDatabase
()
genesis
:=
gspec
.
MustCommit
(
db
)
blockGenerator
:=
func
(
i
int
,
block
*
BlockGen
)
{
block
.
SetCoinbase
(
common
.
Address
{
1
})
for
txi
:=
0
;
txi
<
numTxs
;
txi
++
{
uniq
:=
uint64
(
i
*
numTxs
+
txi
)
recipient
:=
recipientFn
(
uniq
)
//recipient := common.BigToAddress(big.NewInt(0).SetUint64(1337 + uniq))
tx
,
err
:=
types
.
SignTx
(
types
.
NewTransaction
(
uniq
,
recipient
,
big
.
NewInt
(
1
),
params
.
TxGas
,
big
.
NewInt
(
1
),
nil
),
signer
,
testBankKey
)
if
err
!=
nil
{
b
.
Error
(
err
)
}
block
.
AddTx
(
tx
)
}
}
shared
,
_
:=
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
engine
,
db
,
numBlocks
,
blockGenerator
)
b
.
StopTimer
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
// Import the shared chain and the original canonical one
diskdb
,
_
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{})
if
err
!=
nil
{
b
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
b
.
StartTimer
()
if
_
,
err
:=
chain
.
InsertChain
(
shared
);
err
!=
nil
{
b
.
Fatalf
(
"failed to insert shared chain: %v"
,
err
)
}
b
.
StopTimer
()
if
got
:=
chain
.
CurrentBlock
()
.
Transactions
()
.
Len
();
got
!=
numTxs
*
numBlocks
{
b
.
Fatalf
(
"Transactions were not included, expected %d, got %d"
,
(
numTxs
*
numBlocks
),
got
)
}
}
}
func
BenchmarkBlockChain_1x1000ValueTransferToNonexisting
(
b
*
testing
.
B
)
{
var
(
numTxs
=
1000
numBlocks
=
1
)
recipientFn
:=
func
(
nonce
uint64
)
common
.
Address
{
return
common
.
BigToAddress
(
big
.
NewInt
(
0
)
.
SetUint64
(
1337
+
nonce
))
}
dataFn
:=
func
(
nonce
uint64
)
[]
byte
{
return
nil
}
benchmarkLargeNumberOfValueToNonexisting
(
b
,
numTxs
,
numBlocks
,
recipientFn
,
dataFn
)
}
func
BenchmarkBlockChain_1x1000ValueTransferToExisting
(
b
*
testing
.
B
)
{
var
(
numTxs
=
1000
numBlocks
=
1
)
b
.
StopTimer
()
b
.
ResetTimer
()
recipientFn
:=
func
(
nonce
uint64
)
common
.
Address
{
return
common
.
BigToAddress
(
big
.
NewInt
(
0
)
.
SetUint64
(
1337
))
}
dataFn
:=
func
(
nonce
uint64
)
[]
byte
{
return
nil
}
benchmarkLargeNumberOfValueToNonexisting
(
b
,
numTxs
,
numBlocks
,
recipientFn
,
dataFn
)
}
func
BenchmarkBlockChain_1x1000Executions
(
b
*
testing
.
B
)
{
var
(
numTxs
=
1000
numBlocks
=
1
)
b
.
StopTimer
()
b
.
ResetTimer
()
recipientFn
:=
func
(
nonce
uint64
)
common
.
Address
{
return
common
.
BigToAddress
(
big
.
NewInt
(
0
)
.
SetUint64
(
0xc0de
))
}
dataFn
:=
func
(
nonce
uint64
)
[]
byte
{
return
nil
}
benchmarkLargeNumberOfValueToNonexisting
(
b
,
numTxs
,
numBlocks
,
recipientFn
,
dataFn
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment