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

Add Transaction State (Status) RPC #720

Merged
merged 1 commit into from
Feb 19, 2025
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
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"runtime",
"runtime/fuzz",
"node",
"rpc/transaction-rpc"
]

[workspace.package]
Expand All @@ -36,6 +37,7 @@ pallet-vector = { path = "pallets/vector", default-features = false }
da-runtime = { path = "runtime", default-features = false }
kate-rpc = { path = "rpc/kate-rpc" }
testing-rpc = { path = "rpc/testing-rpc" }
transaction-rpc = { path = "rpc/transaction-rpc", default-features = false }
patricia-merkle-trie = { path = "patricia-merkle-trie", default-features = false }

sc-basic-authorship = { path = "client/basic-authorship", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pallet-vector.workspace = true
frame-system-rpc-runtime-api.workspace = true
frame-system = { workspace = true, default-features = false }
sc-basic-authorship.workspace = true
transaction-rpc.workspace = true

# 3rd-party
codec = { package = "parity-scale-codec", version = "3" }
Expand Down
24 changes: 24 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,30 @@ pub struct Cli {
/// This parameter can be used to update the network name and id of the `dev` and `dev_tri` chains.
#[arg(long)]
pub network_name: Option<String>,

/// Enable Transaction State RPC. This allows querying the transaction state (success or failure)
/// using only a transaction hash.
#[clap(long = "enable-tx-state-rpc", default_value_t = false)]
pub tx_state_rpc_enabled: bool,

/// The maximum number of results the transaction state RPC will return for a transaction hash.
/// If a transaction hash appears in multiple blocks, the RPC will return only the top `X` transaction states.
/// In most cases, the transaction hash is unique, so this parameter is usually irrelevant.
#[clap(long, default_value_t = 10)]
pub tx_state_rpc_max_search_results: usize,

/// The maximum number of blocks preserved and stored in the transaction state RPC database.
///
/// The default is 31 days' worth of blocks.
#[clap(long, default_value_t = 133920)]
pub tx_state_rpc_max_stored_block_count: usize,

/// Logging interval for transaction state, in milliseconds.
/// A lower value results in more frequent log updates.
///
/// The default is 300_000 milliseconds (300 seconds).
#[clap(long, default_value_t = 300_000)]
pub tx_state_logging_interval: u64,
}

fn kate_max_cells_size_upper_bound(s: &str) -> Result<usize, String> {
Expand Down
26 changes: 11 additions & 15 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use {
use crate::{
cli::{Cli, Subcommand},
service::{self, new_partial, FullClient},
transaction_state,
};

use avail_node::NODE_VERSION;
Expand Down Expand Up @@ -208,9 +209,8 @@ pub fn run() -> Result<()> {
} = new_partial(
&config,
cli.unsafe_da_sync,
cli.kate_max_cells_size,
cli.kate_rpc_enabled,
cli.kate_rpc_metrics_enabled,
kate_rpc::Deps::default(),
transaction_state::CliDeps::default(),
)?;
Ok((cmd.run(client, import_queue), task_manager))
})
Expand All @@ -225,9 +225,8 @@ pub fn run() -> Result<()> {
} = new_partial(
&config,
cli.unsafe_da_sync,
cli.kate_max_cells_size,
cli.kate_rpc_enabled,
cli.kate_rpc_metrics_enabled,
kate_rpc::Deps::default(),
transaction_state::CliDeps::default(),
)?;
Ok((cmd.run(client, config.database), task_manager))
})
Expand All @@ -242,9 +241,8 @@ pub fn run() -> Result<()> {
} = new_partial(
&config,
cli.unsafe_da_sync,
cli.kate_max_cells_size,
cli.kate_rpc_enabled,
cli.kate_rpc_metrics_enabled,
kate_rpc::Deps::default(),
transaction_state::CliDeps::default(),
)?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
Expand All @@ -260,9 +258,8 @@ pub fn run() -> Result<()> {
} = new_partial(
&config,
cli.unsafe_da_sync,
cli.kate_max_cells_size,
cli.kate_rpc_enabled,
cli.kate_rpc_metrics_enabled,
kate_rpc::Deps::default(),
transaction_state::CliDeps::default(),
)?;
Ok((cmd.run(client, import_queue), task_manager))
})
Expand All @@ -282,9 +279,8 @@ pub fn run() -> Result<()> {
} = new_partial(
&config,
cli.unsafe_da_sync,
cli.kate_max_cells_size,
cli.kate_rpc_enabled,
cli.kate_rpc_metrics_enabled,
kate_rpc::Deps::default(),
transaction_state::CliDeps::default(),
)?;
let aux_revert = Box::new(|client: Arc<FullClient>, backend, blocks| {
sc_consensus_babe::revert(client.clone(), backend, blocks)?;
Expand Down
2 changes: 2 additions & 0 deletions node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ pub mod cli;
pub mod rpc;
pub mod service;

mod transaction_state;

pub const NODE_VERSION: &str = "2.2.1";
1 change: 1 addition & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod cli;
mod command;
mod da_block_import;
mod rpc;
mod transaction_state;

fn main() -> sc_cli::Result<()> {
command::run()
Expand Down
37 changes: 23 additions & 14 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ pub struct FullDeps<C, P, SC, B> {
pub babe: BabeDeps,
/// GRANDPA specific dependencies.
pub grandpa: GrandpaDeps<B>,
/// The maximum number of cells that can be requested in one go.
pub kate_max_cells_size: usize,
/// Enable Kate RPCs
pub kate_rpc_enabled: bool,
/// Enable Kate RPCs Metrics
/// Kate RPC specific dependencies.
///
/// Should not be used unless unless you know what you're doing.
pub kate_rpc_metrics_enabled: bool,
/// Available configs:
/// - pub max_cells_size: usize,
/// - pub rpc_enabled: bool,
/// - pub rpc_metrics_enabled: bool,
pub kate_rpc_deps: kate_rpc::Deps,
/// Transaction RPC specific dependencies.
///
/// Available configs:
/// - TxStateSender,
pub transaction_rpc_deps: Option<transaction_rpc::Deps>,
}

/// Instantiate all Full RPC extensions.
Expand Down Expand Up @@ -152,9 +156,8 @@ where
deny_unsafe,
babe,
grandpa,
kate_max_cells_size,
kate_rpc_enabled,
kate_rpc_metrics_enabled,
kate_rpc_deps,
transaction_rpc_deps,
} = deps;

let BabeDeps {
Expand Down Expand Up @@ -226,20 +229,26 @@ where

io.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?;

if is_dev_chain || kate_rpc_metrics_enabled {
if is_dev_chain || kate_rpc_deps.rpc_metrics_enabled {
io.merge(KateApiMetricsServer::into_rpc(Kate::<C, Block>::new(
client.clone(),
kate_max_cells_size,
kate_rpc_deps.max_cells_size,
)))?;
}

if is_dev_chain || kate_rpc_enabled || kate_rpc_metrics_enabled {
if is_dev_chain || kate_rpc_deps.rpc_enabled || kate_rpc_deps.rpc_metrics_enabled {
io.merge(KateApiServer::into_rpc(Kate::<C, Block>::new(
client,
kate_max_cells_size,
kate_rpc_deps.max_cells_size,
)))?;
}

if let Some(deps) = transaction_rpc_deps {
io.merge(transaction_rpc::TransactionStateServer::into_rpc(
transaction_rpc::System::new(deps),
))?;
}

#[cfg(feature = "testing-environment")]
io.merge(TestingApiServer::into_rpc(TestingEnv))?;

Expand Down
Loading
Loading