mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/txpool/blobpool: speed up blobtx creation in benchmark a bit
This commit is contained in:
parent
a1f4b93d9b
commit
991b00d439
1 changed files with 31 additions and 24 deletions
|
|
@ -1301,42 +1301,49 @@ func benchmarkPoolPending(b *testing.B, datacap uint64) {
|
|||
capacity := datacap / params.BlobTxBlobGasPerBlob
|
||||
|
||||
var (
|
||||
keys = make([]*ecdsa.PrivateKey, capacity)
|
||||
addrs = make([]common.Address, capacity)
|
||||
)
|
||||
for i := 0; i < int(capacity); i++ {
|
||||
keys[i], _ = crypto.GenerateKey()
|
||||
addrs[i] = crypto.PubkeyToAddress(keys[i].PublicKey)
|
||||
}
|
||||
// Create the empty blob pool, initialized with the accounts
|
||||
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewDatabase(memorydb.New())), nil)
|
||||
for _, addr := range addrs {
|
||||
statedb.AddBalance(addr, uint256.NewInt(1_000_000_000))
|
||||
}
|
||||
statedb.Commit(0, true)
|
||||
|
||||
chain := &testBlockChain{
|
||||
basefee = uint64(1050)
|
||||
blobfee = uint64(105)
|
||||
signer = types.LatestSigner(testChainConfig)
|
||||
statedb, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewDatabase(memorydb.New())), nil)
|
||||
chain = &testBlockChain{
|
||||
config: testChainConfig,
|
||||
basefee: uint256.NewInt(1050),
|
||||
blobfee: uint256.NewInt(105),
|
||||
basefee: uint256.NewInt(basefee),
|
||||
blobfee: uint256.NewInt(blobfee),
|
||||
statedb: statedb,
|
||||
}
|
||||
pool := New(Config{Datadir: ""}, chain)
|
||||
pool = New(Config{Datadir: ""}, chain)
|
||||
)
|
||||
|
||||
if err := pool.Init(1, chain.CurrentBlock(), makeAddressReserver()); err != nil {
|
||||
b.Fatalf("failed to create blob pool: %v", err)
|
||||
}
|
||||
defer pool.Close()
|
||||
|
||||
// Fill the pool up with one random transaction from each account with the
|
||||
// same price and everything to maximize the worst case scenario
|
||||
for _, key := range keys {
|
||||
pool.add(makeTx(0, 10, chain.basefee.Uint64()+10, chain.blobfee.Uint64(), key))
|
||||
for i := 0; i < int(capacity); i++ {
|
||||
blobtx := makeUnsignedTx(0, 10, basefee+10, blobfee)
|
||||
blobtx.R = uint256.NewInt(1)
|
||||
blobtx.S = uint256.NewInt(uint64(100 + i))
|
||||
blobtx.V = uint256.NewInt(0)
|
||||
tx := types.NewTx(blobtx)
|
||||
addr, err := types.Sender(signer, tx)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
statedb.AddBalance(addr, uint256.NewInt(1_000_000_000))
|
||||
pool.add(tx)
|
||||
}
|
||||
statedb.Commit(0, true)
|
||||
defer pool.Close()
|
||||
|
||||
// Benchmark assembling the pending
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
pool.Pending(uint256.NewInt(1), chain.basefee, chain.blobfee)
|
||||
p := pool.Pending(uint256.NewInt(1), chain.basefee, chain.blobfee)
|
||||
if len(p) != int(capacity) {
|
||||
b.Fatalf("have %d want %d", len(p), capacity)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue