Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion execution_engine/src/engine_state/engine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub const DEFAULT_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::V2_0_0;
pub const DEFAULT_BALANCE_HOLD_INTERVAL: TimeDiff = TimeDiff::from_seconds(24 * 60 * 60);

/// Default entity flag.
pub const DEFAULT_ENABLE_ENTITY: bool = false;
pub const DEFAULT_ENABLE_ENTITY: bool = true;

pub(crate) const DEFAULT_TRAP_ON_AMBIGUOUS_ENTITY_VERSION: bool = false;

Expand Down
5 changes: 5 additions & 0 deletions execution_engine/src/runtime_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,9 +1301,12 @@ where
}

if self.engine_config.enable_entity {
println!("in ae flow");
// Take an addressable entity out of the global state
let mut entity: AddressableEntity = self.read_gs_typed(&context_key)?;

println!("before {:?}", entity.action_thresholds());

// Exit early in case of error without updating global state
if self.is_authorized_by_admin() {
entity.set_action_threshold_unchecked(action_type, threshold)
Expand All @@ -1312,6 +1315,8 @@ where
}
.map_err(ExecError::from)?;

println!("after {:?}", entity.action_thresholds());

let entity_value = self.addressable_entity_to_validated_value(entity)?;

self.metered_write_gs_unsafe(context_key, entity_value)?;
Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/runtime_context/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn new_tracking_copy(
StoredValue::CLValue(entity_key_cl_value),
),
];
new_temporary_tracking_copy(initial_data, None, true)
new_temporary_tracking_copy(initial_data, None)
}

fn new_addressable_entity_with_purse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl Default for UpgradeRequestBuilder {
validator_minimum_bid_amount: 2_500_000_000_000u64,
maximum_delegation_amount: u64::MAX,
minimum_delegation_amount: 0,
enable_addressable_entity: false,
enable_addressable_entity: true,
rewards_handling: RewardsHandling::Standard,
new_minimum_delegation_rate: None,
}
Expand Down
79 changes: 55 additions & 24 deletions execution_engine_testing/test_support/src/wasm_test_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,26 @@ where
self
}

/// Sets blocktime into global state.
pub fn with_block_time_ae_flag(&mut self, ae_flag: bool) -> &mut Self {
if let Some(state_root_hash) = self.post_state_hash {
let mut tracking_copy = self
.data_access_layer
.tracking_copy(state_root_hash)
.expect("should not error on checkout")
.expect("should checkout tracking copy");

let cl_value = CLValue::from_t(ae_flag).expect("should get cl value");
tracking_copy.write(
Key::BlockGlobal(BlockGlobalAddr::AddressableEntity),
StoredValue::CLValue(cl_value),
);
self.commit_transforms(state_root_hash, tracking_copy.effects());
}

self
}

/// Writes a set of keys and values to global state.
pub fn write_data_and_commit(
&mut self,
Expand Down Expand Up @@ -1642,35 +1662,46 @@ where
.expect("account to exist")
}

/// Retrieve the enable addressable entity flag from gs.
pub fn get_enable_addressable_entity_from_block_global(&self) -> bool {
let key = Key::BlockGlobal(BlockGlobalAddr::AddressableEntity);

self.query(None, key, &[])
.expect("must have stored value")
.as_cl_value()
.expect("must get cl_value")
.to_t()
.expect("must convert to bool")
}

