Skip to content

Commit

Permalink
feat: feature-gate RPC
Browse files Browse the repository at this point in the history
Signed-off-by: ljedrz <[email protected]>
  • Loading branch information
ljedrz committed Feb 10, 2022
1 parent 70c89eb commit e33ebfc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ edition = "2018"
members = ["metrics", "storage", "testing"]

[features]
default = []
default = [ "rpc" ]
cuda = [ "snarkvm/cuda" ]
prometheus = ["snarkos-metrics"]
rpc = [ "jsonrpsee" ]
test = []

[dependencies]
Expand Down Expand Up @@ -70,6 +71,7 @@ version = "0.4"

[dependencies.jsonrpsee]
version = "0.8"
optional = true
features = [ "http-server" ]

[dependencies.num_cpus]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ pub use network::*;
pub mod node;
pub use node::*;

#[cfg(feature = "rpc")]
pub(crate) mod rpc;
17 changes: 11 additions & 6 deletions src/network/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ use crate::{
operator::{Operator, OperatorRouter},
peers::{Peers, PeersRequest, PeersRouter},
prover::{Prover, ProverRouter},
rpc::{context::RpcContext, initialize_rpc_server},
Node,
};
use snarkos_storage::{storage::rocksdb::RocksDB, LedgerState};
use snarkvm::prelude::*;

#[cfg(feature = "rpc")]
use crate::rpc::{context::RpcContext, initialize_rpc_server};
#[cfg(feature = "rpc")]
use tokio::sync::RwLock;

use anyhow::Result;
use std::{net::SocketAddr, sync::Arc, time::Duration};
use tokio::{
net::TcpListener,
sync::{oneshot, RwLock},
task,
};
use tokio::{net::TcpListener, sync::oneshot, task};

pub type LedgerReader<N> = Arc<LedgerState<N>>;

Expand Down Expand Up @@ -154,8 +154,11 @@ impl<N: Network, E: Environment> Server<N, E> {
prover.router(),
)
.await;

// Initialize a new instance of the heartbeat.
Self::initialize_heartbeat(peers.router(), ledger.reader(), ledger.router(), operator.router(), prover.router()).await;

#[cfg(feature = "rpc")]
// Initialize a new instance of the RPC server.
Self::initialize_rpc(
node,
Expand All @@ -167,6 +170,7 @@ impl<N: Network, E: Environment> Server<N, E> {
prover.memory_pool(),
)
.await;

// Initialize a new instance of the notification.
Self::initialize_notification(ledger.reader(), prover.clone(), address).await;

Expand Down Expand Up @@ -338,6 +342,7 @@ impl<N: Network, E: Environment> Server<N, E> {
/// Initialize a new instance of the RPC server.
///
#[inline]
#[cfg(feature = "rpc")]
async fn initialize_rpc(
node: &Node,
address: Option<Address<N>>,
Expand Down

0 comments on commit e33ebfc

Please sign in to comment.