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

Contract level messages #4370

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c8199a7
casper-types: add a new `Key` variant for contract level messages
Sep 22, 2023
10b2388
Merge pull request #4304 from alsrdn/contract-level-events
sacherjj Sep 25, 2023
0263a79
ee: add support for emitting contract level messages
Sep 28, 2023
94f14da
ee: prune old contract messages from GS with every new execution in a…
Oct 4, 2023
5a1f0ec
ee: add message topics to the addressable entity record
Oct 5, 2023
24fe54d
tests/contract_messages: fix lint errors
Oct 5, 2023
27af40b
ee/contract_messages: fix JSON schema for topic name hash
Oct 6, 2023
0d4571b
ee/contract_messages: add topic name hash to the message sent out on …
Oct 6, 2023
c8214ec
types/execution_results: fix lint issue
Oct 6, 2023
1252643
ee/contract_messages: minor cleanups
Oct 6, 2023
566b353
ee/contract_level_messages: address CR comments
Oct 9, 2023
3190647
ee/contract_messages: fix further CR comments
Oct 10, 2023
3b90c2f
Merge pull request #4315 from alsrdn/contract-level-events-alt
bradjohnl Oct 10, 2023
30acebb
ee/contract_messages: add more tests
Oct 10, 2023
a956dc3
types/chainspec: fix `WasmConfig` serialization for message limits
Oct 10, 2023
ee87c9d
types/key: fix `key_max_serialized_length` test
Oct 10, 2023
f6cd4a4
types/key: fix display test for `Key::Message` variants
Oct 10, 2023
8a706e8
types/contract_messages: fix `MessageAddr` from string parsing
Oct 11, 2023
c405dbf
types: fix lint errors caused by the import of `Key` for contract mes…
Oct 11, 2023
f1bf8d3
ee/contract_messages: increase gas cost for each emitted message
Oct 13, 2023
5673e3e
ee/tests: adjust expected costs for faucet host fn metrics
Oct 16, 2023
6df9553
casper-validation: fix fixture for `AddressableEntity`
Oct 16, 2023
c77dfd0
ee/contract_messages: return error if topic is full
Oct 16, 2023
ffe7e18
ee/contract_messages: fix CR comments
Oct 17, 2023
68cfc48
types/contract_messages: add getters for `Message` fields
Oct 18, 2023
8171806
ee/contract_messages: always charge for emit_message
Oct 18, 2023
d05a946
Merge pull request #4344 from alsrdn/contract-level-events-alt
sacherjj Oct 19, 2023
3b13cd3
Merge branch 'feat-2.0' into feat-contract-level-events
Oct 20, 2023
ca7e41e
contract_messages: don't store contract messages with exec results
Oct 20, 2023
9880642
Merge branch 'feat-2.0' into contract-level-events-merge
Oct 25, 2023
97bcc54
Merge branch 'feat-2.0' into contract-level-events-merge
Oct 30, 2023
8da9ebc
types/contract_messages: serialize message checksum to string
Oct 30, 2023
53483e1
contract_messages: address CR comments
Nov 3, 2023
dbc56fe
Merge branch 'feat-2.0' into contract-level-events-merge
Nov 3, 2023
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
25 changes: 25 additions & 0 deletions Cargo.lock

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

89 changes: 73 additions & 16 deletions execution_engine/src/engine_state/execution_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::VecDeque;

use casper_types::{
bytesrepr::FromBytes,
contract_messages::Messages,
execution::{Effects, ExecutionResultV2 as TypesExecutionResult, Transform, TransformKind},
CLTyped, CLValue, Gas, Key, Motes, StoredValue, TransferAddr,
};
Expand All @@ -25,6 +26,8 @@ pub enum ExecutionResult {
cost: Gas,
/// Execution effects.
effects: Effects,
/// Messages emitted during execution.
messages: Messages,
},
/// Execution was finished successfully
Success {
Expand All @@ -34,6 +37,8 @@ pub enum ExecutionResult {
cost: Gas,
/// Execution effects.
effects: Effects,
/// Messages emitted during execution.
messages: Messages,
},
}

Expand All @@ -60,6 +65,7 @@ impl ExecutionResult {
transfers: Vec::default(),
cost: Gas::default(),
effects: Effects::new(),
messages: Vec::default(),
}
}

