Skip to content

Commit

Permalink
latest merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
EdHastingsCasperAssociation committed Feb 8, 2024
1 parent 35041f7 commit 68d73b2
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 314 deletions.
29 changes: 15 additions & 14 deletions execution_engine/src/engine_state/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,20 +321,21 @@ impl TransferRuntimeArgsBuilder {
where
R: StateReader<Key, StoredValue, Error = GlobalStateError>,
{
let (to, target_uref) =
match self.resolve_transfer_target_mode(protocol_version, Rc::clone(&tracking_copy))? {
NewTransferTargetMode::ExistingAccount {
main_purse: purse_uref,
target_account_hash: target_account,
} => (Some(target_account), purse_uref),
NewTransferTargetMode::PurseExists(purse_uref) => (None, purse_uref),
NewTransferTargetMode::CreateAccount(_) => {
// Method "build()" is called after `resolve_transfer_target_mode` is first called
// and handled by creating a new account. Calling `resolve_transfer_target_mode`
// for the second time should never return `CreateAccount` variant.
return Err(Error::reverter(ApiError::Transfer));
}
};
let (to, target_uref) = match self
.resolve_transfer_target_mode(protocol_version, Rc::clone(&tracking_copy))?
{
NewTransferTargetMode::ExistingAccount {
main_purse: purse_uref,
target_account_hash: target_account,
} => (Some(target_account), purse_uref),
NewTransferTargetMode::PurseExists(purse_uref) => (None, purse_uref),
NewTransferTargetMode::CreateAccount(_) => {
// Method "build()" is called after `resolve_transfer_target_mode` is first called
// and handled by creating a new account. Calling `resolve_transfer_target_mode`
// for the second time should never return `CreateAccount` variant.
return Err(Error::reverter(ApiError::Transfer));
}
};

let source_uref =
self.resolve_source_uref(from, entity_named_keys, Rc::clone(&tracking_copy))?;
Expand Down
5 changes: 2 additions & 3 deletions execution_engine/src/engine_state/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ use casper_types::{
package::{EntityVersions, Groups, PackageStatus},
system::{handle_payment::ACCUMULATION_PURSE_KEY, SystemEntityType},
AccessRights, AddressableEntity, AddressableEntityHash, ByteCode, ByteCodeAddr, ByteCodeHash,
ByteCodeKind, ByteCodeKind, CLValue, CLValueError, Digest, EntityAddr, EntryPoints,
FeeHandling, Key, Package, PackageHash, Phase, ProtocolVersion, PublicKey, StoredValue, URef,
U512,
ByteCodeKind, CLValue, CLValueError, Digest, EntityAddr, EntryPoints, FeeHandling, Key,
Package, PackageHash, Phase, ProtocolVersion, PublicKey, StoredValue, URef, U512,
};

use super::EngineConfig;
Expand Down
100 changes: 0 additions & 100 deletions execution_engine/src/runtime_context/dictionary.rs

This file was deleted.

20 changes: 9 additions & 11 deletions execution_engine/src/runtime_context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! The context of execution of WASM code.
pub(crate) mod dictionary;
#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -31,17 +30,16 @@ use casper_types::{
Message, MessageAddr, MessageChecksum, MessageTopicSummary, Messages, TopicNameHash,
},
execution::Effects,
handle_stored_dictionary_value,
system::auction::EraInfo,
AccessRights, AddressableEntity, AddressableEntityHash, BlockTime, CLType, CLValue,
ContextAccessRights, DeployHash, EntityAddr, EntryPointType, Gas, GrantedAccess, Key, KeyTag,
Package, PackageHash, Phase, ProtocolVersion, PublicKey, RuntimeArgs, StoredValue,
SystemContractRegistry, Transfer, TransferAddr, URef, URefAddr, DICTIONARY_ITEM_KEY_MAX_LENGTH,
KEY_HASH_LENGTH, U512,
CLValueDictionary, ContextAccessRights, DeployHash, EntityAddr, EntryPointType, Gas,
GrantedAccess, Key, KeyTag, Package, PackageHash, Phase, ProtocolVersion, PublicKey,
RuntimeArgs, StoredValue, SystemContractRegistry, Transfer, TransferAddr, URef, URefAddr,
DICTIONARY_ITEM_KEY_MAX_LENGTH, KEY_HASH_LENGTH, U512,
};

use crate::{
engine_state::EngineConfig, execution::Error, runtime_context::dictionary::DictionaryValue,
};
use crate::{engine_state::EngineConfig, execution::Error};

/// Number of bytes returned from the `random_bytes` function.
pub const RANDOM_BYTES_COUNT: usize = 32;
Expand Down Expand Up @@ -456,7 +454,7 @@ where
let maybe_stored_value = self.tracking_copy.borrow_mut().read(key)?;

let stored_value = match maybe_stored_value {
Some(stored_value) => dictionary::handle_stored_value(*key, stored_value)?,
Some(stored_value) => handle_stored_dictionary_value(*key, stored_value)?,
None => return Ok(None),
};

