Skip to content

Commit

Permalink
Merge branch 'feat-2.0' of github.com:casper-network/casper-node into…
Browse files Browse the repository at this point in the history
… feat-2.0
  • Loading branch information
sacherjj committed Jun 26, 2024
2 parents d50b5e0 + 30797fb commit ee9c6de
Show file tree
Hide file tree
Showing 25 changed files with 772 additions and 163 deletions.
39 changes: 33 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ lint-smart-contracts:

.PHONY: audit-rs
audit-rs:
$(CARGO) audit --ignore RUSTSEC-2024-0332
$(CARGO) audit --ignore RUSTSEC-2024-0344

.PHONY: audit-as
audit-as:
Expand Down
2 changes: 2 additions & 0 deletions binary_port/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ tokio-util = { version = "0.6.4", features = ["codec"] }
casper-types = { path = "../types", features = ["datasize", "json-schema", "std", "testing"] }
serde_json = "1"
serde_test = "1"
strum = "0.26.2"
strum_macros = "0.26.4"

[package.metadata.docs.rs]
all-features = true
Expand Down
127 changes: 126 additions & 1 deletion binary_port/src/error_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ use core::{convert::TryFrom, fmt};

use casper_types::{InvalidDeploy, InvalidTransaction, InvalidTransactionV1};

#[cfg(test)]
use strum_macros::EnumIter;

/// The error code indicating the result of handling the binary request.
#[derive(Debug, Clone, thiserror::Error)]
#[derive(Debug, Copy, Clone, thiserror::Error, Eq, PartialEq)]
#[repr(u16)]
#[cfg_attr(test, derive(EnumIter))]
pub enum ErrorCode {
/// Request executed correctly.
#[error("request executed correctly")]
Expand Down Expand Up @@ -198,6 +202,75 @@ pub enum ErrorCode {
/// Invalid binary port version.
#[error("binary protocol version mismatch")]
BinaryProtocolVersionMismatch = 61,
/// Blockchain is empty
#[error("blockchain is empty")]
EmptyBlockchain = 62,
/// Expected deploy, but got transaction
#[error("expected deploy, got transaction")]
ExpectedDeploy = 63,
/// Expected transaction, but got deploy
#[error("expected transaction V1, got deploy")]
ExpectedTransaction = 64,
/// Transaction has expired
#[error("transaction has expired")]
TransactionExpired = 65,
/// Transactions parameters are missing or incorrect
#[error("missing or incorrect transaction parameters")]
MissingOrIncorrectParameters = 66,
/// No such addressable entity
#[error("no such addressable entity")]
NoSuchAddressableEntity = 67,
// No such contract at hash
#[error("no such contract at hash")]
NoSuchContractAtHash = 68,
/// No such entry point
#[error("no such entry point")]
NoSuchEntryPoint = 69,
/// No such package at hash
#[error("no such package at hash")]
NoSuchPackageAtHash = 70,
/// Invalid entity at version
#[error("invalid entity at version")]
InvalidEntityAtVersion = 71,
/// Disabled entity at version
#[error("disabled entity at version")]
DisabledEntityAtVersion = 72,
/// Missing entity at version
#[error("missing entity at version")]
MissingEntityAtVersion = 73,
/// Invalid associated keys
#[error("invalid associated keys")]
InvalidAssociatedKeys = 74,
/// Insufficient signature weight
#[error("insufficient signature weight")]
InsufficientSignatureWeight = 75,
/// Insufficient balance
#[error("insufficient balance")]
InsufficientBalance = 76,
/// Unknown balance
#[error("unknown balance")]
UnknownBalance = 77,
/// Invalid payment variant for deploy
#[error("invalid payment variant for deploy")]
DeployInvalidPaymentVariant = 78,
/// Missing payment amount for deploy
#[error("missing payment amount for deploy")]
DeployMissingPaymentAmount = 79,
/// Failed to parse payment amount for deploy
#[error("failed to parse payment amount for deploy")]
DeployFailedToParsePaymentAmount = 80,
/// Missing transfer target for deploy
#[error("missing transfer target for deploy")]
DeployMissingTransferTarget = 81,
/// Missing module bytes for deploy
#[error("missing module bytes for deploy")]
DeployMissingModuleBytes = 82,
/// Entry point cannot be 'call'
#[error("entry point cannot be 'call'")]
InvalidTransactionEntryPointCannotBeCall = 83,
/// Invalid transaction kind
#[error("invalid transaction kind")]
InvalidTransactionInvalidTransactionKind = 84,
}

impl TryFrom<u16> for ErrorCode {
Expand Down Expand Up @@ -266,6 +339,30 @@ impl TryFrom<u16> for ErrorCode {
58 => Ok(ErrorCode::SwitchBlockNotFound),
59 => Ok(ErrorCode::SwitchBlockParentNotFound),
60 => Ok(ErrorCode::UnsupportedRewardsV1Request),
61 => Ok(ErrorCode::BinaryProtocolVersionMismatch),
62 => Ok(ErrorCode::EmptyBlockchain),
63 => Ok(ErrorCode::ExpectedDeploy),
64 => Ok(ErrorCode::ExpectedTransaction),
65 => Ok(ErrorCode::TransactionExpired),
66 => Ok(ErrorCode::MissingOrIncorrectParameters),
67 => Ok(ErrorCode::NoSuchAddressableEntity),
68 => Ok(ErrorCode::NoSuchContractAtHash),
69 => Ok(ErrorCode::NoSuchEntryPoint),
70 => Ok(ErrorCode::NoSuchPackageAtHash),
71 => Ok(ErrorCode::InvalidEntityAtVersion),
72 => Ok(ErrorCode::DisabledEntityAtVersion),
73 => Ok(ErrorCode::MissingEntityAtVersion),
74 => Ok(ErrorCode::InvalidAssociatedKeys),
75 => Ok(ErrorCode::InsufficientSignatureWeight),
76 => Ok(ErrorCode::InsufficientBalance),
77 => Ok(ErrorCode::UnknownBalance),
78 => Ok(ErrorCode::DeployInvalidPaymentVariant),
79 => Ok(ErrorCode::DeployMissingPaymentAmount),
80 => Ok(ErrorCode::DeployFailedToParsePaymentAmount),
81 => Ok(ErrorCode::DeployMissingTransferTarget),
82 => Ok(ErrorCode::DeployMissingModuleBytes),
83 => Ok(ErrorCode::InvalidTransactionEntryPointCannotBeCall),
84 => Ok(ErrorCode::InvalidTransactionInvalidTransactionKind),
_ => Err(UnknownErrorCode),
}
}
Expand Down Expand Up @@ -394,7 +491,35 @@ impl From<InvalidTransactionV1> for ErrorCode {
InvalidTransactionV1::InvalidPricingMode { .. } => {
ErrorCode::InvalidTransactionPricingMode
}
InvalidTransactionV1::EntryPointCannotBeCall => {
ErrorCode::InvalidTransactionEntryPointCannotBeCall
}
InvalidTransactionV1::InvalidTransactionKind(_) => {
ErrorCode::InvalidTransactionInvalidTransactionKind
}
_ => ErrorCode::InvalidTransactionUnspecified,
}
}
}