Expand Down Expand Up @@ -127,19 +133,25 @@ impl ExecutionResult {
error,
transfers,
effects,
messages,
..
} => ExecutionResult::Failure {
error,
transfers,
cost,
effects,
messages,
},
ExecutionResult::Success {
transfers, effects, ..
transfers,
effects,
messages,
..
} => ExecutionResult::Success {
transfers,
cost,
effects,
messages,
},
}
}
Expand All @@ -154,17 +166,25 @@ impl ExecutionResult {
error,
cost,
effects,
messages,
..
} => ExecutionResult::Failure {
error,
transfers,
cost,
effects,
messages,
},
ExecutionResult::Success { cost, effects, .. } => ExecutionResult::Success {
ExecutionResult::Success {
cost,
effects,
messages,
..
} => ExecutionResult::Success {
transfers,
cost,
effects,
messages,
},
}
}
Expand All @@ -180,20 +200,24 @@ impl ExecutionResult {
transfers,
cost,
effects: _,
messages,
} => ExecutionResult::Failure {
error,
transfers,
cost,
effects,
messages,
},
ExecutionResult::Success {
transfers,
cost,
effects: _,
messages,
} => ExecutionResult::Success {
transfers,
cost,
effects,
messages,
},
}
}
Expand Down Expand Up @@ -291,6 +315,7 @@ impl ExecutionResult {
effects,
transfers,
cost: gas_cost,
messages: Vec::default(),
})
}

Expand All @@ -305,28 +330,44 @@ impl ExecutionResult {
}
}

impl From<ExecutionResult> for TypesExecutionResult {
/// A versioned execution result and the messages produced by that execution.
pub struct ExecutionResultAndMessages {
/// Execution result
pub execution_result: TypesExecutionResult,
/// Messages emitted during execution
pub messages: Messages,
}

impl From<ExecutionResult> for ExecutionResultAndMessages {
fn from(execution_result: ExecutionResult) -> Self {
match execution_result {
ExecutionResult::Success {
transfers,
cost,
effects,
} => TypesExecutionResult::Success {
effects,
transfers,
cost: cost.value(),
messages,
} => ExecutionResultAndMessages {
execution_result: TypesExecutionResult::Success {
effects,
transfers,
cost: cost.value(),
},
messages,
},
ExecutionResult::Failure {
error,
transfers,
cost,
effects,
} => TypesExecutionResult::Failure {
effects,
transfers,
cost: cost.value(),
error_message: error.to_string(),
messages,
} => ExecutionResultAndMessages {
execution_result: TypesExecutionResult::Failure {
effects,
transfers,
cost: cost.value(),
error_message: error.to_string(),
},
messages,
},
}
}
Expand Down Expand Up @@ -422,9 +463,11 @@ impl ExecutionResultBuilder {
let mut transfers = self.transfers();
let cost = self.total_cost();

let mut all_effects = match self.payment_execution_result {
let (mut all_effects, mut all_messages) = match self.payment_execution_result {
Some(result @ ExecutionResult::Failure { .. }) => return Ok(result),
Some(ExecutionResult::Success { effects, .. }) => effects,
Some(ExecutionResult::Success {
effects, messages, ..
}) => (effects, messages),
None => return Err(ExecutionResultBuilderError::MissingPaymentExecutionResult),
};

Expand All @@ -436,11 +479,18 @@ impl ExecutionResultBuilder {
transfers: session_transfers,
effects: _,
cost: _,
messages,
}) => {
error = Some(session_error);
transfers = session_transfers;
all_messages.extend(messages);
}
Some(ExecutionResult::Success {
effects, messages, ..
}) => {
all_effects.append(effects);
all_messages.extend(messages);
}
Some(ExecutionResult::Success { effects, .. }) => all_effects.append(effects),
None => return Err(ExecutionResultBuilderError::MissingSessionExecutionResult),
};

Expand All @@ -451,7 +501,12 @@ impl ExecutionResultBuilder {
error::Error::Finalization,
));
}
Some(ExecutionResult::Success { effects, .. }) => all_effects.append(effects),
Some(ExecutionResult::Success {
effects, messages, ..
}) => {
all_effects.append(effects);
all_messages.extend(messages);
}
None => return Err(ExecutionResultBuilderError::MissingFinalizeExecutionResult),
}

Expand All @@ -460,12 +515,14 @@ impl ExecutionResultBuilder {
transfers,
cost,
effects: all_effects,
messages: all_messages,
}),
Some(error) => Ok(ExecutionResult::Failure {
error,
transfers,
cost,
effects: all_effects,
messages: all_messages,
}),
}
}
Expand Down
3 changes: 2 additions & 1 deletion execution_engine/src/engine_state/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};

