@@ -2,32 +2,16 @@ package blockstm
22
33import (
44 "context"
5- "errors"
65 "fmt"
7- "runtime"
86 "strconv"
97 "sync/atomic"
108 "testing"
119
1210 "github.com/test-go/testify/require"
13- "golang.org/x/sync/errgroup"
1411
1512 storetypes "cosmossdk.io/store/types"
1613)
1714
18- func executeBlock (stores map [storetypes.StoreKey ]int , storage MultiStore , worker int , block * MockBlock ) error {
19- incarnationCache := make ([]atomic.Pointer [map [string ]any ], block .Size ())
20- for i := 0 ; i < block .Size (); i ++ {
21- m := make (map [string ]any )
22- incarnationCache [i ].Store (& m )
23- }
24- return ExecuteBlock (context .Background (), block .Size (), stores , storage , worker , func (txn TxnIndex , store MultiStore ) {
25- cache := incarnationCache [txn ].Swap (nil )
26- block .ExecuteTx (txn , store , * cache )
27- incarnationCache [txn ].Store (cache )
28- })
29- }
30-
3115func BenchmarkBlockSTM (b * testing.B ) {
3216 stores := map [storetypes.StoreKey ]int {StoreKeyAuth : 0 , StoreKeyBank : 1 }
3317 for i := 0 ; i < 26 ; i ++ {
@@ -92,17 +76,19 @@ func BenchmarkBlockSTM(b *testing.B) {
9276 b .ResetTimer ()
9377 var executedTotal , validatedTotal uint64
9478 for i := 0 ; i < b .N ; i ++ {
95- executed , validated , err := executeBlockForBench (
79+ executed , validated , err := executeBlockWithEstimatesImpl (
9680 context .Background (),
9781 tc .block .Size (),
9882 stores ,
9983 storage ,
10084 worker ,
85+ nil ,
10186 func (txn TxnIndex , store MultiStore ) {
10287 cache := incarnationCache [txn ].Swap (nil )
10388 tc .block .ExecuteTx (txn , store , * cache )
10489 incarnationCache [txn ].Store (cache )
10590 },
91+ false ,
10692 )
10793 require .NoError (b , err )
10894 executedTotal += executed
@@ -148,47 +134,6 @@ func iterateNewKeysBlock(size int) *MockBlock {
148134 return NewMockBlock (txs )
149135}
150136
151- // executeBlockForBench is a benchmark-only variant of ExecuteBlockWithEstimates that
152- // exposes scheduler counters (executed / validated) without emitting telemetry.
153- func executeBlockForBench (
154- ctx context.Context ,
155- blockSize int ,
156- stores map [storetypes.StoreKey ]int ,
157- storage MultiStore ,
158- executors int ,
159- txExecutor TxExecutor ,
160- ) (executed , validated uint64 , err error ) {
161- if executors < 0 {
162- return 0 , 0 , fmt .Errorf ("invalid number of executors: %d" , executors )
163- }
164- if executors == 0 {
165- executors = min (runtime .GOMAXPROCS (0 ), runtime .NumCPU ())
166- }
167-
168- scheduler := NewScheduler (blockSize )
169- mvMemory := NewMVMemory (blockSize , stores , storage , scheduler )
170-
171- var wg errgroup.Group
172- wg .SetLimit (executors )
173- for i := 0 ; i < executors ; i ++ {
174- e := NewExecutor (ctx , scheduler , txExecutor , mvMemory , i )
175- wg .Go (e .Run )
176- }
177- if err := wg .Wait (); err != nil {
178- return 0 , 0 , err
179- }
180-
181- if ! scheduler .Done () {
182- if ctx .Err () != nil {
183- return 0 , 0 , ctx .Err ()
184- }
185- return 0 , 0 , errors .New ("scheduler did not complete" )
186- }
187-
188- mvMemory .WriteSnapshot (storage )
189- return uint64 (scheduler .executedTxns .Load ()), uint64 (scheduler .validatedTxns .Load ()), nil
190- }
191-
192137func runSequential (storage MultiStore , block * MockBlock ) {
193138 for i , tx := range block .Txs {
194139 block .Results [i ] = tx (storage , nil )
0 commit comments