-
Notifications
You must be signed in to change notification settings - Fork 879
Expand file tree
/
Copy pathbenchmark.go
More file actions
103 lines (87 loc) · 3.31 KB
/
benchmark.go
File metadata and controls
103 lines (87 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Package benchmark provides transaction generation capabilities for benchmarking.
//
// The benchmark system operates in two phases:
//
// 1. Setup Phase: Deploys any contracts required by the configured scenarios.
// During this phase, deployment transactions are generated and submitted.
// After each block, receipts are checked to extract deployed contract addresses.
//
// 2. Load Phase: Once all contracts are deployed, the system transitions to
// generating load transactions according to the configured scenario weights.
//
// Usage:
//
// cfg, _ := benchmark.LoadConfig(configPath, evmChainID, seiChainID)
// gen, _ := benchmark.NewGenerator(cfg, txConfig, logger)
// benchLogger := benchmark.NewLogger(logger)
// proposalCh := gen.StartProposalChannel(ctx, benchLogger)
//
// The generator can be configured via JSON config files that follow the sei-load
// LoadConfig format. See scripts/scenarios/ for example configurations.
package benchmark
import (
"context"
"os"
"github.com/cosmos/cosmos-sdk/client"
"github.com/ethereum/go-ethereum/common"
abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types"
"github.com/sei-protocol/sei-chain/sei-tendermint/libs/log"
evmcfg "github.com/sei-protocol/sei-chain/x/evm/config"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
)
// Manager coordinates benchmark generation and logging.
type Manager struct {
Generator *Generator
Logger *Logger
proposalCh <-chan *abci.ResponsePrepareProposal
// ZeroBaseFee overrides blockCtx.BaseFee to zero during tx execution.
ZeroBaseFee bool
}
// NewManager creates a new benchmark manager from configuration.
func NewManager(ctx context.Context, txConfig client.TxConfig, chainID string, evmChainID int64, logger log.Logger) (*Manager, error) {
// Defensive check: prevent benchmarking on live chains
if evmcfg.IsLiveEVMChainID(evmChainID) {
panic("benchmark not allowed on live chains")
}
// Load config from environment variables or use defaults
configPath := os.Getenv("BENCHMARK_CONFIG")
zeroBaseFee := os.Getenv("ZERO_BASE_FEE") == "true"
cfg, err := LoadConfig(configPath, evmChainID, chainID)
if err != nil {
return nil, err
}
gen, err := NewGenerator(cfg, txConfig, logger)
if err != nil {
return nil, err
}
benchLogger := NewLogger(logger)
go benchLogger.Start(ctx)
proposalCh := gen.StartProposalChannel(ctx, benchLogger)
logger.Info("Benchmark manager initialized",
"configPath", configPath,
"scenarios", len(cfg.Scenarios),
"zeroBaseFee", zeroBaseFee,
)
return &Manager{
Generator: gen,
Logger: benchLogger,
proposalCh: proposalCh,
ZeroBaseFee: zeroBaseFee,
}, nil
}
// ProposalChannel returns the channel of prepared proposals.
func (m *Manager) ProposalChannel() <-chan *abci.ResponsePrepareProposal {
return m.proposalCh
}
// ProcessReceipts forwards receipts to the generator for deployment tracking.
func (m *Manager) ProcessReceipts(receipts map[common.Hash]*evmtypes.Receipt) {
m.Generator.ProcessReceipts(receipts)
}
// IsSetupPhase returns true if the benchmark is still in the setup phase.
func (m *Manager) IsSetupPhase() bool {
return m.Generator.IsSetupPhase()
}
// GetPendingDeployHashes returns the hashes of pending deployment transactions.
func (m *Manager) GetPendingDeployHashes() []common.Hash {
return m.Generator.GetPendingDeployHashes()
}