Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add v53 to config store #6556

Merged
merged 4 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pub enum ProtocolFeature {
CorrectStackLimit,
/// Add `AccessKey` nonce range for implicit accounts, as in `AccessKeyNonceRange` feature.
AccessKeyNonceForImplicitAccounts,
/// Increase cost per deployed code byte to cover for the compilation steps
/// that a deployment triggers. Only affects the action execution cost.
IncreaseDeploymentCost,

// nightly features
#[cfg(feature = "protocol_feature_alt_bn128")]
Expand Down Expand Up @@ -218,6 +221,7 @@ impl ProtocolFeature {
ProtocolFeature::SynchronizeBlockChunkProduction
| ProtocolFeature::CorrectStackLimit => 50,
ProtocolFeature::AccessKeyNonceForImplicitAccounts => 51,
ProtocolFeature::IncreaseDeploymentCost => 53,

// Nightly features
#[cfg(feature = "protocol_feature_alt_bn128")]
Expand Down
81 changes: 81 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,87 @@ 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 new_protocol_version = ProtocolFeature::IncreaseDeploymentCost.protocol_version();
let old_protocol_version = new_protocol_version - 1;

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 in a closure.
let deploy_contract = |env: &mut TestEnv, nonce: u64| {
let tip = env.clients[0].chain.head().unwrap();
let signed_transaction =
Transaction { nonce, 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()
};

let old_outcome = deploy_contract(&mut env, 10);

// 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);
}
}

let new_outcome = deploy_contract(&mut env, 11);

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