Skip to content
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
17 changes: 15 additions & 2 deletions script/src/tendermint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ impl Default for TendermintRPCClient {
pub const DEFAULT_TENDERMINT_RPC_TIMEOUT_SECS: u64 = 20;

/// The default concurrency for Tendermint RPC requests.
pub const DEFAULT_TENDERMINT_RPC_CONCURRENCY: usize = 5;
pub const DEFAULT_TENDERMINT_RPC_CONCURRENCY: usize = 20;

/// The default sleep duration for Tendermint RPC requests in milliseconds.
pub const DEFAULT_TENDERMINT_RPC_SLEEP_MS: Duration = Duration::from_millis(1250);
pub const DEFAULT_TENDERMINT_RPC_SLEEP_MS: Duration = Duration::from_millis(500);

/// The maximum number of failures allowed when retrying a Tendermint RPC request.
pub const DEFAULT_FAILURES_ALLOWED: u32 = 20;
Expand Down Expand Up @@ -128,6 +128,19 @@ impl TendermintRPCClient {
.context("Failed to parse block by height response")
}

/// Fetches the header by its height.
pub async fn fetch_header_by_height(&self, height: u64) -> anyhow::Result<HeaderResponse> {
let url = format!("{}/header?height={}", self.url, height);
self.client
.get(url)
.send()
.await
.context("Failed to fetch header by height")?
.json::<HeaderResponse>()
.await
.context("Failed to parse header by height response")
}

/// Fetches the latest commit from the Tendermint node.
pub async fn fetch_latest_commit(&self) -> anyhow::Result<CommitResponse> {
pub async fn inner(client: &TendermintRPCClient) -> anyhow::Result<CommitResponse> {
Expand Down
12 changes: 11 additions & 1 deletion script/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::Deserialize;
use tendermint::{
block::{self, signed_header::SignedHeader},
block::{self, signed_header::SignedHeader, Header},
validator::Info,
Block,
};
Expand Down Expand Up @@ -32,6 +32,16 @@ pub struct BlockWrapper {
pub block: Block,
}

#[derive(Debug, Deserialize)]
pub struct HeaderResponse {
pub result: HeaderWrapper,
}

#[derive(Debug, Deserialize)]
pub struct HeaderWrapper {
pub header: Header,
}

#[derive(Debug, Deserialize)]
pub struct CommitResponse {
pub result: SignedHeaderWrapper,
Expand Down
9 changes: 7 additions & 2 deletions script/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ pub async fn get_block(client: &TendermintRPCClient, height: u64) -> anyhow::Res
Ok(block.result.block)
}

pub async fn get_header(client: &TendermintRPCClient, height: u64) -> anyhow::Result<Header> {
let block = client.fetch_header_by_height(height).await?;
Ok(block.result.header)
}

/// Retrieves the headers for the given range of block heights. Inclusive of start and end.
pub async fn get_headers_in_range(
client: &TendermintRPCClient,
Expand Down Expand Up @@ -165,7 +170,7 @@ pub async fn get_headers_in_range(

// Chunk the range into batches of DEFAULT_TENDERMINT_RPC_CONCURRENCY.
let batch_headers: Vec<anyhow::Result<Header>> = (next_batch_start..batch_end)
.map(|height| async move { Ok(get_block(client, height).await?.header) })
.map(|height| async move { get_header(client, height).await })
.collect::<FuturesOrdered<_>>()
.collect::<Vec<_>>()
.await;
Expand All @@ -179,7 +184,7 @@ pub async fn get_headers_in_range(
failures += 1;
}

tracing::debug!(
tracing::warn!(
"Got errors fetching headers, successful header count: {}",
err
);
Expand Down
Loading