Skip to content

Commit

Permalink
Merge pull request #268 from rafal-ch/track-feat-2.0-spicy-merge
Browse files Browse the repository at this point in the history
Adapt to the changes to interfaces in the node
  • Loading branch information
rafal-ch authored Apr 8, 2024
2 parents 3cf155e + ae07fbc commit 723aaec
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 450 deletions.
198 changes: 111 additions & 87 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ members = [
"metrics",
"rpc_sidecar",
"sidecar",
"types"
"types",
]

[workspace.dependencies]
anyhow = "1"
async-stream = "0.3.4"
async-trait = "0.1.77"
casper-types = { git = "https://github.com/casper-network/casper-node", branch="feat-2.0" }
casper-types = { git = "https://github.com/casper-network/casper-node", branch = "feat-2.0" }
casper-event-sidecar = { path = "./event_sidecar", version = "1.0.0" }
casper-event-types = { path = "./types", version = "1.0.0" }
casper-rpc-sidecar = { path = "./rpc_sidecar", version = "1.0.0" }
Expand Down
2 changes: 1 addition & 1 deletion event_sidecar/src/types/sse_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn random_execution_result(rng: &mut TestRng) -> ExecutionResult {
ExecutionResult::V1(result_v1)
}
1 => {
let result_v2: ExecutionResultV2 = rng.gen();
let result_v2 = ExecutionResultV2::random(rng);
ExecutionResult::V2(result_v2)
}
_ => panic!("Unexpected value"),
Expand Down
562 changes: 361 additions & 201 deletions resources/test/rpc_schema.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion rpc_sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ bincode = "1"
bytes = "1.5.0"
casper-json-rpc = { version = "1.0.0", path = "../json_rpc" }
casper-types = { workspace = true, features = ["datasize", "json-schema", "std"] }
casper-binary-port = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" }
datasize = { workspace = true, features = ["detailed", "fake_clock-types"] }
futures = { workspace = true }
http = "0.2.1"
Expand All @@ -44,6 +45,7 @@ warp = { version = "0.3.6", features = ["compression"] }
[dev-dependencies]
assert-json-diff = "2"
casper-types = { workspace = true, features = ["datasize", "json-schema", "std", "testing"] }
casper-binary-port = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0", features = ["testing"] }
pretty_assertions = "0.7.2"
regex = "1"
tempfile = "3"
Expand All @@ -56,7 +58,7 @@ vergen = { version = "8.2.1", default-features = false, features = [
] }

[features]
testing = ["casper-types/testing"]
testing = ["casper-types/testing", "casper-binary-port/testing"]

[package.metadata.deb]
revision = "0"
Expand Down
62 changes: 27 additions & 35 deletions rpc_sidecar/src/node_client.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
use crate::{config::ExponentialBackoffConfig, NodeClientConfig, SUPPORTED_PROTOCOL_VERSION};
use anyhow::Error as AnyhowError;
use async_trait::async_trait;
use metrics::rpc::{inc_disconnect, observe_reconnect_time};
use serde::de::DeserializeOwned;
use std::{
convert::{TryFrom, TryInto},
future::Future,
net::SocketAddr,
sync::Arc,
time::Duration,
};