/// Queries for an addressable entity by `AddressableEntityHash`.
pub fn get_addressable_entity(
&self,
entity_hash: AddressableEntityHash,
) -> Option<AddressableEntity> {
if !self.chainspec.core_config.enable_addressable_entity {
let contract_hash = ContractHash::new(entity_hash.value());
return self
.get_contract(contract_hash)
.map(AddressableEntity::from);
}

let entity_key = Key::addressable_entity_key(EntityKindTag::SmartContract, entity_hash);

let value: StoredValue = match self.query(None, entity_key, &[]) {
Ok(stored_value) => stored_value,
Err(_) => self
.query(
None,
Key::addressable_entity_key(EntityKindTag::System, entity_hash),
&[],
)
.ok()?,
};

if let StoredValue::AddressableEntity(entity) = value {
Some(entity)
let enable_addressable_entity = self.get_enable_addressable_entity_from_block_global();
if enable_addressable_entity {
let entity_key = Key::addressable_entity_key(EntityKindTag::SmartContract, entity_hash);

let value: StoredValue = match self.query(None, entity_key, &[]) {
Ok(stored_value) => stored_value,
Err(_) => self
.query(
None,
Key::addressable_entity_key(EntityKindTag::System, entity_hash),
&[],
)
.ok()?,
};

if let StoredValue::AddressableEntity(entity) = value {
Some(entity)
} else {
None
}
} else {
None
self.get_contract(ContractHash::new(entity_hash.value()))
.map(AddressableEntity::from)
}
}

Expand Down Expand Up @@ -1704,7 +1735,7 @@ where

/// Queries for a contract package by `PackageHash`.
pub fn get_package(&self, package_hash: PackageHash) -> Option<Package> {
let key = if self.chainspec.core_config.enable_addressable_entity {
let key = if self.get_enable_addressable_entity_from_block_global() {
Key::SmartContract(package_hash.value())
} else {
Key::Hash(package_hash.value())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@ fn builder_for_calling_entrypoint(
}

fn get_package_hash(builder: &mut LmdbWasmTestBuilder) -> [u8; 32] {
let account = builder.get_account(*DEFAULT_ACCOUNT_ADDR).unwrap();
let account = builder
.get_entity_with_named_keys_by_account_hash(*DEFAULT_ACCOUNT_ADDR)
.unwrap();
let get = account.named_keys().get("package_name");
let package_key = get.unwrap();
let package_hash = match package_key {
Expand All @@ -556,7 +558,7 @@ fn get_contract_hash_for_specific_version(
protocol_version_major: ProtocolVersionMajor,
version: EntityVersion,
) -> Option<HashAddr> {
let maybe_account = builder.get_account(*DEFAULT_ACCOUNT_ADDR);
let maybe_account = builder.get_entity_with_named_keys_by_account_hash(*DEFAULT_ACCOUNT_ADDR);
let account = maybe_account.unwrap();
let get = account.named_keys().get("package_name");
let package_key = get.unwrap();
Expand Down Expand Up @@ -634,7 +636,7 @@ fn upgrade_version(
.with_activation_point(activation_point)
.with_new_gas_hold_handling(HoldBalanceHandling::Accrued)
.with_new_gas_hold_interval(24 * 60 * 60 * 60)
.with_enable_addressable_entity(false)
.with_enable_addressable_entity(true)
.build();
let config = EngineConfigBuilder::new()
.with_trap_on_ambiguous_entity_version(should_trap_on_ambiguous_entity_version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,13 @@ fn should_allow_1x_user_to_add_contract_version_via_transaction_v1_installer_upg
.upgrade(&mut upgrade_request)
.expect_upgrade_success();

let account_as_1x = builder
let account_as_entity = builder
.query(None, Key::Account(*DEFAULT_ACCOUNT_ADDR), &[])
.expect("must have stored value")
.as_account()
.as_cl_value()
.is_some();

assert!(account_as_1x);
// With the one time upgrade, this is no longer a valid assertion
assert!(account_as_entity);
try_add_contract_version(true, true, builder)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use casper_execution_engine::{engine_state::Error as EngineError, execution::Exe
use casper_storage::data_access_layer::GenesisRequest;
use casper_types::{
account::AccountHash, addressable_entity::EntityKindTag, runtime_args, AccessRights,
AddressableEntityHash, ApiError, CLType, CLValue, GenesisAccount, Key, Motes, RuntimeArgs,
StoredValue,
AddressableEntityHash, ApiError, CLType, CLValue, EntityAddr, GenesisAccount, Key, Motes,
RuntimeArgs, StoredValue,
};

use dictionary_call::{NEW_DICTIONARY_ITEM_KEY, NEW_DICTIONARY_VALUE};
Expand Down Expand Up @@ -633,7 +633,7 @@ fn should_query_dictionary_items_with_test_builder() {
// Query through contract's named keys
let queried_value = query_dictionary_item(
&builder,
Key::Hash(entity_hash.value()),
Key::AddressableEntity(EntityAddr::SmartContract(entity_hash.value())),
Some(dictionary::DICTIONARY_NAME.to_string()),
dictionary::DEFAULT_DICTIONARY_NAME.to_string(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const ARG_KNOWN_ADDRESSABLE_ENTITY: &str = "known_addressable_entity";
#[ignore]
#[test]
fn should_run_get_addressable_entity() {
let addressable_entity: bool = false;
let addressable_entity: bool = true;
let addressable_entity_bytes = addressable_entity.to_bytes().expect("should_serialize");
let bytes = casper_types::bytesrepr::Bytes::from(addressable_entity_bytes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ use num_traits::One;

use casper_engine_test_support::{
ExecuteRequest, ExecuteRequestBuilder, LmdbWasmTestBuilder, DEFAULT_ACCOUNT_ADDR,
LOCAL_GENESIS_REQUEST,
};
use casper_execution_engine::{engine_state::Error as CoreError, execution::ExecError};
use casper_execution_engine::{
engine_state::{EngineConfigBuilder, Error as CoreError},
execution::ExecError,
};
use casper_types::{
account::{Account, AccountHash},
contracts::{ContractHash, ContractPackageHash},
runtime_args,
system::{Caller, CallerInfo},
CLValue, EntityAddr, EntryPointType, HashAddr, Key, PackageHash, StoredValue, U512,
CLValue, EntityAddr, EntryPointType, HashAddr, HoldBalanceHandling, Key, PackageHash,
StoredValue, Timestamp, U512,
};

use crate::lmdb_fixture;
use get_call_stack_recursive_subcall::{
Call, ContractAddress, ARG_CALLS, ARG_CURRENT_DEPTH, METHOD_FORWARDER_CONTRACT_NAME,
METHOD_FORWARDER_SESSION_NAME,
Expand Down Expand Up @@ -305,8 +309,16 @@ impl BuilderExt for LmdbWasmTestBuilder {
}

fn setup() -> LmdbWasmTestBuilder {
let mut builder = LmdbWasmTestBuilder::default();
builder.run_genesis(LOCAL_GENESIS_REQUEST.clone());
// let mut builder = LmdbWasmTestBuilder::default();
// builder.run_genesis(LOCAL_GENESIS_REQUEST.clone());
//

let (mut builder, _, _) = lmdb_fixture::builder_from_global_state_fixture("call_stack_fixture");
builder.with_block_time_ae_flag(false);
builder.with_block_time(Timestamp::now().into());
builder.with_gas_hold_config(HoldBalanceHandling::default(), 1200u64);
builder.with_engine_config(EngineConfigBuilder::new().with_enable_entity(false).build());

store_contract(&mut builder, CONTRACT_RECURSIVE_SUBCALL);
builder
}
Expand Down Expand Up @@ -1126,7 +1138,7 @@ mod session {

let effects = builder.get_effects().last().unwrap().clone();

let key = if builder.chainspec().core_config.enable_addressable_entity {
let key = if builder.get_enable_addressable_entity_from_block_global() {
Key::SmartContract(current_contract_package_hash)
} else {
Key::Hash(current_contract_package_hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use casper_engine_test_support::{
};
use casper_types::{
account::AccountHash,
contracts::{ContractHash, ContractPackageHash},
runtime_args,
system::{Caller, CallerInfo},
CLValue, EntityAddr,
CLValue, EntityAddr, PackageHash,
};

const CONTRACT_GET_CALLER: &str = "get_caller.wasm";
Expand Down Expand Up @@ -227,12 +226,12 @@ fn should_load_caller_information_based_on_action() {
.get(LOAD_CALLER_INFO_PACKAGE_HASH)
.expect("must get package key")
.into_hash_addr()
.map(ContractPackageHash::new)
.map(PackageHash::new)
.expect("must get package hash");

let frame = CallerInfo::try_from(Caller::smart_contract(
let frame = CallerInfo::try_from(Caller::entity(
package_hash,
ContractHash::new(caller_info_entity_hash.value()),
EntityAddr::new_smart_contract(caller_info_entity_hash.value()),
))
.expect("must get frame");
let expected_stack = vec![expected_caller, frame];
Expand Down
49 changes: 33 additions & 16 deletions execution_engine_testing/tests/src/test/contract_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,25 @@ fn install_messages_emitter_contract(
.expect_success()
.commit();

let entity = builder
.borrow_mut()
.get_entity_with_named_keys_by_account_hash(*DEFAULT_ACCOUNT_ADDR)
.expect("must have entity");

let package_key = entity
.named_keys()
.get(MESSAGE_EMITTER_PACKAGE_HASH_KEY_NAME)
.expect("must have package key")
.into_hash_addr()
.expect("must have hash addr");

// Get the contract package for the messages_emitter.
let query_result = builder
.borrow_mut()
.query(
None,
Key::from(*DEFAULT_ACCOUNT_ADDR),
&[MESSAGE_EMITTER_PACKAGE_HASH_KEY_NAME.into()],
)
.query(None, Key::SmartContract(package_key), &[])
.expect("should query");

let message_emitter_package = if let StoredValue::ContractPackage(package) = query_result {
let message_emitter_package = if let StoredValue::SmartContract(package) = query_result {
package
} else {
panic!("Stored value is not a contract package: {:?}", query_result);
Expand All @@ -79,9 +87,9 @@ fn install_messages_emitter_contract(
// Get the contract hash of the messages_emitter contract.
message_emitter_package
.versions()
.values()
.iter_entries()
.last()
.map(|contract_hash| AddressableEntityHash::new(contract_hash.value()))
.map(|(_, entity_addr)| AddressableEntityHash::new(entity_addr.value()))
.expect("Should have contract hash")
}

Expand Down Expand Up @@ -123,16 +131,25 @@ fn upgrade_messages_emitter_contract(
}

// Get the contract package for the upgraded messages emitter contract.
let entity = builder
.borrow_mut()
.get_entity_with_named_keys_by_account_hash(*DEFAULT_ACCOUNT_ADDR)
.expect("must have entity");

let package_key = entity
.named_keys()
.get(MESSAGE_EMITTER_PACKAGE_HASH_KEY_NAME)
.expect("must have package key")
.into_hash_addr()
.expect("must have hash addr");

// Get the contract package for the messages_emitter.
let query_result = builder
.borrow_mut()
.query(
None,
Key::from(*DEFAULT_ACCOUNT_ADDR),
&[MESSAGE_EMITTER_PACKAGE_HASH_KEY_NAME.into()],
)
.query(None, Key::SmartContract(package_key), &[])
.expect("should query");

let message_emitter_package = if let StoredValue::ContractPackage(package) = query_result {
let message_emitter_package = if let StoredValue::SmartContract(package) = query_result {
package
} else {
panic!("Stored value is not a contract package: {:?}", query_result);
Expand All @@ -141,9 +158,9 @@ fn upgrade_messages_emitter_contract(
// Get the contract hash of the latest version of the messages emitter contract.
message_emitter_package
.versions()
.values()
.iter_entries()
.last()
.map(|contract_hash| AddressableEntityHash::new(contract_hash.value()))
.map(|(_, addr)| AddressableEntityHash::new(addr.value()))
.expect("Should have contract hash")
}

Expand Down
Loading
Loading