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
… rustSDK-feat-2.0

# Conflicts:
#	types/src/chainspec/transaction_config/transaction_v1_config.rs
  • Loading branch information
gRoussac committed Jul 18, 2024
2 parents 745b85c + db708d2 commit 7161576
Show file tree
Hide file tree
Showing 84 changed files with 904 additions and 328 deletions.
22 changes: 15 additions & 7 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 @@ -152,7 +152,7 @@ lint-smart-contracts:

.PHONY: audit-rs
audit-rs:
$(CARGO) audit --ignore RUSTSEC-2024-0332 --ignore RUSTSEC-2024-0344
$(CARGO) audit --ignore RUSTSEC-2024-0332 --ignore RUSTSEC-2024-0344 --ignore RUSTSEC-2024-0348 --ignore RUSTSEC-2024-0349 --ignore RUSTSEC-2024-0351 --ignore RUSTSEC-2024-0350 --ignore RUSTSEC-2024-0352 --ignore RUSTSEC-2024-0353

.PHONY: audit-as
audit-as:
Expand Down
4 changes: 2 additions & 2 deletions binary_port/src/binary_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl TryFrom<u8> for BinaryRequestTag {
0 => Ok(BinaryRequestTag::Get),
1 => Ok(BinaryRequestTag::TryAcceptTransaction),
2 => Ok(BinaryRequestTag::TrySpeculativeExec),
_ => Err(InvalidBinaryRequestTag(value)),
_ => Err(InvalidBinaryRequestTag),
}
}
}
Expand All @@ -255,7 +255,7 @@ impl From<BinaryRequestTag> for u8 {
}

/// Error raised when trying to convert an invalid u8 into a `BinaryRequestTag`.
pub struct InvalidBinaryRequestTag(u8);
pub struct InvalidBinaryRequestTag;

#[cfg(test)]
mod tests {
Expand Down
19 changes: 16 additions & 3 deletions binary_port/src/information_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub enum InformationRequest {
/// If `None`, the reward for the validator is returned.
delegator: Option<Box<PublicKey>>,
},
/// Returns the current Casper protocol version.
ProtocolVersion,
}

impl InformationRequest {
Expand Down Expand Up @@ -91,6 +93,7 @@ impl InformationRequest {
InformationRequestTag::LatestSwitchBlockHeader
}
InformationRequest::Reward { .. } => InformationRequestTag::Reward,
InformationRequest::ProtocolVersion => InformationRequestTag::ProtocolVersion,
}
}

