diff --git a/Cargo.lock b/Cargo.lock index c35145c91..a27b088f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1770,7 +1770,7 @@ dependencies = [ [[package]] name = "frc42_dispatch" version = "1.0.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#93f90c3cd340a2396ee2e0344fe09bb476362a92" +source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#aa39d65847a57cea2fcf04bab464bac75cf99b97" dependencies = [ "frc42_hasher", "frc42_macros", @@ -1783,7 +1783,7 @@ dependencies = [ [[package]] name = "frc42_hasher" version = "1.0.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#93f90c3cd340a2396ee2e0344fe09bb476362a92" +source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#aa39d65847a57cea2fcf04bab464bac75cf99b97" dependencies = [ "fvm_sdk", "fvm_shared", @@ -1793,7 +1793,7 @@ dependencies = [ [[package]] name = "frc42_macros" version = "1.0.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#93f90c3cd340a2396ee2e0344fe09bb476362a92" +source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#aa39d65847a57cea2fcf04bab464bac75cf99b97" dependencies = [ "blake2b_simd", "frc42_hasher", @@ -1805,7 +1805,7 @@ dependencies = [ [[package]] name = "frc46_token" version = "1.1.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#93f90c3cd340a2396ee2e0344fe09bb476362a92" +source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#aa39d65847a57cea2fcf04bab464bac75cf99b97" dependencies = [ "anyhow", "cid", @@ -1954,7 +1954,7 @@ dependencies = [ [[package]] name = "fvm_actor_utils" version = "0.1.0" -source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#93f90c3cd340a2396ee2e0344fe09bb476362a92" +source = "git+https://github.com/filecoin-project/filecoin-actor-utils?branch=feat/fvm-m2#aa39d65847a57cea2fcf04bab464bac75cf99b97" dependencies = [ "anyhow", "cid", @@ -2060,9 +2060,9 @@ dependencies = [ [[package]] name = "fvm_sdk" -version = "3.0.0-alpha.10" +version = "3.0.0-alpha.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55159c44e404ab1fc9e0e2d15aa8513f71e5e4c3f38363a3f7644d5b7a7a906e" +checksum = "2ee761116262c35151071675ec3345d821b0b90143616dec348c74e46116e150" dependencies = [ "cid", "fvm_ipld_encoding", @@ -2075,11 +2075,12 @@ dependencies = [ [[package]] name = "fvm_shared" -version = "3.0.0-alpha.10" +version = "3.0.0-alpha.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcd5f36e5c1628da1a002931f96a8cc3ea8fc517a6984e8d42457786528b88f0" +checksum = "d66b85f8971273def3bb366008319f8dc855be3172210c3b83b7b20353709b29" dependencies = [ "anyhow", + "bitflags", "blake2b_simd", "byteorder", "cid", @@ -2295,9 +2296,9 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.23.0" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d87c48c02e0dc5e3b849a2041db3029fd066650f8f717c07bf8ed78ccb895cac" +checksum = "59df7c4e19c950e6e0e868dcc0a300b09a9b88e9ec55bd879ca819087a77355d" dependencies = [ "http", "hyper", @@ -2444,9 +2445,12 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" +checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +dependencies = [ + "cpufeatures", +] [[package]] name = "kv-log-macro" diff --git a/actors/account/Cargo.toml b/actors/account/Cargo.toml index 6eef660a6..772dacf3c 100644 --- a/actors/account/Cargo.toml +++ b/actors/account/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } frc42_dispatch = "1.0.0" -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } serde = { version = "1.0.136", features = ["derive"] } num-traits = "0.2.14" num-derive = "0.3.3" diff --git a/actors/cron/Cargo.toml b/actors/cron/Cargo.toml index 7596ecded..47c7ca8e0 100644 --- a/actors/cron/Cargo.toml +++ b/actors/cron/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } num-traits = "0.2.14" num-derive = "0.3.3" log = "0.4.14" diff --git a/actors/datacap/Cargo.toml b/actors/datacap/Cargo.toml index c47233250..269743985 100644 --- a/actors/datacap/Cargo.toml +++ b/actors/datacap/Cargo.toml @@ -23,7 +23,7 @@ fvm_actor_utils = "0.1.0" fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = "0.3.0" fvm_ipld_hamt = "0.6.1" -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } lazy_static = "1.4.0" num-derive = "0.3.3" num-traits = "0.2.14" diff --git a/actors/datacap/src/lib.rs b/actors/datacap/src/lib.rs index 68c68081f..80a1b5cc4 100644 --- a/actors/datacap/src/lib.rs +++ b/actors/datacap/src/lib.rs @@ -390,15 +390,19 @@ where let res = self.rt.send(to, method, params.clone(), value.clone()); let rec = match res { - Ok(bytes) => { - Receipt { exit_code: ExitCode::OK, return_data: bytes, gas_used: fake_gas_used } - } + Ok(bytes) => Receipt { + exit_code: ExitCode::OK, + return_data: bytes, + gas_used: fake_gas_used, + events_root: None, + }, Err(ae) => { info!("datacap messenger failed: {}", ae.msg()); Receipt { exit_code: ae.exit_code(), return_data: RawBytes::default(), gas_used: fake_gas_used, + events_root: None, } } }; diff --git a/actors/eam/Cargo.toml b/actors/eam/Cargo.toml index 28d78ec75..e33134c71 100644 --- a/actors/eam/Cargo.toml +++ b/actors/eam/Cargo.toml @@ -24,7 +24,7 @@ fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = "0.3.0" multihash = { version = "0.16.1", default-features = false } cid = "0.8.6" -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } num-traits = "0.2.15" num-derive = "0.3.3" hex-literal = "0.3.4" diff --git a/actors/embryo/Cargo.toml b/actors/embryo/Cargo.toml index 92f5e9c9d..ee1aaf3a4 100644 --- a/actors/embryo/Cargo.toml +++ b/actors/embryo/Cargo.toml @@ -13,8 +13,8 @@ keywords = ["filecoin", "web3", "wasm"] crate-type = ["cdylib", "lib"] [dependencies] -fvm_sdk = { version = "3.0.0-alpha.10", optional = true } -fvm_shared = { version = "3.0.0-alpha.10", optional = true } +fvm_sdk = { version = "3.0.0-alpha.11", optional = true } +fvm_shared = { version = "3.0.0-alpha.11", optional = true } [features] fil-actor = ["fvm_sdk", "fvm_shared"] diff --git a/actors/evm/Cargo.toml b/actors/evm/Cargo.toml index d87524a27..b36f73c33 100644 --- a/actors/evm/Cargo.toml +++ b/actors/evm/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } fvm_ipld_hamt = "0.6.1" serde = { version = "1.0.136", features = ["derive"] } serde_tuple = "0.5" diff --git a/actors/evm/src/interpreter/instructions/log.rs b/actors/evm/src/interpreter/instructions/log.rs index efa3c60d6..fd72ea910 100644 --- a/actors/evm/src/interpreter/instructions/log.rs +++ b/actors/evm/src/interpreter/instructions/log.rs @@ -1,28 +1,57 @@ +use crate::interpreter::instructions::memory::get_memory_region; +use fvm_ipld_encoding::{to_vec, BytesSer, RawBytes}; +use fvm_shared::event::{Entry, Flags}; use { crate::interpreter::{ExecutionState, StatusCode, System}, fil_actors_runtime::runtime::Runtime, }; -#[cfg(debug_assertions)] -pub fn log( - _state: &mut ExecutionState, - _system: &System, - _num_topics: usize, -) -> Result<(), StatusCode> { - todo!("unimplemented"); -} +/// The event key for the Ethereum log data. +const EVENT_DATA_KEY: &str = "data"; + +/// The event keys for the Ethereum log topics. +const EVENT_TOPIC_KEYS: &[&str] = &["topic1", "topic2", "topic3", "topic4"]; -#[cfg(not(debug_assertions))] #[inline] pub fn log( state: &mut ExecutionState, - _system: &System, + system: &System, num_topics: usize, ) -> Result<(), StatusCode> { - // TODO: Right now, we just drop everything. But we implement this in production anyways so - // things work. - for _ in 0..num_topics { - state.stack.pop(); + // Handle the data. + // Passing in a zero-sized memory region omits the data key entirely. + // LOG0 + a zero-sized memory region emits an event with no entries whatsoever. In this case, + // the FVM will record a hollow event carrying only the emitter actor ID. + let mem_index = state.stack.pop(); + let size = state.stack.pop(); + let region = get_memory_region(&mut state.memory, mem_index, size) + .map_err(|_| StatusCode::InvalidMemoryAccess)?; + + // Extract the topics. Prefer to allocate an extra item than to incur in the cost of a + // decision based on the size of the data. + let mut entries: Vec = Vec::with_capacity(num_topics + 1); + for key in EVENT_TOPIC_KEYS.iter().take(num_topics) { + let topic = state.stack.pop(); + let entry = Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: (*key).to_owned(), + value: to_vec(&topic)?.into(), // U256 serializes as a byte string. + }; + entries.push(entry); } + + // Skip adding the data if it's zero-sized. + if let Some(r) = region { + let data = state.memory[r.offset..r.offset + r.size.get()].to_vec(); + let entry = Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: EVENT_DATA_KEY.to_owned(), + value: RawBytes::serialize(BytesSer(&data))?, + }; + entries.push(entry); + } + + system.rt.emit_event(&entries.into())?; + Ok(()) } diff --git a/actors/evm/tests/events.rs b/actors/evm/tests/events.rs new file mode 100644 index 000000000..0391418d3 --- /dev/null +++ b/actors/evm/tests/events.rs @@ -0,0 +1,133 @@ +mod asm; + +use fvm_ipld_encoding::{to_vec, RawBytes}; +use fvm_shared::event::{ActorEvent, Entry, Flags}; + +mod util; + +#[allow(dead_code)] +pub fn events_contract() -> Vec { + let init = r#" +"#; + let body = r#" +# method dispatch: +# - 0x00000000 -> log_zero_data +# - 0x00000001 -> log_zero_nodata +# - 0x00000002 -> log_four_data + +%dispatch_begin() +%dispatch(0x00, log_zero_data) +%dispatch(0x01, log_zero_nodata) +%dispatch(0x02, log_four_data) +%dispatch_end() + +#### log a zero topic event with data +log_zero_data: +jumpdest +push8 0x1122334455667788 +push1 0x00 +mstore +push1 0x08 +push1 0x18 ## index 24 into memory as mstore writes a full word +log0 +push1 0x00 +push1 0x00 +return + +#### log a zero topic event with no data +log_zero_nodata: +jumpdest +push1 0x00 +push1 0x00 +log0 +push1 0x00 +push1 0x00 +return + +#### log a four topic event with data +log_four_data: +jumpdest +push8 0x1122334455667788 +push1 0x00 +mstore +push4 0x4444 +push3 0x3333 +push2 0x2222 +push2 0x1111 +push1 0x08 +push1 0x18 ## index 24 into memory as mstore writes a full word +log4 +push1 0x00 +push1 0x00 +return + +"#; + + asm::new_contract("events", init, body).unwrap() +} + +#[test] +fn test_events() { + let contract = events_contract(); + + let mut rt = util::construct_and_verify(contract); + + // log zero with data + let mut contract_params = vec![0u8; 32]; + rt.expect_emitted_event(ActorEvent { + entries: vec![Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: "data".to_string(), + value: to_vec(&RawBytes::from( + [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88].to_vec(), + )) + .unwrap() + .into(), + }], + }); + util::invoke_contract(&mut rt, &contract_params); + + // log zero without data + contract_params[3] = 0x01; + rt.expect_emitted_event(ActorEvent { entries: vec![] }); + util::invoke_contract(&mut rt, &contract_params); + + // log four with data + contract_params[3] = 0x02; + rt.expect_emitted_event(ActorEvent { + entries: vec![ + Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: "topic1".to_string(), + value: to_vec(&RawBytes::from([0x11, 0x11].to_vec())).unwrap().into(), + }, + Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: "topic2".to_string(), + value: to_vec(&RawBytes::from([0x22, 0x22].to_vec())).unwrap().into(), + }, + Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: "topic3".to_string(), + value: to_vec(&RawBytes::from([0x33, 0x33].to_vec())).unwrap().into(), + }, + Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: "topic4".to_string(), + value: to_vec(&RawBytes::from([0x44, 0x44].to_vec())).unwrap().into(), + }, + Entry { + flags: Flags::FLAG_INDEXED_VALUE, + key: "data".to_string(), + value: to_vec(&RawBytes::from( + [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88].to_vec(), + )) + .unwrap() + .into(), + }, + ], + }); + util::invoke_contract(&mut rt, &contract_params); + + rt.verify(); +} diff --git a/actors/init/Cargo.toml b/actors/init/Cargo.toml index 6458cc532..6e60068d3 100644 --- a/actors/init/Cargo.toml +++ b/actors/init/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } fvm_ipld_hamt = "0.6.1" serde = { version = "1.0.136", features = ["derive"] } num-traits = "0.2.14" diff --git a/actors/market/Cargo.toml b/actors/market/Cargo.toml index 5d3629f34..be2b4ec2d 100644 --- a/actors/market/Cargo.toml +++ b/actors/market/Cargo.toml @@ -23,7 +23,7 @@ fvm_ipld_bitfield = "0.5.4" fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = "0.3.0" fvm_ipld_hamt = "0.6.1" -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } integer-encoding = { version = "3.0.3", default-features = false } libipld-core = { version = "0.13.1", features = ["serde-codec"] } log = "0.4.14" diff --git a/actors/miner/Cargo.toml b/actors/miner/Cargo.toml index 94880dbe9..5c26de0d7 100644 --- a/actors/miner/Cargo.toml +++ b/actors/miner/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } fvm_ipld_bitfield = "0.5.4" fvm_ipld_amt = { version = "0.5.0", features = ["go-interop"] } fvm_ipld_hamt = "0.6.1" diff --git a/actors/multisig/Cargo.toml b/actors/multisig/Cargo.toml index e9bc2f550..84451c7a3 100644 --- a/actors/multisig/Cargo.toml +++ b/actors/multisig/Cargo.toml @@ -22,7 +22,7 @@ frc42_dispatch = "1.0.0" fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = "0.3.0" fvm_ipld_hamt = "0.6.1" -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } indexmap = { version = "1.8.0", features = ["serde-1"] } integer-encoding = { version = "3.0.3", default-features = false } num-derive = "0.3.3" diff --git a/actors/paych/Cargo.toml b/actors/paych/Cargo.toml index 6eb4a086e..8a9d7fe4f 100644 --- a/actors/paych/Cargo.toml +++ b/actors/paych/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } num-traits = "0.2.14" num-derive = "0.3.3" serde = { version = "1.0.136", features = ["derive"] } diff --git a/actors/power/Cargo.toml b/actors/power/Cargo.toml index 113539a2f..5377d7500 100644 --- a/actors/power/Cargo.toml +++ b/actors/power/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } fvm_ipld_hamt = "0.6.1" num-traits = "0.2.14" num-derive = "0.3.3" diff --git a/actors/reward/Cargo.toml b/actors/reward/Cargo.toml index 515d88e8a..51b57fccd 100644 --- a/actors/reward/Cargo.toml +++ b/actors/reward/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } num-traits = "0.2.14" num-derive = "0.3.3" log = "0.4.14" diff --git a/actors/system/Cargo.toml b/actors/system/Cargo.toml index a06c47a6a..901f2b1f6 100644 --- a/actors/system/Cargo.toml +++ b/actors/system/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "lib"] [dependencies] fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../../runtime" } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } fvm_ipld_encoding = "0.3.0" fvm_ipld_blockstore = "0.1.1" num-traits = "0.2.14" diff --git a/actors/verifreg/Cargo.toml b/actors/verifreg/Cargo.toml index 45fc1583d..6dc89664a 100644 --- a/actors/verifreg/Cargo.toml +++ b/actors/verifreg/Cargo.toml @@ -23,7 +23,7 @@ frc46_token = "1.1.0" fvm_ipld_blockstore = "0.1.1" fvm_ipld_encoding = "0.3.0" fvm_ipld_hamt = "0.6.1" -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } lazy_static = "1.4.0" log = "0.4.14" num-derive = "0.3.3" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 57d718360..e410f58e4 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/filecoin-project/builtin-actors" [dependencies] fvm_ipld_hamt = "0.6.1" fvm_ipld_amt = { version = "0.5.0", features = ["go-interop"] } -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } num-traits = "0.2.14" num-derive = "0.3.3" serde = { version = "1.0.136", features = ["derive"] } @@ -34,7 +34,7 @@ paste = "1.0.9" sha2 = "0.10" # fil-actor -fvm_sdk = { version = "3.0.0-alpha.10", optional = true } +fvm_sdk = { version = "3.0.0-alpha.11", optional = true } # test_util rand = { version = "0.8.5", default-features = false, optional = true } diff --git a/runtime/src/runtime/fvm.rs b/runtime/src/runtime/fvm.rs index 9c6d95e59..713aee76a 100644 --- a/runtime/src/runtime/fvm.rs +++ b/runtime/src/runtime/fvm.rs @@ -13,6 +13,7 @@ use fvm_shared::crypto::signature::{ }; use fvm_shared::econ::TokenAmount; use fvm_shared::error::{ErrorNumber, ExitCode}; +use fvm_shared::event::ActorEvent; use fvm_shared::piece::PieceInfo; use fvm_shared::randomness::RANDOMNESS_LENGTH; use fvm_shared::sector::{ @@ -31,7 +32,7 @@ use crate::runtime::{ ActorCode, ConsensusFault, DomainSeparationTag, MessageInfo, Policy, Primitives, RuntimePolicy, Verifier, }; -use crate::{actor_error, ActorError, Runtime}; +use crate::{actor_error, ActorError, AsActorError, Runtime}; /// A runtime that bridges to the FVM environment through the FVM SDK. pub struct FvmRuntime { @@ -420,6 +421,11 @@ where fn tipset_cid(&self, epoch: i64) -> Option { fvm::network::tipset_cid(epoch).ok() } + + fn emit_event(&self, event: &ActorEvent) -> Result<(), ActorError> { + fvm::event::emit_event(event) + .context_code(ExitCode::USR_ASSERTION_FAILED, "failed to emit event") + } } impl Primitives for FvmRuntime diff --git a/runtime/src/runtime/mod.rs b/runtime/src/runtime/mod.rs index 61229416f..1a15d61e6 100644 --- a/runtime/src/runtime/mod.rs +++ b/runtime/src/runtime/mod.rs @@ -12,6 +12,7 @@ use fvm_shared::crypto::signature::{ Signature, SECP_PUB_LEN, SECP_SIG_LEN, SECP_SIG_MESSAGE_HASH_SIZE, }; use fvm_shared::econ::TokenAmount; +use fvm_shared::event::ActorEvent; use fvm_shared::piece::PieceInfo; use fvm_shared::randomness::RANDOMNESS_LENGTH; use fvm_shared::sector::{ @@ -240,6 +241,9 @@ pub trait Runtime: Primitives + Verifier + RuntimePolicy { /// The hash of on of the last 256 blocks fn tipset_cid(&self, epoch: i64) -> Option; + + /// Emits an event denoting that something externally noteworthy has ocurred. + fn emit_event(&self, event: &ActorEvent) -> Result<(), ActorError>; } /// Message information available to the actor about executing message. diff --git a/runtime/src/test_utils.rs b/runtime/src/test_utils.rs index e72efd6a7..25b8f1bc4 100644 --- a/runtime/src/test_utils.rs +++ b/runtime/src/test_utils.rs @@ -42,6 +42,7 @@ use crate::runtime::{ Verifier, EMPTY_ARR_CID, }; use crate::{actor_error, ActorError}; +use fvm_shared::event::ActorEvent; use libsecp256k1::{recover, Message, RecoveryId, Signature as EcsdaSignature}; lazy_static::lazy_static! { @@ -188,6 +189,7 @@ pub struct Expectations { pub expect_replica_verify: Option, pub expect_gas_charge: VecDeque, pub expect_gas_available: VecDeque, + pub expect_emitted_events: VecDeque, } impl Expectations { @@ -287,6 +289,11 @@ impl Expectations { "expect_gas_charge {:?}, not received", self.expect_gas_available ); + assert!( + self.expect_emitted_events.is_empty(), + "expect_emitted_events {:?}, not received", + self.expect_emitted_events + ); } } @@ -750,6 +757,11 @@ impl MockRuntime { self.expectations.borrow_mut().expect_gas_available.push_back(value); } + #[allow(dead_code)] + pub fn expect_emitted_event(&mut self, event: ActorEvent) { + self.expectations.borrow_mut().expect_emitted_events.push_back(event) + } + ///// Private helpers ///// fn require_in_call(&self) { @@ -1243,6 +1255,19 @@ impl Runtime for MockRuntime { Ok(expected.out) } + + fn emit_event(&self, event: &ActorEvent) -> Result<(), ActorError> { + let expected = self + .expectations + .borrow_mut() + .expect_emitted_events + .pop_front() + .expect("unexpected call to emit_evit"); + + assert_eq!(*event, expected); + + Ok(()) + } } impl Primitives for MockRuntime { diff --git a/state/Cargo.toml b/state/Cargo.toml index 644a085bd..a97268c16 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -27,7 +27,7 @@ fil_actor_reward = { version = "10.0.0-alpha.1", path = "../actors/reward"} fil_actor_system = { version = "10.0.0-alpha.1", path = "../actors/system"} fil_actor_init = { version = "10.0.0-alpha.1", path = "../actors/init"} fil_actors_runtime = { version = "10.0.0-alpha.1", path = "../runtime"} -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } fvm_ipld_encoding = "0.3.0" fvm_ipld_blockstore = "0.1.1" num-traits = "0.2.14" diff --git a/test_vm/Cargo.toml b/test_vm/Cargo.toml index 394449a6e..285ad9832 100644 --- a/test_vm/Cargo.toml +++ b/test_vm/Cargo.toml @@ -37,7 +37,7 @@ fvm_ipld_bitfield = "0.5.4" fvm_ipld_blockstore = { version = "0.1.1", default-features = false } fvm_ipld_encoding = { version = "0.3.0", default-features = false } fvm_ipld_hamt = "0.6.1" -fvm_shared = { version = "3.0.0-alpha.10", default-features = false } +fvm_shared = { version = "3.0.0-alpha.11", default-features = false } indexmap = { version = "1.8.0", features = ["serde-1"] } integer-encoding = { version = "3.0.3", default-features = false } lazy_static = "1.4.0" diff --git a/test_vm/src/lib.rs b/test_vm/src/lib.rs index 59770b977..155ebb431 100644 --- a/test_vm/src/lib.rs +++ b/test_vm/src/lib.rs @@ -47,6 +47,7 @@ use fvm_shared::crypto::signature::{ }; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; +use fvm_shared::event::ActorEvent; use fvm_shared::piece::PieceInfo; use fvm_shared::randomness::Randomness; use fvm_shared::randomness::RANDOMNESS_LENGTH; @@ -1063,6 +1064,11 @@ impl<'invocation, 'bs> Runtime for InvocationCtx<'invocation, 'bs> { fn tipset_cid(&self, _epoch: i64) -> Option { Some(Cid::new_v1(IPLD_RAW, Multihash::wrap(0, b"faketipset").unwrap())) } + + // TODO No support for events yet. + fn emit_event(&self, _event: &ActorEvent) -> Result<(), ActorError> { + Ok(()) + } } impl Primitives for VM<'_> {