#[cfg(test)]
mod tests {
use std::convert::TryFrom;

use strum::IntoEnumIterator;

use crate::ErrorCode;

#[test]
fn try_from_decoded_all_variants() {
for variant in ErrorCode::iter() {
let as_int = variant as u16;
let decoded = ErrorCode::try_from(as_int);
assert!(
decoded.is_ok(),
"variant {} not covered by TryFrom<u16> implementation",
as_int
);
}
}
}
3 changes: 2 additions & 1 deletion binary_port/src/global_state_query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use casper_types::testing::TestRng;

#[cfg(test)]
use casper_types::{ByteCode, ByteCodeKind};
use serde::Serialize;

/// Carries the successful result of the global state query.
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct GlobalStateQueryResult {
/// Stored value.
value: StoredValue,
Expand Down
3 changes: 2 additions & 1 deletion binary_port/src/node_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use casper_types::{
use casper_types::testing::TestRng;
#[cfg(test)]
use rand::Rng;
use serde::Serialize;

use crate::{minimal_block_info::MinimalBlockInfo, type_wrappers::ReactorStateName};

/// Status information about the node.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Serialize)]
pub struct NodeStatus {
/// The node ID and network address of each connected peer.
pub peers: Peers,
Expand Down
17 changes: 9 additions & 8 deletions binary_port/src/type_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use casper_types::{
bytesrepr::{self, Bytes, FromBytes, ToBytes},
EraId, ExecutionInfo, Key, PublicKey, TimeDiff, Timestamp, Transaction, ValidatorChange, U512,
};
use serde::Serialize;

use super::GlobalStateQueryResult;

Expand Down Expand Up @@ -39,7 +40,7 @@ macro_rules! impl_bytesrepr_for_type_wrapper {
}

/// Type representing uptime.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub struct Uptime(u64);

impl Uptime {
Expand Down Expand Up @@ -69,7 +70,7 @@ impl TryFrom<Uptime> for TimeDiff {
}

/// Type representing changes in consensus validators.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "datasize", derive(DataSize))]
pub struct ConsensusValidatorChanges(BTreeMap<PublicKey, Vec<(EraId, ValidatorChange)>>);

Expand All @@ -92,7 +93,7 @@ impl From<ConsensusValidatorChanges> for BTreeMap<PublicKey, Vec<(EraId, Validat
}

/// Type representing network name.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct NetworkName(String);

impl NetworkName {
Expand All @@ -114,7 +115,7 @@ impl From<NetworkName> for String {
}

/// Type representing the reactor state name.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct ReactorStateName(String);

impl ReactorStateName {
Expand All @@ -136,7 +137,7 @@ impl From<ReactorStateName> for String {
}

/// Type representing last progress of the sync process.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct LastProgress(Timestamp);

impl LastProgress {
Expand Down Expand Up @@ -174,7 +175,7 @@ impl GetTrieFullResult {
}

/// Type representing the reward of a validator or a delegator.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct RewardResponse {
amount: U512,
era_id: EraId,
Expand Down Expand Up @@ -223,7 +224,7 @@ impl FromBytes for RewardResponse {
}

/// Describes the consensus status.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct ConsensusStatus {
validator_public_key: PublicKey,
round_length: Option<TimeDiff>,
Expand Down Expand Up @@ -278,7 +279,7 @@ impl FromBytes for ConsensusStatus {
}

/// A transaction with execution info.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct TransactionWithExecutionInfo {
transaction: Transaction,
execution_info: Option<ExecutionInfo>,
Expand Down
Loading

0 comments on commit ee9c6de

Please sign in to comment.