Skip to content

Commit

Permalink
create DeferredCallsConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
modship committed Aug 26, 2024
1 parent a08664e commit b53c77f
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 42 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

14 changes: 9 additions & 5 deletions massa-deferred-calls/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use nom::{
use serde::{Deserialize, Serialize};
use std::ops::Bound;

use crate::config::DeferredCallsConfig;

/// Definition of a call in the future
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DeferredCall {
Expand Down Expand Up @@ -126,20 +128,20 @@ pub struct DeferredCallDeserializer {

impl DeferredCallDeserializer {
/// Deserializes a `Vec<u8>` into an `AsyncCall`
pub fn new(thread_count: u8) -> Self {
pub fn new(config: DeferredCallsConfig) -> Self {
Self {
slot_deserializer: SlotDeserializer::new(
(Bound::Included(0), Bound::Included(u64::MAX)),
(Bound::Included(0), Bound::Excluded(thread_count)),
(Bound::Included(0), Bound::Excluded(config.thread_count)),
),
address_deserializer: AddressDeserializer::new(),
string_deserializer: StringDeserializer::new(U16VarIntDeserializer::new(
Bound::Included(0),
Bound::Included(u16::MAX),
Bound::Included(config.max_function_name_length),
)),
vec_u8_deserializer: VecU8Deserializer::new(
std::ops::Bound::Included(0),
std::ops::Bound::Included(u16::MAX as u64),
std::ops::Bound::Included(config.max_parameter_size as u64),
),
amount_deserializer: AmountDeserializer::new(
Bound::Included(Amount::MIN),
Expand Down Expand Up @@ -224,6 +226,7 @@ impl Deserializer<DeferredCall> for DeferredCallDeserializer {
mod tests {
use std::str::FromStr;

use massa_models::config::{MAX_PARAMETERS_SIZE, THREAD_COUNT};
use massa_serialization::DeserializeError;

use super::*;
Expand All @@ -242,7 +245,8 @@ mod tests {
false,
);
let serializer = DeferredCallSerializer::new();
let deserializer = DeferredCallDeserializer::new(1);

let deserializer = DeferredCallDeserializer::new(DeferredCallsConfig::default());
let mut buffer = Vec::new();
serializer.serialize(&call, &mut buffer).unwrap();
let (rest, deserialized_call) = deserializer
Expand Down
30 changes: 30 additions & 0 deletions massa-deferred-calls/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use massa_models::config::{
MAX_ASYNC_GAS, MAX_FUNCTION_NAME_LENGTH, MAX_PARAMETERS_SIZE, THREAD_COUNT,
};

#[derive(Debug, Clone)]
pub struct DeferredCallsConfig {
/// thread count
pub thread_count: u8,
/// max function name length
pub max_function_name_length: u16,
/// max parameter size
pub max_parameter_size: u32,

pub max_deferred_calls_pool_changes: u64,

pub max_gas: u64,
}

impl Default for DeferredCallsConfig {
fn default() -> Self {
Self {
thread_count: THREAD_COUNT,
max_function_name_length: MAX_FUNCTION_NAME_LENGTH,
max_parameter_size: MAX_PARAMETERS_SIZE,
// TODO: set to a reasonable value
max_deferred_calls_pool_changes: 1000000,
max_gas: MAX_ASYNC_GAS,
}
}
}
13 changes: 5 additions & 8 deletions massa-deferred-calls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use call::{DeferredCallDeserializer, DeferredCallSerializer};
use config::DeferredCallsConfig;
use macros::DEFERRED_CALL_TOTAL_GAS;
use massa_db_exports::{
DBBatch, ShareableMassaDBController, CRUD_ERROR, DEFERRED_CALLS_PREFIX,
Expand All @@ -13,6 +14,7 @@ use registry_changes::{
/// This module implements a new version of the Autonomous Smart Contracts. (ASC)
/// This new version allow asynchronous calls to be registered for a specific slot and ensure his execution.
mod call;
pub mod config;
pub mod registry_changes;
pub mod slot_changes;

Expand All @@ -26,7 +28,6 @@ pub use call::DeferredCall;
use massa_ledger_exports::{SetOrDelete, SetOrKeep};
use massa_models::{
amount::Amount,
config::{DEFERRED_CALL_MAX_POOL_CHANGES, MAX_ASYNC_GAS, THREAD_COUNT},
deferred_calls::{DeferredCallId, DeferredCallIdDeserializer, DeferredCallIdSerializer},
slot::Slot,
};
Expand All @@ -53,18 +54,14 @@ impl DeferredCallRegistry {
*/

// TODO pass args
pub fn new(db: ShareableMassaDBController) -> Self {
pub fn new(db: ShareableMassaDBController, config: DeferredCallsConfig) -> Self {
Self {
db,
call_serializer: DeferredCallSerializer::new(),
call_id_serializer: DeferredCallIdSerializer::new(),
call_deserializer: DeferredCallDeserializer::new(THREAD_COUNT),
call_deserializer: DeferredCallDeserializer::new(config.clone()),
call_id_deserializer: DeferredCallIdDeserializer::new(),
registry_changes_deserializer: DeferredRegistryChangesDeserializer::new(
THREAD_COUNT,
MAX_ASYNC_GAS,
DEFERRED_CALL_MAX_POOL_CHANGES,
),
registry_changes_deserializer: DeferredRegistryChangesDeserializer::new(config),
registry_changes_serializer: DeferredRegistryChangesSerializer::new(),
}
}
Expand Down
16 changes: 7 additions & 9 deletions massa-deferred-calls/src/registry_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use nom::{
use serde::{Deserialize, Serialize};

use crate::{
config::DeferredCallsConfig,
slot_changes::{
DeferredRegistrySlotChanges, DeferredRegistrySlotChangesDeserializer,
DeferredRegistrySlotChangesSerializer,
Expand Down Expand Up @@ -144,20 +145,16 @@ pub struct DeferredRegistryChangesDeserializer {
}

impl DeferredRegistryChangesDeserializer {
pub fn new(thread_count: u8, max_gas: u64, max_deferred_calls_pool_changes: u64) -> Self {
pub fn new(config: DeferredCallsConfig) -> Self {
Self {
slots_length: U64VarIntDeserializer::new(
Included(u64::MIN),
Included(max_deferred_calls_pool_changes),
),
slot_changes_deserializer: DeferredRegistrySlotChangesDeserializer::new(
thread_count,
max_gas,
max_deferred_calls_pool_changes,
Included(config.max_deferred_calls_pool_changes),
),
slot_changes_deserializer: DeferredRegistrySlotChangesDeserializer::new(config.clone()),
slot_deserializer: SlotDeserializer::new(
(Bound::Included(0), Bound::Included(u64::MAX)),
(Bound::Included(0), Bound::Excluded(thread_count)),
(Bound::Included(0), Bound::Excluded(config.thread_count)),
),
total_gas_deserializer: SetOrKeepDeserializer::new(U128VarIntDeserializer::new(
Included(u128::MIN),
Expand Down Expand Up @@ -212,6 +209,7 @@ mod tests {
use massa_serialization::DeserializeError;

use crate::{
config::DeferredCallsConfig,
registry_changes::{
DeferredRegistryChangesDeserializer, DeferredRegistryChangesSerializer,
},
Expand Down Expand Up @@ -272,7 +270,7 @@ mod tests {
let serializer = DeferredRegistryChangesSerializer::new();
serializer.serialize(&changes, &mut buffer).unwrap();

let deserializer = DeferredRegistryChangesDeserializer::new(32, 300_000, 10_000);
let deserializer = DeferredRegistryChangesDeserializer::new(DeferredCallsConfig::default());
let (rest, deserialized) = deserializer
.deserialize::<DeserializeError>(&buffer)
.unwrap();
Expand Down
14 changes: 8 additions & 6 deletions massa-deferred-calls/src/slot_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::BTreeMap;

use crate::{
call::{DeferredCallDeserializer, DeferredCallSerializer},
config::DeferredCallsConfig,
DeferredCall, DeferredRegistryBaseFeeChange, DeferredRegistryCallChange,
DeferredRegistryGasChange,
};
Expand Down Expand Up @@ -140,19 +141,19 @@ pub struct DeferredRegistrySlotChangesDeserializer {
}

impl DeferredRegistrySlotChangesDeserializer {
pub fn new(thread_count: u8, max_gas: u64, max_deferred_calls_pool_changes: u64) -> Self {
pub fn new(config: DeferredCallsConfig) -> Self {
Self {
deferred_registry_slot_changes_length: U64VarIntDeserializer::new(
Included(u64::MIN),
Included(max_deferred_calls_pool_changes),
Included(config.max_deferred_calls_pool_changes),
),
call_id_deserializer: DeferredCallIdDeserializer::new(),
calls_set_or_delete_deserializer: SetOrDeleteDeserializer::new(
DeferredCallDeserializer::new(thread_count),
DeferredCallDeserializer::new(config.clone()),
),
gas_deserializer: SetOrKeepDeserializer::new(U64VarIntDeserializer::new(
Included(0),
Included(max_gas),
Included(config.max_gas),
)),
base_fee_deserializer: SetOrKeepDeserializer::new(AmountDeserializer::new(
Included(Amount::MIN),
Expand Down Expand Up @@ -217,7 +218,7 @@ mod tests {
};
use massa_serialization::{DeserializeError, Deserializer, Serializer};

use crate::DeferredCall;
use crate::{config::DeferredCallsConfig, DeferredCall};

use super::{
DeferredRegistrySlotChanges, DeferredRegistrySlotChangesDeserializer,
Expand Down Expand Up @@ -264,7 +265,8 @@ mod tests {
.serialize(&registry_slot_changes, &mut buffer)
.unwrap();

let deserializer = DeferredRegistrySlotChangesDeserializer::new(32, 3000000, 100_000);
let deserializer =
DeferredRegistrySlotChangesDeserializer::new(DeferredCallsConfig::default());
let (rest, changes_deser) = deserializer
.deserialize::<DeserializeError>(&buffer)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions massa-deferred-calls/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn call_registry_apply_changes() {
Box::new(MassaDB::new(db_config)) as Box<(dyn MassaDBController + 'static)>
));

let registry = DeferredCallRegistry::new(db);
let registry = DeferredCallRegistry::new(db, DeferredCallsConfig::default());

let mut changes = DeferredCallRegistryChanges::default();

Expand Down Expand Up @@ -81,7 +81,7 @@ fn call_registry_get_slot_calls() {
Box::new(MassaDB::new(db_config)) as Box<(dyn MassaDBController + 'static)>
));

let registry = DeferredCallRegistry::new(db);
let registry = DeferredCallRegistry::new(db, DeferredCallsConfig::default());

let mut changes = DeferredCallRegistryChanges::default();

Expand Down
3 changes: 3 additions & 0 deletions massa-final-state/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This file defines a configuration structure containing all settings for final state management
use massa_async_pool::AsyncPoolConfig;
use massa_deferred_calls::config::DeferredCallsConfig;
use massa_executed_ops::{ExecutedDenunciationsConfig, ExecutedOpsConfig};
use massa_ledger_exports::LedgerConfig;
use massa_pos_exports::PoSConfig;
Expand All @@ -16,6 +17,8 @@ pub struct FinalStateConfig {
pub ledger_config: LedgerConfig,
/// asynchronous pool configuration
pub async_pool_config: AsyncPoolConfig,
/// config for deferred calls
pub deferred_calls_config: DeferredCallsConfig,
/// proof-of-stake configuration
pub pos_config: PoSConfig,
/// executed operations configuration
Expand Down
6 changes: 5 additions & 1 deletion massa-final-state/src/final_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ impl FinalState {
let executed_denunciations =
ExecutedDenunciations::new(config.executed_denunciations_config.clone(), db.clone());

let deferred_call_registry = DeferredCallRegistry::new(db.clone());
let deferred_call_registry =
DeferredCallRegistry::new(db.clone(), config.deferred_calls_config.clone());

let mut final_state = FinalState {
ledger,
Expand Down Expand Up @@ -939,6 +940,7 @@ mod test {
use std::str::FromStr;
use std::sync::Arc;

use massa_deferred_calls::config::DeferredCallsConfig;
use num::rational::Ratio;
use parking_lot::RwLock;
use tempfile::tempdir;
Expand Down Expand Up @@ -1008,9 +1010,11 @@ mod test {
keep_executed_history_extra_periods: KEEP_EXECUTED_HISTORY_EXTRA_PERIODS,
};

let deferred_calls_config = DeferredCallsConfig::default();
let final_state_config = FinalStateConfig {
ledger_config: ledger_config.clone(),
async_pool_config,
deferred_calls_config,
pos_config,
executed_ops_config,
executed_denunciations_config,
Expand Down
18 changes: 10 additions & 8 deletions massa-final-state/src/state_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use massa_async_pool::{
AsyncPoolChanges, AsyncPoolChangesDeserializer, AsyncPoolChangesSerializer,
};
use massa_deferred_calls::registry_changes::{
DeferredCallRegistryChanges, DeferredRegistryChangesDeserializer,
DeferredRegistryChangesSerializer,
use massa_deferred_calls::{
config::DeferredCallsConfig,
registry_changes::{
DeferredCallRegistryChanges, DeferredRegistryChangesDeserializer,
DeferredRegistryChangesSerializer,
},
};
use massa_executed_ops::{
ExecutedDenunciationsChanges, ExecutedDenunciationsChangesDeserializer,
Expand Down Expand Up @@ -129,7 +132,7 @@ impl StateChangesDeserializer {
max_ops_changes_length: u64,
endorsement_count: u32,
max_de_changes_length: u64,
max_deferred_call_pool_changes: u64,
deferred_calls_config: DeferredCallsConfig,
) -> Self {
Self {
ledger_changes_deserializer: LedgerChangesDeserializer::new(
Expand All @@ -147,9 +150,7 @@ impl StateChangesDeserializer {
),
// todo max gas
deferred_call_changes_deserializer: DeferredRegistryChangesDeserializer::new(
thread_count,
u64::MAX,
max_deferred_call_pool_changes,
deferred_calls_config,
),
pos_changes_deserializer: PoSChangesDeserializer::new(
thread_count,
Expand Down Expand Up @@ -251,6 +252,7 @@ mod test {
use std::str::FromStr;

use massa_async_pool::AsyncMessage;
use massa_deferred_calls::config::DeferredCallsConfig;
use massa_ledger_exports::{LedgerEntryUpdate, SetUpdateOrDelete};
use massa_models::amount::Amount;
use massa_models::bytecode::Bytecode;
Expand Down Expand Up @@ -340,7 +342,7 @@ mod test {
MAX_EXECUTED_OPS_CHANGES_LENGTH,
ENDORSEMENT_COUNT,
MAX_DENUNCIATION_CHANGES_LENGTH,
DEFERRED_CALL_MAX_POOL_CHANGES,
DeferredCallsConfig::default(),
)
.deserialize::<DeserializeError>(&serialized)
.unwrap();
Expand Down
5 changes: 2 additions & 3 deletions massa-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ dump-block = [
]
db_storage_backend = []
file_storage_backend = []
execution-info = [
"execution-trace"
]
execution-info = ["execution-trace"]

[dependencies]
crossbeam-channel = { workspace = true } # BOM UPGRADE Revert to "0.5.6" if problem
Expand All @@ -64,6 +62,7 @@ massa_bootstrap = { workspace = true }
massa_channel = { workspace = true }
massa_consensus_exports = { workspace = true }
massa_consensus_worker = { workspace = true }
massa_deferred_calls = { workspace = true }
massa_executed_ops = { workspace = true }
massa_execution_exports = { workspace = true }
massa_execution_worker = { workspace = true }
Expand Down
10 changes: 10 additions & 0 deletions massa-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use massa_consensus_exports::{
use massa_consensus_worker::start_consensus_worker;
use massa_db_exports::{MassaDBConfig, MassaDBController};
use massa_db_worker::MassaDB;
use massa_deferred_calls::config::DeferredCallsConfig;
use massa_executed_ops::{ExecutedDenunciationsConfig, ExecutedOpsConfig};
use massa_execution_exports::{
ExecutionChannels, ExecutionConfig, ExecutionManager, GasCosts, StorageCostsConstants,
Expand Down Expand Up @@ -190,9 +191,18 @@ async fn launch(
endorsement_count: ENDORSEMENT_COUNT,
keep_executed_history_extra_periods: KEEP_EXECUTED_HISTORY_EXTRA_PERIODS,
};
let deferred_calls_config = DeferredCallsConfig {
thread_count: THREAD_COUNT,
max_function_name_length: MAX_FUNCTION_NAME_LENGTH,
max_parameter_size: MAX_PARAMETERS_SIZE,
// TODO: set to a reasonable value
max_deferred_calls_pool_changes: 1000000,
max_gas: MAX_ASYNC_GAS,
};
let final_state_config = FinalStateConfig {
ledger_config: ledger_config.clone(),
async_pool_config,
deferred_calls_config,
pos_config,
executed_ops_config,
executed_denunciations_config,
Expand Down

0 comments on commit b53c77f

Please sign in to comment.