Skip to content

Commit

Permalink
deps: use jsonrpsee for the RPC server impl
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 667aa47 commit 2e55a5a
Show file tree
Hide file tree
Showing 13 changed files with 1,110 additions and 1,660 deletions.
21 changes: 7 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,9 @@ version = "2.0"
[dependencies.hex]
version = "0.4"

[dependencies.hyper]
version = "0.14"
features = [ "http1", "runtime", "server", "tcp" ]

[dependencies.json-rpc-types]
version = "1.0.2"

[dependencies.jsonrpc-core]
version = "18"
[dependencies.jsonrpsee]
version = "0.8"
features = [ "http-server" ]

[dependencies.num_cpus]
version = "1"
Expand Down Expand Up @@ -107,7 +101,6 @@ version = "1"

[dependencies.serde_json]
version = "1"
features = [ "arbitrary_precision" ]

[dependencies.structopt]
version = "0.3"
Expand Down Expand Up @@ -144,13 +137,13 @@ version = "0.1"
version = "0.3"
features = ["env-filter", "parking_lot"]

[dev-dependencies.jsonrpsee]
version = "0.8"
features = [ "http-client" ]

[dev-dependencies.rand_chacha]
version = "0.3"

[dev-dependencies.reqwest]
version = "0.11"
features = ["json"]

[dev-dependencies.rusty-hook]
version = "0.11"

Expand Down
33 changes: 17 additions & 16 deletions src/network/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
operator::{Operator, OperatorRouter},
peers::{Peers, PeersRequest, PeersRouter},
prover::{Prover, ProverRouter},
rpc::initialize_rpc_server,
rpc::{context::RpcContext, initialize_rpc_server},
Node,
};
use snarkos_storage::{storage::rocksdb::RocksDB, LedgerState};
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<N: Network, E: Environment> Server<N, E> {
Self::initialize_rpc(
node,
address,
&peers,
peers.clone(),
ledger.reader(),
operator.clone(),
prover.router(),
Expand Down Expand Up @@ -341,28 +341,29 @@ impl<N: Network, E: Environment> Server<N, E> {
async fn initialize_rpc(
node: &Node,
address: Option<Address<N>>,
peers: &Arc<Peers<N, E>>,
peers: Arc<Peers<N, E>>,
ledger_reader: LedgerReader<N>,
operator: Arc<Operator<N, E>>,
prover_router: ProverRouter<N>,
memory_pool: Arc<RwLock<MemoryPool<N>>>,
) {
if !node.norpc {
// Initialize a new instance of the RPC server.
E::tasks().append(
initialize_rpc_server::<N, E>(
node.rpc,
node.rpc_username.clone(),
node.rpc_password.clone(),
address,
peers,
ledger_reader,
operator,
prover_router,
memory_pool,
)
.await,
let rpc_context = RpcContext::new(
node.rpc_username.clone(),
node.rpc_password.clone(),
address,
peers,
ledger_reader,
operator,
prover_router,
memory_pool,
);
let (rpc_server_addr, rpc_server_handle) = initialize_rpc_server::<N, E>(node.rpc, rpc_context).await;

debug!("JSON-RPC server listening on {}", rpc_server_addr);

E::tasks().append(rpc_server_handle);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ pub fn initialize_logger(verbosity: u8, log_sender: Option<mpsc::Sender<Vec<u8>>
.add_directive("hyper::proto::h1::conn=off".parse().unwrap())
.add_directive("hyper::proto::h1::decode=off".parse().unwrap())
.add_directive("hyper::proto::h1::io=off".parse().unwrap())
.add_directive("hyper::proto::h1::role=off".parse().unwrap());
.add_directive("hyper::proto::h1::role=off".parse().unwrap())
.add_directive("jsonrpsee=off".parse().unwrap());

// Initialize tracing.
let _ = tracing_subscriber::fmt()
Expand Down
Loading

0 comments on commit 2e55a5a

Please sign in to comment.