Skip to content

Commit

Permalink
Merge branch 'feat-2.0' into 4443-reduce-test-lmdb-sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderLimonov committed Feb 22, 2024
2 parents 924098f + ce92a85 commit 18b4c19
Show file tree
Hide file tree
Showing 91 changed files with 2,613 additions and 2,234 deletions.
4 changes: 4 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ steps:
environment:
SCCACHE_S3_PUBLIC: true
commands:
- make check-std-features
- make check-testing-features
- make test CARGO_FLAGS=--release
- make test-contracts CARGO_FLAGS=--release
- cachepot --show-stats
Expand All @@ -48,6 +50,8 @@ steps:
- name: cargo-test-push
<<: *buildenv
commands:
- make check-std-features
- make check-testing-features
- make test CARGO_FLAGS=--release
- make test-contracts CARGO_FLAGS=--release
- cachepot --show-stats
Expand Down
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ check-std-features:
cd smart_contracts/contract && $(CARGO) check --all-targets --no-default-features --features=std
cd smart_contracts/contract && $(CARGO) check --all-targets --features=std

.PHONY: check-testing-features
check-testing-features:
cd types && $(CARGO) check --all-targets --no-default-features --features=testing
cd types && $(CARGO) check --all-targets --features=testing

.PHONY: check-format
check-format:
$(CARGO_PINNED_NIGHTLY) fmt --all -- --check
Expand Down Expand Up @@ -158,18 +163,15 @@ check-rs: \
lint \
audit \
check-std-features \
check-testing-features \
test-rs \
test-rs-no-default-features \
test-contracts-rs

.PHONY: check
check: \
check-format \
doc \
lint \
audit \
test \
test-contracts
check-rs \
test-as

.PHONY: clean
clean:
Expand Down
2 changes: 1 addition & 1 deletion ci/nctl_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function dev_branch_settings() {
pushd "$(get_path_to_remotes)"
RC_VERSION="$(ls --group-directories-first -d */ | sort -r | head -n 1 | tr -d '/')"

[[ "$RC_VERSION" =~ (.*[^0-9])([0-9])(.)([0-9]+) ]] && INCREMENT="${BASH_REMATCH[1]}$((${BASH_REMATCH[2]} + 1))${BASH_REMATCH[3]}${BASH_REMATCH[4]}"
[[ "$RC_VERSION" =~ (.*[^0-9])([0-9])(.)([0-9]+) ]] && INCREMENT="2.0${BASH_REMATCH[3]}${BASH_REMATCH[4]}"

RC_VERSION=$(echo "$RC_VERSION" | sed 's/\./\_/g')
INCREMENT=$(echo "$INCREMENT" | sed 's/\./\_/g')
Expand Down
7 changes: 6 additions & 1 deletion execution_engine/src/engine_state/deploy_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ impl DeployItem {
deploy_hash,
}
}

/// Is this a native transfer?
pub fn is_native_transfer(&self) -> bool {
matches!(self.session, ExecutableDeployItem::Transfer { .. })
}
}

impl From<Deploy> for DeployItem {
Expand All @@ -62,7 +67,7 @@ impl From<Deploy> for DeployItem {
deploy.payment().clone(),
deploy.header().gas_price(),
authorization_keys,
casper_types::DeployHash::new(*deploy.hash().inner()),
DeployHash::new(*deploy.hash().inner()),
)
}
}
13 changes: 12 additions & 1 deletion execution_engine/src/engine_state/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use thiserror::Error;

