diff --git a/conf/config.toml b/conf/config.toml index f72c446..874e196 100644 --- a/conf/config.toml +++ b/conf/config.toml @@ -2,5 +2,4 @@ isParallel = false enableAsyncCommit = false maxConcurrency = 4 isBenchmarkMode = true -ignoreConflict = false extraBalanceGas = 0 \ No newline at end of file diff --git a/config/config.go b/config/config.go index 1c9698f..4adf32e 100644 --- a/config/config.go +++ b/config/config.go @@ -8,17 +8,11 @@ import ( ) type Config struct { - IsParallel bool `yaml:"isParallel"` - MaxConcurrency int `yaml:"maxConcurrency"` - IsBenchmarkMode bool `yaml:"isBenchmarkMode"` - AsyncCommit bool `yaml:"asyncCommit"` - IgnoreConflict bool `yaml:"ignoreConflict"` - RateLimitConfig RateLimitConfig `yaml:"rateLimitConfig"` - ExtraBalanceGas uint64 `yaml:"extraBalanceGas"` -} - -type RateLimitConfig struct { - GetReceipt int64 `yaml:"getReceipt"` + IsParallel bool `yaml:"isParallel"` + MaxConcurrency int `yaml:"maxConcurrency"` + IsBenchmarkMode bool `yaml:"isBenchmarkMode"` + AsyncCommit bool `yaml:"asyncCommit"` + ExtraBalanceGas uint64 `yaml:"extraBalanceGas"` } func defaultConfig() *Config { @@ -26,9 +20,6 @@ func defaultConfig() *Config { AsyncCommit: false, IsParallel: true, MaxConcurrency: runtime.NumCPU(), - RateLimitConfig: RateLimitConfig{ - GetReceipt: 2000, - }, } } diff --git a/evm/eth.go b/evm/eth.go index 42ddec1..cc2b8c1 100644 --- a/evm/eth.go +++ b/evm/eth.go @@ -61,24 +61,12 @@ type Solidity struct { coinbaseReward atomic.Uint64 } -func (s *Solidity) StateDB() *state.StateDB { - s.Lock() - defer s.Unlock() - return s.ethState.StateDB() -} - func (s *Solidity) StateDBCopy() *state.StateDB { s.Lock() defer s.Unlock() return s.ethState.StateDB().Copy() } -func (s *Solidity) GetStateDBState(addr common.Address, hash common.Hash) common.Hash { - s.Lock() - defer s.Unlock() - return s.ethState.StateDB().GetState(addr, hash) -} - func (s *Solidity) SetStateDB(d *state.StateDB) { s.Lock() defer s.Unlock() @@ -200,10 +188,8 @@ func NewSolidity(gethConfig *GethConfig) *Solidity { func (s *Solidity) StartBlock(block *yu_types.Block) { metrics.SolidityCounter.WithLabelValues(startBlockLbl, statusSuccess).Inc() - s.Lock() start := time.Now() defer func() { - s.Unlock() metrics.SolidityHist.WithLabelValues(startBlockLbl).Observe(float64(time.Since(start).Microseconds())) }() s.cfg.BlockNumber = big.NewInt(int64(block.Height)) @@ -267,10 +253,8 @@ func (s *Solidity) CheckGasfee(req *TxRequest) error { // Execute sets up an in-memory, temporary, environment for the execution of // the given code. It makes sure that it's restored to its original state afterwards. func (s *Solidity) ExecuteTxn(ctx *context.WriteContext) (err error) { - s.Lock() start := time.Now() defer func() { - s.Unlock() metrics.SolidityHist.WithLabelValues(executeTxnLbl).Observe(float64(time.Since(start).Microseconds())) if err == nil { metrics.SolidityCounter.WithLabelValues(executeTxnLbl, statusSuccess).Inc() diff --git a/parallel/evm_process.go b/parallel/evm_process.go index 176fdb9..82a20b8 100644 --- a/parallel/evm_process.go +++ b/parallel/evm_process.go @@ -25,7 +25,7 @@ const ( type ParallelEVM struct { *tripod.Tripod - db *state.StateDB + cpdb *state.StateDB Solidity *evm.Solidity `tripod:"solidity"` statManager *BlockTxnStatManager objectInc map[common2.Address]int @@ -49,7 +49,7 @@ func (k *ParallelEVM) setupProcessor() { func (k *ParallelEVM) Execute(block *types.Block) error { k.statManager = &BlockTxnStatManager{TxnCount: len(block.Txns)} - k.db = k.Solidity.StateDB() + k.cpdb = k.Solidity.StateDBCopy() k.setupProcessor() start := time.Now() defer func() { @@ -58,6 +58,7 @@ func (k *ParallelEVM) Execute(block *types.Block) error { }() k.processor.Prepare(block) k.processor.Execute(block) + k.Solidity.SetStateDB(k.cpdb) receipts := k.processor.Receipts(block) return k.Commit(block, receipts) } diff --git a/parallel/parallel_evm.go b/parallel/parallel_evm.go index e095d90..40c1e79 100644 --- a/parallel/parallel_evm.go +++ b/parallel/parallel_evm.go @@ -35,7 +35,7 @@ func (e *ParallelEvmExecutor) Prepare(block *types.Block) { e.receipts = receipts e.k.updateTxnObjInc(txnCtxList) e.subTxnList = e.splitTxnCtxList(txnCtxList) - e.cpdb = e.k.Solidity.StateDBCopy() + e.cpdb = e.k.cpdb } func (e *ParallelEvmExecutor) Execute(block *types.Block) { @@ -130,7 +130,7 @@ func (e *ParallelEvmExecutor) executeTxnCtxListInConcurrency(list []*txnCtx) []* break } } - if conflict && !config.GetGlobalConfig().IgnoreConflict { + if conflict { e.k.statManager.TxnBatchRedoCount++ metrics.BatchTxnCounter.WithLabelValues(batchTxnLabelRedo).Inc() return e.k.executeTxnCtxListInOrder(e.cpdb, list, true) diff --git a/parallel/serial_evm.go b/parallel/serial_evm.go index 5e95e69..f3d9994 100644 --- a/parallel/serial_evm.go +++ b/parallel/serial_evm.go @@ -23,7 +23,7 @@ type SerialEvmExecutor struct { func NewSerialEvmExecutor(evm *ParallelEVM) *SerialEvmExecutor { return &SerialEvmExecutor{ k: evm, - db: evm.db, + db: evm.cpdb, } } diff --git a/test/testx/config.go b/test/testx/config.go index 8c8900c..534f602 100644 --- a/test/testx/config.go +++ b/test/testx/config.go @@ -16,7 +16,6 @@ func GenerateConfig(yuConfigPath, evmConfigPath, poaConfigPath string, isParalle config.IsBenchmarkMode = true config.IsParallel = isParallel config.AsyncCommit = false - config.RateLimitConfig.GetReceipt = 0 poaCfg = poa.LoadCfgFromPath(poaConfigPath) return yuCfg, poaCfg, evmConfig, config } diff --git a/utils/ratelimit.go b/utils/ratelimit.go deleted file mode 100644 index 7580cfb..0000000 --- a/utils/ratelimit.go +++ /dev/null @@ -1,26 +0,0 @@ -package utils - -import ( - "github.com/sirupsen/logrus" - "golang.org/x/time/rate" - - "github.com/reddio-com/reddio/config" -) - -var ( - GetReceiptRateLimiter *rate.Limiter -) - -func IniLimiter() { - GetReceiptRateLimiter = GenGetReceiptRateLimiter() - logrus.Infof("GetReceipt Limit %v qps", config.GetGlobalConfig().RateLimitConfig.GetReceipt) -} - -func GenGetReceiptRateLimiter() *rate.Limiter { - qps := config.GetGlobalConfig().RateLimitConfig.GetReceipt - if qps < 1 { - return nil - } - limiter := rate.NewLimiter(rate.Limit(qps), 1) - return limiter -}