use casper_binary_port::{
BinaryRequest, BinaryRequestHeader, BinaryResponse, BinaryResponseAndRequest,
ConsensusValidatorChanges, DictionaryItemIdentifier, DictionaryQueryResult, ErrorCode,
GetRequest, GetTrieFullResult, GlobalStateQueryResult, GlobalStateRequest, InformationRequest,
NodeStatus, PayloadEntity, RecordId, SpeculativeExecutionResult, TransactionWithExecutionInfo,
};
use casper_types::{
binary_port::{
BinaryRequest, BinaryRequestHeader, BinaryResponse, BinaryResponseAndRequest,
ConsensusValidatorChanges, DictionaryItemIdentifier, DictionaryQueryResult,
ErrorCode as BinaryPortError, GetRequest, GetTrieFullResult, GlobalStateQueryResult,
GlobalStateRequest, InformationRequest, NodeStatus, PayloadEntity, RecordId,
SpeculativeExecutionResult, TransactionWithExecutionInfo,
},
bytesrepr::{self, FromBytes, ToBytes},
AvailableBlockRange, BlockHash, BlockHeader, BlockIdentifier, ChainspecRawBytes, Digest,
GlobalStateIdentifier, Key, KeyTag, Peers, ProtocolVersion, SignedBlock, StoredValue,
Timestamp, Transaction, TransactionHash, Transfer,
Transaction, TransactionHash, Transfer,
};
use juliet::{
io::IoCoreBuilder,
protocol::ProtocolBuilder,
rpc::{JulietRpcClient, JulietRpcServer, RpcBuilder},
ChannelConfiguration, ChannelId,
};
use metrics::rpc::{inc_disconnect, observe_reconnect_time};
use serde::de::DeserializeOwned;
use std::{
convert::{TryFrom, TryInto},
fmt::{self, Display, Formatter},
future::Future,
net::SocketAddr,
sync::Arc,
time::{Duration, Instant},
time::Instant,
};
use tokio::{
net::{
Expand Down Expand Up @@ -129,19 +132,9 @@ pub trait NodeClient: Send + Sync {

async fn exec_speculatively(
&self,
state_root_hash: Digest,
block_time: Timestamp,
protocol_version: ProtocolVersion,
transaction: Transaction,
exec_at_block: BlockHeader,
) -> Result<SpeculativeExecutionResult, Error> {
let request = BinaryRequest::TrySpeculativeExec {
transaction,
state_root_hash,
block_time,
protocol_version,
speculative_exec_at_block: exec_at_block,
};
let request = BinaryRequest::TrySpeculativeExec { transaction };
let resp = self.send_request(request).await?;
parse_response::<SpeculativeExecutionResult>(&resp.into())?.ok_or(Error::EmptyEnvelope)
}
Expand Down Expand Up @@ -259,15 +252,14 @@ pub enum Error {

impl Error {
fn from_error_code(code: u8) -> Self {
match BinaryPortError::try_from(code) {
Ok(BinaryPortError::FunctionDisabled) => Self::FunctionIsDisabled,
Ok(BinaryPortError::InvalidTransaction) => Self::InvalidTransaction,
Ok(BinaryPortError::RootNotFound) => Self::UnknownStateRootHash,
Ok(BinaryPortError::QueryFailedToExecute) => Self::QueryFailedToExecute,
Ok(
err @ (BinaryPortError::WasmPreprocessing
| BinaryPortError::InvalidDeployItemVariant),
) => Self::SpecExecutionFailed(err.to_string()),
match ErrorCode::try_from(code) {
Ok(ErrorCode::FunctionDisabled) => Self::FunctionIsDisabled,
Ok(ErrorCode::InvalidTransaction) => Self::InvalidTransaction,
Ok(ErrorCode::RootNotFound) => Self::UnknownStateRootHash,
Ok(ErrorCode::FailedQuery) => Self::QueryFailedToExecute,
Ok(err @ (ErrorCode::WasmPreprocessing | ErrorCode::InvalidItemVariant)) => {
Self::SpecExecutionFailed(err.to_string())
}
Ok(err) => Self::UnexpectedNodeError {
message: err.to_string(),
code,
Expand Down
9 changes: 3 additions & 6 deletions rpc_sidecar/src/rpcs/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,10 @@ impl RpcWithParams for PutTransaction {

#[cfg(test)]
mod tests {
use casper_types::{
binary_port::{
BinaryRequest, BinaryResponse, BinaryResponseAndRequest,
ErrorCode as BinaryPortErrorCode,
},
testing::TestRng,
use casper_binary_port::{
BinaryRequest, BinaryResponse, BinaryResponseAndRequest, ErrorCode as BinaryPortErrorCode,
};
use casper_types::testing::TestRng;
use pretty_assertions::assert_eq;

use crate::{rpcs::ErrorCode, SUPPORTED_PROTOCOL_VERSION};
Expand Down
27 changes: 8 additions & 19 deletions rpc_sidecar/src/rpcs/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static GET_BLOCK_TRANSFERS_RESULT: Lazy<GetBlockTransfersResult> =
Lazy::new(|| GetBlockTransfersResult {
api_version: DOCS_EXAMPLE_API_VERSION,
block_hash: Some(*BlockHash::example()),
transfers: Some(vec![Transfer::default()]),
transfers: Some(vec![Transfer::example().clone()]),
});
static GET_STATE_ROOT_HASH_PARAMS: Lazy<GetStateRootHashParams> =
Lazy::new(|| GetStateRootHashParams {
Expand Down Expand Up @@ -403,15 +403,13 @@ mod tests {
use std::convert::TryFrom;

use crate::{ClientError, SUPPORTED_PROTOCOL_VERSION};
use casper_binary_port::{
BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest,
GlobalStateQueryResult, GlobalStateRequest, InformationRequestTag, RecordId,
};
use casper_types::{
binary_port::{
BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest,
GlobalStateQueryResult, GlobalStateRequest, InformationRequestTag, RecordId,
},
system::auction::EraInfo,
testing::TestRng,
Block, BlockSignaturesV1, BlockSignaturesV2, ChainNameDigest, DeployHash, SignedBlock,
TestBlockBuilder, TestBlockV1Builder,
system::auction::EraInfo, testing::TestRng, Block, BlockSignaturesV1, BlockSignaturesV2,
ChainNameDigest, SignedBlock, TestBlockBuilder, TestBlockV1Builder,
};
use pretty_assertions::assert_eq;
use rand::Rng;
Expand Down Expand Up @@ -481,16 +479,7 @@ mod tests {

let mut transfers = vec![];
for _ in 0..rng.gen_range(0..10) {
transfers.push(Transfer::new(
DeployHash::random(rng),
rng.gen(),
Some(rng.gen()),
rng.gen(),
rng.gen(),
rng.gen(),
rng.gen(),
Some(rng.gen()),
));
transfers.push(Transfer::random(rng));
}
let signatures = BlockSignaturesV2::new(
*block.hash(),
Expand Down
9 changes: 5 additions & 4 deletions rpc_sidecar/src/rpcs/common.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use casper_binary_port::GlobalStateQueryResult;
use once_cell::sync::Lazy;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::rpcs::error::Error;
use casper_types::{
account::AccountHash, addressable_entity::EntityKindTag, binary_port::GlobalStateQueryResult,
bytesrepr::ToBytes, global_state::TrieMerkleProof, Account, AddressableEntity,
AddressableEntityHash, AvailableBlockRange, BlockHeader, BlockIdentifier,
GlobalStateIdentifier, Key, SignedBlock, StoredValue, URef, U512,
account::AccountHash, addressable_entity::EntityKindTag, bytesrepr::ToBytes,
global_state::TrieMerkleProof, Account, AddressableEntity, AddressableEntityHash,
AvailableBlockRange, BlockHeader, BlockIdentifier, GlobalStateIdentifier, Key, SignedBlock,
StoredValue, URef, U512,
};

use crate::NodeClient;
Expand Down
10 changes: 5 additions & 5 deletions rpc_sidecar/src/rpcs/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use std::{collections::BTreeMap, str, sync::Arc};

use async_trait::async_trait;
use casper_binary_port::MinimalBlockInfo;
use once_cell::sync::Lazy;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use casper_types::{
binary_port::MinimalBlockInfo,
execution::{ExecutionResult, ExecutionResultV2},
ActivationPoint, AvailableBlockRange, Block, BlockHash, BlockSynchronizerStatus,
ChainspecRawBytes, Deploy, DeployHash, Digest, EraId, ExecutionInfo, NextUpgrade, Peers,
Expand Down Expand Up @@ -526,11 +526,11 @@ mod tests {
use std::convert::TryFrom;

use crate::{rpcs::ErrorCode, ClientError, SUPPORTED_PROTOCOL_VERSION};
use casper_binary_port::{
BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest, InformationRequest,
InformationRequestTag, TransactionWithExecutionInfo,
};
use casper_types::{
binary_port::{
BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest,
InformationRequest, InformationRequestTag, TransactionWithExecutionInfo,
},
bytesrepr::{FromBytes, ToBytes},
testing::TestRng,
BlockHash, TransactionV1,
Expand Down
Loading

0 comments on commit 723aaec

Please sign in to comment.