use casper_storage::{
global_state::{self, state::CommitError},
system::{genesis::GenesisError, protocol_upgrade::ProtocolUpgradeError},
system::{
genesis::GenesisError, protocol_upgrade::ProtocolUpgradeError, transfer::TransferError,
},
tracking_copy::TrackingCopyError,
};
use casper_types::{
Expand Down Expand Up @@ -120,6 +122,9 @@ pub enum Error {
/// Storage error.
#[error("Tracking copy error: {0}")]
TrackingCopy(TrackingCopyError),
/// Native transfer error.
#[error("Transfer error: {0}")]
Transfer(TransferError),
}

impl Error {
Expand All @@ -133,6 +138,12 @@ impl Error {
}
}

impl From<TransferError> for Error {
fn from(err: TransferError) -> Self {
Error::Transfer(err)
}
}

impl From<execution::Error> for Error {
fn from(error: execution::Error) -> Self {
match error {
Expand Down
61 changes: 46 additions & 15 deletions execution_engine/src/engine_state/execution_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
use std::collections::VecDeque;

use casper_storage::data_access_layer::TransferResult;
use casper_types::{
bytesrepr::FromBytes,
contract_messages::Messages,
execution::{Effects, ExecutionResultV2 as TypesExecutionResult, Transform, TransformKind},
CLTyped, CLValue, Gas, Key, Motes, StoredValue, TransferAddr,
};

use super::error;
use super::Error;
use crate::execution::Error as ExecError;

/// Represents the result of an execution specified by
Expand All @@ -19,7 +20,7 @@ pub enum ExecutionResult {
/// An error condition that happened during execution
Failure {
/// Error causing this `Failure` variant.
error: error::Error,
error: Error,
/// List of transfers that happened during execution up to the point of the failure.
transfers: Vec<TransferAddr>,
/// Gas consumed up to the point of the failure.
Expand Down Expand Up @@ -59,7 +60,7 @@ impl ExecutionResult {
/// Constructs [ExecutionResult::Failure] that has 0 cost and no effects.
/// This is the case for failures that we can't (or don't want to) charge
/// for, like `PreprocessingError` or `InvalidNonce`.
pub fn precondition_failure(error: error::Error) -> ExecutionResult {
pub fn precondition_failure(error: Error) -> ExecutionResult {
ExecutionResult::Failure {
error,
transfers: Vec::default(),
Expand Down Expand Up @@ -224,18 +225,19 @@ impl ExecutionResult {

/// Returns error value, if possible.
///
/// Returns a reference to a wrapped [`error::Error`] instance if the object is a failure
/// variant.
pub fn as_error(&self) -> Option<&error::Error> {
/// Returns a reference to a wrapped [`super::Error`]
/// instance if the object is a failure variant.
pub fn as_error(&self) -> Option<&Error> {
match self {
ExecutionResult::Failure { error, .. } => Some(error),
ExecutionResult::Success { .. } => None,
}
}

/// Consumes [`ExecutionResult`] instance and optionally returns [`error::Error`] instance for
/// Consumes [`ExecutionResult`] instance and optionally returns
/// [`super::Error`] instance for
/// [`ExecutionResult::Failure`] variant.
pub fn take_error(self) -> Option<error::Error> {
pub fn take_error(self) -> Option<Error> {
match self {
ExecutionResult::Failure { error, .. } => Some(error),
ExecutionResult::Success { .. } => None,
Expand Down Expand Up @@ -288,16 +290,16 @@ impl ExecutionResult {
/// The effects that are produced as part of this process would subract `max_payment_cost` from
/// account's main purse, and add `max_payment_cost` to proposer account's balance.
pub fn new_payment_code_error(
error: error::Error,
error: Error,
max_payment_cost: Motes,
account_main_purse_balance: Motes,
gas_cost: Gas,
account_main_purse_balance_key: Key,
proposer_main_purse_balance_key: Key,
) -> Result<ExecutionResult, error::Error> {
) -> Result<ExecutionResult, Error> {
let new_balance = account_main_purse_balance
.checked_sub(max_payment_cost)
.ok_or(error::Error::InsufficientPayment)?;
.ok_or(Error::InsufficientPayment)?;
let new_balance_value =
StoredValue::CLValue(CLValue::from_t(new_balance.value()).map_err(ExecError::from)?);
let mut effects = Effects::new();
Expand Down Expand Up @@ -328,6 +330,37 @@ impl ExecutionResult {
pub(crate) fn take_without_ret<T: FromBytes + CLTyped>(self) -> (Option<T>, Self) {
(None, self)
}

/// A temporary measure to keep things functioning mid-refactor.
#[allow(clippy::result_unit_err)]
pub fn from_transfer_result(transfer_result: TransferResult, cost: Gas) -> Result<Self, ()> {
match transfer_result {
TransferResult::RootNotFound => {
Err(())
}
// native transfer is auto-commit...but execution results does not currently allow
// for a post state hash to be returned.
TransferResult::Success {
transfers, effects, .. // post_state_hash
} => {
Ok(ExecutionResult::Success {
transfers,
cost,
effects,
messages: Messages::default(),
})
}
TransferResult::Failure(te) => {
Ok(ExecutionResult::Failure {
error: Error::Transfer(te),
transfers: vec![],
cost,
effects: Effects::default(), // currently not returning effects on failure
messages: Messages::default(),
})
}
}
}
}

/// A versioned execution result and the messages produced by that execution.
Expand Down Expand Up @@ -459,7 +492,7 @@ impl ExecutionResultBuilder {
/// Builds a final [`ExecutionResult`] based on session result, payment result and a
/// finalization result.
pub fn build(self) -> Result<ExecutionResult, ExecutionResultBuilderError> {
let mut error: Option<error::Error> = None;
let mut error: Option<Error> = None;
let mut transfers = self.transfers();
let cost = self.total_cost();

Expand Down Expand Up @@ -497,9 +530,7 @@ impl ExecutionResultBuilder {
match self.finalize_execution_result {
Some(ExecutionResult::Failure { .. }) => {
// payment_code_spec_5_a: Finalization Error should only ever be raised here
return Ok(ExecutionResult::precondition_failure(
error::Error::Finalization,
));
return Ok(ExecutionResult::precondition_failure(Error::Finalization));
}
Some(ExecutionResult::Success {
effects, messages, ..
Expand Down
Loading

0 comments on commit 18b4c19

Please sign in to comment.