Skip to content

Commit

Permalink
fix native build
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Oct 25, 2023
1 parent d287a9d commit 7938e18
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions celestia/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::PathBuf;
use std::time::Duration;

use anyhow::{bail, Context, Result};
use celestia_node::network::{canonical_network_bootnodes, network_genesis, network_id, Network};
use celestia_node::node::{Node, NodeConfig};
use celestia_node::store::SledStore;
use celestia_rpc::prelude::*;
Expand All @@ -11,8 +12,6 @@ use libp2p::{identity, multiaddr::Protocol, Multiaddr};
use tokio::time::sleep;
use tracing::info;

use celestia_types::network::{canonical_network_bootnodes, network_genesis, network_id, Network};

#[derive(Debug, Parser)]
struct Args {
/// Network to connect.
Expand Down
7 changes: 3 additions & 4 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ celestia-proto = { workspace = true }
celestia-types = { workspace = true }
tendermint-proto = { workspace = true }

anyhow = "1.0.71"
async-trait = "0.1.73"
clap = { version = "4.4.4", features = ["derive"] }
dashmap = "5.5.3"
futures = "0.3.28"
hex = "0.4.3"
instant = "0.1.12"
libp2p = { version = "0.52.3", features = [
"autonat",
Expand All @@ -26,14 +27,12 @@ libp2p = { version = "0.52.3", features = [
prost = "0.12.0"
rand = "0.8.5"
serde = { version = "1.0.164", features = ["derive"] }
serde_repr = "0.1"
smallvec = { version = "1.11.1", features = ["union", "const_generics"] }
thiserror = "1.0.48"
tokio = { version = "1.32.0", features = ["macros", "sync"] }
tokio-util = "0.7.9"
tracing = "0.1.37"
hex = "0.4.3"
clap = { version = "4.4.4", features = ["derive"] }
serde_repr = "0.1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
directories = "5.0.1"
Expand Down
34 changes: 21 additions & 13 deletions node/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::str::FromStr;

use anyhow::{Context, Result};
use celestia_types::hash::Hash;
#[cfg(not(target_arch = "wasm32"))]
use clap::ValueEnum;
use hex::FromHexError;
use libp2p::core::multiaddr::Error as MultiaddrError;
use libp2p::Multiaddr;
use serde_repr::{Deserialize_repr, Serialize_repr};
use thiserror::Error;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;

Expand All @@ -20,9 +22,18 @@ pub enum Network {
Private,
}

#[derive(Debug)]
#[derive(Debug, Error)]
#[error("unknown network {0}")]
pub struct UnknownNetworkError(String);

#[derive(Debug, Error)]
pub enum NetworkGenesisError {
#[error("error decoding genesis hash: {0}")]
HexDecodeError(#[from] FromHexError),
#[error("decoded genesis has invalid length: {0}")]
InvalidLengthError(usize),
}

impl FromStr for Network {
type Err = UnknownNetworkError;

Expand All @@ -44,45 +55,42 @@ pub fn network_id(network: Network) -> &'static str {
}
}

pub fn network_genesis(network: Network) -> Result<Option<Hash>> {
pub fn network_genesis(network: Network) -> Result<Option<Hash>, NetworkGenesisError> {
let hex = match network {
Network::Arabica => "5904E55478BA4B3002EE885621E007A2A6A2399662841912219AECD5D5CBE393",
Network::Mocha => "B93BBE20A0FBFDF955811B6420F8433904664D45DB4BF51022BE4200C1A1680D",
Network::Private => return Ok(None),
};

let bytes = hex::decode(hex).context("Failed to decode genesis hash")?;
let bytes = hex::decode(hex)?;
let array = bytes
.try_into()
.ok()
.context("Failed to decode genesis hash")?;
.map_err(|b: Vec<u8>| NetworkGenesisError::InvalidLengthError(b.len()))?;

Ok(Some(Hash::Sha256(array)))
}

pub fn canonical_network_bootnodes(network: Network) -> Result<Vec<Multiaddr>> {
pub fn canonical_network_bootnodes(network: Network) -> Result<Vec<Multiaddr>, MultiaddrError> {
match network {
Network::Arabica => Ok([
Network::Arabica => [
"/dns4/da-bridge.celestia-arabica-10.com/tcp/2121/p2p/12D3KooWM3e9MWtyc8GkP8QRt74Riu17QuhGfZMytB2vq5NwkWAu",
"/dns4/da-bridge-2.celestia-arabica-10.com/tcp/2121/p2p/12D3KooWKj8mcdiBGxQRe1jqhaMnh2tGoC3rPDmr5UH2q8H4WA9M",
"/dns4/da-full-1.celestia-arabica-10.com/tcp/2121/p2p/12D3KooWBWkgmN7kmJSFovVrCjkeG47FkLGq7yEwJ2kEqNKCsBYk",
"/dns4/da-full-2.celestia-arabica-10.com/tcp/2121/p2p/12D3KooWRByRF67a2kVM2j4MP5Po3jgTw7H2iL2Spu8aUwPkrRfP",
]
.iter()
.map(|s| s.parse().unwrap())
.map(|s| s.parse())
.collect()
)
,
Network::Mocha => Ok([
Network::Mocha => [
"/dns4/da-bridge-mocha-4.celestia-mocha.com/udp/2121/quic/p2p/12D3KooWCBAbQbJSpCpCGKzqz3rAN4ixYbc63K68zJg9aisuAajg",
"/dns4/da-bridge-mocha-4-2.celestia-mocha.com/udp/2121/quic/p2p/12D3KooWK6wJkScGQniymdWtBwBuU36n6BRXp9rCDDUD6P5gJr3G",
"/dns4/da-full-1-mocha-4.celestia-mocha.com/udp/2121/quic/p2p/12D3KooWCUHPLqQXZzpTx1x3TAsdn3vYmTNDhzg66yG8hqoxGGN8",
"/dns4/da-full-2-mocha-4.celestia-mocha.com/udp/2121/quic/p2p/12D3KooWR6SHsXPkkvhCRn6vp1RqSefgaT1X1nMNvrVjU2o3GoYy",
]
.iter()
.map(|s| s.parse().unwrap())
.map(|s| s.parse())
.collect()
)
,
Network::Private => Ok(vec![])
}
Expand Down
6 changes: 2 additions & 4 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ nmt-rs = { workspace = true }
rand = { version = "0.8.5", optional = true }
ruint = { version = "1.8.0", features = ["serde"] }
serde = { version = "1.0.164", features = ["derive"] }
serde_repr = "0.1"
serde_repr = { version = "0.1", optional = true }
sha2 = "0.10.7"
tendermint = { workspace = true, features = ["std", "rust-crypto"] }
tendermint-proto = { workspace = true }
thiserror = "1.0.40"
libp2p = "0.52.3"
wasm-bindgen = "0.2.87"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2.10", features = ["js"] }
Expand All @@ -40,5 +38,5 @@ serde_json = "1.0.97"

[features]
default = ["p2p"]
p2p = ["dep:libp2p-identity", "dep:multiaddr"]
p2p = ["dep:libp2p-identity", "dep:multiaddr", "dep:serde_repr"]
test-utils = ["dep:ed25519-consensus", "dep:rand"]

0 comments on commit 7938e18

Please sign in to comment.