use casper_storage::global_state::state::StateProvider;
use casper_types::{
addressable_entity::{ActionThresholds, NamedKeys},
addressable_entity::{ActionThresholds, MessageTopics, NamedKeys},
execution::Effects,
package::{EntityVersions, Groups, PackageKind, PackageStatus},
system::{
Expand Down Expand Up @@ -1152,6 +1152,7 @@ where
main_purse,
associated_keys,
ActionThresholds::default(),
MessageTopics::default(),
);

let access_key = self
Expand Down
11 changes: 9 additions & 2 deletions execution_engine/src/engine_state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use casper_storage::{

use casper_types::{
account::{Account, AccountHash},
addressable_entity::{AssociatedKeys, NamedKeys},
addressable_entity::{AssociatedKeys, MessageTopics, NamedKeys},
bytesrepr::ToBytes,
execution::Effects,
package::{EntityVersions, Groups, PackageKind, PackageKindTag, PackageStatus},
Expand Down Expand Up @@ -822,6 +822,7 @@ where
account.main_purse(),
associated_keys,
account.action_thresholds().clone().into(),
MessageTopics::default(),
);

let access_key = generator.new_uref(AccessRights::READ_ADD_WRITE);
Expand Down Expand Up @@ -2630,11 +2631,13 @@ fn log_execution_result(preamble: &'static str, result: &ExecutionResult) {
transfers,
cost,
effects,
messages,
} => {
debug!(
%cost,
transfer_count = %transfers.len(),
transforms_count = %effects.len(),
messages_count = %messages.len(),
"{}: execution success",
preamble
);
Expand All @@ -2644,12 +2647,14 @@ fn log_execution_result(preamble: &'static str, result: &ExecutionResult) {
transfers,
cost,
effects,
messages,
} => {
debug!(
%error,
%cost,
transfer_count = %transfers.len(),
transforms_count = %effects.len(),
messages_count = %messages.len(),
"{}: execution failure",
preamble
);
Expand All @@ -2664,6 +2669,7 @@ fn should_charge_for_errors_in_wasm(execution_result: &ExecutionResult) -> bool
transfers: _,
cost: _,
effects: _,
messages: _,
} => match error {
Error::Exec(err) => match err {
ExecError::WasmPreprocessing(_) | ExecError::UnsupportedWasmStart => true,
Expand Down Expand Up @@ -2718,7 +2724,8 @@ fn should_charge_for_errors_in_wasm(execution_result: &ExecutionResult) -> bool
| ExecError::UnexpectedKeyVariant(_)
| ExecError::InvalidPackageKind(_)
| ExecError::Transform(_)
| ExecError::InvalidEntryPointType => false,
| ExecError::InvalidEntryPointType
| ExecError::InvalidMessageTopicOperation => false,
ExecError::DisabledUnrestrictedTransfers => false,
},
Error::WasmPreprocessing(_) => true,
Expand Down
4 changes: 3 additions & 1 deletion execution_engine/src/engine_state/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use thiserror::Error;

use casper_storage::global_state::state::StateProvider;
use casper_types::{
addressable_entity::{ActionThresholds, AssociatedKeys, NamedKeys, Weight},
addressable_entity::{ActionThresholds, AssociatedKeys, MessageTopics, NamedKeys, Weight},
bytesrepr::{self, ToBytes},
execution::Effects,
package::{EntityVersions, Groups, PackageKind, PackageKindTag, PackageStatus},
Expand Down Expand Up @@ -151,6 +151,7 @@ where
URef::default(),
AssociatedKeys::default(),
ActionThresholds::default(),
MessageTopics::default(),
);

let byte_code_key =
Expand Down Expand Up @@ -297,6 +298,7 @@ where
main_purse,
associated_keys,
ActionThresholds::default(),
MessageTopics::default(),
);

let access_key = address_generator.new_uref(AccessRights::READ_ADD_WRITE);
Expand Down
3 changes: 3 additions & 0 deletions execution_engine/src/execution/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ pub enum Error {
/// The EntryPoints contains an invalid entry.
#[error("The EntryPoints contains an invalid entry")]
InvalidEntryPointType,
/// Invalid message topic operation.
#[error("The requested operation is invalid for a message topic")]
InvalidMessageTopicOperation,
}

impl From<PreprocessingError> for Error {
Expand Down
Loading
Loading