Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chainspec setting to enable Addressable Entity #4897

Open
wants to merge 37 commits into
base: feat-2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
da8387d
Rework runtime footprint
darthsiroftardis Sep 19, 2024
093edf7
Prep for tests
darthsiroftardis Sep 20, 2024
276ffdc
Fix named keys for non entity genesis
darthsiroftardis Sep 20, 2024
2fcb339
Wasmless transfer works
darthsiroftardis Sep 23, 2024
26d97ea
EE tests 489 passed; 108 failed;
darthsiroftardis Sep 23, 2024
e9f279c
Continue EE test grind
darthsiroftardis Sep 23, 2024
c813d28
Continue EE test grind pt.2
darthsiroftardis Sep 23, 2024
cfb9a0a
Fix create groups
darthsiroftardis Sep 23, 2024
09de507
Fix several more EE tests
darthsiroftardis Sep 23, 2024
8527779
Fix several more EE tests
darthsiroftardis Sep 24, 2024
e679e08
Fix several more EE tests
darthsiroftardis Sep 24, 2024
a6b711e
Run make lint
darthsiroftardis Sep 24, 2024
3b45a47
Remove print statements
darthsiroftardis Sep 24, 2024
36949a7
Address lint and fmt
darthsiroftardis Sep 24, 2024
628059a
Fix transaction reactor tests
darthsiroftardis Sep 24, 2024
88ebd0a
Bump timeout for out_of_gas_txn_does_not_produce_effects
darthsiroftardis Sep 24, 2024
5254a75
Fix key test in types
darthsiroftardis Sep 24, 2024
edcd610
Fix sample in esponse_type::tests::convert_u8_roundtrip
darthsiroftardis Sep 25, 2024
9882d67
Apply message topics changes
darthsiroftardis Sep 30, 2024
fb9c4d4
Fix sample in esponse_type::tests::convert_u8_roundtrip
darthsiroftardis Sep 30, 2024
6a44fa3
Extend contract FFI for message support
darthsiroftardis Sep 30, 2024
c9c4c34
Have contract message tests passing
darthsiroftardis Sep 30, 2024
0f7d5a6
Address lints
darthsiroftardis Sep 30, 2024
ddc7d2e
Run make format
darthsiroftardis Sep 30, 2024
f37343d
Remove system account write from genesis
darthsiroftardis Oct 2, 2024
302c52c
Apply patch from Ed
darthsiroftardis Oct 2, 2024
eddea73
Remove unused system_account_setup
darthsiroftardis Oct 2, 2024
3e4567f
Address lint issues
darthsiroftardis Oct 2, 2024
913b1e5
Address CI issues
darthsiroftardis Oct 2, 2024
8010dfe
Amend faucet costs
darthsiroftardis Oct 2, 2024
846c503
Initial wireup for caller info
darthsiroftardis Oct 15, 2024
3ac8e35
Fix bytesrepr issue in tests
darthsiroftardis Oct 15, 2024
e1b7d75
Fix get call stack tests
darthsiroftardis Oct 16, 2024
7e36144
Merge remote-tracking branch 'refs/remotes/upstream/feat-2.0' into en…
darthsiroftardis Oct 17, 2024
81cf707
Address merge spillover
darthsiroftardis Oct 17, 2024
d4341bf
Run make format
darthsiroftardis Oct 17, 2024
854c8b7
Fix faucet costs
darthsiroftardis Oct 17, 2024
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
12 changes: 6 additions & 6 deletions binary_port/src/key_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use casper_types::{
bytesrepr::{self, FromBytes, ToBytes, U8_SERIALIZED_LENGTH},
contract_messages::TopicNameHash,
system::{auction::BidAddrTag, mint::BalanceHoldAddrTag},
EntityAddr, KeyTag, URefAddr,
EntityAddr, HashAddr, KeyTag, URefAddr,
};
#[cfg(any(feature = "testing", test))]
use rand::Rng;
Expand All @@ -16,9 +16,9 @@ pub enum KeyPrefix {
/// Retrieves all delegator bid addresses for a given validator.
DelegatorBidAddrsByValidator(AccountHash),
/// Retrieves all messages for a given entity.
MessagesByEntity(EntityAddr),
MessagesByEntity(HashAddr),
/// Retrieves all messages for a given entity and topic.
MessagesByEntityAndTopic(EntityAddr, TopicNameHash),
MessagesByEntityAndTopic(HashAddr, TopicNameHash),
/// Retrieves all named keys for a given entity.
NamedKeysByEntity(EntityAddr),
/// Retrieves all gas balance holds for a given purse.
Expand Down Expand Up @@ -145,13 +145,13 @@ impl FromBytes for KeyPrefix {
}
}
tag if tag == KeyTag::Message as u8 => {
let (entity, remainder) = EntityAddr::from_bytes(remainder)?;
let (hash_addr, remainder) = HashAddr::from_bytes(remainder)?;
if remainder.is_empty() {
(KeyPrefix::MessagesByEntity(entity), remainder)
(KeyPrefix::MessagesByEntity(hash_addr), remainder)
} else {
let (topic, remainder) = TopicNameHash::from_bytes(remainder)?;
(
KeyPrefix::MessagesByEntityAndTopic(entity, topic),
KeyPrefix::MessagesByEntityAndTopic(hash_addr, topic),
remainder,
)
}
Expand Down
2 changes: 1 addition & 1 deletion binary_port/src/response_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl ResponseType {

#[cfg(test)]
pub(crate) fn random(rng: &mut TestRng) -> Self {
Self::try_from(rng.gen_range(0..45)).unwrap()
Self::try_from(rng.gen_range(0..44)).unwrap()
}
}

Expand Down
14 changes: 14 additions & 0 deletions execution_engine/src/engine_state/engine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ pub const DEFAULT_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::V2_0_0;
/// Default period for balance holds to decay (currently 24 hours).
pub const DEFAULT_BALANCE_HOLD_INTERVAL: TimeDiff = TimeDiff::from_seconds(24 * 60 * 60);

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

/// The runtime configuration of the execution engine
#[derive(Debug, Clone)]
pub struct EngineConfig {
Expand Down Expand Up @@ -84,6 +87,7 @@ pub struct EngineConfig {
pub(crate) fee_handling: FeeHandling,
/// Compute auction rewards.
pub(crate) compute_rewards: bool,
pub(crate) enable_entity: bool,
}

impl Default for EngineConfig {
Expand All @@ -105,6 +109,7 @@ impl Default for EngineConfig {
fee_handling: DEFAULT_FEE_HANDLING,
compute_rewards: DEFAULT_COMPUTE_REWARDS,
protocol_version: DEFAULT_PROTOCOL_VERSION,
enable_entity: DEFAULT_ENABLE_ENTITY,
}
}
}
Expand Down Expand Up @@ -235,6 +240,7 @@ pub struct EngineConfigBuilder {
fee_handling: Option<FeeHandling>,
compute_rewards: Option<bool>,
balance_hold_interval: Option<TimeDiff>,
enable_entity: Option<bool>,
}

impl EngineConfigBuilder {
Expand Down Expand Up @@ -376,6 +382,12 @@ impl EngineConfigBuilder {
self
}

/// Sets the enable entity flag.
pub fn with_enable_entity(mut self, enable_entity: bool) -> Self {
self.enable_entity = Some(enable_entity);
self
}

/// Builds a new [`EngineConfig`] object.
pub fn build(self) -> EngineConfig {
let max_associated_keys = self
Expand Down Expand Up @@ -419,6 +431,7 @@ impl EngineConfigBuilder {
.max_delegators_per_validator
.unwrap_or(DEFAULT_MAX_DELEGATORS_PER_VALIDATOR);
let compute_rewards = self.compute_rewards.unwrap_or(DEFAULT_COMPUTE_REWARDS);
let enable_entity = self.enable_entity.unwrap_or(DEFAULT_ENABLE_ENTITY);

EngineConfig {
max_associated_keys,
Expand All @@ -437,6 +450,7 @@ impl EngineConfigBuilder {
vesting_schedule_period_millis,
max_delegators_per_validator,
compute_rewards,
enable_entity,
}
}
}
4 changes: 2 additions & 2 deletions execution_engine/src/engine_state/execution_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> ExecutionKind<'a> {
}
TransactionInvocationTarget::ByPackageHash { addr, version } => {
let package_hash = PackageHash::from(*addr);
let package = tracking_copy.get_package(package_hash)?;
let package = tracking_copy.get_package(*addr)?;

let maybe_version_key =
version.map(|ver| EntityVersionKey::new(protocol_version.value().major, ver));
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<'a> ExecutionKind<'a> {
_ => return Err(Error::InvalidKeyVariant(*package_key)),
};

let package = tracking_copy.get_package(package_hash)?;
let package = tracking_copy.get_package(package_hash.value())?;

let maybe_version_key =
version.map(|ver| EntityVersionKey::new(protocol_version.value().major, ver));
Expand Down
22 changes: 7 additions & 15 deletions execution_engine/src/engine_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use once_cell::sync::Lazy;

use casper_storage::{
global_state::state::StateProvider,
tracking_copy::{TrackingCopyEntityExt, TrackingCopyError, TrackingCopyExt},
tracking_copy::{TrackingCopyEntityExt, TrackingCopyError},
};
use casper_types::U512;

Expand Down Expand Up @@ -93,7 +93,7 @@ impl ExecutionEngineV1 {
)
}
};
let (entity, entity_hash) = {
let (runtime_footprint, entity_addr) = {
match tc.borrow_mut().get_authorized_addressable_entity(
protocol_version,
account_hash,
Expand All @@ -106,16 +106,7 @@ impl ExecutionEngineV1 {
}
}
};
let mut named_keys = match tc
.borrow_mut()
.get_named_keys(entity.entity_addr(entity_hash))
.map_err(Into::into)
{
Ok(named_keys) => named_keys,
Err(tce) => {
return WasmV1Result::precondition_failure(gas_limit, Error::TrackingCopy(tce))
}
};
let mut named_keys = runtime_footprint.named_keys().clone();
let execution_kind = match ExecutionKind::new(
&mut *tc.borrow_mut(),
&named_keys,
Expand All @@ -126,12 +117,13 @@ impl ExecutionEngineV1 {
Ok(execution_kind) => execution_kind,
Err(ese) => return WasmV1Result::precondition_failure(gas_limit, ese),
};
let access_rights = entity.extract_access_rights(entity_hash, &named_keys);
let access_rights =
runtime_footprint.extract_access_rights(entity_addr.value(), &named_keys);
Executor::new(self.config().clone()).exec(
execution_kind,
args,
entity_hash,
&entity,
entity_addr,
&runtime_footprint,
&mut named_keys,
access_rights,
authorization_keys,
Expand Down
22 changes: 14 additions & 8 deletions execution_engine/src/execution/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use casper_storage::{
};
use casper_types::{
account::AccountHash, addressable_entity::NamedKeys, contract_messages::Messages,
execution::Effects, AddressableEntity, AddressableEntityHash, ContextAccessRights,
EntryPointType, Gas, Key, Phase, ProtocolVersion, RuntimeArgs, StoredValue, Tagged,
TransactionHash, U512,
execution::Effects, ContextAccessRights, EntityAddr, EntryPointType, Gas, Key, Phase,
ProtocolVersion, RuntimeArgs, RuntimeFootprint, StoredValue, TransactionHash, U512,
};

use crate::{
Expand Down Expand Up @@ -47,8 +46,8 @@ impl Executor {
&self,
execution_kind: ExecutionKind,
args: RuntimeArgs,
entity_hash: AddressableEntityHash,
entity: &AddressableEntity,
entity_addr: EntityAddr,
entity: &RuntimeFootprint,
named_keys: &mut NamedKeys,
access_rights: ContextAccessRights,
authorization_keys: BTreeSet<AccountHash>,
Expand Down Expand Up @@ -83,7 +82,14 @@ impl Executor {
Rc::new(RefCell::new(generator))
};

let entity_key = Key::addressable_entity_key(entity.kind().tag(), entity_hash);
let entity_key = if self.config.enable_entity {
Key::AddressableEntity(entity_addr)
} else {
match entity_addr {
EntityAddr::System(hash) | EntityAddr::SmartContract(hash) => Key::Hash(hash),
EntityAddr::Account(hash) => Key::Account(AccountHash::new(hash)),
}
};

let calling_add_contract_version = match execution_kind {
ExecutionKind::InstallerUpgrader(_)
Expand Down Expand Up @@ -156,7 +162,7 @@ impl Executor {
fn create_runtime_context<'a, R>(
&self,
named_keys: &'a mut NamedKeys,
entity: &'a AddressableEntity,
runtime_footprint: &'a RuntimeFootprint,
entity_key: Key,
authorization_keys: BTreeSet<AccountHash>,
access_rights: ContextAccessRights,
Expand All @@ -181,7 +187,7 @@ impl Executor {

RuntimeContext::new(
named_keys,
entity,
runtime_footprint,
entity_key,
authorization_keys,
access_rights,
Expand Down
1 change: 1 addition & 0 deletions execution_engine/src/resolvers/v1_function_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) enum FunctionIndex {
ReadHostBufferIndex,
CreateContractPackageAtHash,
AddContractVersion,
AddContractVersionWithMessageTopics,
AddPackageVersion,
DisableContractVersion,
CallVersionedContract,
Expand Down
4 changes: 4 additions & 0 deletions execution_engine/src/resolvers/v1_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl ModuleImportResolver for RuntimeModuleImportResolver {
Signature::new(&[ValueType::I32; 10][..], Some(ValueType::I32)),
FunctionIndex::AddContractVersion.into(),
),
"casper_add_contract_version_with_message_topics" => FuncInstance::alloc_host(
Signature::new(&[ValueType::I32; 11][..], Some(ValueType::I32)),
FunctionIndex::AddContractVersionWithMessageTopics.into(),
),
"casper_add_package_version" => FuncInstance::alloc_host(
Signature::new(&[ValueType::I32; 11][..], Some(ValueType::I32)),
FunctionIndex::AddPackageVersion.into(),
Expand Down
25 changes: 23 additions & 2 deletions execution_engine/src/runtime/auction_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ where
})?;

let contract_key: Key = match maybe_value {
Some(StoredValue::Account(account)) => {
self.mint_transfer_direct(
Some(account_hash),
*unbonding_purse.bonding_purse(),
account.main_purse(),
*unbonding_purse.amount(),
None,
)
.map_err(|_| Error::Transfer)?
.map_err(|_| Error::Transfer)?;
return Ok(());
}
Some(StoredValue::CLValue(cl_value)) => {
let contract_key: Key = cl_value.into_t().map_err(|_| Error::CLValue)?;
contract_key
Expand Down Expand Up @@ -265,7 +277,13 @@ where
amount: U512,
id: Option<u64>,
) -> Result<Result<(), mint::Error>, Error> {
if !(self.context.entity().main_purse().addr() == source.addr()
if !(self
.context
.runtime_footprint()
.main_purse()
.expect("didnt have purse")
.addr()
== source.addr()
|| self.context.get_caller() == PublicKey::System.to_account_hash())
{
return Err(Error::InvalidCaller);
Expand Down Expand Up @@ -377,7 +395,10 @@ where
fn get_main_purse(&self) -> Result<URef, Error> {
// NOTE: this is used by the system and is not (and should not be made to be) accessible
// from userland.
Ok(Runtime::context(self).entity().main_purse())
Runtime::context(self)
.runtime_footprint()
.main_purse()
.ok_or(Error::InvalidContext)
}
}

Expand Down
85 changes: 85 additions & 0 deletions execution_engine/src/runtime/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,91 @@ where
)?;
Ok(Some(RuntimeValue::I32(api_error::i32_from(ret))))
}
FunctionIndex::AddContractVersionWithMessageTopics => {
// args(0) = pointer to package hash in wasm memory
// args(1) = size of package hash in wasm memory
// args(2) = pointer to entity version in wasm memory
// args(3) = pointer to entrypoints in wasm memory
// args(4) = size of entrypoints in wasm memory
// args(5) = pointer to named keys in wasm memory
// args(6) = size of named keys in wasm memory
// args(7) = pointer to the new topic names in wasm memory
// args(8) = size of the new topic names in wasm memory
// args(9) = pointer to output buffer for serialized key
// args(10) = size of output buffer
let (
contract_package_hash_ptr,
contract_package_hash_size,
version_ptr,
entry_points_ptr,
entry_points_size,
named_keys_ptr,
named_keys_size,
message_topics_ptr,
message_topics_size,
output_ptr,
output_size,
) = Args::parse(args)?;
self.charge_host_function_call(
&host_function_costs.add_package_version,
[
contract_package_hash_ptr,
contract_package_hash_size,
version_ptr,
entry_points_ptr,
entry_points_size,
named_keys_ptr,
named_keys_size,
message_topics_ptr,
message_topics_size,
output_ptr,
output_size,
],
)?;

// Exit if unable to return output.
if output_size < 32 {
// `output_size` must be >= actual length of serialized hash bytes
return Ok(Some(RuntimeValue::I32(api_error::i32_from(Err(
ApiError::BufferTooSmall,
)))));
}

let package_hash: PackageHash =
self.t_from_mem(contract_package_hash_ptr, contract_package_hash_size)?;
let entry_points: EntryPoints =
self.t_from_mem(entry_points_ptr, entry_points_size)?;
let named_keys: NamedKeys = self.t_from_mem(named_keys_ptr, named_keys_size)?;
let message_topics: BTreeMap<String, MessageTopicOperation> =
self.t_from_mem(message_topics_ptr, message_topics_size)?;

// Check that the names of the topics that are added are within the configured
// limits.
let message_limits = self.context.engine_config().wasm_config().messages_limits();
for (topic_name, _) in
message_topics
.iter()
.filter(|(_, operation)| match operation {
MessageTopicOperation::Add => true,
})
{
if topic_name.len() > message_limits.max_topic_name_size() as usize {
return Ok(Some(RuntimeValue::I32(api_error::i32_from(Err(
ApiError::MaxTopicNameSizeExceeded,
)))));
}
}

let ret = self.add_contract_version(
package_hash,
version_ptr,
entry_points,
named_keys,
message_topics,
output_ptr,
)?;
Ok(Some(RuntimeValue::I32(api_error::i32_from(ret))))
}

FunctionIndex::AddPackageVersion => {
// args(0) = pointer to package hash in wasm memory
Expand Down
Loading
Loading