diff --git a/Cargo.lock b/Cargo.lock index 842c5902d7b..15cbe2e90e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3511,9 +3511,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "log", diff --git a/Cargo.toml b/Cargo.toml index 829f0eb81c9..432564d2eb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,7 +148,7 @@ jsonrpsee-http-client = "0.20" jsonrpsee-ws-client = "0.20" lazy_static = "1.4" libsecp256k1 = "=0.7" -mio = "0.8" +mio = "0.8.11" mockall = "0.11" mockall_wrap = { git = "https://github.com/AurelienFT/mockall-wrap", rev = "18f88253a000df96cf407dfe4b9158c69c0aeb96" } more-asserts = "0.3" diff --git a/massa-api/src/public.rs b/massa-api/src/public.rs index 0f16aa768b1..48908e7d806 100644 --- a/massa-api/src/public.rs +++ b/massa-api/src/public.rs @@ -636,17 +636,40 @@ impl MassaRpcServer for API { for (id, (operation, in_blocks), in_pool, is_operation_final, op_exec_status) in zipped_iterator { - res.push(OperationInfo { - id, - in_pool, - is_operation_final, - thread: operation - .content_creator_address - .get_thread(api_cfg.thread_count), - operation, - in_blocks: in_blocks.into_iter().collect(), - op_exec_status, - }); + #[cfg(feature = "execution-trace")] + { + let mut transfer = None; + if is_operation_final.is_none() || op_exec_status.is_none() { + transfer = self.0.execution_controller.get_transfer_for_op(&id); + } + let is_operation_final = is_operation_final.or(Some(transfer.is_some())); + let op_exec_status = op_exec_status.or(transfer.map(|t| t.succeed)); + res.push(OperationInfo { + id, + in_pool, + is_operation_final, + thread: operation + .content_creator_address + .get_thread(api_cfg.thread_count), + operation, + in_blocks: in_blocks.into_iter().collect(), + op_exec_status, + }); + } + #[cfg(not(feature = "execution-trace"))] + { + res.push(OperationInfo { + id, + in_pool, + is_operation_final, + thread: operation + .content_creator_address + .get_thread(api_cfg.thread_count), + operation, + in_blocks: in_blocks.into_iter().collect(), + op_exec_status, + }); + } } // return values in the right order diff --git a/massa-execution-exports/src/controller_traits.rs b/massa-execution-exports/src/controller_traits.rs index ff51154f27a..6e427f53d54 100644 --- a/massa-execution-exports/src/controller_traits.rs +++ b/massa-execution-exports/src/controller_traits.rs @@ -127,6 +127,10 @@ pub trait ExecutionController: Send + Sync { /// Get the all transfers of MAS for a given slot fn get_transfers_for_slot(&self, slot: Slot) -> Option>; + #[cfg(feature = "execution-trace")] + /// Get the transfer of MAS for a given operation id + fn get_transfer_for_op(&self, op_id: &OperationId) -> Option; + /// Returns a boxed clone of self. /// Useful to allow cloning `Box`. fn clone_box(&self) -> Box; diff --git a/massa-execution-exports/src/test_exports/config.rs b/massa-execution-exports/src/test_exports/config.rs index 12cfbc95f9d..d5a8183c760 100644 --- a/massa-execution-exports/src/test_exports/config.rs +++ b/massa-execution-exports/src/test_exports/config.rs @@ -71,7 +71,7 @@ impl Default for ExecutionConfig { chain_id: *CHAINID, broadcast_traces_enabled: true, broadcast_slot_execution_traces_channel_capacity: 5000, - max_execution_traces_slot_limit: 5000, + max_execution_traces_slot_limit: 320, } } } diff --git a/massa-execution-worker/src/controller.rs b/massa-execution-worker/src/controller.rs index 9651b126868..0399ca6c1a8 100644 --- a/massa-execution-worker/src/controller.rs +++ b/massa-execution-worker/src/controller.rs @@ -496,6 +496,15 @@ impl ExecutionController for ExecutionControllerImpl { .fetch_transfers_for_slot(&slot) } + #[cfg(feature = "execution-trace")] + fn get_transfer_for_op(&self, op_id: &OperationId) -> Option { + self.execution_state + .read() + .trace_history + .read() + .fetch_transfer_for_op(op_id) + } + /// Returns a boxed clone of self. /// Allows cloning `Box`, /// see `massa-execution-exports/controller_traits.rs` diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 625a9424af8..9d0003ae727 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -24,6 +24,7 @@ use massa_ledger_exports::{SetOrDelete, SetUpdateOrDelete}; use massa_metrics::MassaMetrics; use massa_models::address::ExecutionAddressCycleInfo; use massa_models::bytecode::Bytecode; + use massa_models::datastore::get_prefix_bounds; use massa_models::denunciation::{Denunciation, DenunciationIndex}; use massa_models::execution::EventFilter; @@ -53,7 +54,7 @@ use crate::trace_history::TraceHistory; #[cfg(feature = "execution-trace")] use massa_execution_exports::{AbiTrace, SlotAbiCallStack, Transfer}; #[cfg(feature = "execution-trace")] -use massa_models::config::MAX_OPERATIONS_PER_BLOCK; +use massa_models::config::{BASE_OPERATION_GAS_COST, MAX_GAS_PER_BLOCK, MAX_OPERATIONS_PER_BLOCK}; #[cfg(feature = "execution-trace")] use massa_models::prehash::PreHashMap; @@ -197,7 +198,10 @@ impl ExecutionState { #[cfg(feature = "execution-trace")] trace_history: Arc::new(RwLock::new(TraceHistory::new( config.max_execution_traces_slot_limit as u32, - MAX_OPERATIONS_PER_BLOCK, + std::cmp::min( + MAX_OPERATIONS_PER_BLOCK, + (MAX_GAS_PER_BLOCK / BASE_OPERATION_GAS_COST) as u32, + ), ))), config, } diff --git a/massa-execution-worker/src/trace_history.rs b/massa-execution-worker/src/trace_history.rs index 7a5c2576eab..7f8261a2f6b 100644 --- a/massa-execution-worker/src/trace_history.rs +++ b/massa-execution-worker/src/trace_history.rs @@ -17,7 +17,7 @@ impl TraceHistory { Self { trace_per_slot: LruMap::new(ByLength::new(max_slot_size_cache)), op_per_slot: LruMap::new(ByLength::new(max_slot_size_cache * op_per_slot)), - transfer_per_slot: LruMap::new(ByLength::new(max_slot_size_cache * op_per_slot)), + transfer_per_slot: LruMap::new(ByLength::new(max_slot_size_cache)), } } @@ -44,6 +44,19 @@ impl TraceHistory { self.transfer_per_slot.peek(slot).cloned() } + /// Fetch transfers for a given operation id + pub(crate) fn fetch_transfer_for_op(&self, op_id: &OperationId) -> Option { + self.op_per_slot + .peek(op_id) + .and_then(|slot| self.transfer_per_slot.peek(slot).cloned()) + .map(|transfers| { + transfers + .into_iter() + .find(|transfer| transfer.op_id == *op_id) + }) + .flatten() + } + /// Save execution traces for a given slot pub(crate) fn save_traces_for_slot(&mut self, slot: Slot, traces: SlotAbiCallStack) { for (op_id, _) in traces.operation_call_stacks.iter() { @@ -54,6 +67,9 @@ impl TraceHistory { /// Save transfer for a given slot pub(crate) fn save_transfers_for_slot(&mut self, slot: Slot, transfers: Vec) { + for transfer in transfers.iter() { + self.op_per_slot.insert(transfer.op_id, slot); + } self.transfer_per_slot.insert(slot, transfers); } } diff --git a/massa-node/base_config/config.toml b/massa-node/base_config/config.toml index 1f92ec42396..6b2fb0f3b05 100644 --- a/massa-node/base_config/config.toml +++ b/massa-node/base_config/config.toml @@ -217,8 +217,8 @@ broadcast_slot_execution_output_channel_capacity = 5000 # slot execution traces channel capacity broadcast_slot_execution_traces_channel_capacity = 5000 - # Max execution traces (group by block id) to keep in cache - execution_traces_limit = 5000 + # Max slots execution traces to keep in cache + execution_traces_limit = 320 [ledger] # path to the initial ledger