Expand Down Expand Up @@ -1303,7 +1301,7 @@ where
.map_err(Into::<Error>::into)?;

if let Some(stored_value) = maybe_stored_value {
let stored_value = dictionary::handle_stored_value(dictionary_key, stored_value)?;
let stored_value = handle_stored_dictionary_value(dictionary_key, stored_value)?;
let cl_value = CLValue::try_from(stored_value).map_err(Error::TypeMismatch)?;
Ok(Some(cl_value))
} else {
Expand All @@ -1330,7 +1328,7 @@ where
self.validate_cl_value(&cl_value)?;

let wrapped_cl_value = {
let dictionary_value = DictionaryValue::new(
let dictionary_value = CLValueDictionary::new(
cl_value,
seed_uref.addr().to_vec(),
dictionary_item_key_bytes.to_vec(),
Expand Down
28 changes: 14 additions & 14 deletions execution_engine_testing/tests/src/test/system_contracts/upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::BTreeMap;

use casper_execution_engine::engine_state::{EngineConfigBuilder, SystemContractRegistry};
use casper_execution_engine::engine_state::EngineConfigBuilder;
use num_rational::Ratio;

use casper_engine_test_support::{
Expand All @@ -19,19 +19,19 @@ use casper_types::{
mint::ROUND_SEIGNIORAGE_RATE_KEY,
},
BrTableCost, CLValue, ControlFlowCosts, EntityAddr, EraId, HostFunctionCosts, Key,
MessageLimits, OpcodeCosts, ProtocolVersion, StorageCosts, StoredValue, WasmConfig,
DEFAULT_ADD_COST, DEFAULT_BIT_COST, DEFAULT_CONST_COST, DEFAULT_CONTROL_FLOW_BLOCK_OPCODE,
DEFAULT_CONTROL_FLOW_BR_IF_OPCODE, DEFAULT_CONTROL_FLOW_BR_OPCODE,
DEFAULT_CONTROL_FLOW_BR_TABLE_MULTIPLIER, DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE,
DEFAULT_CONTROL_FLOW_CALL_INDIRECT_OPCODE, DEFAULT_CONTROL_FLOW_CALL_OPCODE,
DEFAULT_CONTROL_FLOW_DROP_OPCODE, DEFAULT_CONTROL_FLOW_ELSE_OPCODE,
DEFAULT_CONTROL_FLOW_END_OPCODE, DEFAULT_CONTROL_FLOW_IF_OPCODE,
DEFAULT_CONTROL_FLOW_LOOP_OPCODE, DEFAULT_CONTROL_FLOW_RETURN_OPCODE,
DEFAULT_CONTROL_FLOW_SELECT_OPCODE, DEFAULT_CONVERSION_COST, DEFAULT_CURRENT_MEMORY_COST,
DEFAULT_DIV_COST, DEFAULT_GLOBAL_COST, DEFAULT_GROW_MEMORY_COST,
DEFAULT_INTEGER_COMPARISON_COST, DEFAULT_LOAD_COST, DEFAULT_LOCAL_COST,
DEFAULT_MAX_STACK_HEIGHT, DEFAULT_MUL_COST, DEFAULT_NOP_COST, DEFAULT_STORE_COST,
DEFAULT_UNREACHABLE_COST, DEFAULT_WASM_MAX_MEMORY, U256, U512,
MessageLimits, OpcodeCosts, ProtocolVersion, StorageCosts, StoredValue, SystemContractRegistry,
WasmConfig, DEFAULT_ADD_COST, DEFAULT_BIT_COST, DEFAULT_CONST_COST,
DEFAULT_CONTROL_FLOW_BLOCK_OPCODE, DEFAULT_CONTROL_FLOW_BR_IF_OPCODE,
DEFAULT_CONTROL_FLOW_BR_OPCODE, DEFAULT_CONTROL_FLOW_BR_TABLE_MULTIPLIER,
DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE, DEFAULT_CONTROL_FLOW_CALL_INDIRECT_OPCODE,
DEFAULT_CONTROL_FLOW_CALL_OPCODE, DEFAULT_CONTROL_FLOW_DROP_OPCODE,
DEFAULT_CONTROL_FLOW_ELSE_OPCODE, DEFAULT_CONTROL_FLOW_END_OPCODE,
DEFAULT_CONTROL_FLOW_IF_OPCODE, DEFAULT_CONTROL_FLOW_LOOP_OPCODE,
DEFAULT_CONTROL_FLOW_RETURN_OPCODE, DEFAULT_CONTROL_FLOW_SELECT_OPCODE,
DEFAULT_CONVERSION_COST, DEFAULT_CURRENT_MEMORY_COST, DEFAULT_DIV_COST, DEFAULT_GLOBAL_COST,
DEFAULT_GROW_MEMORY_COST, DEFAULT_INTEGER_COMPARISON_COST, DEFAULT_LOAD_COST,
DEFAULT_LOCAL_COST, DEFAULT_MAX_STACK_HEIGHT, DEFAULT_MUL_COST, DEFAULT_NOP_COST,
DEFAULT_STORE_COST, DEFAULT_UNREACHABLE_COST, DEFAULT_WASM_MAX_MEMORY, U256, U512,
};

const PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::V1_0_0;
Expand Down
4 changes: 0 additions & 4 deletions storage/src/tracking_copy/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use casper_types::{
addressable_entity::{AddKeyFailure, RemoveKeyFailure, SetThresholdFailure, UpdateKeyFailure},
bytesrepr,
execution::TransformError,
package::PackageKind,
system, AccessRights, AddressableEntityHash, ApiError, ByteCodeHash, CLType, CLValueError,
EntityVersionKey, Key, PackageHash, StoredValueTypeMismatch, URef,
};
Expand Down Expand Up @@ -169,9 +168,6 @@ pub enum Error {
/// Invalid key
#[error("Invalid key {0}")]
UnexpectedKeyVariant(Key),
/// Invalid Contract package kind.
#[error("Invalid contract package kind: {0}")]
InvalidPackageKind(PackageKind),
/// Failed to transfer tokens on a private chain.
#[error("Failed to transfer with unrestricted transfers disabled")]
DisabledUnrestrictedTransfers,
Expand Down
22 changes: 11 additions & 11 deletions storage/src/tracking_copy/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use casper_types::{
addressable_entity::{EntityKindTag, MessageTopics, NamedKeyAddr, NamedKeys},
bytesrepr,
package::{EntityVersions, Groups, PackageStatus},
AccessRights, AddressableEntity, AddressableEntityHash, ByteCode, ByteCodeHash, ByteCodeKind,
AccessRights, AddressableEntity, AddressableEntityHash, ByteCode, ByteCodeAddr, ByteCodeHash,
CLValue, ChecksumRegistry, EntityAddr, EntityKind, EntryPoints, Key, KeyTag, Motes, Package,
PackageHash, Phase, ProtocolVersion, StoredValue, StoredValueTypeMismatch,
SystemContractRegistry, URef,
Expand Down Expand Up @@ -288,7 +288,7 @@ where
}

fn get_byte_code(&mut self, byte_code_hash: ByteCodeHash) -> Result<ByteCode, Self::Error> {
let key = Key::ByteCode(ByteCodeKind::V1CasperWasm, byte_code_hash.value());
let key = Key::ByteCode(ByteCodeAddr::V1CasperWasm(byte_code_hash.value()));
match self.get(&key)? {
Some(StoredValue::ByteCode(byte_code)) => Ok(byte_code),
Some(other) => Err(TrackingCopyError::TypeMismatch(
Expand Down Expand Up @@ -333,7 +333,7 @@ where
Key::NamedKey(entry_addr)
};

let cl_value = CLValue::from_t(*key).map_err(execution::Error::CLValue)?;
let cl_value = CLValue::from_t(*key).map_err(TrackingCopyError::CLValue)?;

self.write(entry_key, StoredValue::CLValue(cl_value))
}
Expand All @@ -347,7 +347,7 @@ where
.map_err(Self::Error::BytesRepr)?;

let mut ret: BTreeSet<Key> = BTreeSet::new();
let keys = self.reader.keys_with_prefix(&prefix).map_err(Into::into)?;
let keys = self.reader.keys_with_prefix(&prefix)?;
let pruned = &self.cache.prunes_cached;
// don't include keys marked for pruning
for key in keys {
Expand All @@ -374,29 +374,29 @@ where
let mut named_keys = NamedKeys::new();

for entry_key in ret.iter() {
match self.read(entry_key).map_err(Into::into)? {
match self.read(entry_key)? {
Some(StoredValue::NamedKey(named_key)) => {
let key = named_key.get_key().map_err(execution::Error::CLValue)?;
let name = named_key.get_name().map_err(execution::Error::CLValue)?;
let key = named_key.get_key().map_err(TrackingCopyError::CLValue)?;
let name = named_key.get_name().map_err(TrackingCopyError::CLValue)?;
named_keys.insert(name, key);
}
Some(other) => {
return Err(execution::Error::TypeMismatch(
return Err(TrackingCopyError::TypeMismatch(
StoredValueTypeMismatch::new("CLValue".to_string(), other.type_name()),
))
}
None => match self.cache.reads_cached.get(entry_key) {
Some(StoredValue::NamedKey(named_key_value)) => {
let key = named_key_value
.get_key()
.map_err(execution::Error::CLValue)?;
.map_err(TrackingCopyError::CLValue)?;
let name = named_key_value
.get_name()
.map_err(execution::Error::CLValue)?;
.map_err(TrackingCopyError::CLValue)?;
named_keys.insert(name, key);
}
Some(_) | None => {
return Err(execution::Error::KeyNotFound(*entry_key));
return Err(TrackingCopyError::KeyNotFound(*entry_key));
}
},
};
Expand Down
Loading

0 comments on commit 68d73b2

Please sign in to comment.