Skip to content

Commit

Permalink
Add versioning to massa event cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Besancon committed Dec 19, 2024
1 parent 500a8e4 commit 47aee0c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions massa-event-cache/src/event_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ mod tests {
use tempfile::TempDir;
// internal
use massa_models::config::{
MAX_EVENT_DATA_SIZE, MAX_EVENT_PER_OPERATION, MAX_OPERATIONS_PER_BLOCK,
MAX_EVENT_DATA_SIZE_V0, MAX_EVENT_PER_OPERATION, MAX_OPERATIONS_PER_BLOCK,
MAX_RECURSIVE_CALLS_DEPTH, THREAD_COUNT,
};
use massa_models::operation::OperationId;
Expand All @@ -957,7 +957,7 @@ mod tests {
300,
THREAD_COUNT,
MAX_RECURSIVE_CALLS_DEPTH,
MAX_EVENT_DATA_SIZE as u64,
MAX_EVENT_DATA_SIZE_V0 as u64,
MAX_EVENT_PER_OPERATION as u64,
MAX_OPERATIONS_PER_BLOCK as u64,
5000, // MAX_EVENTS_PER_QUERY,
Expand Down
16 changes: 12 additions & 4 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,12 @@ impl ExecutionContext {
serde_json::json!({ "massa_execution_error": format!("{}", error) }).to_string(),
true,
);
if event.data.len() > self.config.max_event_size {
event.data.truncate(self.config.max_event_size);
let max_event_size = match self.execution_component_version {
0 => self.config.max_event_size_v0,
_ => self.config.max_event_size_v1,
};
if event.data.len() > max_event_size {
event.data.truncate(max_event_size);
}
self.event_emit(event);

Expand Down Expand Up @@ -1460,8 +1464,12 @@ impl ExecutionContext {

let mut event =
self.event_create(format!("DeferredCall execution fail call_id:{}", id), true);
if event.data.len() > self.config.max_event_size {
event.data.truncate(self.config.max_event_size);
let max_event_size = match self.execution_component_version {
0 => self.config.max_event_size_v0,
_ => self.config.max_event_size_v1,
};
if event.data.len() > max_event_size {
event.data.truncate(max_event_size);
}
self.event_emit(event);

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 @@ -477,8 +477,12 @@ impl ExecutionState {
context.transfer_coins(Some(sender_addr), None, operation.content.fee, false)
{
let mut error = format!("could not spend fees: {}", err);
if error.len() > self.config.max_event_size {
error.truncate(self.config.max_event_size);
let max_event_size = match execution_component_version {
0 => self.config.max_event_size_v0,
_ => self.config.max_event_size_v1,
};
if error.len() > max_event_size {
error.truncate(max_event_size);
}
let event = context.event_create(error.clone(), true);
context.event_emit(event);
Expand Down
2 changes: 1 addition & 1 deletion massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ async fn launch(
event_cache_path: SETTINGS.execution.event_cache_path.clone(),
max_event_cache_length: SETTINGS.execution.event_cache_size,
snip_amount: SETTINGS.execution.event_snip_amount,
max_event_data_length: MAX_EVENT_DATA_SIZE as u64,
max_event_data_length: MAX_EVENT_DATA_SIZE_V0 as u64,
thread_count: THREAD_COUNT,
// Note: SCOutputEvent call stack comes from the execution module, and we assume
// this should return a limited call stack length
Expand Down

0 comments on commit 47aee0c

Please sign in to comment.