-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e89ed0
commit b424c66
Showing
5 changed files
with
138 additions
and
0 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
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,44 @@ | ||
[package] | ||
name = "congestion-metrics" | ||
version.workspace = true | ||
authors.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
actix-rt.workspace = true | ||
actix.workspace = true | ||
anyhow.workspace = true | ||
clap.workspace = true | ||
futures.workspace = true | ||
pin-project.workspace = true | ||
rand.workspace = true | ||
rayon.workspace = true | ||
serde.workspace = true | ||
serde_json.workspace = true | ||
tempfile.workspace = true | ||
tokio.workspace = true | ||
tracing.workspace = true | ||
|
||
near-actix-test-utils.workspace = true | ||
near-time.workspace = true | ||
near-chain.workspace = true | ||
near-chain-configs.workspace = true | ||
near-client.workspace = true | ||
near-crypto.workspace = true | ||
near-chunks.workspace = true | ||
near-epoch-manager.workspace = true | ||
near-jsonrpc.workspace = true | ||
near-jsonrpc-client.workspace = true | ||
near-network.workspace = true | ||
near-store.workspace = true | ||
near-o11y.workspace = true | ||
near-telemetry.workspace = true | ||
near-performance-metrics.workspace = true | ||
near-primitives.workspace = true | ||
nearcore.workspace = true | ||
|
||
[lints] | ||
workspace = true |
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,46 @@ | ||
use near_jsonrpc::primitives::types::chunks::ChunkReference; | ||
use near_jsonrpc::primitives::types::congestion::RpcCongestionLevelRequest; | ||
use near_jsonrpc_client::new_client; | ||
use tokio::fs::File; | ||
use tokio::io::AsyncWriteExt; | ||
|
||
use near_primitives::types::{BlockId, BlockReference}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut file = File::create("data.csv").await?; | ||
file.write_all(b"block_height,shard_id,congestion_level\n").await?; | ||
|
||
let client = new_client("https://archival-rpc.mainnet.near.org"); | ||
let start_height: u64 = 133453990; | ||
let end_height: u64 = 133454000; | ||
let mut current_height = end_height; | ||
|
||
while current_height >= start_height { | ||
let block = | ||
client.block(BlockReference::BlockId(BlockId::Height(current_height))).await.unwrap(); | ||
for chunk in block.chunks { | ||
let congestion_level = client | ||
.EXPERIMENTAL_congestion_level(RpcCongestionLevelRequest { | ||
chunk_reference: ChunkReference::BlockShardId { | ||
block_id: BlockId::Height(current_height), | ||
shard_id: chunk.shard_id, | ||
}, | ||
}) | ||
.await | ||
.unwrap(); | ||
file.write_all( | ||
format!( | ||
"{},{},{}\n", | ||
current_height, chunk.shard_id, congestion_level.congestion_level | ||
) | ||
.as_bytes(), | ||
) | ||
.await?; | ||
} | ||
current_height = block.header.prev_height.unwrap(); | ||
} | ||
|
||
file.flush().await?; | ||
Ok(()) | ||
} |