From 27ca46c6131cf1b9446939e6065d79c664f67362 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 19 Dec 2024 17:22:41 +0100 Subject: [PATCH] Fix versioning of massa event cache --- massa-event-cache/src/event_cache.rs | 4 ++-- massa-execution-worker/src/active_history.rs | 2 +- massa-execution-worker/src/execution.rs | 24 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/massa-event-cache/src/event_cache.rs b/massa-event-cache/src/event_cache.rs index 37bd1fecf1..370a486de6 100644 --- a/massa-event-cache/src/event_cache.rs +++ b/massa-event-cache/src/event_cache.rs @@ -942,7 +942,7 @@ mod tests { use tempfile::TempDir; // internal use massa_models::config::{ - MAX_EVENT_DATA_SIZE_V0, MAX_EVENT_PER_OPERATION, MAX_OPERATIONS_PER_BLOCK, + MAX_EVENT_DATA_SIZE_V1, MAX_EVENT_PER_OPERATION, MAX_OPERATIONS_PER_BLOCK, MAX_RECURSIVE_CALLS_DEPTH, THREAD_COUNT, }; use massa_models::operation::OperationId; @@ -957,7 +957,7 @@ mod tests { 300, THREAD_COUNT, MAX_RECURSIVE_CALLS_DEPTH, - MAX_EVENT_DATA_SIZE_V0 as u64, + MAX_EVENT_DATA_SIZE_V1 as u64, MAX_EVENT_PER_OPERATION as u64, MAX_OPERATIONS_PER_BLOCK as u64, 5000, // MAX_EVENTS_PER_QUERY, diff --git a/massa-execution-worker/src/active_history.rs b/massa-execution-worker/src/active_history.rs index 47c85a7272..1661adb05b 100644 --- a/massa-execution-worker/src/active_history.rs +++ b/massa-execution-worker/src/active_history.rs @@ -567,7 +567,7 @@ mod test { // Expect updates to be empty (or default) here { let current_updates = AsyncMessageUpdate::default(); - let fetched = active_history.fetch_message(&message_id_3_2, current_updates); + let fetched = active_history.fetch_message(&message_id_3_2, current_updates, 1); if let HistorySearchResult::Present(SetUpdateOrDelete::Update(updates)) = fetched { assert_eq!(updates, AsyncMessageUpdate::default()); } else { diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 220459eb7f..1bcea890cf 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -301,6 +301,30 @@ impl ExecutionState { // append generated events to the final event store exec_out.events.finalize(); + + let ts = get_block_slot_timestamp( + self.config.thread_count, + self.config.t0, + self.config.genesis_timestamp, + exec_out.slot, + ) + .expect("Time overflow"); + + let cur_version = self + .final_state + .read() + .get_mip_store() + .get_network_version_active_at(ts); + + if cur_version == 0 { + // Truncate the events before saving them to the event store + // Note: this is only needed during the MIP transition period + // When it becomes active, we will refuse such events so no need to truncate them + for event in exec_out.events.0.iter_mut() { + event.data.truncate(self.config.max_event_size_v1); + } + } + self.final_events_cache.save_events(exec_out.events.0); // update the prometheus metrics