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
eab4d898
Unverified
Commit
eab4d898
authored
Oct 27, 2021
by
Martin Holst Swende
Committed by
GitHub
Oct 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: fix benchmark tests (#23803)
Fixes crashes in various benchmarks in the core package
parent
526c3f6b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
20 deletions
+51
-20
bench_test.go
core/bench_test.go
+41
-12
blockchain_test.go
core/blockchain_test.go
+1
-1
rlp_test.go
core/rlp_test.go
+1
-1
tx_list_test.go
core/tx_list_test.go
+8
-6
No files found.
core/bench_test.go
View file @
eab4d898
...
...
@@ -75,7 +75,7 @@ var (
// This is the content of the genesis block used by the benchmarks.
benchRootKey
,
_
=
crypto
.
HexToECDSA
(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
)
benchRootAddr
=
crypto
.
PubkeyToAddress
(
benchRootKey
.
PublicKey
)
benchRootFunds
=
math
.
BigPow
(
2
,
1
00
)
benchRootFunds
=
math
.
BigPow
(
2
,
2
00
)
)
// genValueTx returns a block generator that includes a single
...
...
@@ -86,7 +86,19 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
toaddr
:=
common
.
Address
{}
data
:=
make
([]
byte
,
nbytes
)
gas
,
_
:=
IntrinsicGas
(
data
,
nil
,
false
,
false
,
false
)
tx
,
_
:=
types
.
SignTx
(
types
.
NewTransaction
(
gen
.
TxNonce
(
benchRootAddr
),
toaddr
,
big
.
NewInt
(
1
),
gas
,
nil
,
data
),
types
.
HomesteadSigner
{},
benchRootKey
)
signer
:=
types
.
MakeSigner
(
gen
.
config
,
big
.
NewInt
(
int64
(
i
)))
gasPrice
:=
big
.
NewInt
(
0
)
if
gen
.
header
.
BaseFee
!=
nil
{
gasPrice
=
gen
.
header
.
BaseFee
}
tx
,
_
:=
types
.
SignNewTx
(
benchRootKey
,
signer
,
&
types
.
LegacyTx
{
Nonce
:
gen
.
TxNonce
(
benchRootAddr
),
To
:
&
toaddr
,
Value
:
big
.
NewInt
(
1
),
Gas
:
gas
,
Data
:
data
,
GasPrice
:
gasPrice
,
})
gen
.
AddTx
(
tx
)
}
}
...
...
@@ -110,24 +122,38 @@ func init() {
// and fills the blocks with many small transactions.
func
genTxRing
(
naccounts
int
)
func
(
int
,
*
BlockGen
)
{
from
:=
0
availableFunds
:=
new
(
big
.
Int
)
.
Set
(
benchRootFunds
)
return
func
(
i
int
,
gen
*
BlockGen
)
{
block
:=
gen
.
PrevBlock
(
i
-
1
)
gas
:=
block
.
GasLimit
()
gasPrice
:=
big
.
NewInt
(
0
)
if
gen
.
header
.
BaseFee
!=
nil
{
gasPrice
=
gen
.
header
.
BaseFee
}
signer
:=
types
.
MakeSigner
(
gen
.
config
,
big
.
NewInt
(
int64
(
i
)))
for
{
gas
-=
params
.
TxGas
if
gas
<
params
.
TxGas
{
break
}
to
:=
(
from
+
1
)
%
naccounts
tx
:=
types
.
NewTransaction
(
gen
.
TxNonce
(
ringAddrs
[
from
]),
ringAddrs
[
to
],
benchRootFunds
,
params
.
TxGas
,
nil
,
nil
,
)
tx
,
_
=
types
.
SignTx
(
tx
,
types
.
HomesteadSigner
{},
ringKeys
[
from
])
burn
:=
new
(
big
.
Int
)
.
SetUint64
(
params
.
TxGas
)
burn
.
Mul
(
burn
,
gen
.
header
.
BaseFee
)
availableFunds
.
Sub
(
availableFunds
,
burn
)
if
availableFunds
.
Cmp
(
big
.
NewInt
(
1
))
<
0
{
panic
(
"not enough funds"
)
}
tx
,
err
:=
types
.
SignNewTx
(
ringKeys
[
from
],
signer
,
&
types
.
LegacyTx
{
Nonce
:
gen
.
TxNonce
(
ringAddrs
[
from
]),
To
:
&
ringAddrs
[
to
],
Value
:
availableFunds
,
Gas
:
params
.
TxGas
,
GasPrice
:
gasPrice
,
})
if
err
!=
nil
{
panic
(
err
)
}
gen
.
AddTx
(
tx
)
from
=
to
}
...
...
@@ -245,6 +271,7 @@ func makeChainForBench(db ethdb.Database, full bool, count uint64) {
block
:=
types
.
NewBlockWithHeader
(
header
)
rawdb
.
WriteBody
(
db
,
hash
,
n
,
block
.
Body
())
rawdb
.
WriteReceipts
(
db
,
hash
,
n
,
nil
)
rawdb
.
WriteHeadBlockHash
(
db
,
hash
)
}
}
}
...
...
@@ -278,6 +305,8 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
}
makeChainForBench
(
db
,
full
,
count
)
db
.
Close
()
cacheConfig
:=
*
defaultCacheConfig
cacheConfig
.
TrieDirtyDisabled
=
true
b
.
ReportAllocs
()
b
.
ResetTimer
()
...
...
@@ -287,7 +316,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
if
err
!=
nil
{
b
.
Fatalf
(
"error opening database at %v: %v"
,
dir
,
err
)
}
chain
,
err
:=
NewBlockChain
(
db
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{},
nil
,
nil
)
chain
,
err
:=
NewBlockChain
(
db
,
&
cacheConfig
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{},
nil
,
nil
)
if
err
!=
nil
{
b
.
Fatalf
(
"error creating chain: %v"
,
err
)
}
...
...
core/blockchain_test.go
View file @
eab4d898
...
...
@@ -2385,7 +2385,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
for
txi
:=
0
;
txi
<
numTxs
;
txi
++
{
uniq
:=
uint64
(
i
*
numTxs
+
txi
)
recipient
:=
recipientFn
(
uniq
)
tx
,
err
:=
types
.
SignTx
(
types
.
NewTransaction
(
uniq
,
recipient
,
big
.
NewInt
(
1
),
params
.
TxGas
,
b
ig
.
NewInt
(
1
)
,
nil
),
signer
,
testBankKey
)
tx
,
err
:=
types
.
SignTx
(
types
.
NewTransaction
(
uniq
,
recipient
,
big
.
NewInt
(
1
),
params
.
TxGas
,
b
lock
.
header
.
BaseFee
,
nil
),
signer
,
testBankKey
)
if
err
!=
nil
{
b
.
Error
(
err
)
}
...
...
core/rlp_test.go
View file @
eab4d898
...
...
@@ -40,7 +40,7 @@ func getBlock(transactions int, uncles int, dataSize int) *types.Block {
// A sender who makes transactions, has some funds
key
,
_
=
crypto
.
HexToECDSA
(
"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
)
address
=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
funds
=
big
.
NewInt
(
1
000000000000
000
)
funds
=
big
.
NewInt
(
1
_000_000_000_000_000_
000
)
gspec
=
&
Genesis
{
Config
:
params
.
TestChainConfig
,
Alloc
:
GenesisAlloc
{
address
:
{
Balance
:
funds
}},
...
...
core/tx_list_test.go
View file @
eab4d898
...
...
@@ -51,7 +51,7 @@ func TestStrictTxListAdd(t *testing.T) {
}
}
func
BenchmarkTxListAdd
(
t
*
testing
.
B
)
{
func
BenchmarkTxListAdd
(
b
*
testing
.
B
)
{
// Generate a list of transactions to insert
key
,
_
:=
crypto
.
GenerateKey
()
...
...
@@ -60,11 +60,13 @@ func BenchmarkTxListAdd(t *testing.B) {
txs
[
i
]
=
transaction
(
uint64
(
i
),
0
,
key
)
}
// Insert the transactions in a random order
list
:=
newTxList
(
true
)
priceLimit
:=
big
.
NewInt
(
int64
(
DefaultTxPoolConfig
.
PriceLimit
))
t
.
ResetTimer
()
for
_
,
v
:=
range
rand
.
Perm
(
len
(
txs
))
{
list
.
Add
(
txs
[
v
],
DefaultTxPoolConfig
.
PriceBump
)
list
.
Filter
(
priceLimit
,
DefaultTxPoolConfig
.
PriceBump
)
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
list
:=
newTxList
(
true
)
for
_
,
v
:=
range
rand
.
Perm
(
len
(
txs
))
{
list
.
Add
(
txs
[
v
],
DefaultTxPoolConfig
.
PriceBump
)
list
.
Filter
(
priceLimit
,
DefaultTxPoolConfig
.
PriceBump
)
}
}
}
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