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

chore: remove genesis hash from node configuration #316

Merged
merged 3 commits into from
Jul 3, 2024
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
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 1 addition & 3 deletions cli/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use directories::ProjectDirs;
use libp2p::{identity, multiaddr::Protocol, Multiaddr};
use lumina_node::blockstore::RedbBlockstore;
use lumina_node::events::NodeEvent;
use lumina_node::network::{canonical_network_bootnodes, network_genesis, network_id, Network};
use lumina_node::network::{canonical_network_bootnodes, network_id, Network};
use lumina_node::node::{Node, NodeConfig};
use lumina_node::store::{RedbStore, Store};
use tokio::task::spawn_blocking;
Expand Down Expand Up @@ -54,7 +54,6 @@ pub(crate) async fn run(args: Params) -> Result<()> {
};

let network_id = network_id(network).to_owned();
let genesis_hash = network_genesis(network);

info!("Initializing store");
let db = open_db(args.store, &network_id).await?;
Expand All @@ -70,7 +69,6 @@ pub(crate) async fn run(args: Params) -> Result<()> {

let (_node, mut events) = Node::new_subscribed(NodeConfig {
network_id,
genesis_hash,
p2p_local_keypair,
p2p_bootnodes,
p2p_listen_on: args.listen_addrs,
Expand Down
6 changes: 1 addition & 5 deletions cli/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use axum::http::{header, StatusCode};
use axum::response::Response;
use axum::routing::get;
use axum::{Json, Router};
use celestia_types::hash::Hash;
use clap::Args;
use libp2p::multiaddr::Protocol;
use libp2p::Multiaddr;
use lumina_node::network::{canonical_network_bootnodes, network_genesis};
use lumina_node::network::canonical_network_bootnodes;
use rust_embed::RustEmbed;
use serde::Serialize;
use tokio::net::TcpListener;
Expand All @@ -25,7 +24,6 @@ const SERVER_DEFAULT_BIND_ADDR: &str = "127.0.0.1:9876";
struct WasmNodeArgs {
pub network: ArgNetwork,
pub bootnodes: Vec<Multiaddr>,
pub genesis_hash: Option<Hash>,
}

#[derive(RustEmbed)]
Expand Down Expand Up @@ -53,7 +51,6 @@ pub(crate) struct Params {

pub(crate) async fn run(args: Params) -> Result<()> {
let network = args.network.into();
let genesis_hash = network_genesis(network);
let bootnodes = if args.bootnodes.is_empty() {
canonical_network_bootnodes(network)
.filter(|addr| addr.iter().any(|proto| proto == Protocol::WebTransport))
Expand All @@ -65,7 +62,6 @@ pub(crate) async fn run(args: Params) -> Result<()> {
let state = WasmNodeArgs {
network: args.network,
bootnodes,
genesis_hash,
};

let app = Router::new()
Expand Down
3 changes: 0 additions & 3 deletions cli/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ <h3>Network</h3>
<option value="3">Private</option>
</select>

<h3>Genesis Hash</h3>
<input type="text" id="genesis-hash" class="config" size=64 />

<h3>Bootnodes</h3>
<textarea id="bootnodes" class="config" cols=120 rows=8></textarea>

Expand Down
11 changes: 1 addition & 10 deletions cli/static/run_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ async function fetch_config() {
if (json.bootnodes.length !== 0) {
config.bootnodes = json.bootnodes;
}
if (json.genesis) {
config.genesis = json.genesis;
}

return config;
}
Expand Down Expand Up @@ -53,12 +50,10 @@ async function show_stats(node) {

function bind_config(data) {
const network_div = document.getElementById("network-id");
const genesis_div = document.getElementById("genesis-hash");
const bootnodes_div = document.getElementById("bootnodes");

const update_config_elements = () => {
network_div.value = window.config.network;
genesis_div.value = window.config.genesis_hash || "";
bootnodes_div.value = window.config.bootnodes.join("\n");
}

Expand All @@ -67,9 +62,8 @@ function bind_config(data) {
if (prop == "network") {
const config = NodeConfig.default(Number(value));
obj.network = config.network;
obj.genesis_hash = config.genesis_hash;
obj.bootnodes = config.bootnodes;
} else if (prop == "genesis_hash" || prop == "bootnodes") {
} else if (prop == "bootnodes") {
obj[prop] = value;
} else {
return Reflect.set(obj, prop, value);
Expand All @@ -87,9 +81,6 @@ function bind_config(data) {
network_div.addEventListener("change", event => {
window.config.network = Number(event.target.value.trim());
});
genesis_div.addEventListener("change", event => {
window.config.genesis_hash = event.target.value.trim();
});
bootnodes_div.addEventListener("change", event => {
window.config.bootnodes = event.target.value.trim().split("\n").map(multiaddr => multiaddr.trim());
});
Expand Down
15 changes: 2 additions & 13 deletions node-wasm/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use wasm_bindgen::prelude::*;
use web_sys::BroadcastChannel;

use lumina_node::blockstore::IndexedDbBlockstore;
use lumina_node::network::{canonical_network_bootnodes, network_genesis, network_id};
use lumina_node::network::{canonical_network_bootnodes, network_id};
use lumina_node::node::NodeConfig;
use lumina_node::store::IndexedDbStore;

Expand All @@ -27,9 +27,6 @@ const LUMINA_WORKER_NAME: &str = "lumina";
pub struct WasmNodeConfig {
/// A network to connect to.
pub network: Network,
/// Hash of the genesis block in the network.
#[wasm_bindgen(getter_with_clone)]
pub genesis_hash: Option<String>,
/// A list of bootstrap peers to connect to.
#[wasm_bindgen(getter_with_clone)]
pub bootnodes: Vec<String>,
Expand Down Expand Up @@ -347,11 +344,10 @@ impl NodeDriver {

#[wasm_bindgen(js_class = NodeConfig)]
impl WasmNodeConfig {
/// Get the configuration with default bootnodes and genesis hash for provided network
/// Get the configuration with default bootnodes for provided network
pub fn default(network: Network) -> WasmNodeConfig {
WasmNodeConfig {
network,
genesis_hash: network_genesis(network.into()).map(|h| h.to_string()),
bootnodes: canonical_network_bootnodes(network.into())
.filter(|addr| addr.iter().any(|proto| proto == Protocol::WebTransport))
.map(|addr| addr.to_string())
Expand All @@ -372,12 +368,6 @@ impl WasmNodeConfig {

let p2p_local_keypair = Keypair::generate_ed25519();

let genesis_hash = self
.genesis_hash
.map(|h| h.parse())
.transpose()
.context("genesis hash invalid")?;

let p2p_bootnodes = self
.bootnodes
.iter()
Expand All @@ -387,7 +377,6 @@ impl WasmNodeConfig {

Ok(NodeConfig {
network_id: network_id.to_string(),
genesis_hash,
p2p_bootnodes,
p2p_local_keypair,
p2p_listen_on: vec![],
Expand Down
1 change: 0 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ beetswap = "0.1.1"
cid = { version = "0.11.1", features = ["serde-codec"] }
dashmap = "5.5.3"
futures = "0.3.30"
hex = "0.4.3"
instant = "0.1.13"
prost = "0.12.6"
rand = "0.8.5"
Expand Down
4 changes: 1 addition & 3 deletions node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;
use libp2p::{identity, multiaddr::Protocol, Multiaddr};
use lumina_node::blockstore::RedbBlockstore;
use lumina_node::network::{
canonical_network_bootnodes, network_genesis, network_id, Network,
canonical_network_bootnodes, network_id, Network,
};
use lumina_node::node::{Node, NodeConfig};
use lumina_node::store::RedbStore;
Expand All @@ -18,7 +18,6 @@ async fn main() {
let p2p_local_keypair = identity::Keypair::generate_ed25519();
let network = Network::Mainnet;
let network_id = network_id(network).to_owned();
let genesis_hash = network_genesis(network);
let p2p_bootnodes = canonical_network_bootnodes(network).collect();

let db = spawn_blocking(|| redb::Database::create("path/to/db"))
Expand All @@ -34,7 +33,6 @@ async fn main() {

let node = Node::new(NodeConfig {
network_id,
genesis_hash,
p2p_local_keypair,
p2p_bootnodes,
p2p_listen_on: vec!["/ip4/0.0.0.0/tcp/0".parse().unwrap()],
Expand Down
31 changes: 0 additions & 31 deletions node/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::str::FromStr;

use celestia_types::hash::Hash;
use libp2p::Multiaddr;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -49,21 +48,6 @@ pub fn network_id(network: Network) -> &'static str {
}
}

/// Get the hash of a genesis block for the given network.
pub fn network_genesis(network: Network) -> Option<Hash> {
let hex = match network {
Network::Mainnet => "6BE39EFD10BA412A9DB5288488303F5DD32CF386707A5BEF33617F4C43301872",
Network::Arabica => "5904E55478BA4B3002EE885621E007A2A6A2399662841912219AECD5D5CBE393",
Network::Mocha => "B93BBE20A0FBFDF955811B6420F8433904664D45DB4BF51022BE4200C1A1680D",
Network::Private => return None,
};

let bytes = hex::decode(hex).expect("failed decoding genesis hash");
let array = bytes.try_into().expect("invalid genesis hash lenght");

Some(Hash::Sha256(array))
}

/// Get official Celestia and Lumina bootnodes for the given network.
pub fn canonical_network_bootnodes(network: Network) -> impl Iterator<Item = Multiaddr> {
let peers: &[_] = match network {
Expand Down Expand Up @@ -103,21 +87,6 @@ pub fn canonical_network_bootnodes(network: Network) -> impl Iterator<Item = Mul
mod tests {
use super::*;

#[test]
fn test_network_genesis() {
let mainnet = network_genesis(Network::Mainnet);
assert!(mainnet.is_some());

let arabica = network_genesis(Network::Arabica);
assert!(arabica.is_some());

let mocha = network_genesis(Network::Mocha);
assert!(mocha.is_some());

let private = network_genesis(Network::Private);
assert!(private.is_none());
}

#[test]
fn test_canonical_network_bootnodes() {
// canonical_network_bootnodes works on const data, test it doesn't panic and the data is there
Expand Down
2 changes: 0 additions & 2 deletions node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ where
{
/// An id of the network to connect to.
pub network_id: String,
/// The hash of the genesis block in network.
pub genesis_hash: Option<Hash>,
/// The keypair to be used as [`Node`]s identity.
pub p2p_local_keypair: Keypair,
/// List of bootstrap nodes to connect to and trust.
Expand Down
1 change: 0 additions & 1 deletion node/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub fn test_node_config() -> NodeConfig<InMemoryBlockstore, InMemoryStore> {
let node_keypair = identity::Keypair::generate_ed25519();
NodeConfig {
network_id: "private".to_string(),
genesis_hash: None,
p2p_local_keypair: node_keypair,
p2p_bootnodes: vec![],
p2p_listen_on: vec![],
Expand Down
Loading