diff --git a/core/application/src/app.rs b/core/application/src/app.rs index 943346627..566c1cba3 100644 --- a/core/application/src/app.rs +++ b/core/application/src/app.rs @@ -5,10 +5,12 @@ use std::time::Duration; use affair::{Executor, TokioSpawn}; use anyhow::{anyhow, Result}; use lightning_interfaces::prelude::*; +use lightning_interfaces::types::{ChainId, NodeInfo}; use tracing::{error, info}; use crate::config::{Config, StorageConfig}; use crate::env::{Env, UpdateWorker}; +use crate::genesis::Genesis; use crate::query_runner::QueryRunner; pub struct Application { update_socket: Mutex>, @@ -119,4 +121,21 @@ impl ApplicationInterface for Application { } } } + + fn get_chain_id() -> Result { + let genesis = Genesis::load()?; + + Ok(genesis.chain_id) + } + + fn get_genesis_committee() -> Result> { + let genesis = Genesis::load()?; + + Ok(genesis + .node_info + .iter() + .filter(|node| node.genesis_committee) + .map(NodeInfo::from) + .collect()) + } } diff --git a/core/cli/Cargo.toml b/core/cli/Cargo.toml index e91e34872..8a674c080 100644 --- a/core/cli/Cargo.toml +++ b/core/cli/Cargo.toml @@ -12,9 +12,6 @@ lightning-node = { path = "../node" } lightning-final-bindings = { path = "../final-bindings" } lightning-utils = { path = "../utils" } -# TODO: cli ideally shouldn't depend on this directly -lightning-application = { path = "../application" } - fleek-crypto.workspace = true resolved-pathbuf.workspace = true tokio.workspace = true diff --git a/core/cli/src/commands/opt.rs b/core/cli/src/commands/opt.rs index 1151d2682..2383eff86 100644 --- a/core/cli/src/commands/opt.rs +++ b/core/cli/src/commands/opt.rs @@ -9,7 +9,6 @@ use fleek_crypto::{ TransactionSender, TransactionSignature, }; -use lightning_application::genesis::Genesis; use lightning_interfaces::prelude::*; use lightning_interfaces::types::{ ChainId, @@ -51,8 +50,8 @@ async fn opt_in(config_path: ResolvedPathBuf) -> Result<()> { .connect_timeout(Duration::from_secs(5)) .build()?; - let genesis_committee = - get_genesis_committee().context("Failed to load genesis committee info.")?; + let genesis_committee = C::ApplicationInterface::get_genesis_committee() + .context("Failed to load genesis committee info.")?; let node_info = query_node_info(public_key, &genesis_committee, &rpc_client) .await @@ -75,7 +74,8 @@ async fn opt_in(config_path: ResolvedPathBuf) -> Result<()> { return Ok(()); } - let chain_id = get_chain_id().context("Failed to load Chain ID from genesis.")?; + let chain_id = + C::ApplicationInterface::get_chain_id().context("Failed to load Chain ID from genesis.")?; let tx = create_update_request( UpdateMethod::OptIn {}, @@ -118,8 +118,8 @@ async fn opt_out(config_path: ResolvedPathBuf) -> Result<()> { .connect_timeout(Duration::from_secs(5)) .build()?; - let genesis_committee = - get_genesis_committee().context("Failed to load genesis committee info.")?; + let genesis_committee = C::ApplicationInterface::get_genesis_committee() + .context("Failed to load genesis committee info.")?; let node_info = query_node_info(public_key, &genesis_committee, &rpc_client) .await @@ -132,7 +132,8 @@ async fn opt_out(config_path: ResolvedPathBuf) -> Result<()> { return Ok(()); } - let chain_id = get_chain_id().context("Failed to load Chain ID from genesis.")?; + let chain_id = + C::ApplicationInterface::get_chain_id().context("Failed to load Chain ID from genesis.")?; let tx = create_update_request( UpdateMethod::OptOut {}, @@ -170,8 +171,8 @@ async fn status(config_path: ResolvedPathBuf) -> Result<()> { .connect_timeout(Duration::from_secs(5)) .build()?; - let genesis_committee = - get_genesis_committee().context("Failed to load genesis committee info.")?; + let genesis_committee = C::ApplicationInterface::get_genesis_committee() + .context("Failed to load genesis committee info.")?; let node_info = query_node_info(public_key, &genesis_committee, &rpc_client) .await @@ -263,21 +264,6 @@ fn create_update_request( } } -fn get_chain_id() -> Result { - let genesis = Genesis::load()?; - Ok(genesis.chain_id) -} - -fn get_genesis_committee() -> Result> { - let genesis = Genesis::load()?; - Ok(genesis - .node_info - .iter() - .filter(|node| node.genesis_committee) - .map(NodeInfo::from) - .collect()) -} - pub async fn query_node_info( public_key: NodePublicKey, nodes: &[NodeInfo], diff --git a/core/interfaces/src/application.rs b/core/interfaces/src/application.rs index 6d6b3377c..37fc4694a 100644 --- a/core/interfaces/src/application.rs +++ b/core/interfaces/src/application.rs @@ -20,6 +20,7 @@ use hp_fixed::unsigned::HpUfixed; use lightning_types::{ AccountInfo, Blake3Hash, + ChainId, Committee, CommodityTypes, Metadata, @@ -87,6 +88,12 @@ pub trait ApplicationInterface: checkpoint: Vec, checkpoint_hash: [u8; 32], ) -> Result<()>; + + /// Used to get the chain id from the genesis file instead of state + fn get_chain_id() -> Result; + + /// Returns the committee from the geneis of the network + fn get_genesis_committee() -> Result>; } #[interfaces_proc::blank]