Skip to content

Commit

Permalink
refactor(jsonrpc-primitives): move adversarial to own specialized cra…
Browse files Browse the repository at this point in the history
…te (#4912)

#4651 successfully removed `near-jsonrpc-primitives`-s heavy dependency on `near-network` which in turn depended on `rocksdb`. #4112 reintroduced that dependency on `near-network`, though optionally, this hinders the publishing process.

This PR extracts the adversarial features that depend on `near-network` into a private, specialized crate: `near-jsonrpc-adversarial-primitives` and sets us right on track for publishing `jsonrpc-primitives`.
  • Loading branch information
miraclx authored Oct 4, 2021
1 parent ecf6f6a commit ee6903d
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 20 deletions.
13 changes: 12 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
"chain/jsonrpc/client",
"chain/jsonrpc/test-utils",
"chain/jsonrpc-primitives",
"chain/jsonrpc-adversarial-primitives",
"chain/rosetta-rpc",
"test-utils/actix-test-utils",
"test-utils/loadtester",
Expand Down
23 changes: 23 additions & 0 deletions chain/jsonrpc-adversarial-primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "near-jsonrpc-adversarial-primitives"
version = "0.2.0"
authors = ["Near Inc <hello@nearprotocol.com>"]
publish = false
edition = "2018"

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
near-primitives = { path = "../../core/primitives" }

near-jsonrpc-primitives = { path = "../jsonrpc-primitives", optional = true }
near-network = { path = "../network" }


[features]
ser_de = [
"serde_json",
"serde",
"near-jsonrpc-primitives",
"near-network/adversarial"
]
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use crate::errors::RpcError;
#[cfg(feature = "ser_de")]
use near_jsonrpc_primitives::errors::RpcError;
use near_network::routing::{Edge, SimpleEdge};
use near_primitives::network::PeerId;
#[cfg(feature = "ser_de")]
use serde::Deserialize;
#[cfg(feature = "ser_de")]
use serde_json::Value;

#[derive(Deserialize)]
#[cfg_attr(feature = "ser_de", derive(Deserialize))]
pub struct SetRoutingTableRequest {
pub add_edges: Option<Vec<Edge>>,
pub remove_edges: Option<Vec<SimpleEdge>>,
pub prune_edges: Option<bool>,
}

#[cfg(feature = "ser_de")]
impl SetRoutingTableRequest {
pub fn parse(value: Option<Value>) -> Result<Self, RpcError> {
if let Some(value) = value {
Expand All @@ -22,14 +26,14 @@ impl SetRoutingTableRequest {
}
}

#[derive(Deserialize)]
#[cfg_attr(feature = "ser_de", derive(Deserialize))]
pub struct SetAdvOptionsRequest {
pub disable_edge_signature_verification: Option<bool>,
pub disable_edge_propagation: Option<bool>,
pub disable_edge_pruning: Option<bool>,
}

#[derive(Deserialize)]
#[cfg_attr(feature = "ser_de", derive(Deserialize))]
pub struct StartRoutingTableSyncRequest {
pub peer_id: PeerId,
}
3 changes: 1 addition & 2 deletions chain/jsonrpc-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ near-metrics = { path = "../../core/metrics" }
near-primitives = { path = "../../core/primitives" }
near-primitives-core = { path = "../../core/primitives-core" }
near-rpc-error-macro = { path = "../../tools/rpctypegen/macro" }
near-network = { path = "../network", optional = true, features = ["adversarial"] }

[features]
adversarial = ["near-network"]
adversarial = []
2 changes: 0 additions & 2 deletions chain/jsonrpc-primitives/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(feature = "adversarial")]
pub mod adversarial;
pub mod blocks;
pub mod changes;
pub mod chunks;
Expand Down
4 changes: 3 additions & 1 deletion chain/jsonrpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ near-client = { path = "../client" }
near-network = { path = "../network" }
near-jsonrpc-client = { path = "client" }
near-jsonrpc-primitives = { path = "../jsonrpc-primitives" }
near-jsonrpc-adversarial-primitives = { path = "../jsonrpc-adversarial-primitives", optional = true }
near-rpc-error-macro = { path = "../../tools/rpctypegen/macro" }
near-performance-metrics = { path = "../../utils/near-performance-metrics" }

Expand All @@ -38,6 +39,7 @@ near-actix-test-utils = { path = "../../test-utils/actix-test-utils" }

[features]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
adversarial = ["near-jsonrpc-primitives/adversarial"]
adversarial = ["near-client/adversarial", "near-jsonrpc-primitives/adversarial", "near-jsonrpc-adversarial-primitives/ser_de"]
nightly_protocol = ["near-primitives/nightly_protocol"]
sandbox = []
protocol_feature_routing_exchange_algorithm = []
17 changes: 7 additions & 10 deletions chain/jsonrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ use near_client::{
GetStateChangesInBlock, GetValidatorInfo, GetValidatorOrdered, Query, Status, TxStatus,
TxStatusError, ViewClientActor,
};
#[cfg(feature = "adversarial")]
use near_jsonrpc_adversarial_primitives::SetAdvOptionsRequest;
#[cfg(all(feature = "adversarial", feature = "protocol_feature_routing_exchange_algorithm"))]
use near_jsonrpc_adversarial_primitives::SetRoutingTableRequest;
#[cfg(all(feature = "adversarial", feature = "protocol_feature_routing_exchange_algorithm"))]
use near_jsonrpc_adversarial_primitives::StartRoutingTableSyncRequest;
pub use near_jsonrpc_client as client;
use near_jsonrpc_primitives::errors::RpcError;
use near_jsonrpc_primitives::message::{Message, Request};
#[cfg(feature = "adversarial")]
use near_jsonrpc_primitives::types::adversarial::SetAdvOptionsRequest;
#[cfg(feature = "adversarial")]
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
use near_jsonrpc_primitives::types::adversarial::SetRoutingTableRequest;
#[cfg(feature = "adversarial")]
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
use near_jsonrpc_primitives::types::adversarial::StartRoutingTableSyncRequest;
use near_jsonrpc_primitives::types::config::RpcProtocolConfigResponse;
use near_metrics::{Encoder, TextEncoder};
#[cfg(feature = "adversarial")]
Expand All @@ -37,8 +35,7 @@ use near_network::types::{
};
#[cfg(feature = "sandbox")]
use near_network::types::{NetworkSandboxMessage, SandboxResponse};
#[cfg(feature = "adversarial")]
#[cfg(feature = "protocol_feature_routing_exchange_algorithm")]
#[cfg(all(feature = "adversarial", feature = "protocol_feature_routing_exchange_algorithm"))]
use near_network::types::{SetRoutingTable, StartRoutingTableSync};
#[cfg(feature = "adversarial")]
use near_network::PeerManagerActor;
Expand Down

0 comments on commit ee6903d

Please sign in to comment.