Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,39 @@ jobs:
next_era: [""]
cardano_node_version: ["10.4.1", "10.5.1"]
hard_fork_latest_era_at_epoch: [0]
run_id: ["#1", "#2", "#3"]
extra_args: ["--aggregate-signature-type=Concatenation"]
run_id:
[
"#1",
"#2",
"#3",
"#4",
"#5",
"#6",
"#7",
"#8",
"#9",
"#10",
"#11",
"#12",
"#13",
"#14",
"#15",
"#16",
"#17",
"#18",
"#19",
"#20",
"#21",
"#22",
"#23",
"#24",
"#25",
]
extra_args:
[
"--aggregate-signature-type=Concatenation",
"--number-of-aggregators=2 --use-relays --relay-signer-registration-mode=passthrough --relay-signature-registration-mode=p2p --aggregate-signature-type=Concatenation",
]

include:
# Include a test for partial decentralization with leader/follower signer registration and P2P signature registration
Expand Down
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.

1 change: 1 addition & 0 deletions mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mithril-doc = { path = "../internal/mithril-doc" }
mithril-era = { path = "../internal/mithril-era" }
mithril-metric = { path = "../internal/mithril-metric" }
mithril-persistence = { path = "../internal/mithril-persistence" }
mithril-protocol-config = { path = "../internal/mithril-protocol-config" }
mithril-resource-pool = { path = "../internal/mithril-resource-pool" }
mithril-signed-entity-lock = { path = "../internal/signed-entity/mithril-signed-entity-lock" }
mithril-signed-entity-preloader = { path = "../internal/signed-entity/mithril-signed-entity-preloader" }
Expand Down
61 changes: 44 additions & 17 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub trait ConfigurationSource {
}