Expand Down Expand Up @@ -131,6 +134,7 @@ impl InformationRequest {
validator: PublicKey::random(rng).into(),
delegator: rng.gen::<bool>().then(|| PublicKey::random(rng).into()),
},
InformationRequestTag::ProtocolVersion => InformationRequest::ProtocolVersion,
}
}
}
Expand Down Expand Up @@ -169,7 +173,8 @@ impl ToBytes for InformationRequest {
| InformationRequest::ConsensusStatus
| InformationRequest::ChainspecRawBytes
| InformationRequest::NodeStatus
| InformationRequest::LatestSwitchBlockHeader => Ok(()),
| InformationRequest::LatestSwitchBlockHeader
| InformationRequest::ProtocolVersion => Ok(()),
InformationRequest::Reward {
era_identifier,
validator,
Expand Down Expand Up @@ -207,7 +212,8 @@ impl ToBytes for InformationRequest {
| InformationRequest::ConsensusStatus
| InformationRequest::ChainspecRawBytes
| InformationRequest::NodeStatus
| InformationRequest::LatestSwitchBlockHeader => 0,
| InformationRequest::LatestSwitchBlockHeader
| InformationRequest::ProtocolVersion => 0,
InformationRequest::Reward {
era_identifier,
validator,
Expand Down Expand Up @@ -283,6 +289,9 @@ impl TryFrom<(InformationRequestTag, &[u8])> for InformationRequest {
remainder,
)
}
InformationRequestTag::ProtocolVersion => {
(InformationRequest::ProtocolVersion, key_bytes)
}
};
if !remainder.is_empty() {
return Err(bytesrepr::Error::LeftOverBytes);
Expand Down Expand Up @@ -340,12 +349,14 @@ pub enum InformationRequestTag {
LatestSwitchBlockHeader = 15,
/// Reward for a validator or a delegator in a specific era.
Reward = 16,
/// Protocol version request.
ProtocolVersion = 17,
}

impl InformationRequestTag {
#[cfg(test)]
pub(crate) fn random(rng: &mut TestRng) -> Self {
match rng.gen_range(0..16) {
match rng.gen_range(0..18) {
0 => InformationRequestTag::BlockHeader,
1 => InformationRequestTag::SignedBlock,
2 => InformationRequestTag::Transaction,
Expand All @@ -363,6 +374,7 @@ impl InformationRequestTag {
14 => InformationRequestTag::NodeStatus,
15 => InformationRequestTag::LatestSwitchBlockHeader,
16 => InformationRequestTag::Reward,
17 => InformationRequestTag::ProtocolVersion,
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -390,6 +402,7 @@ impl TryFrom<u16> for InformationRequestTag {
14 => Ok(InformationRequestTag::NodeStatus),
15 => Ok(InformationRequestTag::LatestSwitchBlockHeader),
16 => Ok(InformationRequestTag::Reward),
17 => Ok(InformationRequestTag::ProtocolVersion),
_ => Err(UnknownInformationRequestTag(value)),
}
}
Expand Down
10 changes: 9 additions & 1 deletion binary_port/src/payload_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use casper_types::{
execution::{ExecutionResult, ExecutionResultV1},
AvailableBlockRange, BlockBody, BlockBodyV1, BlockHeader, BlockHeaderV1, BlockSignatures,
BlockSignaturesV1, BlockSynchronizerStatus, ChainspecRawBytes, Deploy, NextUpgrade, Peers,
SignedBlock, StoredValue, Transaction, Transfer,
ProtocolVersion, SignedBlock, StoredValue, Transaction, Transfer,
};

use crate::{
Expand Down Expand Up @@ -108,6 +108,8 @@ pub enum PayloadType {
BalanceResponse,
/// Reward response.
Reward,
/// Protocol version.
ProtocolVersion,
}

impl PayloadType {
Expand Down Expand Up @@ -199,6 +201,7 @@ impl TryFrom<u8> for PayloadType {
x if x == PayloadType::WasmV1Result as u8 => Ok(PayloadType::WasmV1Result),
x if x == PayloadType::BalanceResponse as u8 => Ok(PayloadType::BalanceResponse),
x if x == PayloadType::Reward as u8 => Ok(PayloadType::Reward),
x if x == PayloadType::ProtocolVersion as u8 => Ok(PayloadType::ProtocolVersion),
_ => Err(()),
}
}
Expand Down Expand Up @@ -253,6 +256,7 @@ impl fmt::Display for PayloadType {
PayloadType::DictionaryQueryResult => write!(f, "DictionaryQueryResult"),
PayloadType::BalanceResponse => write!(f, "BalanceResponse"),
PayloadType::Reward => write!(f, "Reward"),
PayloadType::ProtocolVersion => write!(f, "ProtocolVersion"),
}
}
}
Expand Down Expand Up @@ -391,6 +395,10 @@ impl PayloadEntity for RewardResponse {
const PAYLOAD_TYPE: PayloadType = PayloadType::Reward;
}

impl PayloadEntity for ProtocolVersion {
const PAYLOAD_TYPE: PayloadType = PayloadType::ProtocolVersion;
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
38 changes: 22 additions & 16 deletions execution_engine/src/execution/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use casper_storage::{
AddressGenerator,
};
use casper_types::{
account::AccountHash, addressable_entity::NamedKeys, execution::Effects, AddressableEntity,
AddressableEntityHash, BlockTime, ContextAccessRights, EntryPointType, Gas, Key, Phase,
ProtocolVersion, RuntimeArgs, StoredValue, Tagged, TransactionHash, U512,
account::AccountHash, addressable_entity::NamedKeys, contract_messages::Messages,
execution::Effects, AddressableEntity, AddressableEntityHash, BlockTime, ContextAccessRights,
EntryPointType, Gas, Key, Phase, ProtocolVersion, RuntimeArgs, StoredValue, Tagged,
TransactionHash, U512,
};

use crate::{
Expand Down Expand Up @@ -130,19 +131,24 @@ impl Executor {
}
};

let err = match result {
Ok(_) => None,
Err(error) => Some(error.into()),
};

return WasmV1Result::new(
gas_limit,
runtime.context().gas_counter(),
runtime.context().effects(),
runtime.context().transfers().to_owned(),
runtime.context().messages(),
err,
);
match result {
Ok(_) => WasmV1Result::new(
gas_limit,
runtime.context().gas_counter(),
runtime.context().effects(),
runtime.context().transfers().to_owned(),
runtime.context().messages(),
None,
),
Err(error) => WasmV1Result::new(
gas_limit,
runtime.context().gas_counter(),
Effects::new(),
vec![],
Messages::new(),
Some(error.into()),
),
}
}

/// Creates new runtime context.
Expand Down
8 changes: 4 additions & 4 deletions execution_engine/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ where
self.context.access_rights_extend(&urefs);
{
let transfers = self.context.transfers_mut();
*transfers = mint_runtime.context.transfers().to_owned();
mint_runtime.context.transfers().clone_into(transfers);
}
Ok(ret)
}
Expand Down Expand Up @@ -888,7 +888,7 @@ where
self.context.access_rights_extend(&urefs);
{
let transfers = self.context.transfers_mut();
*transfers = runtime.context.transfers().to_owned();
runtime.context.transfers().clone_into(transfers);
}
Ok(ret)
}
Expand Down Expand Up @@ -1138,7 +1138,7 @@ where
self.context.access_rights_extend(&urefs);
{
let transfers = self.context.transfers_mut();
*transfers = runtime.context.transfers().to_owned();
runtime.context.transfers().clone_into(transfers);
}

Ok(ret)
Expand Down Expand Up @@ -1622,7 +1622,7 @@ where
self.context
.set_emit_message_cost(runtime.context.emit_message_cost());
let transfers = self.context.transfers_mut();
*transfers = runtime.context.transfers().to_owned();
runtime.context.transfers().clone_into(transfers);

return match result {
Ok(_) => {
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/runtime_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ where
"Contract".to_string(),
other.type_name(),
))),
None => Err(TrackingCopyError::KeyNotFound(key)).map_err(Into::into),
None => Err(TrackingCopyError::KeyNotFound(key).into()),
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion execution_engine_testing/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ base16 = "0.2.1"
casper-engine-test-support = { path = "../test_support" }
casper-execution-engine = { path = "../../execution_engine", features = ["test-support"] }
casper-storage = { path = "../../storage" }
casper-types = { path = "../../types", default_features = false, features = ["datasize", "json-schema"] }
casper-types = { path = "../../types", default-features = false, features = ["datasize", "json-schema"] }
casper-wasm = "0.46.0"
clap = "2"
fs_extra = "1.2.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::convert::TryFrom;
use std::path::PathBuf;

use casper_engine_test_support::{
Expand Down Expand Up @@ -39,7 +38,7 @@ fn test_check_transfer_success_with_source_only() {
);

// Doing a transfer from main purse to create new purse and store URef under NEW_PURSE_NAME.
let transfer_amount = U512::try_from(FIRST_TRANSFER_AMOUNT).expect("U512 from u64");
let transfer_amount = U512::from(FIRST_TRANSFER_AMOUNT);
let path = PathBuf::from(TRANSFER_WASM);
let session_args = runtime_args! {
ARG_DESTINATION => NEW_PURSE_NAME,
Expand Down Expand Up @@ -100,9 +99,9 @@ fn test_check_transfer_success_with_source_only_errors() {
);

// Doing a transfer from main purse to create new purse and store Uref under NEW_PURSE_NAME.
let transfer_amount = U512::try_from(FIRST_TRANSFER_AMOUNT).expect("U512 from u64");
let transfer_amount = U512::from(FIRST_TRANSFER_AMOUNT);
// Setup mismatch between transfer_amount performed and given to trigger assertion.
let wrong_transfer_amount = transfer_amount - U512::try_from(100u64).expect("U512 from 64");
let wrong_transfer_amount = transfer_amount - U512::from(100u64);

let path = PathBuf::from(TRANSFER_WASM);
let session_args = runtime_args! {
Expand Down Expand Up @@ -160,7 +159,7 @@ fn test_check_transfer_success_with_source_and_target() {
DEFAULT_CHAINSPEC_REGISTRY.clone(),
);

let transfer_amount = U512::try_from(SECOND_TRANSFER_AMOUNT).expect("U512 from u64");
let transfer_amount = U512::from(SECOND_TRANSFER_AMOUNT);
// Doing a transfer from main purse to create new purse and store URef under NEW_PURSE_NAME.
let path = PathBuf::from(TRANSFER_WASM);
let session_args = runtime_args! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ fn should_produce_per_block_message_ordering() {
.get_last_exec_result()
.unwrap()
.messages()
.get(0)
.first()
.unwrap()
.block_index(),
expected_index
Expand Down
6 changes: 3 additions & 3 deletions execution_engine_testing/tests/src/test/regression/ee_1120.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ fn should_run_ee_1120_slash_delegators() {

let unbond_purses_after: UnbondingPurses = builder.get_unbonds();
assert_ne!(unbond_purses_before, unbond_purses_after);
assert!(unbond_purses_after.get(&VALIDATOR_1_ADDR).is_none());
assert!(unbond_purses_after.get(&DELEGATOR_1_ADDR).is_some());
assert!(unbond_purses_after.get(&VALIDATOR_2_ADDR).is_some());
assert!(!unbond_purses_after.contains_key(&VALIDATOR_1_ADDR));
assert!(unbond_purses_after.contains_key(&DELEGATOR_1_ADDR));
assert!(unbond_purses_after.contains_key(&VALIDATOR_2_ADDR));

// slash validator 1 to clear remaining bids and unbonding purses
let slash_request_2 = ExecuteRequestBuilder::contract_call_by_hash(
Expand Down
Loading

0 comments on commit 7161576

Please sign in to comment.