Skip to content

Commit

Permalink
near-vm-runner: remove reliance on protocol version for import gating (
Browse files Browse the repository at this point in the history
…near#9476)

* near-vm-runner: remove reliance on protocol version for import gating

I had entirely forgotten/missed that this was still using
protocol versioning rather than configs to control availability of host
functions for the contracts. This hopefully should be the last place
where we truly depend on them (outside of tests?)

* Style fixes
  • Loading branch information
nagisa authored Sep 12, 2023
1 parent 55a19d3 commit 9ddfd49
Show file tree
Hide file tree
Showing 67 changed files with 1,107 additions and 161 deletions.
14 changes: 3 additions & 11 deletions chain/client/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ impl near_network::client::Client for Adapter {
) -> Option<Box<FinalExecutionOutcomeView>> {
match self
.view_client_addr
.send(
TxStatusRequest { tx_hash: tx_hash, signer_account_id: account_id }
.with_span_context(),
)
.send(TxStatusRequest { tx_hash, signer_account_id: account_id }.with_span_context())
.await
{
Ok(res) => res,
Expand Down Expand Up @@ -194,9 +191,7 @@ impl near_network::client::Client for Adapter {
) -> Result<Option<StateResponseInfo>, ReasonForBan> {
match self
.view_client_addr
.send(
StateRequestHeader { shard_id: shard_id, sync_hash: sync_hash }.with_span_context(),
)
.send(StateRequestHeader { shard_id, sync_hash }.with_span_context())
.await
{
Ok(Some(StateResponse(resp))) => Ok(Some(*resp)),
Expand All @@ -216,10 +211,7 @@ impl near_network::client::Client for Adapter {
) -> Result<Option<StateResponseInfo>, ReasonForBan> {
match self
.view_client_addr
.send(
StateRequestPart { shard_id: shard_id, sync_hash: sync_hash, part_id: part_id }
.with_span_context(),
)
.send(StateRequestPart { shard_id, sync_hash, part_id }.with_span_context())
.await
{
Ok(Some(StateResponse(resp))) => Ok(Some(*resp)),
Expand Down
4 changes: 4 additions & 0 deletions core/primitives-core/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ pub enum Parameter {
FlatStorageReads,
ImplicitAccountCreation,
FixContractLoadingCost,
MathExtension,
Ed25519Verify,
AltBn128,
FunctionCallWeight,
}

#[derive(
Expand Down
1 change: 1 addition & 0 deletions core/primitives/res/runtime_configs/46.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
math_extension: { old: false, new: true }
1 change: 1 addition & 0 deletions core/primitives/res/runtime_configs/53.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ action_deploy_contract_per_byte: {
wasmer2_stack_limit: { new: 204_800 }
max_length_storage_key: { old: 4_194_304, new: 2_048 }
max_locals_per_contract: { new: 1_000_000 }
function_call_weight: { old: false, new: true }
1 change: 1 addition & 0 deletions core/primitives/res/runtime_configs/55.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alt_bn128: { old: false, new: true }
3 changes: 2 additions & 1 deletion core/primitives/res/runtime_configs/59.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ed25519_verify: { old: false, new: true }
action_create_account: {
old: {
send_sir: 99_607_375_000,
Expand All @@ -9,4 +10,4 @@ action_create_account: {
send_not_sir: 3_850_000_000_000,
execution: 3_850_000_000_000,
}
}
}
4 changes: 4 additions & 0 deletions core/primitives/res/runtime_configs/parameters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,8 @@ disable_9393_fix false
flat_storage_reads true
implicit_account_creation true
fix_contract_loading_cost true
math_extension true
ed25519_verify true
alt_bn128 true
function_call_weight true

4 changes: 4 additions & 0 deletions core/primitives/res/runtime_configs/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,7 @@ disable_9393_fix: false
flat_storage_reads: false
implicit_account_creation: false
fix_contract_loading_cost: false
math_extension: false
ed25519_verify: false
alt_bn128: false
function_call_weight: false
4 changes: 4 additions & 0 deletions core/primitives/res/runtime_configs/parameters_testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,7 @@ disable_9393_fix: false
flat_storage_reads: false
implicit_account_creation: false
fix_contract_loading_cost: false
math_extension: false
ed25519_verify: false
alt_bn128: false
function_call_weight: false
25 changes: 16 additions & 9 deletions core/primitives/src/runtime/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static BASE_CONFIG: &str = include_config!("parameters.yaml");
static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[
(35, include_config!("35.yaml")),
(42, include_config!("42.yaml")),
(46, include_config!("46.yaml")),
(48, include_config!("48.yaml")),
(49, include_config!("49.yaml")),
(50, include_config!("50.yaml")),
Expand All @@ -28,6 +29,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[
// Increased deployment costs, increased wasmer2 stack_limit, added limiting of contract locals,
// set read_cached_trie_node cost, decrease storage key limit
(53, include_config!("53.yaml")),
(55, include_config!("55.yaml")),
(57, include_config!("57.yaml")),
// Introduce Zero Balance Account and increase account creation cost to 7.7Tgas
(59, include_config!("59.yaml")),
Expand Down Expand Up @@ -262,19 +264,24 @@ mod tests {
store.get_config(LowerStorageCost.protocol_version() - 1).as_ref()
);

let expected_config = {
base_params.apply_diff(CONFIG_DIFFS[0].1.parse().unwrap()).unwrap();
base_params.apply_diff(CONFIG_DIFFS[1].1.parse().unwrap()).unwrap();
RuntimeConfig::new(&base_params).unwrap()
};
for (ver, diff) in &CONFIG_DIFFS[..] {
if *ver <= LowerStorageCost.protocol_version() {
base_params.apply_diff(diff.parse().unwrap()).unwrap();
}
}
let expected_config = RuntimeConfig::new(&base_params).unwrap();
assert_eq!(**config, expected_config);

let config = store.get_config(LowerDataReceiptAndEcrecoverBaseCost.protocol_version());
assert_eq!(config.fees.fee(ActionCosts::new_data_receipt_base).send_sir, 36_486_732_312);
let expected_config = {
base_params.apply_diff(CONFIG_DIFFS[2].1.parse().unwrap()).unwrap();
RuntimeConfig::new(&base_params).unwrap()
};
for (ver, diff) in &CONFIG_DIFFS[..] {
if *ver <= LowerStorageCost.protocol_version() {
continue;
} else if *ver <= LowerDataReceiptAndEcrecoverBaseCost.protocol_version() {
base_params.apply_diff(diff.parse().unwrap()).unwrap();
}
}
let expected_config = RuntimeConfig::new(&base_params).unwrap();
assert_eq!(config.as_ref(), &expected_config);
}

Expand Down
4 changes: 4 additions & 0 deletions core/primitives/src/runtime/parameter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ impl TryFrom<&ParameterTable> for RuntimeConfig {
false => StorageGetMode::Trie,
},
implicit_account_creation: params.get(Parameter::ImplicitAccountCreation)?,
math_extension: params.get(Parameter::MathExtension)?,
ed25519_verify: params.get(Parameter::Ed25519Verify)?,
alt_bn128: params.get(Parameter::AltBn128)?,
function_call_weight: params.get(Parameter::FunctionCallWeight)?,
},
account_creation_config: AccountCreationConfig {
min_allowed_top_level_account_length: params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ expression: config_view
"storage_get_mode": "Trie",
"fix_contract_loading_cost": false,
"implicit_account_creation": false,
"math_extension": false,
"ed25519_verify": false,
"alt_bn128": false,
"function_call_weight": false,
"limit_config": {
"max_gas_burnt": 200000000000000,
"max_stack_height": 16384,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ expression: config_view
"storage_get_mode": "FlatStorage",
"fix_contract_loading_cost": true,
"implicit_account_creation": true,
"math_extension": true,
"ed25519_verify": true,
"alt_bn128": true,
"function_call_weight": true,
"limit_config": {
"max_gas_burnt": 300000000000000,
"max_stack_height": 262144,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ expression: config_view
"storage_get_mode": "Trie",
"fix_contract_loading_cost": false,
"implicit_account_creation": true,
"math_extension": false,
"ed25519_verify": false,
"alt_bn128": false,
"function_call_weight": false,
"limit_config": {
"max_gas_burnt": 200000000000000,
"max_stack_height": 16384,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ expression: config_view
"storage_get_mode": "Trie",
"fix_contract_loading_cost": false,
"implicit_account_creation": true,
"math_extension": false,
"ed25519_verify": false,
"alt_bn128": false,
"function_call_weight": false,
"limit_config": {
"max_gas_burnt": 200000000000000,
"max_stack_height": 16384,
Expand Down
Loading

0 comments on commit 9ddfd49

Please sign in to comment.