Skip to content

Commit

Permalink
Merge branch 'refs/heads/feat-2.0' into delegation-amounts
Browse files Browse the repository at this point in the history
# Conflicts:
#	binary_port/src/error_code.rs
  • Loading branch information
darthsiroftardis committed Jul 22, 2024
2 parents 68feaf0 + 32c973b commit ca7def2
Show file tree
Hide file tree
Showing 72 changed files with 718 additions and 267 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

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
12 changes: 10 additions & 2 deletions binary_port/src/error_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,12 @@ pub enum ErrorCode {
/// Invalid transaction kind
#[error("invalid transaction kind")]
InvalidTransactionInvalidTransactionKind = 84,
/// Gas price tolerance too low
#[error("gas price tolerance too low")]
GasPriceToleranceTooLow = 85,
/// Received V1 Transaction for spec exec.
#[error("received v1 transaction for speculative execution")]
ReceivedV1Transaction = 85,
ReceivedV1Transaction = 86,
}

impl TryFrom<u16> for ErrorCode {
Expand Down Expand Up @@ -366,7 +369,8 @@ impl TryFrom<u16> for ErrorCode {
82 => Ok(ErrorCode::DeployMissingModuleBytes),
83 => Ok(ErrorCode::InvalidTransactionEntryPointCannotBeCall),
84 => Ok(ErrorCode::InvalidTransactionInvalidTransactionKind),
85 => Ok(ErrorCode::ReceivedV1Transaction),
85 => Ok(ErrorCode::GasPriceToleranceTooLow),
86 => Ok(ErrorCode::ReceivedV1Transaction),
_ => Err(UnknownErrorCode),
}
}
Expand Down Expand Up @@ -437,6 +441,7 @@ impl From<InvalidDeploy> for ErrorCode {
InvalidDeploy::UnableToCalculateGasCost => {
ErrorCode::InvalidDeployUnableToCalculateGasCost
}
InvalidDeploy::GasPriceToleranceTooLow { .. } => ErrorCode::GasPriceToleranceTooLow,
_ => ErrorCode::InvalidDeployUnspecified,
}
}
Expand Down Expand Up @@ -501,6 +506,9 @@ impl From<InvalidTransactionV1> for ErrorCode {
InvalidTransactionV1::InvalidTransactionKind(_) => {
ErrorCode::InvalidTransactionInvalidTransactionKind
}
InvalidTransactionV1::GasPriceToleranceTooLow { .. } => {
ErrorCode::GasPriceToleranceTooLow
}
_ => ErrorCode::InvalidTransactionUnspecified,
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn should_run_successful_bond_and_unbond_and_slashing() {
builder.exec(exec_request_5).expect_success().commit();

let unbond_purses: UnbondingPurses = builder.get_unbonds();
assert!(unbond_purses.get(&*DEFAULT_ACCOUNT_ADDR).is_none());
assert!(!unbond_purses.contains_key(&*DEFAULT_ACCOUNT_ADDR));

let bids = builder.get_bids();
assert!(bids.validator_bid(&DEFAULT_ACCOUNT_PUBLIC_KEY).is_none());
Expand Down Expand Up @@ -460,7 +460,7 @@ fn should_run_successful_bond_and_unbond_with_release() {
);

let unbond_purses: UnbondingPurses = builder.get_unbonds();
assert!(unbond_purses.get(&*DEFAULT_ACCOUNT_ADDR).is_none());
assert!(!unbond_purses.contains_key(&*DEFAULT_ACCOUNT_ADDR));

let bids = builder.get_bids();
assert!(!bids.is_empty());
Expand Down Expand Up @@ -650,7 +650,7 @@ fn should_run_successful_unbond_funds_after_changing_unbonding_delay() {
);

let unbond_purses: UnbondingPurses = builder.get_unbonds();
assert!(unbond_purses.get(&*DEFAULT_ACCOUNT_ADDR).is_none());
assert!(!unbond_purses.contains_key(&*DEFAULT_ACCOUNT_ADDR));

let bids = builder.get_bids();
assert!(!bids.is_empty());
Expand Down
60 changes: 27 additions & 33 deletions node/src/cli/arglang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,39 @@ fn parse_stream<I>(tokens: &mut Peekable<I>) -> Result<Value, Error>
where
I: Iterator<Item = Token>,
{
loop {
match tokens.next() {
Some(Token::String(value)) => return Ok(Value::String(value)),
Some(Token::I64(value)) => return Ok(Value::Integer(value)),
Some(Token::Boolean(value)) => return Ok(Value::Boolean(value)),
Some(Token::OpenBracket) => {
// Special case for empty list.
if tokens.peek() == Some(&Token::CloseBracket) {
tokens.next();
return Ok(Value::Array(Vec::new()));
}
match tokens.next() {
Some(Token::String(value)) => Ok(Value::String(value)),
Some(Token::I64(value)) => Ok(Value::Integer(value)),
Some(Token::Boolean(value)) => Ok(Value::Boolean(value)),
Some(Token::OpenBracket) => {
// Special case for empty list.
if tokens.peek() == Some(&Token::CloseBracket) {
tokens.next();
return Ok(Value::Array(Vec::new()));
}

let mut items = Vec::new();
loop {
items.push(parse_stream(tokens)?);
let mut items = Vec::new();
loop {
items.push(parse_stream(tokens)?);

match tokens.next() {
Some(Token::CloseBracket) => {
return Ok(Value::Array(items));
}
Some(Token::Comma) => {
// Continue parsing next time.
}
Some(t) => {
return Err(Error::UnexpectedToken(t));
}
None => {
return Err(Error::UnexpectedEndOfInput);
}
match tokens.next() {
Some(Token::CloseBracket) => {
return Ok(Value::Array(items));
}
Some(Token::Comma) => {
// Continue parsing next time.
}
Some(t) => {
return Err(Error::UnexpectedToken(t));
}
None => {
return Err(Error::UnexpectedEndOfInput);
}
}
}
Some(t @ Token::CloseBracket) | Some(t @ Token::Comma) => {
return Err(Error::UnexpectedToken(t));
}
None => {
return Err(Error::UnexpectedEndOfInput);
}
}
Some(t @ Token::CloseBracket) | Some(t @ Token::Comma) => Err(Error::UnexpectedToken(t)),
None => Err(Error::UnexpectedEndOfInput),
}
}

Expand Down
4 changes: 0 additions & 4 deletions node/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ pub(crate) trait InitializedComponent<REv>: Component<REv> {
self.state() == &ComponentState::Uninitialized
}

fn is_initialized(&self) -> bool {
self.state() == &ComponentState::Initialized
}

fn is_fatal(&self) -> bool {
matches!(self.state(), ComponentState::Fatal(_))
}
Expand Down
2 changes: 1 addition & 1 deletion node/src/components/block_accumulator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ async fn block_accumulator_doesnt_purge_with_delayed_block_execution() {
// block can be delayed. Since we would purge an acceptor if the purge interval has passed,
// we want to simulate a situation in which the purge interval was exceeded in order to test
// the special case that if an acceptor that had sufficient finality, it is not purged.
tokio::time::sleep(
time::sleep(
Duration::from(runner.reactor().block_accumulator.purge_interval) + Duration::from_secs(1),
)
.await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) enum Error {
}

impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Error::BlockHashMismatch { expected, actual } => {
write!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) enum Event {
result: PutTrieResult,
},
#[from]
TrieAccumulatorEvent(TrieAccumulatorEvent),
TrieAccumulator(TrieAccumulatorEvent),
}

#[derive(Debug, DataSize)]
Expand Down Expand Up @@ -651,8 +651,8 @@ where
raw: trie_raw,
result: put_trie_result,
} => self.handle_put_trie_result(trie_raw.hash(), put_trie_result, effect_builder),
Event::TrieAccumulatorEvent(event) => reactor::wrap_effects(
Event::TrieAccumulatorEvent,
Event::TrieAccumulator(event) => reactor::wrap_effects(
Event::TrieAccumulator,
self.trie_accumulator
.handle_event(effect_builder, rng, event),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mod tests {
);

// Signature for the validator #0 weighting 1:
let (public_0, secret_0) = validators.get(0).unwrap();
let (public_0, secret_0) = validators.first().unwrap();
let finality_signature = FinalitySignatureV2::create(
block_hash,
block_height,
Expand Down Expand Up @@ -427,7 +427,7 @@ mod tests {
);

// Set the validator #0 weighting 1 as pending:
let (public_0, secret_0) = validators.get(0).unwrap();
let (public_0, secret_0) = validators.first().unwrap();
signature_acquisition.register_pending(public_0.clone());
assert_iter_equal!(signature_acquisition.have_signatures(), []);
assert_iter_equal!(signature_acquisition.not_vacant(), [public_0]);
Expand Down
Loading

0 comments on commit ca7def2

Please sign in to comment.