From f7565474badad55d4df64ae9f465d0901043d5d3 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 1 Nov 2023 18:05:13 +0800 Subject: [PATCH 01/15] Use target gas from attributes --- lib/ain-evm/src/block.rs | 14 ++++++-------- lib/ain-evm/src/evm.rs | 4 +++- lib/ain-grpc/src/rpc/debug.rs | 2 +- lib/ain-rs-exports/src/evm.rs | 2 +- test/functional/feature_evm.py | 21 +++++++++++++++++++++ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/ain-evm/src/block.rs b/lib/ain-evm/src/block.rs index f97c9a70a8..370ef98c50 100644 --- a/lib/ain-evm/src/block.rs +++ b/lib/ain-evm/src/block.rs @@ -3,6 +3,7 @@ use std::{ sync::Arc, }; +use ain_cpp_imports::get_attribute_defaults; use anyhow::format_err; use ethereum::{BlockAny, TransactionAny}; use ethereum_types::U256; @@ -146,10 +147,9 @@ impl BlockService { ) } - pub fn calculate_base_fee(&self, parent_hash: H256) -> Result { + pub fn calculate_base_fee(&self, parent_hash: H256, mnview_ptr: Option) -> Result { // constants let base_fee_max_change_denominator = U256::from(8); - let elasticity_multiplier = U256::from(2); // first block has 1 gwei base fee if parent_hash == H256::zero() { @@ -164,9 +164,7 @@ impl BlockService { .ok_or(format_err!("Parent block not found"))?; let parent_base_fee = parent_block.header.base_fee; let parent_gas_used = u64::try_from(parent_block.header.gas_used)?; - let parent_gas_target = - u64::try_from(parent_block.header.gas_limit / elasticity_multiplier)?; // safe to use normal division since we know elasticity_multiplier is non-zero - + let parent_gas_target = get_attribute_defaults(mnview_ptr).block_gas_target; // TODO: this is using the current target but it should be using the target from the previous block self.get_base_fee( parent_gas_used, parent_gas_target, @@ -184,7 +182,7 @@ impl BlockService { Some((hash, _)) => hash, }; - self.calculate_base_fee(current_block_hash) + self.calculate_base_fee(current_block_hash, None) } pub fn fee_history( @@ -297,9 +295,9 @@ impl BlockService { .storage .get_block_by_number(&first_block)? .ok_or_else(|| format_err!("Block {} out of range", first_block))?; - self.calculate_base_fee(block.header.hash())? + self.calculate_base_fee(block.header.hash(), None)? } - Some(block) => self.calculate_base_fee(block.header.hash())?, + Some(block) => self.calculate_base_fee(block.header.hash(), None)?, }; base_fee_per_gas.reverse(); diff --git a/lib/ain-evm/src/evm.rs b/lib/ain-evm/src/evm.rs index c0c746df90..beeb3dc21b 100644 --- a/lib/ain-evm/src/evm.rs +++ b/lib/ain-evm/src/evm.rs @@ -482,7 +482,9 @@ impl EVMServices { .block .get_latest_block_hash_and_number()? .unwrap_or_default(); // Safe since calculate_base_fee will default to INITIAL_BASE_FEE - let block_base_fee_per_gas = self.block.calculate_base_fee(parent_hash)?; + let block_base_fee_per_gas = self + .block + .calculate_base_fee(parent_hash, Some(mnview_ptr))?; let block_gas_limit = U256::from(ain_cpp_imports::get_attribute_defaults(Some(mnview_ptr)).block_gas_limit); diff --git a/lib/ain-grpc/src/rpc/debug.rs b/lib/ain-grpc/src/rpc/debug.rs index e2f0d400ae..9252602a85 100644 --- a/lib/ain-grpc/src/rpc/debug.rs +++ b/lib/ain-grpc/src/rpc/debug.rs @@ -199,7 +199,7 @@ impl MetachainDebugRPCServer for MetachainDebugRPCModule { let block_base_fee = self .handler .block - .calculate_base_fee(block_hash) + .calculate_base_fee(block_hash, None) .map_err(to_custom_err)?; let gas_price = call.get_effective_gas_price(block_base_fee)?; diff --git a/lib/ain-rs-exports/src/evm.rs b/lib/ain-rs-exports/src/evm.rs index d0be6d7c88..524d5019d6 100644 --- a/lib/ain-rs-exports/src/evm.rs +++ b/lib/ain-rs-exports/src/evm.rs @@ -853,7 +853,7 @@ fn evm_try_get_tx_miner_info_from_raw_tx(raw_tx: &str) -> Result { .try_get_or_create(raw_tx)?; let nonce = u64::try_from(signed_tx.nonce())?; - let initial_base_fee = SERVICES.evm.block.calculate_base_fee(H256::zero())?; + let initial_base_fee = SERVICES.evm.block.calculate_base_fee(H256::zero(), None)?; let tip_fee = calculate_max_tip_gas_fee(&signed_tx, initial_base_fee)?; let min_rbf_tip_fee = calculate_min_rbf_tip_gas_fee(&signed_tx, tip_fee)?; diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index 2a2bb126a7..284137b38a 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -1532,6 +1532,25 @@ def test_attributes_update(self): block = self.nodes[0].eth_getBlockByNumber("latest") assert_equal(block["gasLimit"], hex(60000000)) + def test_gas_target_update(self): + self.nodes[0].setgov( + { + "ATTRIBUTES": { + "v0/evm/block/gas_target": "10000", + } + } + ) + self.nodes[0].generate(1) + + base_fee = self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] + nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) + self.nodes[0].evmtx(self.eth_address, nonce, 10, 21001, self.to_address, 1) + self.nodes[0].generate(2) # tx takes two blocks to get into block + + assert ( + self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] > base_fee + ) # if base fee increases, it means the gas target was applied successfully + def run_test(self): # Check ERC55 wallet support self.erc55_wallet_support() @@ -1572,6 +1591,8 @@ def run_test(self): # Check attributes values update self.test_attributes_update() + self.test_gas_target_update() + if __name__ == "__main__": EVMTest().main() From 2742a3e26386c49446bc498c56220637ac6550e8 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Wed, 1 Nov 2023 18:10:29 +0800 Subject: [PATCH 02/15] Correct comment --- test/functional/feature_evm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index 284137b38a..4c684f39f4 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -1545,7 +1545,7 @@ def test_gas_target_update(self): base_fee = self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) self.nodes[0].evmtx(self.eth_address, nonce, 10, 21001, self.to_address, 1) - self.nodes[0].generate(2) # tx takes two blocks to get into block + self.nodes[0].generate(2) # base fee increases one block after block with above TX assert ( self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] > base_fee From a5d08ccba081893a04e8c210c226ddb04aed900a Mon Sep 17 00:00:00 2001 From: Bushstar Date: Wed, 1 Nov 2023 11:23:16 +0000 Subject: [PATCH 03/15] Change gas_target to gas_limit_multiplier --- lib/ain-cpp-imports/src/bridge.rs | 2 +- lib/ain-cpp-imports/src/lib.rs | 4 ++-- lib/ain-evm/src/block.rs | 6 ++++-- lib/ain-evm/src/core.rs | 6 +++--- lib/ain-evm/src/evm.rs | 2 +- lib/ain-grpc/src/rpc/debug.rs | 2 +- lib/ain-grpc/src/rpc/eth.rs | 6 +++--- src/dfi/govvariables/attributes.cpp | 24 ++++++++++++++++++------ src/dfi/govvariables/attributes.h | 2 +- src/ffi/ffiexports.cpp | 7 ++++--- src/ffi/ffiexports.h | 6 +++--- test/functional/feature_evm.py | 16 +++++++++------- 12 files changed, 50 insertions(+), 33 deletions(-) diff --git a/lib/ain-cpp-imports/src/bridge.rs b/lib/ain-cpp-imports/src/bridge.rs index 486786c60c..44be5e3c35 100644 --- a/lib/ain-cpp-imports/src/bridge.rs +++ b/lib/ain-cpp-imports/src/bridge.rs @@ -2,7 +2,7 @@ pub mod ffi { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Attributes { - pub block_gas_target: u64, + pub block_gas_limit_multiplier: u64, pub block_gas_limit: u64, pub finality_count: u64, pub rbf_fee_increment: u64, diff --git a/lib/ain-cpp-imports/src/lib.rs b/lib/ain-cpp-imports/src/lib.rs index 2ca7392648..01a38fb55e 100644 --- a/lib/ain-cpp-imports/src/lib.rs +++ b/lib/ain-cpp-imports/src/lib.rs @@ -10,7 +10,7 @@ use bridge::ffi; #[allow(non_snake_case)] mod ffi { pub struct Attributes { - pub block_gas_target: u64, + pub block_gas_limit_multiplier: u64, pub block_gas_limit: u64, pub finality_count: u64, pub rbf_fee_increment: u64, @@ -195,7 +195,7 @@ pub fn get_sync_status() -> Result<(i32, i32), Box> { Ok((current_block as i32, highest_block as i32)) } -pub fn get_attribute_defaults(mnview_ptr: Option) -> ffi::Attributes { +pub fn get_attribute_values(mnview_ptr: Option) -> ffi::Attributes { ffi::getAttributeValues(mnview_ptr.unwrap_or_default()) } diff --git a/lib/ain-evm/src/block.rs b/lib/ain-evm/src/block.rs index 370ef98c50..63aae56737 100644 --- a/lib/ain-evm/src/block.rs +++ b/lib/ain-evm/src/block.rs @@ -3,7 +3,7 @@ use std::{ sync::Arc, }; -use ain_cpp_imports::get_attribute_defaults; +use ain_cpp_imports::get_attribute_values; use anyhow::format_err; use ethereum::{BlockAny, TransactionAny}; use ethereum_types::U256; @@ -150,6 +150,7 @@ impl BlockService { pub fn calculate_base_fee(&self, parent_hash: H256, mnview_ptr: Option) -> Result { // constants let base_fee_max_change_denominator = U256::from(8); + let elasticity_multiplier = get_attribute_values(mnview_ptr).block_gas_limit_multiplier; // first block has 1 gwei base fee if parent_hash == H256::zero() { @@ -164,7 +165,8 @@ impl BlockService { .ok_or(format_err!("Parent block not found"))?; let parent_base_fee = parent_block.header.base_fee; let parent_gas_used = u64::try_from(parent_block.header.gas_used)?; - let parent_gas_target = get_attribute_defaults(mnview_ptr).block_gas_target; // TODO: this is using the current target but it should be using the target from the previous block + let parent_gas_target = + u64::try_from(parent_block.header.gas_limit / elasticity_multiplier)?; // safe to use normal division since we know elasticity_multiplier is non-zero self.get_base_fee( parent_gas_used, parent_gas_target, diff --git a/lib/ain-evm/src/core.rs b/lib/ain-evm/src/core.rs index c394440134..c8b3cdca87 100644 --- a/lib/ain-evm/src/core.rs +++ b/lib/ain-evm/src/core.rs @@ -208,7 +208,7 @@ impl EVMCoreService { genesis_path, )?; - let gas_limit = ain_cpp_imports::get_attribute_defaults(None).block_gas_limit; + let gas_limit = ain_cpp_imports::get_attribute_values(None).block_gas_limit; let block: Block = Block::new( PartialHeader { state_root, @@ -357,7 +357,7 @@ impl EVMCoreService { // Validate gas limit let gas_limit = signed_tx.gas_limit(); - let block_gas_limit = ain_cpp_imports::get_attribute_defaults(None).block_gas_limit; + let block_gas_limit = ain_cpp_imports::get_attribute_values(None).block_gas_limit; if gas_limit > U256::from(block_gas_limit) { debug!("[validate_raw_tx] gas limit higher than max_gas_per_block"); return Err(format_err!("gas limit higher than max_gas_per_block").into()); @@ -931,7 +931,7 @@ impl EVMCoreService { Arc::clone(&self.storage), Vicinity { block_gas_limit: U256::from( - ain_cpp_imports::get_attribute_defaults(None).block_gas_limit, + ain_cpp_imports::get_attribute_values(None).block_gas_limit, ), ..Vicinity::default() }, diff --git a/lib/ain-evm/src/evm.rs b/lib/ain-evm/src/evm.rs index beeb3dc21b..c5a70181c0 100644 --- a/lib/ain-evm/src/evm.rs +++ b/lib/ain-evm/src/evm.rs @@ -487,7 +487,7 @@ impl EVMServices { .calculate_base_fee(parent_hash, Some(mnview_ptr))?; let block_gas_limit = - U256::from(ain_cpp_imports::get_attribute_defaults(Some(mnview_ptr)).block_gas_limit); + U256::from(ain_cpp_imports::get_attribute_values(Some(mnview_ptr)).block_gas_limit); let vicinity = Vicinity { beneficiary, block_number: target_block, diff --git a/lib/ain-grpc/src/rpc/debug.rs b/lib/ain-grpc/src/rpc/debug.rs index 9252602a85..fe74c2dbe3 100644 --- a/lib/ain-grpc/src/rpc/debug.rs +++ b/lib/ain-grpc/src/rpc/debug.rs @@ -191,7 +191,7 @@ impl MetachainDebugRPCServer for MetachainDebugRPCModule { .unwrap_or_default(); // Get gas - let block_gas_limit = ain_cpp_imports::get_attribute_defaults(None).block_gas_limit; + let block_gas_limit = ain_cpp_imports::get_attribute_values(None).block_gas_limit; let gas_limit = u64::try_from(call.gas.unwrap_or(U256::from(block_gas_limit))) .map_err(to_custom_err)?; diff --git a/lib/ain-grpc/src/rpc/eth.rs b/lib/ain-grpc/src/rpc/eth.rs index 6029714d17..32d64bde85 100644 --- a/lib/ain-grpc/src/rpc/eth.rs +++ b/lib/ain-grpc/src/rpc/eth.rs @@ -290,7 +290,7 @@ impl MetachainRPCModule { self.handler.storage.get_latest_block().and_then(|block| { block.map_or(Ok(None), |block| { let finality_count = - ain_cpp_imports::get_attribute_defaults(None).finality_count; + ain_cpp_imports::get_attribute_values(None).finality_count; block .header @@ -319,7 +319,7 @@ impl MetachainRPCServer for MetachainRPCModule { let data = byte_data.0.as_slice(); // Get gas - let block_gas_limit = ain_cpp_imports::get_attribute_defaults(None).block_gas_limit; + let block_gas_limit = ain_cpp_imports::get_attribute_values(None).block_gas_limit; let gas_limit = u64::try_from(call.gas.unwrap_or(U256::from(block_gas_limit))) .map_err(to_custom_err)?; @@ -778,7 +778,7 @@ impl MetachainRPCServer for MetachainRPCModule { let byte_data = call.get_data()?; let data = byte_data.0.as_slice(); - let block_gas_limit = ain_cpp_imports::get_attribute_defaults(None).block_gas_limit; + let block_gas_limit = ain_cpp_imports::get_attribute_values(None).block_gas_limit; let call_gas = u64::try_from(call.gas.unwrap_or(U256::from(block_gas_limit))) .map_err(to_custom_err)?; diff --git a/src/dfi/govvariables/attributes.cpp b/src/dfi/govvariables/attributes.cpp index 79ce79ff3e..055bef3047 100644 --- a/src/dfi/govvariables/attributes.cpp +++ b/src/dfi/govvariables/attributes.cpp @@ -22,7 +22,7 @@ enum class EVMAttributesTypes : uint32_t { Finalized = 1, GasLimit = 2, - GasTarget = 3, + GasLimitMultipler = 3, RbfIncrementMinPct = 4, }; @@ -288,7 +288,7 @@ const std::map> &ATTRIBUTES::allowedKeys { {"finality_count", EVMKeys::Finalized}, {"gas_limit", EVMKeys::GasLimit}, - {"gas_target", EVMKeys::GasTarget}, + {"gas_limit_multiplier", EVMKeys::GasLimitMultipler}, {"rbf_increment_fee_pct", EVMKeys::RbfIncrementMinPct}, }}, {AttributeTypes::Governance, @@ -393,7 +393,7 @@ const std::map> &ATTRIBUTES::displayKeys { {EVMKeys::Finalized, "finality_count"}, {EVMKeys::GasLimit, "gas_limit"}, - {EVMKeys::GasTarget, "gas_target"}, + {EVMKeys::GasLimitMultipler, "gas_limit_multiplier"}, {EVMKeys::RbfIncrementMinPct, "rbf_increment_fee_pct"}, }}, {AttributeTypes::Live, @@ -488,6 +488,18 @@ static ResVal VerifyUInt64(const std::string &str) { return {x, Res::Ok()}; } +static ResVal VerifyMoreThenZeroUInt64(const std::string &str) { + auto resVal = VerifyUInt64(str); + if (!resVal) { + return resVal; + } + const auto value = std::get(*resVal.val); + if (value == 0) { + return DeFiErrors::GovVarVerifyMultiplier(); + } + return resVal; +} + static ResVal VerifyInt64(const std::string &str) { CAmount int64; if (!ParseInt64(str, &int64) || int64 < 0) { @@ -830,7 +842,7 @@ const std::map( { {EVMKeys::Finalized, VerifyUInt64}, {EVMKeys::GasLimit, VerifyUInt64}, - {EVMKeys::GasTarget, VerifyUInt64}, + {EVMKeys::GasLimitMultipler, VerifyMoreThenZeroUInt64}, {EVMKeys::RbfIncrementMinPct, VerifyPctInt64}, }}, {AttributeTypes::Governance, @@ -994,8 +1006,8 @@ static Res CheckValidAttrV0Key(const uint8_t type, const uint32_t typeId, const } } else if (type == AttributeTypes::EVMType) { if (typeId == EVMIDs::Block) { - if (typeKey != EVMKeys::Finalized && typeKey != EVMKeys::GasLimit && typeKey != EVMKeys::GasTarget && - typeKey != EVMKeys::RbfIncrementMinPct) { + if (typeKey != EVMKeys::Finalized && typeKey != EVMKeys::GasLimit && + typeKey != EVMKeys::GasLimitMultipler && typeKey != EVMKeys::RbfIncrementMinPct) { return DeFiErrors::GovVarVariableUnsupportedEVMType(typeKey); } } else { diff --git a/src/dfi/govvariables/attributes.h b/src/dfi/govvariables/attributes.h index 97b02cf266..cd3a00b328 100644 --- a/src/dfi/govvariables/attributes.h +++ b/src/dfi/govvariables/attributes.h @@ -57,7 +57,7 @@ enum EVMIDs : uint8_t { enum EVMKeys : uint8_t { Finalized = 'a', GasLimit = 'b', - GasTarget = 'c', + GasLimitMultipler = 'c', RbfIncrementMinPct = 'd', }; diff --git a/src/ffi/ffiexports.cpp b/src/ffi/ffiexports.cpp index d81ab00118..42660c8717 100644 --- a/src/ffi/ffiexports.cpp +++ b/src/ffi/ffiexports.cpp @@ -283,13 +283,14 @@ Attributes getAttributeValues(std::size_t mnview_ptr) { const auto attributes = view->GetAttributes(); - CDataStructureV0 blockGasTargetKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasTarget}; + CDataStructureV0 blockGasLimitMultiplierKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasLimitMultipler}; CDataStructureV0 blockGasLimitKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasLimit}; CDataStructureV0 finalityCountKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::Finalized}; CDataStructureV0 rbfIncrementMinPctKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::RbfIncrementMinPct}; - if (attributes->CheckKey(blockGasTargetKey)) { - val.blockGasTarget = attributes->GetValue(blockGasTargetKey, DEFAULT_EVM_BLOCK_GAS_TARGET); + if (attributes->CheckKey(blockGasLimitMultiplierKey)) { + val.blockGasLimitMultiplier = + attributes->GetValue(blockGasLimitMultiplierKey, DEFAULT_EVM_BLOCK_GAS_TARGET_MULTIPLIER); } if (attributes->CheckKey(blockGasLimitKey)) { val.blockGasLimit = attributes->GetValue(blockGasLimitKey, DEFAULT_EVM_BLOCK_GAS_LIMIT); diff --git a/src/ffi/ffiexports.h b/src/ffi/ffiexports.h index b541403f4d..ea3e90b6c9 100644 --- a/src/ffi/ffiexports.h +++ b/src/ffi/ffiexports.h @@ -6,7 +6,7 @@ #include // Defaults for attributes relating to EVM functionality -static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_TARGET = 15000000; +static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_TARGET_MULTIPLIER = 15000000; static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_LIMIT = 30000000; static constexpr uint64_t DEFAULT_EVM_FINALITY_COUNT = 100; static constexpr CAmount DEFAULT_EVM_RBF_FEE_INCREMENT = COIN / 10; @@ -19,14 +19,14 @@ static constexpr bool DEFAULT_ETH_DEBUG_ENABLED = false; static constexpr bool DEFAULT_ETH_DEBUG_TRACE_ENABLED = true; struct Attributes { - uint64_t blockGasTarget; + uint64_t blockGasLimitMultiplier; uint64_t blockGasLimit; uint64_t finalityCount; uint64_t rbfIncrementMinPct; static Attributes Default() { return Attributes{ - DEFAULT_EVM_BLOCK_GAS_TARGET, + DEFAULT_EVM_BLOCK_GAS_TARGET_MULTIPLIER, DEFAULT_EVM_BLOCK_GAS_LIMIT, DEFAULT_EVM_FINALITY_COUNT, DEFAULT_EVM_RBF_FEE_INCREMENT, diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index 4c684f39f4..cccaa2d765 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -283,7 +283,7 @@ def evm_gov_vars(self): -32600, "Cannot be set before Metachain", self.nodes[0].setgov, - {"ATTRIBUTES": {"v0/evm/block/gas_target": "100"}}, + {"ATTRIBUTES": {"v0/evm/block/gas_limit_multiplier": "100"}}, ) assert_raises_rpc_error( -32600, @@ -335,7 +335,7 @@ def evm_gov_vars(self): "ATTRIBUTES": { "v0/evm/block/finality_count": "100", "v0/evm/block/gas_limit": "30000000", - "v0/evm/block/gas_target": "15000000", + "v0/evm/block/gas_limit_multiplier": "2", "v0/evm/block/rbf_increment_fee_pct": "0.1", "v0/rules/tx/core_op_return_max_size_bytes": 20000, "v0/rules/tx/evm_op_return_max_size_bytes": 20000, @@ -349,7 +349,7 @@ def evm_gov_vars(self): result = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"] assert_equal(result["v0/evm/block/finality_count"], "100") assert_equal(result["v0/evm/block/gas_limit"], "30000000") - assert_equal(result["v0/evm/block/gas_target"], "15000000") + assert_equal(result["v0/evm/block/gas_limit_multiplier"], "2") assert_equal(result["v0/evm/block/rbf_increment_fee_pct"], "0.1") assert_equal(result["v0/rules/tx/core_op_return_max_size_bytes"], "20000") assert_equal(result["v0/rules/tx/evm_op_return_max_size_bytes"], "20000") @@ -1532,11 +1532,11 @@ def test_attributes_update(self): block = self.nodes[0].eth_getBlockByNumber("latest") assert_equal(block["gasLimit"], hex(60000000)) - def test_gas_target_update(self): + def test_gas_limit_multiplier_update(self): self.nodes[0].setgov( { "ATTRIBUTES": { - "v0/evm/block/gas_target": "10000", + "v0/evm/block/gas_limit_multiplier": "1500", } } ) @@ -1545,7 +1545,9 @@ def test_gas_target_update(self): base_fee = self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) self.nodes[0].evmtx(self.eth_address, nonce, 10, 21001, self.to_address, 1) - self.nodes[0].generate(2) # base fee increases one block after block with above TX + self.nodes[0].generate( + 2 + ) # base fee increases one block after block with above TX assert ( self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] > base_fee @@ -1591,7 +1593,7 @@ def run_test(self): # Check attributes values update self.test_attributes_update() - self.test_gas_target_update() + self.test_gas_limit_multiplier_update() if __name__ == "__main__": From 849e59f0ff6f88c336f093ecbd3d17c4323bb58b Mon Sep 17 00:00:00 2001 From: Bushstar Date: Wed, 1 Nov 2023 12:15:59 +0000 Subject: [PATCH 04/15] Add more EVM TXs to fix test --- test/functional/feature_evm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index cccaa2d765..ad35534ab0 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -1544,7 +1544,11 @@ def test_gas_limit_multiplier_update(self): base_fee = self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) - self.nodes[0].evmtx(self.eth_address, nonce, 10, 21001, self.to_address, 1) + for _ in range(10): + self.nodes[0].evmtx( + self.eth_address, nonce, 10, 21001, self.to_address, 0.01 + ) + nonce += 1 self.nodes[0].generate( 2 ) # base fee increases one block after block with above TX From 44ce92428d4255247305678e039ab37f9716cef2 Mon Sep 17 00:00:00 2001 From: Bushstar Date: Wed, 1 Nov 2023 12:56:54 +0000 Subject: [PATCH 05/15] Rename multiplier to factor --- lib/ain-cpp-imports/src/bridge.rs | 2 +- lib/ain-cpp-imports/src/lib.rs | 2 +- lib/ain-evm/src/block.rs | 2 +- src/dfi/errors.h | 2 ++ src/dfi/govvariables/attributes.cpp | 14 +++++++------- src/dfi/govvariables/attributes.h | 2 +- src/ffi/ffiexports.cpp | 7 +++---- src/ffi/ffiexports.h | 6 +++--- test/functional/feature_evm.py | 12 ++++++------ 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/ain-cpp-imports/src/bridge.rs b/lib/ain-cpp-imports/src/bridge.rs index 44be5e3c35..e6d2c28075 100644 --- a/lib/ain-cpp-imports/src/bridge.rs +++ b/lib/ain-cpp-imports/src/bridge.rs @@ -2,7 +2,7 @@ pub mod ffi { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Attributes { - pub block_gas_limit_multiplier: u64, + pub block_gas_limit_factor: u64, pub block_gas_limit: u64, pub finality_count: u64, pub rbf_fee_increment: u64, diff --git a/lib/ain-cpp-imports/src/lib.rs b/lib/ain-cpp-imports/src/lib.rs index 01a38fb55e..0ae77c32a4 100644 --- a/lib/ain-cpp-imports/src/lib.rs +++ b/lib/ain-cpp-imports/src/lib.rs @@ -10,7 +10,7 @@ use bridge::ffi; #[allow(non_snake_case)] mod ffi { pub struct Attributes { - pub block_gas_limit_multiplier: u64, + pub block_gas_limit_factor: u64, pub block_gas_limit: u64, pub finality_count: u64, pub rbf_fee_increment: u64, diff --git a/lib/ain-evm/src/block.rs b/lib/ain-evm/src/block.rs index 63aae56737..51573dd276 100644 --- a/lib/ain-evm/src/block.rs +++ b/lib/ain-evm/src/block.rs @@ -150,7 +150,7 @@ impl BlockService { pub fn calculate_base_fee(&self, parent_hash: H256, mnview_ptr: Option) -> Result { // constants let base_fee_max_change_denominator = U256::from(8); - let elasticity_multiplier = get_attribute_values(mnview_ptr).block_gas_limit_multiplier; + let elasticity_multiplier = get_attribute_values(mnview_ptr).block_gas_limit_factor; // first block has 1 gwei base fee if parent_hash == H256::zero() { diff --git a/src/dfi/errors.h b/src/dfi/errors.h index 0e03969096..e371829c68 100644 --- a/src/dfi/errors.h +++ b/src/dfi/errors.h @@ -162,6 +162,8 @@ class DeFiErrors { static Res GovVarVerifyMultiplier() { return Res::Err("Mutliplier cannot be zero"); } + static Res GovVarVerifyFactor() { return Res::Err("Factor cannot be zero"); } + static Res GovVarVerifyPair() { return Res::Err("Exactly two entires expected for currency pair"); } static Res GovVarVerifyValues() { return Res::Err("Empty token / currency"); } diff --git a/src/dfi/govvariables/attributes.cpp b/src/dfi/govvariables/attributes.cpp index 055bef3047..590d457e60 100644 --- a/src/dfi/govvariables/attributes.cpp +++ b/src/dfi/govvariables/attributes.cpp @@ -22,7 +22,7 @@ enum class EVMAttributesTypes : uint32_t { Finalized = 1, GasLimit = 2, - GasLimitMultipler = 3, + GasLimitFactor = 3, RbfIncrementMinPct = 4, }; @@ -288,7 +288,7 @@ const std::map> &ATTRIBUTES::allowedKeys { {"finality_count", EVMKeys::Finalized}, {"gas_limit", EVMKeys::GasLimit}, - {"gas_limit_multiplier", EVMKeys::GasLimitMultipler}, + {"gas_limit_factor", EVMKeys::GasLimitFactor}, {"rbf_increment_fee_pct", EVMKeys::RbfIncrementMinPct}, }}, {AttributeTypes::Governance, @@ -393,7 +393,7 @@ const std::map> &ATTRIBUTES::displayKeys { {EVMKeys::Finalized, "finality_count"}, {EVMKeys::GasLimit, "gas_limit"}, - {EVMKeys::GasLimitMultipler, "gas_limit_multiplier"}, + {EVMKeys::GasLimitFactor, "gas_limit_factor"}, {EVMKeys::RbfIncrementMinPct, "rbf_increment_fee_pct"}, }}, {AttributeTypes::Live, @@ -495,7 +495,7 @@ static ResVal VerifyMoreThenZeroUInt64(const std::string &str) } const auto value = std::get(*resVal.val); if (value == 0) { - return DeFiErrors::GovVarVerifyMultiplier(); + return DeFiErrors::GovVarVerifyFactor(); } return resVal; } @@ -842,7 +842,7 @@ const std::map( { {EVMKeys::Finalized, VerifyUInt64}, {EVMKeys::GasLimit, VerifyUInt64}, - {EVMKeys::GasLimitMultipler, VerifyMoreThenZeroUInt64}, + {EVMKeys::GasLimitFactor, VerifyMoreThenZeroUInt64}, {EVMKeys::RbfIncrementMinPct, VerifyPctInt64}, }}, {AttributeTypes::Governance, @@ -1006,8 +1006,8 @@ static Res CheckValidAttrV0Key(const uint8_t type, const uint32_t typeId, const } } else if (type == AttributeTypes::EVMType) { if (typeId == EVMIDs::Block) { - if (typeKey != EVMKeys::Finalized && typeKey != EVMKeys::GasLimit && - typeKey != EVMKeys::GasLimitMultipler && typeKey != EVMKeys::RbfIncrementMinPct) { + if (typeKey != EVMKeys::Finalized && typeKey != EVMKeys::GasLimit && typeKey != EVMKeys::GasLimitFactor && + typeKey != EVMKeys::RbfIncrementMinPct) { return DeFiErrors::GovVarVariableUnsupportedEVMType(typeKey); } } else { diff --git a/src/dfi/govvariables/attributes.h b/src/dfi/govvariables/attributes.h index cd3a00b328..b0b1469d30 100644 --- a/src/dfi/govvariables/attributes.h +++ b/src/dfi/govvariables/attributes.h @@ -57,7 +57,7 @@ enum EVMIDs : uint8_t { enum EVMKeys : uint8_t { Finalized = 'a', GasLimit = 'b', - GasLimitMultipler = 'c', + GasLimitFactor = 'c', RbfIncrementMinPct = 'd', }; diff --git a/src/ffi/ffiexports.cpp b/src/ffi/ffiexports.cpp index 42660c8717..57425ff43a 100644 --- a/src/ffi/ffiexports.cpp +++ b/src/ffi/ffiexports.cpp @@ -283,14 +283,13 @@ Attributes getAttributeValues(std::size_t mnview_ptr) { const auto attributes = view->GetAttributes(); - CDataStructureV0 blockGasLimitMultiplierKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasLimitMultipler}; + CDataStructureV0 blockGasLimitFactorKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasLimitFactor}; CDataStructureV0 blockGasLimitKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasLimit}; CDataStructureV0 finalityCountKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::Finalized}; CDataStructureV0 rbfIncrementMinPctKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::RbfIncrementMinPct}; - if (attributes->CheckKey(blockGasLimitMultiplierKey)) { - val.blockGasLimitMultiplier = - attributes->GetValue(blockGasLimitMultiplierKey, DEFAULT_EVM_BLOCK_GAS_TARGET_MULTIPLIER); + if (attributes->CheckKey(blockGasLimitFactorKey)) { + val.blockGasLimitFactor = attributes->GetValue(blockGasLimitFactorKey, DEFAULT_EVM_BLOCK_GAS_TARGET_FACTOR); } if (attributes->CheckKey(blockGasLimitKey)) { val.blockGasLimit = attributes->GetValue(blockGasLimitKey, DEFAULT_EVM_BLOCK_GAS_LIMIT); diff --git a/src/ffi/ffiexports.h b/src/ffi/ffiexports.h index ea3e90b6c9..6f5ef83c81 100644 --- a/src/ffi/ffiexports.h +++ b/src/ffi/ffiexports.h @@ -6,7 +6,7 @@ #include // Defaults for attributes relating to EVM functionality -static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_TARGET_MULTIPLIER = 15000000; +static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_TARGET_FACTOR = 15000000; static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_LIMIT = 30000000; static constexpr uint64_t DEFAULT_EVM_FINALITY_COUNT = 100; static constexpr CAmount DEFAULT_EVM_RBF_FEE_INCREMENT = COIN / 10; @@ -19,14 +19,14 @@ static constexpr bool DEFAULT_ETH_DEBUG_ENABLED = false; static constexpr bool DEFAULT_ETH_DEBUG_TRACE_ENABLED = true; struct Attributes { - uint64_t blockGasLimitMultiplier; + uint64_t blockGasLimitFactor; uint64_t blockGasLimit; uint64_t finalityCount; uint64_t rbfIncrementMinPct; static Attributes Default() { return Attributes{ - DEFAULT_EVM_BLOCK_GAS_TARGET_MULTIPLIER, + DEFAULT_EVM_BLOCK_GAS_TARGET_FACTOR, DEFAULT_EVM_BLOCK_GAS_LIMIT, DEFAULT_EVM_FINALITY_COUNT, DEFAULT_EVM_RBF_FEE_INCREMENT, diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index ad35534ab0..2cb4eff0f9 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -283,7 +283,7 @@ def evm_gov_vars(self): -32600, "Cannot be set before Metachain", self.nodes[0].setgov, - {"ATTRIBUTES": {"v0/evm/block/gas_limit_multiplier": "100"}}, + {"ATTRIBUTES": {"v0/evm/block/gas_limit_factor": "100"}}, ) assert_raises_rpc_error( -32600, @@ -335,7 +335,7 @@ def evm_gov_vars(self): "ATTRIBUTES": { "v0/evm/block/finality_count": "100", "v0/evm/block/gas_limit": "30000000", - "v0/evm/block/gas_limit_multiplier": "2", + "v0/evm/block/gas_limit_factor": "2", "v0/evm/block/rbf_increment_fee_pct": "0.1", "v0/rules/tx/core_op_return_max_size_bytes": 20000, "v0/rules/tx/evm_op_return_max_size_bytes": 20000, @@ -349,7 +349,7 @@ def evm_gov_vars(self): result = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"] assert_equal(result["v0/evm/block/finality_count"], "100") assert_equal(result["v0/evm/block/gas_limit"], "30000000") - assert_equal(result["v0/evm/block/gas_limit_multiplier"], "2") + assert_equal(result["v0/evm/block/gas_limit_factor"], "2") assert_equal(result["v0/evm/block/rbf_increment_fee_pct"], "0.1") assert_equal(result["v0/rules/tx/core_op_return_max_size_bytes"], "20000") assert_equal(result["v0/rules/tx/evm_op_return_max_size_bytes"], "20000") @@ -1532,11 +1532,11 @@ def test_attributes_update(self): block = self.nodes[0].eth_getBlockByNumber("latest") assert_equal(block["gasLimit"], hex(60000000)) - def test_gas_limit_multiplier_update(self): + def test_gas_limit_factor_update(self): self.nodes[0].setgov( { "ATTRIBUTES": { - "v0/evm/block/gas_limit_multiplier": "1500", + "v0/evm/block/gas_limit_factor": "1500", } } ) @@ -1597,7 +1597,7 @@ def run_test(self): # Check attributes values update self.test_attributes_update() - self.test_gas_limit_multiplier_update() + self.test_gas_limit_factor_update() if __name__ == "__main__": From 6e3a9a0a1f5012a69d5b71b9fa13eddaca40812d Mon Sep 17 00:00:00 2001 From: Bushstar Date: Wed, 1 Nov 2023 13:18:25 +0000 Subject: [PATCH 06/15] Set default factor to 2 --- src/ffi/ffiexports.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ffi/ffiexports.h b/src/ffi/ffiexports.h index 6f5ef83c81..8d908032b2 100644 --- a/src/ffi/ffiexports.h +++ b/src/ffi/ffiexports.h @@ -6,7 +6,7 @@ #include // Defaults for attributes relating to EVM functionality -static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_TARGET_FACTOR = 15000000; +static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_TARGET_FACTOR = 2; static constexpr uint64_t DEFAULT_EVM_BLOCK_GAS_LIMIT = 30000000; static constexpr uint64_t DEFAULT_EVM_FINALITY_COUNT = 100; static constexpr CAmount DEFAULT_EVM_RBF_FEE_INCREMENT = COIN / 10; From b5aa0caee6799ddc6e9cbb3577b6eb9e2b704487 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Wed, 1 Nov 2023 22:54:21 +0800 Subject: [PATCH 07/15] Consistent renames, use gas_target_factor --- lib/ain-cpp-imports/src/bridge.rs | 2 +- lib/ain-cpp-imports/src/lib.rs | 2 +- lib/ain-evm/src/block.rs | 2 +- src/dfi/govvariables/attributes.cpp | 10 +- src/dfi/govvariables/attributes.h | 2 +- src/ffi/ffiexports.cpp | 6 +- src/ffi/ffiexports.h | 2 +- test/functional/feature_evm.py | 244 ++++++++++++++++------------ 8 files changed, 157 insertions(+), 113 deletions(-) diff --git a/lib/ain-cpp-imports/src/bridge.rs b/lib/ain-cpp-imports/src/bridge.rs index e6d2c28075..295ff6b592 100644 --- a/lib/ain-cpp-imports/src/bridge.rs +++ b/lib/ain-cpp-imports/src/bridge.rs @@ -2,7 +2,7 @@ pub mod ffi { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Attributes { - pub block_gas_limit_factor: u64, + pub block_gas_target_factor: u64, pub block_gas_limit: u64, pub finality_count: u64, pub rbf_fee_increment: u64, diff --git a/lib/ain-cpp-imports/src/lib.rs b/lib/ain-cpp-imports/src/lib.rs index 0ae77c32a4..1831e65536 100644 --- a/lib/ain-cpp-imports/src/lib.rs +++ b/lib/ain-cpp-imports/src/lib.rs @@ -10,7 +10,7 @@ use bridge::ffi; #[allow(non_snake_case)] mod ffi { pub struct Attributes { - pub block_gas_limit_factor: u64, + pub block_gas_target_factor: u64, pub block_gas_limit: u64, pub finality_count: u64, pub rbf_fee_increment: u64, diff --git a/lib/ain-evm/src/block.rs b/lib/ain-evm/src/block.rs index 51573dd276..2e7454446a 100644 --- a/lib/ain-evm/src/block.rs +++ b/lib/ain-evm/src/block.rs @@ -150,7 +150,7 @@ impl BlockService { pub fn calculate_base_fee(&self, parent_hash: H256, mnview_ptr: Option) -> Result { // constants let base_fee_max_change_denominator = U256::from(8); - let elasticity_multiplier = get_attribute_values(mnview_ptr).block_gas_limit_factor; + let elasticity_multiplier = get_attribute_values(mnview_ptr).block_gas_target_factor; // first block has 1 gwei base fee if parent_hash == H256::zero() { diff --git a/src/dfi/govvariables/attributes.cpp b/src/dfi/govvariables/attributes.cpp index 590d457e60..6d177b4753 100644 --- a/src/dfi/govvariables/attributes.cpp +++ b/src/dfi/govvariables/attributes.cpp @@ -22,7 +22,7 @@ enum class EVMAttributesTypes : uint32_t { Finalized = 1, GasLimit = 2, - GasLimitFactor = 3, + GasTargetFactor = 3, RbfIncrementMinPct = 4, }; @@ -288,7 +288,7 @@ const std::map> &ATTRIBUTES::allowedKeys { {"finality_count", EVMKeys::Finalized}, {"gas_limit", EVMKeys::GasLimit}, - {"gas_limit_factor", EVMKeys::GasLimitFactor}, + {"gas_target_factor", EVMKeys::GasTargetFactor}, {"rbf_increment_fee_pct", EVMKeys::RbfIncrementMinPct}, }}, {AttributeTypes::Governance, @@ -393,7 +393,7 @@ const std::map> &ATTRIBUTES::displayKeys { {EVMKeys::Finalized, "finality_count"}, {EVMKeys::GasLimit, "gas_limit"}, - {EVMKeys::GasLimitFactor, "gas_limit_factor"}, + {EVMKeys::GasTargetFactor, "gas_target_factor"}, {EVMKeys::RbfIncrementMinPct, "rbf_increment_fee_pct"}, }}, {AttributeTypes::Live, @@ -842,7 +842,7 @@ const std::map( { {EVMKeys::Finalized, VerifyUInt64}, {EVMKeys::GasLimit, VerifyUInt64}, - {EVMKeys::GasLimitFactor, VerifyMoreThenZeroUInt64}, + {EVMKeys::GasTargetFactor, VerifyMoreThenZeroUInt64}, {EVMKeys::RbfIncrementMinPct, VerifyPctInt64}, }}, {AttributeTypes::Governance, @@ -1006,7 +1006,7 @@ static Res CheckValidAttrV0Key(const uint8_t type, const uint32_t typeId, const } } else if (type == AttributeTypes::EVMType) { if (typeId == EVMIDs::Block) { - if (typeKey != EVMKeys::Finalized && typeKey != EVMKeys::GasLimit && typeKey != EVMKeys::GasLimitFactor && + if (typeKey != EVMKeys::Finalized && typeKey != EVMKeys::GasLimit && typeKey != EVMKeys::GasTargetFactor && typeKey != EVMKeys::RbfIncrementMinPct) { return DeFiErrors::GovVarVariableUnsupportedEVMType(typeKey); } diff --git a/src/dfi/govvariables/attributes.h b/src/dfi/govvariables/attributes.h index b0b1469d30..2910c376bc 100644 --- a/src/dfi/govvariables/attributes.h +++ b/src/dfi/govvariables/attributes.h @@ -57,7 +57,7 @@ enum EVMIDs : uint8_t { enum EVMKeys : uint8_t { Finalized = 'a', GasLimit = 'b', - GasLimitFactor = 'c', + GasTargetFactor = 'c', RbfIncrementMinPct = 'd', }; diff --git a/src/ffi/ffiexports.cpp b/src/ffi/ffiexports.cpp index 57425ff43a..b197db359b 100644 --- a/src/ffi/ffiexports.cpp +++ b/src/ffi/ffiexports.cpp @@ -283,13 +283,13 @@ Attributes getAttributeValues(std::size_t mnview_ptr) { const auto attributes = view->GetAttributes(); - CDataStructureV0 blockGasLimitFactorKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasLimitFactor}; + CDataStructureV0 blockGasTargetFactorKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasTargetFactor}; CDataStructureV0 blockGasLimitKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::GasLimit}; CDataStructureV0 finalityCountKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::Finalized}; CDataStructureV0 rbfIncrementMinPctKey{AttributeTypes::EVMType, EVMIDs::Block, EVMKeys::RbfIncrementMinPct}; - if (attributes->CheckKey(blockGasLimitFactorKey)) { - val.blockGasLimitFactor = attributes->GetValue(blockGasLimitFactorKey, DEFAULT_EVM_BLOCK_GAS_TARGET_FACTOR); + if (attributes->CheckKey(blockGasTargetFactorKey)) { + val.blockGasTargetFactor = attributes->GetValue(blockGasTargetFactorKey, DEFAULT_EVM_BLOCK_GAS_TARGET_FACTOR); } if (attributes->CheckKey(blockGasLimitKey)) { val.blockGasLimit = attributes->GetValue(blockGasLimitKey, DEFAULT_EVM_BLOCK_GAS_LIMIT); diff --git a/src/ffi/ffiexports.h b/src/ffi/ffiexports.h index 8d908032b2..ce5d95edfb 100644 --- a/src/ffi/ffiexports.h +++ b/src/ffi/ffiexports.h @@ -19,7 +19,7 @@ static constexpr bool DEFAULT_ETH_DEBUG_ENABLED = false; static constexpr bool DEFAULT_ETH_DEBUG_TRACE_ENABLED = true; struct Attributes { - uint64_t blockGasLimitFactor; + uint64_t blockGasTargetFactor; uint64_t blockGasLimit; uint64_t finalityCount; uint64_t rbfIncrementMinPct; diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index 2cb4eff0f9..e4691354b1 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -22,50 +22,28 @@ class EVMTest(DefiTestFramework): def set_test_params(self): self.num_nodes = 2 self.setup_clean_chain = True - self.extra_args = [ - [ - "-txordering=2", - "-dummypos=0", - "-txnotokens=0", - "-amkheight=50", - "-bayfrontheight=51", - "-dakotaheight=50", - "-eunosheight=80", - "-fortcanningheight=82", - "-fortcanninghillheight=84", - "-fortcanningroadheight=86", - "-fortcanningcrunchheight=88", - "-fortcanningspringheight=90", - "-fortcanninggreatworldheight=94", - "-fortcanningepilogueheight=96", - "-grandcentralheight=101", - "-metachainheight=105", - "-subsidytest=1", - "-txindex=1", - "-ethdebug=1", - ], - [ - "-txordering=2", - "-dummypos=0", - "-txnotokens=0", - "-amkheight=50", - "-bayfrontheight=51", - "-dakotaheight=50", - "-eunosheight=80", - "-fortcanningheight=82", - "-fortcanninghillheight=84", - "-fortcanningroadheight=86", - "-fortcanningcrunchheight=88", - "-fortcanningspringheight=90", - "-fortcanninggreatworldheight=94", - "-fortcanningepilogueheight=96", - "-grandcentralheight=101", - "-metachainheight=105", - "-subsidytest=1", - "-txindex=1", - "-ethdebug=1", - ], + args = [ + "-txordering=2", + "-dummypos=0", + "-txnotokens=0", + "-amkheight=50", + "-bayfrontheight=51", + "-dakotaheight=50", + "-eunosheight=80", + "-fortcanningheight=82", + "-fortcanninghillheight=84", + "-fortcanningroadheight=86", + "-fortcanningcrunchheight=88", + "-fortcanningspringheight=90", + "-fortcanninggreatworldheight=94", + "-fortcanningepilogueheight=96", + "-grandcentralheight=101", + "-metachainheight=105", + "-subsidytest=1", + "-txindex=1", + "-ethdebug=1", ] + self.extra_args = [args, args] def test_tx_without_chainid(self): node = self.nodes[0] @@ -99,7 +77,8 @@ def test_tx_without_chainid(self): "gasPrice": node.w3.to_wei(10, "gwei"), } - signed_tx = node.w3.eth.account.sign_transaction(tx, evmkeypair.privkey) + signed_tx = node.w3.eth.account.sign_transaction( + tx, evmkeypair.privkey) node.w3.eth.send_raw_transaction(signed_tx.rawTransaction) node.generate(1) @@ -283,7 +262,7 @@ def evm_gov_vars(self): -32600, "Cannot be set before Metachain", self.nodes[0].setgov, - {"ATTRIBUTES": {"v0/evm/block/gas_limit_factor": "100"}}, + {"ATTRIBUTES": {"v0/evm/block/gas_target_factor": "100"}}, ) assert_raises_rpc_error( -32600, @@ -311,11 +290,14 @@ def evm_gov_vars(self): assert_equal( result["v0/transferdomain/dvm-evm/src-formats"], ["bech32", "p2pkh"] ) - assert_equal(result["v0/transferdomain/dvm-evm/dest-formats"], ["erc55"]) - assert_equal(result["v0/transferdomain/dvm-evm/native-enabled"], "true") + assert_equal( + result["v0/transferdomain/dvm-evm/dest-formats"], ["erc55"]) + assert_equal( + result["v0/transferdomain/dvm-evm/native-enabled"], "true") assert_equal(result["v0/transferdomain/dvm-evm/dat-enabled"], "false") assert_equal(result["v0/transferdomain/evm-dvm/enabled"], "true") - assert_equal(result["v0/transferdomain/evm-dvm/src-formats"], ["erc55"]) + assert_equal( + result["v0/transferdomain/evm-dvm/src-formats"], ["erc55"]) assert_equal( result["v0/transferdomain/evm-dvm/dest-formats"], ["bech32", "p2pkh"] ) @@ -323,11 +305,15 @@ def evm_gov_vars(self): result["v0/transferdomain/evm-dvm/auth-formats"], ["bech32-erc55", "p2pkh-erc55"], ) - assert_equal(result["v0/transferdomain/evm-dvm/native-enabled"], "true") + assert_equal( + result["v0/transferdomain/evm-dvm/native-enabled"], "true") assert_equal(result["v0/transferdomain/evm-dvm/dat-enabled"], "false") - assert_equal(result["v0/rules/tx/core_op_return_max_size_bytes"], "1024") - assert_equal(result["v0/rules/tx/evm_op_return_max_size_bytes"], "65536") - assert_equal(result["v0/rules/tx/dvm_op_return_max_size_bytes"], "4096") + assert_equal( + result["v0/rules/tx/core_op_return_max_size_bytes"], "1024") + assert_equal( + result["v0/rules/tx/evm_op_return_max_size_bytes"], "65536") + assert_equal( + result["v0/rules/tx/dvm_op_return_max_size_bytes"], "4096") # Set OP_RETURN self.nodes[0].setgov( @@ -335,7 +321,7 @@ def evm_gov_vars(self): "ATTRIBUTES": { "v0/evm/block/finality_count": "100", "v0/evm/block/gas_limit": "30000000", - "v0/evm/block/gas_limit_factor": "2", + "v0/evm/block/gas_target_factor": "2", "v0/evm/block/rbf_increment_fee_pct": "0.1", "v0/rules/tx/core_op_return_max_size_bytes": 20000, "v0/rules/tx/evm_op_return_max_size_bytes": 20000, @@ -349,11 +335,14 @@ def evm_gov_vars(self): result = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"] assert_equal(result["v0/evm/block/finality_count"], "100") assert_equal(result["v0/evm/block/gas_limit"], "30000000") - assert_equal(result["v0/evm/block/gas_limit_factor"], "2") + assert_equal(result["v0/evm/block/gas_target_factor"], "2") assert_equal(result["v0/evm/block/rbf_increment_fee_pct"], "0.1") - assert_equal(result["v0/rules/tx/core_op_return_max_size_bytes"], "20000") - assert_equal(result["v0/rules/tx/evm_op_return_max_size_bytes"], "20000") - assert_equal(result["v0/rules/tx/dvm_op_return_max_size_bytes"], "20000") + assert_equal( + result["v0/rules/tx/core_op_return_max_size_bytes"], "20000") + assert_equal( + result["v0/rules/tx/evm_op_return_max_size_bytes"], "20000") + assert_equal( + result["v0/rules/tx/dvm_op_return_max_size_bytes"], "20000") def verify_evm_not_enabled(): # Check error before EVM enabled @@ -453,7 +442,8 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain PKHash address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/src-formats": ["bech32"]}} + {"ATTRIBUTES": { + "v0/transferdomain/dvm-evm/src-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -476,7 +466,8 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain PKHash address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/src-formats": ["p2pkh"]}} + {"ATTRIBUTES": { + "v0/transferdomain/dvm-evm/src-formats": ["p2pkh"]}} ) self.nodes[0].generate(1) @@ -512,7 +503,8 @@ def verify_transferdomain_not_enabled_post_evm_on(): self.nodes[0].generate(1) self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/dest-formats": ["bech32"]}} + {"ATTRIBUTES": { + "v0/transferdomain/dvm-evm/dest-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -539,7 +531,8 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/dest-formats": ["erc55"]}} + {"ATTRIBUTES": { + "v0/transferdomain/dvm-evm/dest-formats": ["erc55"]}} ) self.nodes[0].generate(1) @@ -616,7 +609,8 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Deactivate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/src-formats": ["bech32"]}} + {"ATTRIBUTES": { + "v0/transferdomain/evm-dvm/src-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -639,13 +633,15 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/src-formats": ["erc55"]}} + {"ATTRIBUTES": { + "v0/transferdomain/evm-dvm/src-formats": ["erc55"]}} ) self.nodes[0].generate(1) # Dectivate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/dest-formats": ["bech32"]}} + {"ATTRIBUTES": { + "v0/transferdomain/evm-dvm/dest-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -668,7 +664,8 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/dest-formats": ["p2pkh"]}} + {"ATTRIBUTES": { + "v0/transferdomain/evm-dvm/dest-formats": ["p2pkh"]}} ) self.nodes[0].generate(1) @@ -705,7 +702,8 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Dectivate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/auth-formats": ["p2pkh-erc55"]}} + {"ATTRIBUTES": { + "v0/transferdomain/evm-dvm/auth-formats": ["p2pkh-erc55"]}} ) self.nodes[0].generate(1) @@ -732,12 +730,14 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/auth-formats": ["bech32-erc55"]}} + {"ATTRIBUTES": { + "v0/transferdomain/evm-dvm/auth-formats": ["bech32-erc55"]}} ) self.nodes[0].generate(1) # Test setting of finalized block - self.nodes[0].setgov({"ATTRIBUTES": {"v0/evm/block/finality_count": "100"}}) + self.nodes[0].setgov( + {"ATTRIBUTES": {"v0/evm/block/finality_count": "100"}}) self.nodes[0].generate(1) # Check Gov var is present @@ -772,14 +772,16 @@ def setup_accounts(self): eth_balance = self.nodes[0].eth_getBalance(self.eth_address) assert_equal(dfi_balance, Decimal("100")) assert_equal(eth_balance, int_to_eth_u256(200)) - assert_equal(len(self.nodes[0].getaccount(self.eth_address, {}, True)), 1) + assert_equal(len(self.nodes[0].getaccount( + self.eth_address, {}, True)), 1) # Check Eth balances before transfer assert_equal( int(self.nodes[0].eth_getBalance(self.eth_address)[2:], 16), 200000000000000000000, ) - assert_equal(int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) + assert_equal( + int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) # Send tokens to burn address self.burn_address = "mfburnZSAM7Gs1hpDeNaMotJXSGA7edosG" @@ -788,7 +790,8 @@ def setup_accounts(self): ) result = self.nodes[0].getburninfo() assert_equal(result["address"], self.burn_address) - self.nodes[0].accounttoaccount(self.address, {self.burn_address: "1@DFI"}) + self.nodes[0].accounttoaccount( + self.address, {self.burn_address: "1@DFI"}) self.nodes[0].generate(1) def nonce_order_and_rbf(self): @@ -803,9 +806,11 @@ def nonce_order_and_rbf(self): # Check accounting of EVM fees attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"] - assert_equal(attributes["v0/live/economy/evm/block/fee_burnt"], Decimal("0E-8")) assert_equal( - attributes["v0/live/economy/evm/block/fee_priority"], Decimal("0E-8") + attributes["v0/live/economy/evm/block/fee_burnt"], Decimal("0E-8")) + assert_equal( + attributes["v0/live/economy/evm/block/fee_priority"], Decimal( + "0E-8") ) # Test EVM Tx added first in time ordering @@ -813,11 +818,16 @@ def nonce_order_and_rbf(self): self.sync_mempools() # Add more EVM Txs to test block ordering - tx5 = self.nodes[0].evmtx(self.eth_address, 5, 21, 21001, self.to_address, 1) - tx4 = self.nodes[0].evmtx(self.eth_address, 4, 21, 21001, self.to_address, 1) - tx2 = self.nodes[0].evmtx(self.eth_address, 2, 21, 21001, self.to_address, 1) - tx1 = self.nodes[0].evmtx(self.eth_address, 1, 21, 21001, self.to_address, 1) - tx3 = self.nodes[0].evmtx(self.eth_address, 3, 21, 21001, self.to_address, 1) + tx5 = self.nodes[0].evmtx( + self.eth_address, 5, 21, 21001, self.to_address, 1) + tx4 = self.nodes[0].evmtx( + self.eth_address, 4, 21, 21001, self.to_address, 1) + tx2 = self.nodes[0].evmtx( + self.eth_address, 2, 21, 21001, self.to_address, 1) + tx1 = self.nodes[0].evmtx( + self.eth_address, 1, 21, 21001, self.to_address, 1) + tx3 = self.nodes[0].evmtx( + self.eth_address, 3, 21, 21001, self.to_address, 1) raw_tx = self.nodes[0].getrawtransaction(tx5) self.sync_mempools() @@ -864,7 +874,8 @@ def nonce_order_and_rbf(self): ) # Create replacement for nonce 0 TX with higher fee - tx0 = self.nodes[0].evmtx(self.eth_address, 0, 24, 21001, self.to_address, 1) + tx0 = self.nodes[0].evmtx( + self.eth_address, 0, 24, 21001, self.to_address, 1) assert_equal(len(self.nodes[0].getrawmempool()), 6) self.sync_mempools() @@ -961,7 +972,8 @@ def nonce_order_and_rbf(self): ) # Get miner account balance after transfer - miner_after = Decimal(self.nodes[0].w3.eth.get_balance(self.miner_eth_address)) + miner_after = Decimal( + self.nodes[0].w3.eth.get_balance(self.miner_eth_address)) self.miner_fee = miner_after - self.miner_before # Check EVM Tx shows in block on EVM side @@ -1001,9 +1013,11 @@ def validate_xvm_coinbase(self): # Check EVM miner fee opreturn_priority_fee_sats = coinbase_xvm["msg"]["evm"]["priorityFee"] - opreturn_priority_fee_amount = Decimal(opreturn_priority_fee_sats) / 100000000 + opreturn_priority_fee_amount = Decimal( + opreturn_priority_fee_sats) / 100000000 assert_equal( - opreturn_priority_fee_amount, self.miner_fee / int(math.pow(10, 18)) + opreturn_priority_fee_amount, self.miner_fee / + int(math.pow(10, 18)) ) # Check EVM beneficiary address @@ -1030,19 +1044,22 @@ def evm_rollback(self): int(self.nodes[0].eth_getBalance(self.eth_address)[2:], 16), 200000000000000000000, ) - assert_equal(int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) + assert_equal( + int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) def multiple_eth_rbf(self): nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) # Transfer some balance to to_address - self.nodes[0].evmtx(self.eth_address, nonce, 11, 21001, self.to_address, 1) + self.nodes[0].evmtx(self.eth_address, nonce, 11, + 21001, self.to_address, 1) self.nodes[0].generate(1) blockHash = self.nodes[0].getblockhash(self.nodes[0].getblockcount()) # Test multiple replacement TXs with differing fees nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) - self.nodes[0].evmtx(self.eth_address, nonce, 21, 21001, self.to_address, 1) + self.nodes[0].evmtx(self.eth_address, nonce, 21, + 21001, self.to_address, 1) # Send tx with less than 10% in increase fees assert_raises_rpc_error( @@ -1058,7 +1075,8 @@ def multiple_eth_rbf(self): ) # Valid RBF - self.nodes[0].evmtx(self.eth_address, nonce, 23, 21001, self.to_address, 1) + self.nodes[0].evmtx(self.eth_address, nonce, 23, + 21001, self.to_address, 1) # Valid RBF tx0 = self.nodes[0].evmtx( @@ -1105,7 +1123,8 @@ def multiple_eth_rbf(self): ) to_nonce = self.nodes[0].w3.eth.get_transaction_count(self.to_address) - self.nodes[0].evmtx(self.to_address, to_nonce, 30, 21001, self.eth_address, 1) + self.nodes[0].evmtx(self.to_address, to_nonce, 30, + 21001, self.eth_address, 1) # Send tx with less than 10% in increase fees assert_raises_rpc_error( @@ -1121,7 +1140,8 @@ def multiple_eth_rbf(self): ) # Send tx with exactly 10% in increase fees, RBF should happen - self.nodes[0].evmtx(self.to_address, to_nonce, 32, 21001, self.eth_address, 1) + self.nodes[0].evmtx(self.to_address, to_nonce, 32, + 21001, self.eth_address, 1) # Send tx with less than 10% in increase fees assert_raises_rpc_error( @@ -1327,7 +1347,8 @@ def sendtransaction_auto_nonce(self): def toggle_evm_enablement(self): # Deactivate EVM - self.nodes[0].setgov({"ATTRIBUTES": {"v0/params/feature/evm": "false"}}) + self.nodes[0].setgov( + {"ATTRIBUTES": {"v0/params/feature/evm": "false"}}) self.nodes[0].generate(1) evm_disabling_block = self.nodes[0].eth_getBlockByNumber("latest") @@ -1479,7 +1500,8 @@ def delete_account_from_trie(self): codeBefore[2:], deployedBytecode, ) - storageBefore = self.nodes[0].eth_getStorageAt(self.contract_address, "0x0") + storageBefore = self.nodes[0].eth_getStorageAt( + self.contract_address, "0x0") assert_equal( Web3.to_checksum_address(storageBefore[26:]), self.evm_key_pair.address, @@ -1501,7 +1523,8 @@ def delete_account_from_trie(self): hash = self.nodes[0].w3.eth.send_raw_transaction(signed.rawTransaction) self.nodes[0].generate(1) - codeAfterSelfDestruct = self.nodes[0].eth_getCode(self.contract_address) + codeAfterSelfDestruct = self.nodes[0].eth_getCode( + self.contract_address) assert_equal( codeAfterSelfDestruct, "0x", @@ -1532,29 +1555,50 @@ def test_attributes_update(self): block = self.nodes[0].eth_getBlockByNumber("latest") assert_equal(block["gasLimit"], hex(60000000)) - def test_gas_limit_factor_update(self): + def test_gas_target_factor_update(self): self.nodes[0].setgov( { "ATTRIBUTES": { - "v0/evm/block/gas_limit_factor": "1500", + "v0/evm/block/gas_target_factor": "1500", + "v0/evm/block/gas_limit": "50000", } } ) self.nodes[0].generate(1) + def print_base_fee(): + base_fee_per_gas = self.nodes[0].w3.eth.get_block( + "latest")["baseFeePerGas"] + print("base_fee_per_gas: {}", base_fee_per_gas) + + print_base_fee() + base_fee = self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) - for _ in range(10): + + for _ in range(20): self.nodes[0].evmtx( self.eth_address, nonce, 10, 21001, self.to_address, 0.01 ) nonce += 1 - self.nodes[0].generate( - 2 - ) # base fee increases one block after block with above TX - + # base fee increases one block after block with above TX + self.nodes[0].generate(1) + print_base_fee() + + for _ in range(20): + for _ in range(2): + self.nodes[0].evmtx( + self.eth_address, nonce, 10, 21001, self.to_address, 0.01 + ) + nonce += 1 + # base fee increases one block after block with above TX + self.nodes[0].generate(1) + print_base_fee() + + base_fee_per_gas = self.nodes[0].w3.eth.get_block( + "latest")["baseFeePerGas"] assert ( - self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] > base_fee + base_fee_per_gas > base_fee ) # if base fee increases, it means the gas target was applied successfully def run_test(self): @@ -1597,7 +1641,7 @@ def run_test(self): # Check attributes values update self.test_attributes_update() - self.test_gas_limit_factor_update() + self.test_gas_target_factor_update() if __name__ == "__main__": From 8d260e05d65d9600cca8b1a96cc551ddf6aed13c Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 2 Nov 2023 07:59:59 +0800 Subject: [PATCH 08/15] Better tests to verify --- test/functional/feature_evm.py | 96 ++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 23 deletions(-) diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index e4691354b1..ffc4a9edcd 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -1555,51 +1555,100 @@ def test_attributes_update(self): block = self.nodes[0].eth_getBlockByNumber("latest") assert_equal(block["gasLimit"], hex(60000000)) - def test_gas_target_factor_update(self): + def test_gas_target_factor(self): self.nodes[0].setgov( { "ATTRIBUTES": { - "v0/evm/block/gas_target_factor": "1500", + "v0/evm/block/gas_target_factor": "2", "v0/evm/block/gas_limit": "50000", } } ) self.nodes[0].generate(1) - def print_base_fee(): - base_fee_per_gas = self.nodes[0].w3.eth.get_block( - "latest")["baseFeePerGas"] - print("base_fee_per_gas: {}", base_fee_per_gas) + def print_fee_info(): + block_info = self.nodes[0].w3.eth.get_block( + "latest") + gas_limit = block_info["gasLimit"] + gas_used = block_info["gasUsed"] + base_fee_per_gas = block_info["baseFeePerGas"] + print("(gas - limit, used, fee): ", gas_limit, gas_used, base_fee_per_gas) + + print_fee_info() - print_base_fee() - - base_fee = self.nodes[0].w3.eth.get_block("latest")["baseFeePerGas"] nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) + # Increase test for _ in range(20): - self.nodes[0].evmtx( - self.eth_address, nonce, 10, 21001, self.to_address, 0.01 - ) - nonce += 1 + for _ in range(3): + self.nodes[0].evmtx( + self.eth_address, nonce, 100, 21001, self.to_address, 0.01 + ) + nonce += 1 # base fee increases one block after block with above TX self.nodes[0].generate(1) - print_base_fee() + print_fee_info() + + self.nodes[0].setgov( + { + "ATTRIBUTES": { + "v0/evm/block/gas_target_factor": "1", + "v0/evm/block/gas_limit": "50000", + } + } + ) + self.nodes[0].generate(1) + + # Increase test + for _ in range(30): + # base fee increases one block after block with above TX + self.nodes[0].generate(1) + print_fee_info() + + def test_gas_limit(self): + self.nodes[0].setgov( + { + "ATTRIBUTES": { + "v0/evm/block/gas_target_factor": "2", + "v0/evm/block/gas_limit": "50000", + } + } + ) + self.nodes[0].generate(1) + + def print_fee_info(): + block_info = self.nodes[0].w3.eth.get_block( + "latest") + gas_limit = block_info["gasLimit"] + gas_used = block_info["gasUsed"] + base_fee_per_gas = block_info["baseFeePerGas"] + print("(gas - limit, used, fee): ", gas_limit, gas_used, base_fee_per_gas) + print_fee_info() + + nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) + + print_fee_info() + # Note: base fee increases one block after block with above TX + + # Increase test for _ in range(20): - for _ in range(2): + for _ in range(3): self.nodes[0].evmtx( - self.eth_address, nonce, 10, 21001, self.to_address, 0.01 + self.eth_address, nonce, 100, 21001, self.to_address, 0.01 ) nonce += 1 # base fee increases one block after block with above TX self.nodes[0].generate(1) - print_base_fee() + print_fee_info() - base_fee_per_gas = self.nodes[0].w3.eth.get_block( - "latest")["baseFeePerGas"] - assert ( - base_fee_per_gas > base_fee - ) # if base fee increases, it means the gas target was applied successfully + # Mine any left overs + self.nodes[0].generate(1) + + # Decrease test + for _ in range(20): + self.nodes[0].generate(1) + print_fee_info() def run_test(self): # Check ERC55 wallet support @@ -1641,7 +1690,8 @@ def run_test(self): # Check attributes values update self.test_attributes_update() - self.test_gas_target_factor_update() + # self.test_gas_limit() + # self.test_gas_target_factor() if __name__ == "__main__": From 82dcb56242d1d9a5c9661cff1995641a8ab28313 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 2 Nov 2023 08:04:09 +0800 Subject: [PATCH 09/15] Fix lints --- test/functional/feature_evm.py | 141 +++++++++++---------------------- 1 file changed, 47 insertions(+), 94 deletions(-) diff --git a/test/functional/feature_evm.py b/test/functional/feature_evm.py index ffc4a9edcd..d67a38e8a3 100755 --- a/test/functional/feature_evm.py +++ b/test/functional/feature_evm.py @@ -77,8 +77,7 @@ def test_tx_without_chainid(self): "gasPrice": node.w3.to_wei(10, "gwei"), } - signed_tx = node.w3.eth.account.sign_transaction( - tx, evmkeypair.privkey) + signed_tx = node.w3.eth.account.sign_transaction(tx, evmkeypair.privkey) node.w3.eth.send_raw_transaction(signed_tx.rawTransaction) node.generate(1) @@ -290,14 +289,11 @@ def evm_gov_vars(self): assert_equal( result["v0/transferdomain/dvm-evm/src-formats"], ["bech32", "p2pkh"] ) - assert_equal( - result["v0/transferdomain/dvm-evm/dest-formats"], ["erc55"]) - assert_equal( - result["v0/transferdomain/dvm-evm/native-enabled"], "true") + assert_equal(result["v0/transferdomain/dvm-evm/dest-formats"], ["erc55"]) + assert_equal(result["v0/transferdomain/dvm-evm/native-enabled"], "true") assert_equal(result["v0/transferdomain/dvm-evm/dat-enabled"], "false") assert_equal(result["v0/transferdomain/evm-dvm/enabled"], "true") - assert_equal( - result["v0/transferdomain/evm-dvm/src-formats"], ["erc55"]) + assert_equal(result["v0/transferdomain/evm-dvm/src-formats"], ["erc55"]) assert_equal( result["v0/transferdomain/evm-dvm/dest-formats"], ["bech32", "p2pkh"] ) @@ -305,15 +301,11 @@ def evm_gov_vars(self): result["v0/transferdomain/evm-dvm/auth-formats"], ["bech32-erc55", "p2pkh-erc55"], ) - assert_equal( - result["v0/transferdomain/evm-dvm/native-enabled"], "true") + assert_equal(result["v0/transferdomain/evm-dvm/native-enabled"], "true") assert_equal(result["v0/transferdomain/evm-dvm/dat-enabled"], "false") - assert_equal( - result["v0/rules/tx/core_op_return_max_size_bytes"], "1024") - assert_equal( - result["v0/rules/tx/evm_op_return_max_size_bytes"], "65536") - assert_equal( - result["v0/rules/tx/dvm_op_return_max_size_bytes"], "4096") + assert_equal(result["v0/rules/tx/core_op_return_max_size_bytes"], "1024") + assert_equal(result["v0/rules/tx/evm_op_return_max_size_bytes"], "65536") + assert_equal(result["v0/rules/tx/dvm_op_return_max_size_bytes"], "4096") # Set OP_RETURN self.nodes[0].setgov( @@ -337,12 +329,9 @@ def evm_gov_vars(self): assert_equal(result["v0/evm/block/gas_limit"], "30000000") assert_equal(result["v0/evm/block/gas_target_factor"], "2") assert_equal(result["v0/evm/block/rbf_increment_fee_pct"], "0.1") - assert_equal( - result["v0/rules/tx/core_op_return_max_size_bytes"], "20000") - assert_equal( - result["v0/rules/tx/evm_op_return_max_size_bytes"], "20000") - assert_equal( - result["v0/rules/tx/dvm_op_return_max_size_bytes"], "20000") + assert_equal(result["v0/rules/tx/core_op_return_max_size_bytes"], "20000") + assert_equal(result["v0/rules/tx/evm_op_return_max_size_bytes"], "20000") + assert_equal(result["v0/rules/tx/dvm_op_return_max_size_bytes"], "20000") def verify_evm_not_enabled(): # Check error before EVM enabled @@ -442,8 +431,7 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain PKHash address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/dvm-evm/src-formats": ["bech32"]}} + {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/src-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -466,8 +454,7 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain PKHash address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/dvm-evm/src-formats": ["p2pkh"]}} + {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/src-formats": ["p2pkh"]}} ) self.nodes[0].generate(1) @@ -503,8 +490,7 @@ def verify_transferdomain_not_enabled_post_evm_on(): self.nodes[0].generate(1) self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/dvm-evm/dest-formats": ["bech32"]}} + {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/dest-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -531,8 +517,7 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/dvm-evm/dest-formats": ["erc55"]}} + {"ATTRIBUTES": {"v0/transferdomain/dvm-evm/dest-formats": ["erc55"]}} ) self.nodes[0].generate(1) @@ -609,8 +594,7 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Deactivate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/evm-dvm/src-formats": ["bech32"]}} + {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/src-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -633,15 +617,13 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/evm-dvm/src-formats": ["erc55"]}} + {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/src-formats": ["erc55"]}} ) self.nodes[0].generate(1) # Dectivate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/evm-dvm/dest-formats": ["bech32"]}} + {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/dest-formats": ["bech32"]}} ) self.nodes[0].generate(1) @@ -664,8 +646,7 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/evm-dvm/dest-formats": ["p2pkh"]}} + {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/dest-formats": ["p2pkh"]}} ) self.nodes[0].generate(1) @@ -702,8 +683,7 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Dectivate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/evm-dvm/auth-formats": ["p2pkh-erc55"]}} + {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/auth-formats": ["p2pkh-erc55"]}} ) self.nodes[0].generate(1) @@ -730,14 +710,12 @@ def verify_transferdomain_not_enabled_post_evm_on(): # Activate transferdomain ERC55 address self.nodes[0].setgov( - {"ATTRIBUTES": { - "v0/transferdomain/evm-dvm/auth-formats": ["bech32-erc55"]}} + {"ATTRIBUTES": {"v0/transferdomain/evm-dvm/auth-formats": ["bech32-erc55"]}} ) self.nodes[0].generate(1) # Test setting of finalized block - self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/evm/block/finality_count": "100"}}) + self.nodes[0].setgov({"ATTRIBUTES": {"v0/evm/block/finality_count": "100"}}) self.nodes[0].generate(1) # Check Gov var is present @@ -772,16 +750,14 @@ def setup_accounts(self): eth_balance = self.nodes[0].eth_getBalance(self.eth_address) assert_equal(dfi_balance, Decimal("100")) assert_equal(eth_balance, int_to_eth_u256(200)) - assert_equal(len(self.nodes[0].getaccount( - self.eth_address, {}, True)), 1) + assert_equal(len(self.nodes[0].getaccount(self.eth_address, {}, True)), 1) # Check Eth balances before transfer assert_equal( int(self.nodes[0].eth_getBalance(self.eth_address)[2:], 16), 200000000000000000000, ) - assert_equal( - int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) + assert_equal(int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) # Send tokens to burn address self.burn_address = "mfburnZSAM7Gs1hpDeNaMotJXSGA7edosG" @@ -790,8 +766,7 @@ def setup_accounts(self): ) result = self.nodes[0].getburninfo() assert_equal(result["address"], self.burn_address) - self.nodes[0].accounttoaccount( - self.address, {self.burn_address: "1@DFI"}) + self.nodes[0].accounttoaccount(self.address, {self.burn_address: "1@DFI"}) self.nodes[0].generate(1) def nonce_order_and_rbf(self): @@ -806,11 +781,9 @@ def nonce_order_and_rbf(self): # Check accounting of EVM fees attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"] + assert_equal(attributes["v0/live/economy/evm/block/fee_burnt"], Decimal("0E-8")) assert_equal( - attributes["v0/live/economy/evm/block/fee_burnt"], Decimal("0E-8")) - assert_equal( - attributes["v0/live/economy/evm/block/fee_priority"], Decimal( - "0E-8") + attributes["v0/live/economy/evm/block/fee_priority"], Decimal("0E-8") ) # Test EVM Tx added first in time ordering @@ -818,16 +791,11 @@ def nonce_order_and_rbf(self): self.sync_mempools() # Add more EVM Txs to test block ordering - tx5 = self.nodes[0].evmtx( - self.eth_address, 5, 21, 21001, self.to_address, 1) - tx4 = self.nodes[0].evmtx( - self.eth_address, 4, 21, 21001, self.to_address, 1) - tx2 = self.nodes[0].evmtx( - self.eth_address, 2, 21, 21001, self.to_address, 1) - tx1 = self.nodes[0].evmtx( - self.eth_address, 1, 21, 21001, self.to_address, 1) - tx3 = self.nodes[0].evmtx( - self.eth_address, 3, 21, 21001, self.to_address, 1) + tx5 = self.nodes[0].evmtx(self.eth_address, 5, 21, 21001, self.to_address, 1) + tx4 = self.nodes[0].evmtx(self.eth_address, 4, 21, 21001, self.to_address, 1) + tx2 = self.nodes[0].evmtx(self.eth_address, 2, 21, 21001, self.to_address, 1) + tx1 = self.nodes[0].evmtx(self.eth_address, 1, 21, 21001, self.to_address, 1) + tx3 = self.nodes[0].evmtx(self.eth_address, 3, 21, 21001, self.to_address, 1) raw_tx = self.nodes[0].getrawtransaction(tx5) self.sync_mempools() @@ -874,8 +842,7 @@ def nonce_order_and_rbf(self): ) # Create replacement for nonce 0 TX with higher fee - tx0 = self.nodes[0].evmtx( - self.eth_address, 0, 24, 21001, self.to_address, 1) + tx0 = self.nodes[0].evmtx(self.eth_address, 0, 24, 21001, self.to_address, 1) assert_equal(len(self.nodes[0].getrawmempool()), 6) self.sync_mempools() @@ -972,8 +939,7 @@ def nonce_order_and_rbf(self): ) # Get miner account balance after transfer - miner_after = Decimal( - self.nodes[0].w3.eth.get_balance(self.miner_eth_address)) + miner_after = Decimal(self.nodes[0].w3.eth.get_balance(self.miner_eth_address)) self.miner_fee = miner_after - self.miner_before # Check EVM Tx shows in block on EVM side @@ -1013,11 +979,9 @@ def validate_xvm_coinbase(self): # Check EVM miner fee opreturn_priority_fee_sats = coinbase_xvm["msg"]["evm"]["priorityFee"] - opreturn_priority_fee_amount = Decimal( - opreturn_priority_fee_sats) / 100000000 + opreturn_priority_fee_amount = Decimal(opreturn_priority_fee_sats) / 100000000 assert_equal( - opreturn_priority_fee_amount, self.miner_fee / - int(math.pow(10, 18)) + opreturn_priority_fee_amount, self.miner_fee / int(math.pow(10, 18)) ) # Check EVM beneficiary address @@ -1044,22 +1008,19 @@ def evm_rollback(self): int(self.nodes[0].eth_getBalance(self.eth_address)[2:], 16), 200000000000000000000, ) - assert_equal( - int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) + assert_equal(int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16), 0) def multiple_eth_rbf(self): nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) # Transfer some balance to to_address - self.nodes[0].evmtx(self.eth_address, nonce, 11, - 21001, self.to_address, 1) + self.nodes[0].evmtx(self.eth_address, nonce, 11, 21001, self.to_address, 1) self.nodes[0].generate(1) blockHash = self.nodes[0].getblockhash(self.nodes[0].getblockcount()) # Test multiple replacement TXs with differing fees nonce = self.nodes[0].w3.eth.get_transaction_count(self.eth_address) - self.nodes[0].evmtx(self.eth_address, nonce, 21, - 21001, self.to_address, 1) + self.nodes[0].evmtx(self.eth_address, nonce, 21, 21001, self.to_address, 1) # Send tx with less than 10% in increase fees assert_raises_rpc_error( @@ -1075,8 +1036,7 @@ def multiple_eth_rbf(self): ) # Valid RBF - self.nodes[0].evmtx(self.eth_address, nonce, 23, - 21001, self.to_address, 1) + self.nodes[0].evmtx(self.eth_address, nonce, 23, 21001, self.to_address, 1) # Valid RBF tx0 = self.nodes[0].evmtx( @@ -1123,8 +1083,7 @@ def multiple_eth_rbf(self): ) to_nonce = self.nodes[0].w3.eth.get_transaction_count(self.to_address) - self.nodes[0].evmtx(self.to_address, to_nonce, 30, - 21001, self.eth_address, 1) + self.nodes[0].evmtx(self.to_address, to_nonce, 30, 21001, self.eth_address, 1) # Send tx with less than 10% in increase fees assert_raises_rpc_error( @@ -1140,8 +1099,7 @@ def multiple_eth_rbf(self): ) # Send tx with exactly 10% in increase fees, RBF should happen - self.nodes[0].evmtx(self.to_address, to_nonce, 32, - 21001, self.eth_address, 1) + self.nodes[0].evmtx(self.to_address, to_nonce, 32, 21001, self.eth_address, 1) # Send tx with less than 10% in increase fees assert_raises_rpc_error( @@ -1347,8 +1305,7 @@ def sendtransaction_auto_nonce(self): def toggle_evm_enablement(self): # Deactivate EVM - self.nodes[0].setgov( - {"ATTRIBUTES": {"v0/params/feature/evm": "false"}}) + self.nodes[0].setgov({"ATTRIBUTES": {"v0/params/feature/evm": "false"}}) self.nodes[0].generate(1) evm_disabling_block = self.nodes[0].eth_getBlockByNumber("latest") @@ -1500,8 +1457,7 @@ def delete_account_from_trie(self): codeBefore[2:], deployedBytecode, ) - storageBefore = self.nodes[0].eth_getStorageAt( - self.contract_address, "0x0") + storageBefore = self.nodes[0].eth_getStorageAt(self.contract_address, "0x0") assert_equal( Web3.to_checksum_address(storageBefore[26:]), self.evm_key_pair.address, @@ -1523,8 +1479,7 @@ def delete_account_from_trie(self): hash = self.nodes[0].w3.eth.send_raw_transaction(signed.rawTransaction) self.nodes[0].generate(1) - codeAfterSelfDestruct = self.nodes[0].eth_getCode( - self.contract_address) + codeAfterSelfDestruct = self.nodes[0].eth_getCode(self.contract_address) assert_equal( codeAfterSelfDestruct, "0x", @@ -1567,8 +1522,7 @@ def test_gas_target_factor(self): self.nodes[0].generate(1) def print_fee_info(): - block_info = self.nodes[0].w3.eth.get_block( - "latest") + block_info = self.nodes[0].w3.eth.get_block("latest") gas_limit = block_info["gasLimit"] gas_used = block_info["gasUsed"] base_fee_per_gas = block_info["baseFeePerGas"] @@ -1617,8 +1571,7 @@ def test_gas_limit(self): self.nodes[0].generate(1) def print_fee_info(): - block_info = self.nodes[0].w3.eth.get_block( - "latest") + block_info = self.nodes[0].w3.eth.get_block("latest") gas_limit = block_info["gasLimit"] gas_used = block_info["gasUsed"] base_fee_per_gas = block_info["baseFeePerGas"] From af569547d4e705d3f1fd8e5566d329074b6168d2 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 2 Nov 2023 08:21:59 +0800 Subject: [PATCH 10/15] Minor update to mempool tests --- test/functional/feature_evm_mempool.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/functional/feature_evm_mempool.py b/test/functional/feature_evm_mempool.py index fef685a328..3e20f99e88 100755 --- a/test/functional/feature_evm_mempool.py +++ b/test/functional/feature_evm_mempool.py @@ -196,9 +196,8 @@ def mempool_tx_limit(self): # Test max limit of TX from a specific sender for i in range(64): - self.nodes[0].evmtx( - self.ethAddress, nonce + i, 21, 21001, self.toAddress, 1 - ) + self.nodes[0].evmtx(self.ethAddress, nonce, 21, 21001, self.toAddress, 1) + nonce += 1 # Test error at the 64th EVM TX assert_raises_rpc_error( @@ -206,7 +205,7 @@ def mempool_tx_limit(self): "too-many-evm-txs-by-sender", self.nodes[0].evmtx, self.ethAddress, - nonce + 64, + nonce, 21, 21001, self.toAddress, @@ -215,12 +214,22 @@ def mempool_tx_limit(self): # Mint a block self.nodes[0].generate(1) - self.blockHash = self.nodes[0].getblockhash(self.nodes[0].getblockcount()) + height_checkpoint = self.nodes[0].getblockcount() + + # Check that now we can send again. + self.nodes[0].evmtx(self.ethAddress, nonce, 21, 21001, self.toAddress, 1) + self.nodes[0].generate(1) block_txs = self.nodes[0].getblock( self.nodes[0].getblockhash(self.nodes[0].getblockcount()) )["tx"] + assert_equal(len(block_txs), 2) + self.rollback_to(height_checkpoint) + + self.blockHash = self.nodes[0].getblockhash(height_checkpoint) + block_txs = self.nodes[0].getblock(self.blockHash)["tx"] assert_equal(len(block_txs), 65) + # Check accounting of EVM fees txLegacy = { "nonce": "0x1", @@ -279,7 +288,7 @@ def mempool_tx_limit(self): # Try and send another TX to make sure mempool has removed entries tx = self.nodes[0].evmtx( - self.ethAddress, nonce + 64, 21, 21001, self.toAddress, 1 + self.ethAddress, nonce, 21, 21001, self.toAddress, 1 ) self.nodes[0].generate(1) self.blockHash1 = self.nodes[0].getblockhash(self.nodes[0].getblockcount()) From 582e08be86fbf07d97bcda67fb8bb6579b5bdda5 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 2 Nov 2023 08:25:17 +0800 Subject: [PATCH 11/15] fmt --- test/functional/feature_evm_mempool.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/functional/feature_evm_mempool.py b/test/functional/feature_evm_mempool.py index 3e20f99e88..19ed9ac347 100755 --- a/test/functional/feature_evm_mempool.py +++ b/test/functional/feature_evm_mempool.py @@ -223,13 +223,13 @@ def mempool_tx_limit(self): self.nodes[0].getblockhash(self.nodes[0].getblockcount()) )["tx"] assert_equal(len(block_txs), 2) + self.rollback_to(height_checkpoint) self.blockHash = self.nodes[0].getblockhash(height_checkpoint) block_txs = self.nodes[0].getblock(self.blockHash)["tx"] assert_equal(len(block_txs), 65) - # Check accounting of EVM fees txLegacy = { "nonce": "0x1", @@ -287,9 +287,7 @@ def mempool_tx_limit(self): ) # Try and send another TX to make sure mempool has removed entries - tx = self.nodes[0].evmtx( - self.ethAddress, nonce, 21, 21001, self.toAddress, 1 - ) + tx = self.nodes[0].evmtx(self.ethAddress, nonce, 21, 21001, self.toAddress, 1) self.nodes[0].generate(1) self.blockHash1 = self.nodes[0].getblockhash(self.nodes[0].getblockcount()) From 2ddbb579ff6381af6b47fbd004270373ab6769ff Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 2 Nov 2023 09:13:40 +0800 Subject: [PATCH 12/15] Fix lints --- test/functional/feature_evm_mempool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/feature_evm_mempool.py b/test/functional/feature_evm_mempool.py index 19ed9ac347..01e21c7309 100755 --- a/test/functional/feature_evm_mempool.py +++ b/test/functional/feature_evm_mempool.py @@ -223,7 +223,7 @@ def mempool_tx_limit(self): self.nodes[0].getblockhash(self.nodes[0].getblockcount()) )["tx"] assert_equal(len(block_txs), 2) - + self.rollback_to(height_checkpoint) self.blockHash = self.nodes[0].getblockhash(height_checkpoint) From 6bad6302cb30f9887bd108c04c6e2db92557aa7d Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 2 Nov 2023 09:15:59 +0800 Subject: [PATCH 13/15] Fix more lints --- test/functional/feature_evm_mempool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/feature_evm_mempool.py b/test/functional/feature_evm_mempool.py index 01e21c7309..e3ab843bf4 100755 --- a/test/functional/feature_evm_mempool.py +++ b/test/functional/feature_evm_mempool.py @@ -195,7 +195,7 @@ def mempool_tx_limit(self): nonce = self.nodes[0].w3.eth.get_transaction_count(self.ethAddress) # Test max limit of TX from a specific sender - for i in range(64): + for _ in range(64): self.nodes[0].evmtx(self.ethAddress, nonce, 21, 21001, self.toAddress, 1) nonce += 1 From 4d5b3b710bf923a492ccbcdad091d38c2cd7ad15 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Thu, 2 Nov 2023 10:25:49 +0800 Subject: [PATCH 14/15] Cleanup redundant tests --- test/functional/feature_evm_mempool.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/test/functional/feature_evm_mempool.py b/test/functional/feature_evm_mempool.py index e3ab843bf4..d2dfac43b0 100755 --- a/test/functional/feature_evm_mempool.py +++ b/test/functional/feature_evm_mempool.py @@ -199,7 +199,7 @@ def mempool_tx_limit(self): self.nodes[0].evmtx(self.ethAddress, nonce, 21, 21001, self.toAddress, 1) nonce += 1 - # Test error at the 64th EVM TX + # Test error at the 65th EVM TX assert_raises_rpc_error( -26, "too-many-evm-txs-by-sender", @@ -214,19 +214,8 @@ def mempool_tx_limit(self): # Mint a block self.nodes[0].generate(1) - height_checkpoint = self.nodes[0].getblockcount() - - # Check that now we can send again. - self.nodes[0].evmtx(self.ethAddress, nonce, 21, 21001, self.toAddress, 1) - self.nodes[0].generate(1) - block_txs = self.nodes[0].getblock( - self.nodes[0].getblockhash(self.nodes[0].getblockcount()) - )["tx"] - assert_equal(len(block_txs), 2) - - self.rollback_to(height_checkpoint) - - self.blockHash = self.nodes[0].getblockhash(height_checkpoint) + current_height = self.nodes[0].getblockcount() + self.blockHash = self.nodes[0].getblockhash(current_height) block_txs = self.nodes[0].getblock(self.blockHash)["tx"] assert_equal(len(block_txs), 65) From 9e78fb82f82fda1c5682c1660bbb73735aeb8226 Mon Sep 17 00:00:00 2001 From: Niven Date: Thu, 2 Nov 2023 10:58:48 +0800 Subject: [PATCH 15/15] Cleanup --- test/functional/feature_evm_mempool.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/functional/feature_evm_mempool.py b/test/functional/feature_evm_mempool.py index d2dfac43b0..208563b190 100755 --- a/test/functional/feature_evm_mempool.py +++ b/test/functional/feature_evm_mempool.py @@ -214,8 +214,7 @@ def mempool_tx_limit(self): # Mint a block self.nodes[0].generate(1) - current_height = self.nodes[0].getblockcount() - self.blockHash = self.nodes[0].getblockhash(current_height) + self.blockHash = self.nodes[0].getblockhash(self.nodes[0].getblockcount()) block_txs = self.nodes[0].getblock(self.blockHash)["tx"] assert_equal(len(block_txs), 65)