Skip to content
Draft
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
297 changes: 269 additions & 28 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"monitor-client",
"p2p-load-test",
"web",
"avail-rust-conversion",
]
default-members = ["client"]
resolver = "2"
Expand All @@ -21,10 +22,13 @@ repository = "https://github.com/availproject/avail-light"
# Internal deps
avail-core = { git = "https://github.com/availproject/avail-core", default-features = false, tag = "core-node-11", features = ["serde"] }
avail-rust = { git = "https://github.com/availproject/avail-rust.git", rev = "e2e02a7b6d08fb7a8cffad8c2856b742b6587b1f", default-features = false }
avail-rust-next = { package = "avail-rust-client", version = "0.4.0-rc.5", default-features = false }
kate = { git = "https://github.com/availproject/avail-core", default-features = false, tag = "core-node-11", features = ["serde"] }
kate-recovery = { git = "https://github.com/availproject/avail-core", default-features = false, tag = "core-node-11", features = ["serde"] }
avail-light-core = { path = "./core", default-features = false }
sp-core = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-12", default-features = false, features = ["serde"] }
avail-rust-conversion = { path = "./avail-rust-conversion" }


anyhow = "1.0.71"
async-std = { version = "1.12.0", features = ["attributes"] }
Expand Down
13 changes: 13 additions & 0 deletions avail-rust-conversion/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "avail-rust-conversion"
version = "0.1.0"
edition = "2021"

