Skip to content

Commit

Permalink
fix(temporary mitigation): Skip genesis bootstrapping for statelessnet (
Browse files Browse the repository at this point in the history
#11727)

This is a mitigation for the failure that is caused by the stabilization
PR #11701.

[Zulip
thread](https://near.zulipchat.com/#narrow/stream/308695-nearone.2Fprivate/topic/Cherrypicks.20to.20statelessnet.20branch/near/449016937)

Context: In statelessnet, the genesis version is above 68, so it assumes
that genesis has the congestion control is enabled and hitting an issue
that attempts to bootstrap congestion info (again) and hitting missing
state roots.

We attempted to move the version numbers for congestion control and
stateless validation back to 80 and 81 to mitigate the problem, [in this
PR](#11719) but it became
unnecessarily complex and risky.

Thus, in this PR, we simply bypass the problematic bootstrap for
statelessnet only. We moved the check for the chain id after the genesis
protocol version check so we will not run it for testnet and mainnet.
  • Loading branch information
tayfunelmas committed Jul 5, 2024
1 parent d9a6e23 commit b2f1772
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions chain/chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3951,8 +3951,14 @@ fn get_genesis_congestion_infos_impl(
let mut result = vec![];
for (shard_id, &state_root) in state_roots.iter().enumerate() {
let shard_id = shard_id as ShardId;
let congestion_info =
get_congestion_info(runtime, protocol_version, &prev_hash, shard_id, state_root)?;
let congestion_info = get_congestion_info(
runtime,
protocol_version,
&prev_hash,
shard_id,
state_root,
&epoch_id,
)?;
result.push(congestion_info);
}
Ok(result)
Expand All @@ -3964,11 +3970,21 @@ fn get_congestion_info(
prev_hash: &CryptoHash,
shard_id: ShardId,
state_root: StateRoot,
epoch_id: &EpochId,
) -> Result<Option<CongestionInfo>, Error> {
if !ProtocolFeature::CongestionControl.enabled(protocol_version) {
return Ok(None);
}

// Since the congestion info is already bootstrapped in statelessnet, skip another bootstrap.
// TODO: This is temporary mitigation for the failing genesis congestion info due to garbage
// collected genesis state roots. It can be removed after the statelessnet network is turned down.
if let Ok(protocol_config) = runtime.get_protocol_config(&epoch_id) {
if protocol_config.genesis_config.chain_id == near_primitives::chains::STATELESSNET {
return Ok(None);
}
}

// Get the view trie because it's possible that the chain is ahead of
// genesis and doesn't have this block in flat state and memtrie.
let trie = runtime.get_view_trie_for_shard(shard_id, prev_hash, state_root)?;
Expand Down
2 changes: 1 addition & 1 deletion chain/chain/src/test_utils/kv_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ impl RuntimeAdapter for KeyValueRuntime {
}

fn get_protocol_config(&self, _epoch_id: &EpochId) -> Result<ProtocolConfig, Error> {
unreachable!("get_protocol_config should not be called in KeyValueRuntime");
Err(Error::Other("get_protocol_config should not be used in KeyValueRuntime".into()))
}

fn get_runtime_config(
Expand Down

0 comments on commit b2f1772

Please sign in to comment.