-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move NightshadeRuntime to chain (#10675)
This PR is a part of getting rid of `KeyValueRuntime` (#10678) and `MockEpochManager` (#10634). Currently `NightshadeRuntime` is part of `nearcore` which makes it impossible to use it in `chain` since `chain` depends on `nearcore`. We need to use `NightshadeRuntime` as a replacement for `KeyValueRuntime` in `chain` tests. Ideally it would be great to move it to `node-runtime` crate, but currently it has a lot of dependencies from `near_chain` which makes it very challenging, so as the first step let's move it to `chain`. This PR includes: * move `nearcore::runtime` to `near_chain::runtime` * introduce `NightshadeRuntimeExt` to expose `NightshadeRuntime::from_config` separately since `NearConfig` is part of `nearcore` * move `GenesisExt` test methods directly to `Genesis`, also duplicate some constants for now (will be refactored separately to reduce size of this PR). * move the necessary migrations code to `chain`
- Loading branch information
Showing
75 changed files
with
489 additions
and
378 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
nearcore/src/runtime/errors.rs → chain/chain/src/runtime/errors.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use near_o11y::metrics::{ | ||
exponential_buckets, linear_buckets, processing_time_buckets, try_create_histogram_vec, | ||
try_create_int_gauge_vec, HistogramVec, IntGaugeVec, | ||
}; | ||
|
||
use once_cell::sync::Lazy; | ||
|
||
pub(crate) static APPLY_CHUNK_DELAY: Lazy<HistogramVec> = Lazy::new(|| { | ||
try_create_histogram_vec( | ||
"near_apply_chunk_delay_seconds", | ||
"Time to process a chunk. Gas used by the chunk is a metric label, rounded up to 100 teragas.", | ||
&["tgas_ceiling"], | ||
Some(linear_buckets(0.0, 0.05, 50).unwrap()), | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) static DELAYED_RECEIPTS_COUNT: Lazy<IntGaugeVec> = Lazy::new(|| { | ||
try_create_int_gauge_vec( | ||
"near_delayed_receipts_count", | ||
"The count of the delayed receipts. Indicator of congestion.", | ||
&["shard_id"], | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) static PREPARE_TX_SIZE: Lazy<HistogramVec> = Lazy::new(|| { | ||
try_create_histogram_vec( | ||
"near_prepare_tx_size", | ||
"Sum of transaction sizes per produced chunk, as a histogram", | ||
&["shard_id"], | ||
// Maximum is < 14MB, typical values are unknown right now so buckets | ||
// might need to be adjusted later when we have collected data | ||
Some(vec![1_000.0, 10_000., 100_000., 500_000., 1e6, 2e6, 4e6, 8e6, 12e6]), | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub static APPLYING_CHUNKS_TIME: Lazy<HistogramVec> = Lazy::new(|| { | ||
try_create_histogram_vec( | ||
"near_applying_chunks_time", | ||
"Time taken to apply chunks per shard", | ||
&["shard_id"], | ||
Some(processing_time_buckets()), | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) static STATE_SYNC_OBTAIN_PART_DELAY: Lazy<HistogramVec> = Lazy::new(|| { | ||
try_create_histogram_vec( | ||
"near_state_sync_obtain_part_delay_sec", | ||
"Latency of applying a state part", | ||
&["shard_id", "result"], | ||
Some(exponential_buckets(0.001, 2.0, 20).unwrap()), | ||
) | ||
.unwrap() | ||
}); | ||
|
||
pub(crate) static STATE_SYNC_APPLY_PART_DELAY: Lazy<HistogramVec> = Lazy::new(|| { | ||
try_create_histogram_vec( | ||
"near_state_sync_apply_part_delay_sec", | ||
"Latency of applying a state part", | ||
&["shard_id"], | ||
Some(exponential_buckets(0.001, 2.0, 20).unwrap()), | ||
) | ||
.unwrap() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use near_primitives::receipt::ReceiptResult; | ||
use near_primitives::runtime::migration_data::MigrationData; | ||
use near_primitives::types::Gas; | ||
|
||
/// In test runs reads and writes here used 442 TGas, but in test on live net migration take | ||
/// between 4 and 4.5s. We do not want to process any receipts in this block | ||
const GAS_USED_FOR_STORAGE_USAGE_DELTA_MIGRATION: Gas = 1_000_000_000_000_000; | ||
|
||
pub fn load_migration_data(chain_id: &str) -> MigrationData { | ||
let is_mainnet = chain_id == near_primitives::chains::MAINNET; | ||
MigrationData { | ||
storage_usage_delta: if is_mainnet { | ||
near_mainnet_res::mainnet_storage_usage_delta() | ||
} else { | ||
Vec::new() | ||
}, | ||
storage_usage_fix_gas: if is_mainnet { | ||
GAS_USED_FOR_STORAGE_USAGE_DELTA_MIGRATION | ||
} else { | ||
0 | ||
}, | ||
restored_receipts: if is_mainnet { | ||
near_mainnet_res::mainnet_restored_receipts() | ||
} else { | ||
ReceiptResult::default() | ||
}, | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use near_mainnet_res::mainnet_restored_receipts; | ||
use near_mainnet_res::mainnet_storage_usage_delta; | ||
use near_primitives::hash::hash; | ||
|
||
#[test] | ||
fn test_migration_data() { | ||
assert_eq!( | ||
hash(serde_json::to_string(&mainnet_storage_usage_delta()).unwrap().as_bytes()) | ||
.to_string(), | ||
"2fEgaLFBBJZqgLQEvHPsck4NS3sFzsgyKaMDqTw5HVvQ" | ||
); | ||
let mainnet_migration_data = load_migration_data(near_primitives::chains::MAINNET); | ||
assert_eq!(mainnet_migration_data.storage_usage_delta.len(), 3112); | ||
let testnet_migration_data = load_migration_data(near_primitives::chains::TESTNET); | ||
assert_eq!(testnet_migration_data.storage_usage_delta.len(), 0); | ||
} | ||
|
||
#[test] | ||
fn test_restored_receipts_data() { | ||
assert_eq!( | ||
hash(serde_json::to_string(&mainnet_restored_receipts()).unwrap().as_bytes()) | ||
.to_string(), | ||
"48ZMJukN7RzvyJSW9MJ5XmyQkQFfjy2ZxPRaDMMHqUcT" | ||
); | ||
let mainnet_migration_data = load_migration_data(near_primitives::chains::MAINNET); | ||
assert_eq!(mainnet_migration_data.restored_receipts.get(&0u64).unwrap().len(), 383); | ||
let testnet_migration_data = load_migration_data(near_primitives::chains::TESTNET); | ||
assert!(testnet_migration_data.restored_receipts.is_empty()); | ||
} | ||
} |
Oops, something went wrong.