[dependencies]
avail-rust = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
avail-rust-next = { workspace = true, features = ["native", "reqwest"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
avail-rust-next = { workspace = true, features = ["wasm", "reqwest"] }
90 changes: 90 additions & 0 deletions avail-rust-conversion/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use avail_rust::avail::runtime_types::avail_core::data_lookup::compact::CompactDataLookup as LegacyCompactDataLookup;
use avail_rust::avail::runtime_types::avail_core::data_lookup::compact::DataLookupItem as LegacyDataLookupItem;
use avail_rust::avail::runtime_types::avail_core::header::extension::v3::HeaderExtension as LegacyV3HeaderExtension;
use avail_rust::avail::runtime_types::avail_core::header::extension::HeaderExtension as LegacyHeaderExtension;
use avail_rust::avail::runtime_types::avail_core::kate_commitment::v3::KateCommitment as LegacyKateCommitment;
use avail_rust::subxt::ext::subxt_core::config::substrate::Digest as LegacyDigest;
use avail_rust::subxt::ext::subxt_core::config::substrate::DigestItem as LegacyDigestItem;
use avail_rust::AvailHeader as LegacyAvailHeader;

use avail_rust_next::avail_rust_core::header::DataLookupItem as NextDataLookupItem;
use avail_rust_next::avail_rust_core::CompactDataLookup as NextCompactDataLookup;
use avail_rust_next::subxt_core::config::substrate::Digest as NextDigest;
use avail_rust_next::subxt_core::config::substrate::DigestItem as NextDigestItem;
use avail_rust_next::AvailHeader as NextAvailHeader;
use avail_rust_next::HeaderExtension as NextHeaderExtension;
use avail_rust_next::KateCommitment as NextKateCommitment;
use avail_rust_next::V3HeaderExtension as NextV3HeaderExtension;

pub fn from_next_to_legacy_header(next: NextAvailHeader) -> LegacyAvailHeader {
LegacyAvailHeader {
parent_hash: next.parent_hash,
number: next.number,
state_root: next.state_root,
extrinsics_root: next.extrinsics_root,
digest: next_to_legacy_digest(next.digest),
extension: next_to_legacy_header_extension(next.extension),
}
}

fn next_to_legacy_digest(next: NextDigest) -> LegacyDigest {
LegacyDigest {
logs: next
.logs
.into_iter()
.map(next_to_legacy_digest_item)
.collect(),
}
}

pub fn next_to_legacy_digest_item(next: NextDigestItem) -> LegacyDigestItem {
match next {
NextDigestItem::PreRuntime(x, items) => LegacyDigestItem::PreRuntime(x, items),
NextDigestItem::Consensus(x, items) => LegacyDigestItem::Consensus(x, items),
NextDigestItem::Seal(x, items) => LegacyDigestItem::Seal(x, items),
NextDigestItem::Other(x) => LegacyDigestItem::Other(x),
NextDigestItem::RuntimeEnvironmentUpdated => LegacyDigestItem::RuntimeEnvironmentUpdated,
}
}

pub fn next_to_legacy_header_extension(next: NextHeaderExtension) -> LegacyHeaderExtension {
match next {
NextHeaderExtension::V3(x) => {
LegacyHeaderExtension::V3(next_to_legacy_v3_header_extension(x))
},
}
}

pub fn next_to_legacy_v3_header_extension(next: NextV3HeaderExtension) -> LegacyV3HeaderExtension {
LegacyV3HeaderExtension {
app_lookup: next_to_legacy_compact_data_lookup(next.app_lookup),
commitment: next_to_legacy_kate_commitment(next.commitment),
}
}

pub fn next_to_legacy_compact_data_lookup(next: NextCompactDataLookup) -> LegacyCompactDataLookup {
LegacyCompactDataLookup {
size: next.size,
index: next
.index
.into_iter()
.map(next_to_legacy_data_lookup_item)
.collect(),
}
}

pub fn next_to_legacy_data_lookup_item(next: NextDataLookupItem) -> LegacyDataLookupItem {
LegacyDataLookupItem {
app_id: next.app_id.into(),
start: next.start,
}
}

pub fn next_to_legacy_kate_commitment(next: NextKateCommitment) -> LegacyKateCommitment {
LegacyKateCommitment {
rows: next.rows,
cols: next.cols,
commitment: next.commitment,
data_root: next.data_root,
}
}
14 changes: 9 additions & 5 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use avail_light_core::{
updater,
utils::{self, default_subscriber, install_panic_hooks, json_subscriber, spawn_in_span},
};
use avail_rust::account;
use clap::Parser;
use color_eyre::{
eyre::{eyre, WrapErr},
Expand Down Expand Up @@ -199,10 +198,11 @@ async fn run(
.await?;

let account_id = identity_cfg.avail_key_pair.public_key().to_account_id();
let client = rpc_client.current_client().await;
let client_next = rpc_client.current_next_client().await;

let account_address = account_id.to_string();
let nonce = account::nonce_node(&client.client, &account_address)
let nonce = client_next
.chain()
.account_nonce(account_id.to_string())
.await
.map_err(|error| eyre!("{:?}", error))?;
db.put(SignerNonceKey, nonce);
Expand Down Expand Up @@ -475,7 +475,11 @@ pub fn load_runtime_config(opts: &CliOpts) -> Result<RuntimeConfig> {
network.bootstrap_peer_id(),
network.bootstrap_multiaddr(&cfg.libp2p.listeners),
);
cfg.rpc.full_node_ws = network.full_node_ws();
cfg.rpc.full_node_ws_http = network
.full_node_ws()
.into_iter()
.zip(network.full_node_http())
.collect();
cfg.libp2p.bootstraps = vec![PeerAddress::PeerIdAndMultiaddr(bootstrap)];
cfg.otel.ot_collector_endpoint = network.ot_collector_endpoint().to_string();
cfg.genesis_hash = network.genesis_hash().to_string();
Expand Down
9 changes: 6 additions & 3 deletions compatibility-tests/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ use tokio::sync::broadcast;

#[derive(Parser)]
struct CommandArgs {
#[arg(short, long, value_name = "URL", default_value_t = String::from("ws://localhost:9944"))]
#[arg(short, long, value_name = "WS URL", default_value_t = String::from("ws://localhost:9944"))]
url: String,
#[arg(long, value_name = "HTTP URL", default_value_t = String::from("http://localhost:9944"))]
url_next: String,
#[arg(short, long, value_name = "path", default_value_t = String::from("avail_path"))]
avail_path: String,
}

#[tokio::main]
async fn main() -> Result<()> {
let command_args = CommandArgs::parse();
println!("Using URL: {}", command_args.url);
println!("Using WS URL: {}", command_args.url);
println!("Using HTTP URL: {}", command_args.url_next);
println!("Using Path: {}", command_args.avail_path);

#[cfg(not(feature = "rocksdb"))]
Expand All @@ -33,7 +36,7 @@ async fn main() -> Result<()> {
let db = DB::open(&command_args.avail_path)?;

let rpc_cfg = RPCConfig {
full_node_ws: vec![command_args.url],
full_node_ws_http: vec![(command_args.url, command_args.url_next)],
retry: RetryConfig::Exponential(ExponentialConfig {
base: 10,
max_delay: Duration::from_millis(4000),
Expand Down
3 changes: 3 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ avail-core = { workspace = true }
kate = { workspace = true }
kate-recovery = { workspace = true }
sp-core = { workspace = true }
avail-rust-conversion = { workspace = true }

# 3rd-party
async-stream = "0.3.5"
Expand Down Expand Up @@ -54,6 +55,7 @@ flate2 = "1.1"
tar = "0.4"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
avail-rust-next = { workspace = true, features = ["native", "reqwest"] }
avail-rust = { workspace = true, default-features = true }
async-std = { workspace = true }
color-eyre = { workspace = true, default-features = true }
Expand Down Expand Up @@ -88,6 +90,7 @@ opentelemetry-otlp = { workspace = true }
opentelemetry_sdk = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
avail-rust-next = { workspace = true, features = ["wasm", "reqwest"] }
avail-rust = { workspace = true, default-features = false, features = ["wasm"] }
blake2b_simd = "1.0.2"
color-eyre = { workspace = true }
Expand Down
22 changes: 17 additions & 5 deletions core/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use async_trait::async_trait;
use avail_core::kate::COMMITMENT_SIZE;
use avail_rust::H256;
use avail_rust_next::constants::*;
use clap::ValueEnum;
use color_eyre::{eyre::WrapErr, Result};
use kate_recovery::{
Expand Down Expand Up @@ -411,17 +412,28 @@ impl Network {

pub fn full_node_ws(&self) -> Vec<String> {
match self {
Network::Local => vec!["ws://127.0.0.1:9944".to_string()],
Network::Local => vec![LOCAL_WS_ENDPOINT.into()],
Network::Hex => vec!["wss://rpc-hex-devnet.avail.tools/ws".to_string()],
Network::Turing => vec!["wss://turing-rpc.avail.so/ws".to_string()],
Network::Turing => vec![TURING_WS_ENDPOINT.into()],
Network::Mainnet => vec![
"wss://mainnet.avail-rpc.com/".to_string(),
"wss://avail-mainnet.public.blastapi.io/".to_string(),
"wss://mainnet-rpc.avail.so/ws".to_string(),
// TODO Temp removed
//"wss://mainnet.avail-rpc.com/".to_string(),
//"wss://avail-mainnet.public.blastapi.io/".to_string(),
// "wss://mainnet-rpc.avail.so/ws".to_string(),
MAINNET_WS_ENDPOINT.into(),
],
}
}

pub fn full_node_http(&self) -> Vec<String> {
match self {
Network::Local => vec![LOCAL_ENDPOINT.into()],
Network::Hex => vec!["https://rpc-hex-devnet.avail.tools/rpc".to_string()],
Network::Turing => vec![TURING_ENDPOINT.into()],
Network::Mainnet => vec![MAINNET_ENDPOINT.into()],
}
}

pub fn ot_collector_endpoint(&self) -> &str {
match self {
Network::Local => "http://127.0.0.1:4317",
Expand Down
11 changes: 8 additions & 3 deletions core/src/network/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl<'de> Deserialize<'de> for WrappedProof {
#[derive(Clone, Debug, Serialize, Deserialize, Decode, Encode)]
pub struct Node {
pub host: String,
pub host_next: String,
pub system_version: String,
pub spec_version: u32,
pub genesis_hash: H256,
Expand All @@ -95,12 +96,14 @@ pub struct Node {
impl Node {
pub fn new(
host: String,
host_next: String,
system_version: String,
spec_version: u32,
genesis_hash: H256,
) -> Self {
Self {
host,
host_next,
system_version,
spec_version,
genesis_hash,
Expand All @@ -121,6 +124,7 @@ impl Default for Node {
fn default() -> Self {
Self {
host: "{host}".to_string(),
host_next: "{host_next}".to_string(),
system_version: "{system_version}".to_string(),
spec_version: 0,
genesis_hash: Default::default(),
Expand All @@ -140,7 +144,7 @@ pub struct Nodes {
}

impl Nodes {
pub fn new(nodes: &[String]) -> Self {
pub fn new(nodes: &[(String, String)]) -> Self {
let candidates = nodes.to_owned();
Self {
list: candidates
Expand All @@ -149,7 +153,8 @@ impl Nodes {
genesis_hash: Default::default(),
spec_version: Default::default(),
system_version: Default::default(),
host: s.to_string(),
host: s.0.to_string(),
host_next: s.1.to_string(),
})
.collect(),
}
Expand Down Expand Up @@ -207,7 +212,7 @@ pub async fn init<T: Database + Clone>(
) -> Result<(Client<T>, SubscriptionLoop<T>)> {
let rpc_client = Client::new(
db.clone(),
Nodes::new(&rpc.full_node_ws),
Nodes::new(&rpc.full_node_ws_http),
genesis_hash,
rpc.retry.clone(),
shutdown,
Expand Down
Loading
Loading