Skip to content

Commit

Permalink
[stateless_validation] Add a soft size limit for state witness (#10703)
Browse files Browse the repository at this point in the history
This PR adds a new runtime config `state_witness_size_soft_limit` with
size about 16 MB to begin with along with an implementation to enforce
it in runtime.

This is the first step of #10259

What is state witness size soft limit?

In order to limit the size of the state witness, as a first step, we are
adding a limit to the max size of the state witness partial trie or
proof. In runtime, we record all the trie nodes touched by the chunk
execution and include these in the state witness. With the limit in
place, if the size of the state witness exceeds 16 MB, then we would
stop applying receipts further and push all receipts into the delayed
queue.

The reason we call this a soft limit is that we stop the execution of
the receipts AFTER the size of the state witness has exceeded 16 MB.

We are including this as part of a new protocol version 83

Future steps
- Introduce limits on other parts of the state witness like new
transactions
- Introduce a hard size limit for individual contract executions
- Monitor size of state witness
- Add metrics in a separate PR
  • Loading branch information
Shreyan Gupta authored Mar 7, 2024
1 parent d50e30c commit 8e0bdf3
Show file tree
Hide file tree
Showing 57 changed files with 686 additions and 64 deletions.
1 change: 1 addition & 0 deletions core/parameters/res/runtime_configs/83.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
storage_proof_size_soft_limit: {old: 999_999_999_999_999, new: 16_000_000}
2 changes: 1 addition & 1 deletion core/parameters/res/runtime_configs/parameters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ description: THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
---
burnt_gas_reward 3 / 10
pessimistic_gas_price_inflation 103 / 100
storage_proof_size_soft_limit 999_999_999_999_999
min_allowed_top_level_account_length 65
registrar_account_id registrar
storage_amount_per_byte 10000000000000000000
Expand Down Expand Up @@ -180,4 +181,3 @@ function_call_weight true
vm_kind NearVm
eth_implicit_accounts false
yield_resume false

3 changes: 3 additions & 0 deletions core/parameters/res/runtime_configs/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pessimistic_gas_price_inflation: {
denominator: 100,
}

# Stateless validation config
storage_proof_size_soft_limit: 999_999_999_999_999

# Account creation config
min_allowed_top_level_account_length: 32
registrar_account_id: "registrar"
Expand Down
3 changes: 3 additions & 0 deletions core/parameters/res/runtime_configs/parameters_testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pessimistic_gas_price_inflation: {
denominator: 100,
}

# Stateless validation config
storage_proof_size_soft_limit: 999_999_999_999_999

# Account creation config
min_allowed_top_level_account_length: 0
registrar_account_id: "registrar"
Expand Down
4 changes: 4 additions & 0 deletions core/parameters/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct RuntimeConfig {
pub wasm_config: crate::vm::Config,
/// Config that defines rules for account creation.
pub account_creation_config: AccountCreationConfig,
/// The maximum size of the storage proof in state witness after which we defer execution of any new receipts.
pub storage_proof_size_soft_limit: usize,
}

impl RuntimeConfig {
Expand All @@ -45,6 +47,7 @@ impl RuntimeConfig {
fees: RuntimeFeesConfig::test(),
wasm_config,
account_creation_config: AccountCreationConfig::default(),
storage_proof_size_soft_limit: usize::MAX,
}
}

Expand All @@ -57,6 +60,7 @@ impl RuntimeConfig {
fees: RuntimeFeesConfig::free(),
wasm_config,
account_creation_config: AccountCreationConfig::default(),
storage_proof_size_soft_limit: usize::MAX,
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/parameters/src/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[
(62, include_config!("62.yaml")),
(63, include_config!("63.yaml")),
(64, include_config!("64.yaml")),
(83, include_config!("83.yaml")),
(129, include_config!("129.yaml")),
// Introduce ETH-implicit accounts.
(138, include_config!("138.yaml")),
Expand Down Expand Up @@ -317,6 +318,7 @@ mod tests {
/// the new snapshot if it looks right.
#[test]
#[cfg(not(feature = "nightly"))]
#[cfg(not(feature = "statelessnet_protocol"))]
#[cfg(not(feature = "calimero_zero_storage"))]
fn test_json_unchanged() {
use crate::view::RuntimeConfigView;
Expand Down
3 changes: 3 additions & 0 deletions core/parameters/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum Parameter {
BurntGasReward,
PessimisticGasPriceInflation,

// Stateless validation config
StorageProofSizeSoftLimit,

// Account creation config
MinAllowedTopLevelAccountLength,
RegistrarAccountId,
Expand Down
1 change: 1 addition & 0 deletions core/parameters/src/parameter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ impl TryFrom<&ParameterTable> for RuntimeConfig {
.get(Parameter::MinAllowedTopLevelAccountLength)?,
registrar_account_id: params.get(Parameter::RegistrarAccountId)?,
},
storage_proof_size_soft_limit: params.get(Parameter::StorageProofSizeSoftLimit)?,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 16000000
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 16000000
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 16000000
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ expression: config_view
"pessimistic_gas_price_inflation_ratio": [
103,
100
]
],
"storage_proof_size_soft_limit": 999999999999999
},
"wasm_config": {
"ext_costs": {
Expand Down
Loading

0 comments on commit 8e0bdf3

Please sign in to comment.