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(congestion) - Correctly handle receipt gas and size calculation in protocol upgrades #12031

Merged
merged 20 commits into from
Sep 23, 2024
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
9 changes: 6 additions & 3 deletions chain/client/src/test_utils/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,12 @@ impl TestEnv {
pub fn print_block_summary(&self, height: u64) {
let client = &self.clients[0];
let block = client.chain.get_block_by_height(height);
let Ok(block) = block else {
tracing::info!(target: "test", "Block {}: missing", height);
return;
let block = match block {
Ok(block) => block,
Err(err) => {
tracing::info!(target: "test", ?err, "Block {}: missing", height);
return;
}
};
let prev_hash = block.header().prev_hash();
let epoch_id = client.epoch_manager.get_epoch_id_from_prev_block(prev_hash).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions core/parameters/res/runtime_configs/72.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
main_storage_proof_size_soft_limit: {old: 3_000_000, new: 4_000_000}

use_state_stored_receipt: { old: false, new: true }

# See https://github.com/near/nearcore/pull/12044 for why the values are set to these values.
# In addition, `gas` is set to 1 for the large read variants, because we need that in actual code.
# For this to be transparent for smart contracts, the `read_base` and `read_value_byte` values were
Expand Down
1 change: 1 addition & 0 deletions core/parameters/res/runtime_configs/parameters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,4 @@ allowed_shard_outgoing_gas 1_000_000_000_000_000
max_tx_gas 500_000_000_000_000
min_tx_gas 20_000_000_000_000
reject_tx_congestion_threshold 50 / 100
use_state_stored_receipt true
2 changes: 2 additions & 0 deletions core/parameters/res/runtime_configs/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,5 @@ reject_tx_congestion_threshold: {
numerator: 1,
denominator: 1,
}

use_state_stored_receipt: false
2 changes: 2 additions & 0 deletions core/parameters/res/runtime_configs/parameters_testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,5 @@ reject_tx_congestion_threshold: {
numerator: 1,
denominator: 1,
}

use_state_stored_receipt: false
5 changes: 5 additions & 0 deletions core/parameters/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub struct RuntimeConfig {
pub congestion_control_config: CongestionControlConfig,
/// Configuration specific to ChunkStateWitness.
pub witness_config: WitnessConfig,

/// Whether receipts should be stored as [StateStoredReceipt].
pub use_state_stored_receipt: bool,
}

impl RuntimeConfig {
Expand Down Expand Up @@ -59,6 +62,7 @@ impl RuntimeConfig {
account_creation_config: AccountCreationConfig::default(),
congestion_control_config: runtime_config.congestion_control_config,
witness_config: runtime_config.witness_config,
use_state_stored_receipt: runtime_config.use_state_stored_receipt,
}
}

Expand All @@ -75,6 +79,7 @@ impl RuntimeConfig {
account_creation_config: AccountCreationConfig::default(),
congestion_control_config: runtime_config.congestion_control_config,
witness_config: runtime_config.witness_config,
use_state_stored_receipt: runtime_config.use_state_stored_receipt,
}
}

Expand Down
8 changes: 7 additions & 1 deletion core/parameters/src/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static CONFIG_DIFFS: &[(ProtocolVersion, &str)] = &[
(69, include_config!("69.yaml")),
// Introduce ETH-implicit accounts.
(70, include_config!("70.yaml")),
// Increase main_storage_proof_size_soft_limit
// Increase main_storage_proof_size_soft_limit and introduces StateStoredReceipt
(72, include_config!("72.yaml")),
(129, include_config!("129.yaml")),
];
Expand Down Expand Up @@ -119,6 +119,7 @@ impl RuntimeConfigStore {
account_creation_config: runtime_config.account_creation_config.clone(),
congestion_control_config: runtime_config.congestion_control_config,
witness_config: runtime_config.witness_config,
use_state_stored_receipt: runtime_config.use_state_stored_receipt,
}),
);
store.insert(0, Arc::new(runtime_config.clone()));
Expand Down Expand Up @@ -164,6 +165,11 @@ impl RuntimeConfigStore {
Self { store: BTreeMap::from_iter([(0, Arc::new(runtime_config))].iter().cloned()) }
}

/// Constructs store with custom configs. This should only be used for testing.
pub fn new_custom(store: BTreeMap<ProtocolVersion, Arc<RuntimeConfig>>) -> Self {
Self { store }
}

/// Constructs test store.
pub fn test() -> Self {
Self::with_one_config(RuntimeConfig::test())
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 @@ -220,6 +220,9 @@ pub enum Parameter {
MaxTxGas,
MinTxGas,
RejectTxCongestionThreshold,

// Use the StateStoredReceipt structure when storing receipts in State.
UseStateStoredReceipt,
}

#[derive(
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 @@ -344,6 +344,7 @@ impl TryFrom<&ParameterTable> for RuntimeConfig {
new_transactions_validation_state_size_soft_limit: params
.get(Parameter::NewTransactionsValidationStateSizeSoftLimit)?,
},
use_state_stored_receipt: params.get(Parameter::UseStateStoredReceipt)?,
})
}
}
Expand Down
5 changes: 4 additions & 1 deletion core/primitives-core/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ pub enum ProtocolFeature {
// in order to calculate the rewards and kickouts for the chunk validators.
// This feature introduces BlockHeaderV5.
ChunkEndorsementsInBlockHeader,
/// Store receipts in State in the StateStoredReceipt format.
StateStoredReceipt,
}

impl ProtocolFeature {
Expand Down Expand Up @@ -226,7 +228,8 @@ impl ProtocolFeature {
ProtocolFeature::FixMinStakeRatio => 71,
ProtocolFeature::IncreaseStorageProofSizeSoftLimit
| ProtocolFeature::ChunkEndorsementV2
| ProtocolFeature::ChunkEndorsementsInBlockHeader => 72,
| ProtocolFeature::ChunkEndorsementsInBlockHeader
| ProtocolFeature::StateStoredReceipt => 72,

// This protocol version is reserved for use in resharding tests. An extra resharding
// is simulated on top of the latest shard layout in production. Note that later
Expand Down
Loading
Loading