/// Protocol parameters
fn protocol_parameters(&self) -> ProtocolParameters {
fn protocol_parameters(&self) -> Option<ProtocolParameters> {
panic!("protocol_parameters is not implemented.");
}

Expand Down Expand Up @@ -251,10 +251,15 @@ pub trait ConfigurationSource {
}

/// Cardano transactions signing configuration
fn cardano_transactions_signing_config(&self) -> CardanoTransactionsSigningConfig {
fn cardano_transactions_signing_config(&self) -> Option<CardanoTransactionsSigningConfig> {
panic!("cardano_transactions_signing_config is not implemented.");
}

/// Blocks offset, from the tip of the chain, to exclude during the cardano transactions preload
fn preload_security_parameter(&self) -> BlockNumber {
panic!("preload_security_parameter is not implemented.");
}

/// Maximum number of transactions hashes allowed by request to the prover of the Cardano transactions
fn cardano_transactions_prover_max_hashes_allowed_by_request(&self) -> usize {
panic!("cardano_transactions_prover_max_hashes_allowed_by_request is not implemented.");
Expand Down Expand Up @@ -373,12 +378,20 @@ pub trait ConfigurationSource {
}
}

/// Infer the [AggregatorEpochSettings] from the configuration.
fn get_epoch_settings_configuration(&self) -> AggregatorEpochSettings {
AggregatorEpochSettings {
protocol_parameters: self.protocol_parameters(),
cardano_transactions_signing_config: self.cardano_transactions_signing_config(),
}
/// `leader aggregator only` Infer the [AggregatorEpochSettings] from the configuration.
fn get_leader_aggregator_epoch_settings_configuration(
&self,
) -> StdResult<AggregatorEpochSettings> {
Ok(AggregatorEpochSettings {
protocol_parameters: self.protocol_parameters().with_context(
|| "Configuration `protocol_parameter` is mandatory for a Leader Aggregator",
)?,
cardano_transactions_signing_config: self
.cardano_transactions_signing_config()
.with_context(
|| "Configuration `cardano_transactions_signing_config` is mandatory for a Leader Aggregator",
)?,
})
}

/// Check if the aggregator is running in follower mode.
Expand Down Expand Up @@ -453,7 +466,7 @@ pub struct ServeCommandConfiguration {

/// Protocol parameters
#[example = "`{ k: 5, m: 100, phi_f: 0.65 }`"]
pub protocol_parameters: ProtocolParameters,
pub protocol_parameters: Option<ProtocolParameters>,

/// Type of snapshot uploader to use
#[example = "`gcp` or `local`"]
Expand Down Expand Up @@ -556,7 +569,11 @@ pub struct ServeCommandConfiguration {

/// Cardano transactions signing configuration
#[example = "`{ security_parameter: 3000, step: 120 }`"]
pub cardano_transactions_signing_config: CardanoTransactionsSigningConfig,
pub cardano_transactions_signing_config: Option<CardanoTransactionsSigningConfig>,

/// Blocks offset, from the tip of the chain, to exclude during the cardano transactions preload
/// `[default: 2160]`.
pub preload_security_parameter: BlockNumber,

/// Maximum number of transactions hashes allowed by request to the prover of the Cardano transactions
pub cardano_transactions_prover_max_hashes_allowed_by_request: usize,
Expand Down Expand Up @@ -672,11 +689,11 @@ impl ServeCommandConfiguration {
network_magic: Some(42),
dmq_network_magic: Some(3141592),
chain_observer_type: ChainObserverType::Fake,
protocol_parameters: ProtocolParameters {
protocol_parameters: Some(ProtocolParameters {
k: 5,
m: 100,
phi_f: 0.95,
},
}),
snapshot_uploader_type: SnapshotUploaderType::Local,
snapshot_bucket_name: None,
snapshot_use_cdn_domain: false,
Expand Down Expand Up @@ -710,10 +727,11 @@ impl ServeCommandConfiguration {
allow_unparsable_block: false,
cardano_transactions_prover_cache_pool_size: 3,
cardano_transactions_database_connection_pool_size: 5,
cardano_transactions_signing_config: CardanoTransactionsSigningConfig {
cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(120),
step: BlockNumber(15),
},
}),
preload_security_parameter: BlockNumber(30),
cardano_transactions_prover_max_hashes_allowed_by_request: 100,
cardano_transactions_block_streamer_max_roll_forwards_per_poll: 1000,
enable_metrics_server: true,
Expand Down Expand Up @@ -773,7 +791,7 @@ impl ConfigurationSource for ServeCommandConfiguration {
self.chain_observer_type.clone()
}

fn protocol_parameters(&self) -> ProtocolParameters {
fn protocol_parameters(&self) -> Option<ProtocolParameters> {
self.protocol_parameters.clone()
}

Expand Down Expand Up @@ -877,10 +895,14 @@ impl ConfigurationSource for ServeCommandConfiguration {
self.cardano_transactions_database_connection_pool_size
}

fn cardano_transactions_signing_config(&self) -> CardanoTransactionsSigningConfig {
fn cardano_transactions_signing_config(&self) -> Option<CardanoTransactionsSigningConfig> {
self.cardano_transactions_signing_config.clone()
}

fn preload_security_parameter(&self) -> BlockNumber {
self.preload_security_parameter
}

fn cardano_transactions_prover_max_hashes_allowed_by_request(&self) -> usize {
self.cardano_transactions_prover_max_hashes_allowed_by_request
}
Expand Down Expand Up @@ -981,6 +1003,9 @@ pub struct DefaultConfiguration {
/// Cardano transactions signing configuration
pub cardano_transactions_signing_config: CardanoTransactionsSigningConfig,

/// Blocks offset, from the tip of the chain, to exclude during the cardano transactions preload
pub preload_security_parameter: u64,

/// Maximum number of transactions hashes allowed by request to the prover of the Cardano transactions
pub cardano_transactions_prover_max_hashes_allowed_by_request: u32,

Expand Down Expand Up @@ -1026,6 +1051,7 @@ impl Default for DefaultConfiguration {
security_parameter: BlockNumber(3000),
step: BlockNumber(120),
},
preload_security_parameter: 2160,
cardano_transactions_prover_max_hashes_allowed_by_request: 100,
cardano_transactions_block_streamer_max_roll_forwards_per_poll: 10000,
enable_metrics_server: "false".to_string(),
Expand Down Expand Up @@ -1104,14 +1130,15 @@ impl Source for DefaultConfiguration {
&namespace,
myself.persist_usage_report_interval_in_seconds
);
register_config_value!(result, &namespace, myself.preload_security_parameter);
register_config_value!(
result,
&namespace,
myself.cardano_transactions_signing_config,
|v: CardanoTransactionsSigningConfig| HashMap::from([
(
"security_parameter".to_string(),
ValueKind::from(*v.security_parameter,),
ValueKind::from(*v.security_parameter),
),
("step".to_string(), ValueKind::from(*v.step),)
])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use sqlite::Value;

use mithril_persistence::sqlite::{Query, SourceAlias, SqLiteEntity, WhereCondition};

use crate::database::record::EpochSettingsRecord;

/// Query to update [EpochSettingsRecord] in the sqlite database
pub struct InsertOrIgnoreEpochSettingsQuery {
condition: WhereCondition,
}

impl InsertOrIgnoreEpochSettingsQuery {
pub fn one(epoch_settings: EpochSettingsRecord) -> Self {
Self {
condition: WhereCondition::new(
"(epoch_setting_id, protocol_parameters, cardano_transactions_signing_config) values (?1, ?2, ?3)",
vec![
Value::Integer(*epoch_settings.epoch_settings_id as i64),
Value::String(
serde_json::to_string(&epoch_settings.protocol_parameters).unwrap(),
),
Value::String(
serde_json::to_string(&epoch_settings.cardano_transactions_signing_config)
.unwrap(),
),
],
),
}
}
}

impl Query for InsertOrIgnoreEpochSettingsQuery {
type Entity = EpochSettingsRecord;

fn filters(&self) -> WhereCondition {
self.condition.clone()
}

fn get_definition(&self, condition: &str) -> String {
// it is important to alias the fields with the same name as the table
// since the table cannot be aliased in a RETURNING statement in SQLite.
let projection = Self::Entity::get_projection()
.expand(SourceAlias::new(&[("{:epoch_setting:}", "epoch_setting")]));

format!("insert or ignore into epoch_setting {condition} returning {projection}")
}
}

#[cfg(test)]
mod tests {
use mithril_common::entities::{BlockNumber, CardanoTransactionsSigningConfig, Epoch};
use mithril_common::test::double::fake_data;
use mithril_persistence::sqlite::ConnectionExtensions;

use crate::database::query::GetEpochSettingsQuery;
use crate::database::test_helper::main_db_connection;

use super::*;

#[test]
fn test_insert_epoch_setting_in_empty_db() {
let connection = main_db_connection().unwrap();

let expected_epoch_settings = EpochSettingsRecord {
epoch_settings_id: Epoch(3),
protocol_parameters: fake_data::protocol_parameters(),
cardano_transactions_signing_config: CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(24),
step: BlockNumber(62),
},
};
let record = connection
.fetch_first(InsertOrIgnoreEpochSettingsQuery::one(
expected_epoch_settings.clone(),
))
.unwrap();

assert_eq!(Some(expected_epoch_settings), record);
}

#[test]
fn test_cant_replace_existing_value() {
let connection = main_db_connection().unwrap();

let expected_epoch_settings = EpochSettingsRecord {
epoch_settings_id: Epoch(3),
protocol_parameters: fake_data::protocol_parameters(),
cardano_transactions_signing_config: CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(24),
step: BlockNumber(62),
},
};
let record = connection
.fetch_first(InsertOrIgnoreEpochSettingsQuery::one(
expected_epoch_settings.clone(),
))
.unwrap();
assert!(record.is_some());

let record = connection
.fetch_first(InsertOrIgnoreEpochSettingsQuery::one(EpochSettingsRecord {
cardano_transactions_signing_config: CardanoTransactionsSigningConfig {
security_parameter: BlockNumber(134),
step: BlockNumber(872),
},
..expected_epoch_settings.clone()
}))
.unwrap();
assert!(record.is_none());

let record_in_db = connection
.fetch_first(GetEpochSettingsQuery::by_epoch(Epoch(3)).unwrap())
.unwrap();
assert_eq!(Some(expected_epoch_settings), record_in_db);
}
}
4 changes: 2 additions & 2 deletions mithril-aggregator/src/database/query/epoch_settings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod delete_epoch_settings;
mod get_epoch_settings;
mod update_epoch_settings;
mod insert_or_ignore_epoch_settings;

pub use delete_epoch_settings::*;
pub use get_epoch_settings::*;
pub use update_epoch_settings::*;
pub use insert_or_ignore_epoch_settings::*;
Loading
Loading