Skip to content

Commit

Permalink
Reduce size caching transfers & add backup for infos in get_operation…
Browse files Browse the repository at this point in the history
… using execution-trace (#4659)

* Reduce size caching

* Remove config change not wanted

* Upgrade mio

* Fix cache size

* Address review

* Fix compil error
  • Loading branch information
AurelienFT authored Mar 7, 2024
1 parent d9613a4 commit 7dd1ac2
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 34 additions & 11 deletions massa-api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,17 +636,40 @@ impl MassaRpcServer for API<Public> {
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
Expand Down
4 changes: 4 additions & 0 deletions massa-execution-exports/src/controller_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Transfer>>;

#[cfg(feature = "execution-trace")]
/// Get the transfer of MAS for a given operation id
fn get_transfer_for_op(&self, op_id: &OperationId) -> Option<Transfer>;

/// Returns a boxed clone of self.
/// Useful to allow cloning `Box<dyn ExecutionController>`.
fn clone_box(&self) -> Box<dyn ExecutionController>;
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-exports/src/test_exports/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
9 changes: 9 additions & 0 deletions massa-execution-worker/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Transfer> {
self.execution_state
.read()
.trace_history
.read()
.fetch_transfer_for_op(op_id)
}

/// Returns a boxed clone of self.
/// Allows cloning `Box<dyn ExecutionController>`,
/// see `massa-execution-exports/controller_traits.rs`
Expand Down
8 changes: 6 additions & 2 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
}
Expand Down
18 changes: 17 additions & 1 deletion massa-execution-worker/src/trace_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
}

Expand All @@ -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<Transfer> {
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() {
Expand All @@ -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<Transfer>) {
for transfer in transfers.iter() {
self.op_per_slot.insert(transfer.op_id, slot);
}
self.transfer_per_slot.insert(slot, transfers);
}
}
4 changes: 2 additions & 2 deletions massa-node/base_config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7dd1ac2

Please sign in to comment.