Skip to content

Commit

Permalink
Merge pull request #70 from darthsiroftardis/get-era-summary
Browse files Browse the repository at this point in the history
Update era response validation logic
  • Loading branch information
sacherjj authored May 9, 2023
2 parents ea5fced + c9cee94 commit cb7cff1
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ doc = false
async-trait = "0.1.51"
base16 = "0.2.1"
base64 = "0.13.0"
casper-execution-engine = "=3.0.0"
casper-node = "=1.4.13"
casper-hashing = "=1.4.3"
casper-types = "=1.5.0"
casper-execution-engine = "3.1.0"
casper-node = "1.4.15"
casper-hashing = "1.4.3"
casper-types = {version = "1.6.0", features = ["std"]}
clap = "2"
humantime = "2"
jsonrpc-lite = "0.5.0"
Expand Down
6 changes: 3 additions & 3 deletions lib/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::{
use casper_execution_engine::core::engine_state::ExecutableDeployItem;
use casper_node::{
rpcs::{account::PutDeploy, chain::GetBlockResult, info::GetDeploy, RpcWithParams},
types::{Deploy, DeployHash, TimeDiff, Timestamp},
types::{Deploy, DeployHash},
};
use casper_types::{
account::AccountHash, AsymmetricType, ProtocolVersion, PublicKey, RuntimeArgs, SecretKey,
UIntParseError, URef, U512,
TimeDiff, Timestamp, UIntParseError, URef, U512,
};

use crate::{
Expand Down Expand Up @@ -339,7 +339,7 @@ impl DeployExt for Deploy {
mod tests {
use std::convert::TryInto;

use casper_node::{crypto::AsymmetricKeyExt, types::ExcessiveSizeDeployError};
use casper_node::types::ExcessiveSizeDeployError;

use super::*;
use crate::{DeployStrParams, PaymentStrParams, SessionStrParams};
Expand Down
5 changes: 3 additions & 2 deletions lib/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use humantime::{DurationError, TimestampError};
use jsonrpc_lite::JsonRpc;
use thiserror::Error;

use casper_node::{crypto::Error as CryptoError, types::ExcessiveSizeDeployError};
use casper_node::types::ExcessiveSizeDeployError;
use casper_types::{
bytesrepr::Error as ToBytesError, CLValueError, UIntParseError, URefFromStrError,
bytesrepr::Error as ToBytesError, crypto::ErrorExt as CryptoError, CLValueError,
UIntParseError, URefFromStrError,
};

use crate::validation::ValidateResponseError;
Expand Down
3 changes: 1 addition & 2 deletions lib/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use std::{fs, path::Path};

use casper_node::crypto::AsymmetricKeyExt;
use casper_types::{AsymmetricType, PublicKey, SecretKey};
use casper_types::{crypto::SecretKey, AsymmetricType, PublicKey};

use crate::error::{Error, Result};

Expand Down
6 changes: 4 additions & 2 deletions lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1551,15 +1551,17 @@ mod param_tests {

#[test]
fn should_fail_to_convert_with_bad_dependencies() {
use casper_node::crypto::Error as CryptoError;
use casper_types::crypto::ErrorExt as CryptoError;
let mut params = test_value();
params.dependencies = vec!["invalid dep"];
let result: StdResult<DeployParams, Error> = params.try_into();
assert!(matches!(
result,
Err(Error::CryptoError {
context: "dependencies",
error: CryptoError::FromHex(base16::DecodeError::InvalidLength { length: 11 })
error: CryptoError::CryptoError(casper_types::crypto::Error::FromHex(
base16::DecodeError::InvalidLength { length: 11 }
))
})
));
}
Expand Down
7 changes: 2 additions & 5 deletions lib/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ use serde::{self, Deserialize};

use casper_execution_engine::core::engine_state::executable_deploy_item::ExecutableDeployItem;
use casper_hashing::Digest;
use casper_node::{
crypto::AsymmetricKeyExt,
types::{DeployHash, TimeDiff, Timestamp},
};
use casper_node::types::DeployHash;
use casper_types::{
bytesrepr, AsymmetricType, CLType, CLValue, HashAddr, Key, NamedArg, PublicKey, RuntimeArgs,
SecretKey, UIntParseError, U512,
SecretKey, TimeDiff, Timestamp, UIntParseError, U512,
};

use crate::{
Expand Down
5 changes: 2 additions & 3 deletions lib/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use serde_json::{json, Map, Value};
use casper_execution_engine::core::engine_state::ExecutableDeployItem;
use casper_hashing::Digest;
use casper_node::{
crypto,
rpcs::{
account::{PutDeploy, PutDeployParams},
chain::{
Expand All @@ -28,7 +27,7 @@ use casper_node::{
},
types::{BlockHash, Deploy, DeployHash},
};
use casper_types::{AsymmetricType, Key, PublicKey, URef};
use casper_types::{crypto, AsymmetricType, Key, PublicKey, URef};

use crate::{
deploy::{DeployExt, DeployParams, SendDeploy, Transfer},
Expand Down Expand Up @@ -414,7 +413,7 @@ pub fn map_hashing_error(hashing_error: casper_hashing::Error) -> impl Fn(&'stat
move |context: &'static str| match &hashing_error {
casper_hashing::Error::Base16DecodeError(decode_error) => Error::CryptoError {
context,
error: crypto::Error::FromHex(decode_error.clone()),
error: crypto::Error::FromHex(decode_error.clone()).into(),
},
casper_hashing::Error::IncorrectDigestLength(length) => Error::InvalidArgument {
context,
Expand Down
17 changes: 14 additions & 3 deletions lib/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ pub(crate) fn validate_get_era_info_response(
.map_err(|_| ValidateResponseError::ValidateResponseFailedToParse)?;
let proofs: Vec<TrieMerkleProof<Key, StoredValue>> =
bytesrepr::deserialize(proof_bytes)?;
let key = Key::EraInfo(era_id);
let path = &[];

let proof_value = match stored_value {
Expand All @@ -110,8 +109,20 @@ pub(crate) fn validate_get_era_info_response(
_ => return Err(ValidateResponseError::ValidateResponseFailedToParse),
};

core::validate_query_proof(&state_root_hash, &proofs, &key, path, &proof_value)
.map_err(Into::into)
match core::validate_query_proof(
&state_root_hash,
&proofs,
&Key::EraSummary,
path,
&proof_value,
) {
Ok(_) => Ok(()),
Err(_) => {
let key = Key::EraInfo(era_id);
core::validate_query_proof(&state_root_hash, &proofs, &key, path, &proof_value)
.map_err(Into::into)
}
}
}
None => Ok(()),
}
Expand Down
1 change: 0 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ pub mod block_identifier {
/// Internal module to handle providing the arg for and retrieval of the public key or session
/// account.
mod sealed_public_key {
use casper_node::crypto::AsymmetricKeyExt;
use casper_types::AsymmetricType;

use super::*;
Expand Down
1 change: 0 additions & 1 deletion src/get_dictionary_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ enum DisplayOrder {

/// Handles providing the arg for and retrieval of the key.
mod key {
use casper_node::crypto::AsymmetricKeyExt;
use casper_types::AsymmetricType;

use super::*;
Expand Down
1 change: 0 additions & 1 deletion src/query_global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ mod block_hash {

/// Handles providing the arg for and retrieval of the key.
mod key {
use casper_node::crypto::AsymmetricKeyExt;
use casper_types::{AsymmetricType, PublicKey};

use super::*;
Expand Down
39 changes: 24 additions & 15 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ use casper_client::{
DeployStrParams, DictionaryItemStrParams, Error, GlobalStateStrParams, PaymentStrParams,
SessionStrParams,
};
use casper_node::{
crypto::Error as CryptoError,
rpcs::{
account::{PutDeploy, PutDeployParams},
chain::{GetStateRootHash, GetStateRootHashParams},
info::{GetDeploy, GetDeployParams},
state::{GetBalance, GetBalanceParams, GetDictionaryItem, GetDictionaryItemParams},
RpcWithOptionalParams, RpcWithParams,
},
use casper_node::rpcs::{
account::{PutDeploy, PutDeployParams},
chain::{GetStateRootHash, GetStateRootHashParams},
info::{GetDeploy, GetDeployParams},
state::{GetBalance, GetBalanceParams, GetDictionaryItem, GetDictionaryItemParams},
RpcWithOptionalParams, RpcWithParams,
};
use casper_types::crypto::ErrorExt as CryptoError;

const VALID_PURSE_UREF: &str =
"uref-0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20-007";
Expand Down Expand Up @@ -593,7 +591,9 @@ mod get_item {
.await,
Err(Error::CryptoError {
context: "state_root_hash",
error: CryptoError::FromHex(base16::DecodeError::InvalidLength { length: 25 })
error: CryptoError::CryptoError(casper_types::crypto::Error::FromHex(
base16::DecodeError::InvalidLength { length: 25 }
))
})
));
}
Expand All @@ -618,13 +618,16 @@ mod get_item {
.await,
Err(Error::CryptoError {
context: "state_root_hash",
error: CryptoError::FromHex(base16::DecodeError::InvalidLength { length: 25 })
error: CryptoError::CryptoError(casper_types::crypto::Error::FromHex(
base16::DecodeError::InvalidLength { length: 25 }
))
})
));
}
}

mod get_dictionary_item {

use super::*;

#[tokio::test(flavor = "multi_thread")]
Expand Down Expand Up @@ -720,7 +723,9 @@ mod get_dictionary_item {
.await,
Err(Error::CryptoError {
context: "state_root_hash",
error: CryptoError::FromHex(base16::DecodeError::InvalidLength { length: _ })
error: CryptoError::CryptoError(casper_types::crypto::Error::FromHex(
base16::DecodeError::InvalidLength { length: _ }
))
})
));
}
Expand Down Expand Up @@ -768,7 +773,9 @@ mod query_global_state {
.await,
Err(Error::CryptoError {
context: "global_state_identifier",
error: CryptoError::FromHex(base16::DecodeError::InvalidLength { length: _ })
error: CryptoError::CryptoError(casper_types::crypto::Error::FromHex(
base16::DecodeError::InvalidLength { length: _ }
))
})
));
}
Expand Down Expand Up @@ -803,7 +810,9 @@ mod query_global_state {
.await,
Err(Error::CryptoError {
context: "global_state_identifier",
error: CryptoError::FromHex(base16::DecodeError::InvalidLength { length: _ }),
error: CryptoError::CryptoError(casper_types::crypto::Error::FromHex(
base16::DecodeError::InvalidLength { length: _ }
))
})
));
}
Expand Down Expand Up @@ -1371,7 +1380,7 @@ mod put_deploy {

mod rate_limit {
use super::*;
use casper_node::types::Timestamp;
use casper_types::Timestamp;

#[tokio::test(flavor = "multi_thread")]
async fn client_should_should_be_rate_limited_to_approx_1_qps() {
Expand Down

0 comments on commit cb7cff1

Please sign in to comment.