From 6c254e30ef491eed79375272875405a862d4b6ab Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 8 Apr 2022 02:19:47 +0200 Subject: [PATCH] fix: Add v53 to config store When updating #6397 to protocol v53 right before merging, I forgot to add the configuration JSON file to the config store. Test plan --------- Added a test to verify that cost indeed increases. --- core/primitives/src/runtime/config_store.rs | 2 + .../src/tests/client/process_blocks.rs | 90 +++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/core/primitives/src/runtime/config_store.rs b/core/primitives/src/runtime/config_store.rs index 9a187f6472d..50a0ce3bb77 100644 --- a/core/primitives/src/runtime/config_store.rs +++ b/core/primitives/src/runtime/config_store.rs @@ -22,6 +22,7 @@ static CONFIGS: &[(ProtocolVersion, &[u8])] = &[ (50, include_config!("50.json")), // max_gas_burnt increased to 300 TGas (52, include_config!("52.json")), + (53, include_config!("53.json")), ]; pub static INITIAL_TESTNET_CONFIG: &[u8] = include_config!("29_testnet.json"); @@ -122,6 +123,7 @@ mod tests { "2cuq2HvuHT7Z27LUbgEtMxP2ejqrHK34J2V1GL1joiMn", "HFetcNKaC5s8Mj7bQz7jGMF7Rsvtuc3kjZRevWQ334n4", "EP9bv2znwbuBuimUgrSQm48ymHqwbHyUArZcWavSbPce", + "Gs3KXwHmXYGghRZvcVNGXVpbJxVF5SDRNMB3f32DiXUF", ]; let actual_hashes = CONFIGS .iter() diff --git a/integration-tests/src/tests/client/process_blocks.rs b/integration-tests/src/tests/client/process_blocks.rs index 3be7dc9bd30..77c96f44f53 100644 --- a/integration-tests/src/tests/client/process_blocks.rs +++ b/integration-tests/src/tests/client/process_blocks.rs @@ -3459,6 +3459,96 @@ fn test_catchup_no_sharding_change() { } } +/// Tests if the cost of deployment is higher after the protocol update 53 +#[test] +fn test_deploy_cost_increased() { + let old_protocol_version = 52; + let new_protocol_version = 53; + + let contract_size = 1024 * 1024; + let test_contract = near_test_contracts::sized_contract(contract_size); + + // Prepare TestEnv with a contract at the old protocol version. + let epoch_length = 5; + let mut env = { + let mut genesis = Genesis::test(vec!["test0".parse().unwrap()], 1); + genesis.config.epoch_length = epoch_length; + genesis.config.protocol_version = old_protocol_version; + let chain_genesis = ChainGenesis::from(&genesis); + let runtimes: Vec> = + vec![Arc::new(nearcore::NightshadeRuntime::test_with_runtime_config_store( + Path::new("../../../.."), + create_test_store(), + &genesis, + TrackedConfig::new_empty(), + RuntimeConfigStore::new(None), + ))]; + TestEnv::builder(chain_genesis).runtime_adapters(runtimes).build() + }; + + let signer = InMemorySigner::from_seed("test0".parse().unwrap(), KeyType::ED25519, "test0"); + let tx = Transaction { + signer_id: "test0".parse().unwrap(), + receiver_id: "test0".parse().unwrap(), + public_key: signer.public_key(), + actions: vec![Action::DeployContract(DeployContractAction { code: test_contract })], + nonce: 0, + block_hash: CryptoHash::default(), + }; + + // Run the transaction & get tx outcome. + let old_outcome = { + let tip = env.clients[0].chain.head().unwrap(); + let signed_transaction = + Transaction { nonce: 10, block_hash: tip.last_block_hash, ..tx.clone() }.sign(&signer); + let tx_hash = signed_transaction.get_hash(); + env.clients[0].process_tx(signed_transaction, false, false); + for i in 0..epoch_length { + env.produce_block(0, tip.height + i + 1); + } + env.clients[0].chain.get_final_transaction_result(&tx_hash).unwrap() + }; + + // Move to the new protocol version. + { + let tip = env.clients[0].chain.head().unwrap(); + let epoch_id = env.clients[0] + .runtime_adapter + .get_epoch_id_from_prev_block(&tip.last_block_hash) + .unwrap(); + let block_producer = + env.clients[0].runtime_adapter.get_block_producer(&epoch_id, tip.height).unwrap(); + let mut block = env.clients[0].produce_block(tip.height + 1).unwrap().unwrap(); + set_block_protocol_version(&mut block, block_producer, new_protocol_version); + let (_, res) = env.clients[0].process_block(block.clone().into(), Provenance::NONE); + assert!(res.is_ok()); + for i in 0..epoch_length { + env.produce_block(0, tip.height + i + 2); + } + } + + // Re-run the transaction & get tx outcome. + let new_outcome = { + let tip = env.clients[0].chain.head().unwrap(); + let signed_transaction = + Transaction { nonce: 11, block_hash: tip.last_block_hash, ..tx }.sign(&signer); + let tx_hash = signed_transaction.get_hash(); + env.clients[0].process_tx(signed_transaction, false, false); + for i in 0..epoch_length { + env.produce_block(0, tip.height + i + 1); + } + env.clients[0].chain.get_final_transaction_result(&tx_hash).unwrap() + }; + + assert!(matches!(old_outcome.status, FinalExecutionStatus::SuccessValue(_))); + assert!(matches!(new_outcome.status, FinalExecutionStatus::SuccessValue(_))); + + let old_deploy_gas = old_outcome.receipts_outcome[0].outcome.gas_burnt; + let new_deploy_gas = new_outcome.receipts_outcome[0].outcome.gas_burnt; + assert!(new_deploy_gas > old_deploy_gas); + assert_eq!(new_deploy_gas - old_deploy_gas, contract_size as u64 * (64_572_944 - 6_812_999)); +} + mod access_key_nonce_range_tests { use super::*; use near_chain::chain::NUM_ORPHAN_ANCESTORS_CHECK;