Skip to content

Commit

Permalink
fix: Add v53 to config store
Browse files Browse the repository at this point in the history
When updating near#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.
  • Loading branch information
jakmeier committed Apr 8, 2022
1 parent ceb27ed commit 6c254e3
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/primitives/src/runtime/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -122,6 +123,7 @@ mod tests {
"2cuq2HvuHT7Z27LUbgEtMxP2ejqrHK34J2V1GL1joiMn",
"HFetcNKaC5s8Mj7bQz7jGMF7Rsvtuc3kjZRevWQ334n4",
"EP9bv2znwbuBuimUgrSQm48ymHqwbHyUArZcWavSbPce",
"Gs3KXwHmXYGghRZvcVNGXVpbJxVF5SDRNMB3f32DiXUF",
];
let actual_hashes = CONFIGS
.iter()
Expand Down
90 changes: 90 additions & 0 deletions integration-tests/src/tests/client/process_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<dyn RuntimeAdapter>> =
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;
Expand Down

0 comments on commit 6c254e3

Please sign in to comment.