Skip to content

Commit c8ce494

Browse files
committed
fix bugs
1 parent 3d5f5ca commit c8ce494

File tree

17 files changed

+841
-130
lines changed

17 files changed

+841
-130
lines changed

app/app.go

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import (
124124
"github.com/sei-protocol/sei-chain/x/evm"
125125
evmante "github.com/sei-protocol/sei-chain/x/evm/ante"
126126
"github.com/sei-protocol/sei-chain/x/evm/blocktest"
127+
evmconfig "github.com/sei-protocol/sei-chain/x/evm/config"
127128
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
128129
"github.com/sei-protocol/sei-chain/x/evm/querier"
129130
"github.com/sei-protocol/sei-chain/x/evm/replay"
@@ -263,8 +264,11 @@ var (
263264
// EnableOCC allows tests to override default OCC enablement behavior
264265
EnableOCC = true
265266
// EnablePipelineProcessing enables the new pipeline-based block processing path
266-
EnablePipelineProcessing = true
267+
EnablePipelineProcessing = false
267268
EmptyAppOptions []AppOption
269+
270+
// EnableBenchmarkMode enables benchmark mode using sei-load generator
271+
EnableBenchmarkMode = false
268272
)
269273

270274
var (
@@ -397,6 +401,10 @@ type App struct {
397401

398402
// Pipeline processing (if enabled)
399403
blockPipeline *BlockPipeline
404+
405+
// Benchmark mode - generator channel for load testing
406+
benchmarkGeneratorCh <-chan *abci.ResponsePrepareProposal
407+
enableBenchmarkMode bool
400408
}
401409

402410
type AppOption func(*App)
@@ -466,6 +474,7 @@ func New(
466474
stateStore: stateStore,
467475
httpServerStartSignal: make(chan struct{}, 1),
468476
wsServerStartSignal: make(chan struct{}, 1),
477+
enableBenchmarkMode: EnableBenchmarkMode,
469478
}
470479

471480
for _, option := range appOptions {
@@ -921,7 +930,11 @@ func New(
921930
app.SetAnteDepGenerator(anteDepGenerator)
922931
app.SetMidBlocker(app.MidBlocker)
923932
app.SetEndBlocker(app.EndBlocker)
924-
app.SetPrepareProposalHandler(app.PrepareProposalHandler)
933+
if app.enableBenchmarkMode {
934+
app.SetPrepareProposalHandler(app.PrepareProposalGeneratorHandler)
935+
} else {
936+
app.SetPrepareProposalHandler(app.PrepareProposalHandler)
937+
}
925938
app.SetProcessProposalHandler(app.ProcessProposalHandler)
926939
app.SetFinalizeBlocker(app.FinalizeBlocker)
927940
app.SetInplaceTestnetInitializer(app.inplacetestnetInitializer)
@@ -996,7 +1009,7 @@ func New(
9961009
PreprocessBlock,
9971010
ExecutePreprocessedEVMTransaction,
9981011
ExecuteCosmosTransaction,
999-
10, // preprocessorWorkers
1012+
25, // preprocessorWorkers
10001013
1000, // bufferSize
10011014
1, // startSequence
10021015
)
@@ -1008,6 +1021,20 @@ func New(
10081021
logger.Info("Using legacy block processing", "mode", "legacy")
10091022
}
10101023

1024+
// Initialize benchmark generator if enabled
1025+
if app.enableBenchmarkMode {
1026+
logger.Info("Initializing benchmark mode generator", "mode", "benchmark")
1027+
genCtx := context.Background()
1028+
// Get EVM chain ID from config mapping (not Cosmos chain ID)
1029+
evmChainID := evmconfig.GetEVMChainID(app.ChainID).Int64()
1030+
// Use a reasonable default for MaxTxBytes (20MB - conservative estimate)
1031+
// The generator will filter transactions to fit within this limit
1032+
// Tendermint will still validate the final proposal doesn't exceed req.MaxTxBytes
1033+
defaultMaxTxBytes := int64(20 * 1024 * 1024) // 20MB
1034+
app.benchmarkGeneratorCh = NewGeneratorCh(genCtx, app.encodingConfig.TxConfig, evmChainID, defaultMaxTxBytes, logger)
1035+
logger.Info("Benchmark generator initialized and started", "maxTxBytes", defaultMaxTxBytes)
1036+
}
1037+
10111038
return app
10121039
}
10131040

@@ -1147,6 +1174,25 @@ func (app *App) PrepareProposalHandler(_ sdk.Context, req *abci.RequestPreparePr
11471174
}, nil
11481175
}
11491176

1177+
func (app *App) PrepareProposalGeneratorHandler(_ sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
1178+
// Pull from generator channel - the generator has already filtered transactions by size
1179+
select {
1180+
case proposal, ok := <-app.benchmarkGeneratorCh:
1181+
if proposal == nil || !ok {
1182+
// Channel closed or no proposal available, return empty (req.Txs will remain in mempool)
1183+
return &abci.ResponsePrepareProposal{
1184+
TxRecords: []*abci.TxRecord{},
1185+
}, nil
1186+
}
1187+
return proposal, nil
1188+
default:
1189+
// No proposal ready yet, return empty (req.Txs will remain in mempool)
1190+
return &abci.ResponsePrepareProposal{
1191+
TxRecords: []*abci.TxRecord{},
1192+
}, nil
1193+
}
1194+
}
1195+
11501196
func (app *App) GetOptimisticProcessingInfo() OptimisticProcessingInfo {
11511197
app.optimisticProcessingInfoMutex.RLock()
11521198
defer app.optimisticProcessingInfoMutex.RUnlock()
@@ -1266,6 +1312,12 @@ func (app *App) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock)
12661312
return nil, fmt.Errorf("timeout waiting for pipeline result")
12671313
}
12681314

1315+
// Check if preprocessing failed
1316+
if processed.ExecutedBlock.PreprocessedBlock.PreprocessError != nil {
1317+
ctx.Logger().Error("Pipeline preprocessing failed", "error", processed.ExecutedBlock.PreprocessedBlock.PreprocessError, "height", req.Height)
1318+
return nil, fmt.Errorf("pipeline preprocessing failed: %w", processed.ExecutedBlock.PreprocessedBlock.PreprocessError)
1319+
}
1320+
12691321
// Verify we got the correct block
12701322
if processed.ExecutedBlock.PreprocessedBlock.Height != req.Height {
12711323
ctx.Logger().Error("Pipeline returned wrong block", "expected", req.Height, "got", processed.ExecutedBlock.PreprocessedBlock.Height)

app/execution.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ func ExecutePreprocessedEVMTransaction(ctx sdk.Context, preprocessed *pipelinety
128128
vmError = result.Err.Error()
129129
}
130130

131+
// Write receipt and deferred info during execution (needed for EndBlock)
132+
// Set TxIndex in context - this is critical for deferred info storage
133+
execCtx := ctx.WithTxIndex(preprocessed.TxIndex)
134+
135+
// Write receipt (needed for deferred info bloom)
136+
receipt, err := helper.GetKeeper().WriteReceipt(execCtx, stateDB, preprocessed.EVMMessage, uint32(etx.Type()), etx.Hash(), result.UsedGas, vmError)
137+
if err != nil {
138+
return &pipelinetypes.TransactionResult{
139+
Code: sdkerrors.ErrInvalidRequest.ABCICode(),
140+
Codespace: sdkerrors.RootCodespace,
141+
Log: fmt.Sprintf("failed to write receipt: %s", err.Error()),
142+
Surplus: sdk.ZeroInt(),
143+
}, fmt.Errorf("failed to write receipt: %w", err)
144+
}
145+
146+
// Write deferred info (needed for EndBlock)
147+
bloom := ethtypes.Bloom{}
148+
bloom.SetBytes(receipt.LogsBloom)
149+
helper.GetKeeper().AppendToEvmTxDeferredInfo(execCtx, bloom, etx.Hash(), surplus)
150+
131151
return &pipelinetypes.TransactionResult{
132152
GasUsed: int64(result.UsedGas), //nolint:gosec // GasUsed is bounded by block gas limit
133153
ReturnData: result.ReturnData,

app/generator.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package app
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/cosmos/cosmos-sdk/client"
8+
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
9+
"github.com/sei-protocol/sei-chain/x/evm/types/ethtx"
10+
"github.com/sei-protocol/sei-load/config"
11+
"github.com/sei-protocol/sei-load/generator"
12+
"github.com/sei-protocol/sei-load/generator/scenarios"
13+
abci "github.com/tendermint/tendermint/abci/types"
14+
"github.com/tendermint/tendermint/libs/log"
15+
)
16+
17+
func NewGeneratorCh(ctx context.Context, txConfig client.TxConfig, chainID int64, maxTxBytes int64, logger log.Logger) <-chan *abci.ResponsePrepareProposal {
18+
gen, err := generator.NewConfigBasedGenerator(&config.LoadConfig{
19+
ChainID: chainID,
20+
SeiChainID: fmt.Sprintf("%d", chainID), // Use chainID as string for SeiChainID
21+
Accounts: &config.AccountConfig{Accounts: 5000},
22+
Scenarios: []config.Scenario{{
23+
Name: scenarios.EVMTransfer,
24+
Weight: 1,
25+
}},
26+
})
27+
if err != nil {
28+
panic("failed to initialize generator: " + err.Error())
29+
}
30+
ch := make(chan *abci.ResponsePrepareProposal, 1000)
31+
go func() {
32+
defer close(ch)
33+
var height int64
34+
for {
35+
// bail on ctx err
36+
if ctx.Err() != nil {
37+
return
38+
}
39+
// generate txs like: txs := gen.GenerateN(1000)
40+
loadTxs := gen.GenerateN(1000)
41+
if len(loadTxs) == 0 {
42+
continue
43+
}
44+
45+
// Convert LoadTx to Cosmos SDK transaction bytes and filter by size
46+
var totalBytes int64
47+
txRecords := make([]*abci.TxRecord, 0, len(loadTxs))
48+
for _, loadTx := range loadTxs {
49+
if loadTx.EthTx == nil {
50+
continue
51+
}
52+
53+
// Convert Ethereum transaction to Cosmos SDK format
54+
txData, err := ethtx.NewTxDataFromTx(loadTx.EthTx)
55+
if err != nil {
56+
logger.Error("failed to convert eth tx to tx data", "error", err)
57+
continue
58+
}
59+
60+
msg, err := evmtypes.NewMsgEVMTransaction(txData)
61+
if err != nil {
62+
logger.Error("failed to create msg evm transaction", "error", err)
63+
continue
64+
}
65+
66+
gasUsedEstimate := loadTx.EthTx.Gas() // Use gas limit from transaction
67+
68+
txBuilder := txConfig.NewTxBuilder()
69+
if err = txBuilder.SetMsgs(msg); err != nil {
70+
logger.Error("failed to set msgs", "error", err)
71+
continue
72+
}
73+
txBuilder.SetGasEstimate(gasUsedEstimate)
74+
75+
txbz, encodeErr := txConfig.TxEncoder()(txBuilder.GetTx())
76+
if encodeErr != nil {
77+
logger.Error("failed to encode tx", "error", encodeErr)
78+
continue
79+
}
80+
81+
// Filter by MaxTxBytes - stop adding transactions if we exceed the limit
82+
txSize := int64(len(txbz))
83+
if totalBytes+txSize > maxTxBytes {
84+
break
85+
}
86+
totalBytes += txSize
87+
88+
txRecords = append(txRecords, &abci.TxRecord{
89+
Action: abci.TxRecord_GENERATED,
90+
Tx: txbz,
91+
})
92+
}
93+
94+
if len(txRecords) == 0 {
95+
continue
96+
}
97+
98+
proposal := &abci.ResponsePrepareProposal{
99+
TxRecords: txRecords,
100+
}
101+
102+
height++
103+
fmt.Println("Generating Block ", height)
104+
select {
105+
case ch <- proposal:
106+
case <-ctx.Done():
107+
return
108+
}
109+
}
110+
}()
111+
return ch
112+
}

0 commit comments

Comments
 (0)