-
Notifications
You must be signed in to change notification settings - Fork 52
Add aggregator CLI commands for configuration parameters #3438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
turmelclem
wants to merge
19
commits into
main
Choose a base branch
from
ctl/3392-add-aggregator-CLI-command-for-configuration-parameters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,317
−18
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4e82e00
feature(aggregator): init new import/export commands for protocol con…
turmelclem ec93e25
feature(aggregator, protocol-config, common): implementing CBOR conve…
turmelclem 730b7c4
feature(protocol-config, aggregator): introduce a Signed payload stru…
turmelclem 7e4440d
feature(protocol-config): implement a dummy protocol configuration ad…
turmelclem 03af381
feature(protocol-config): init protocol configuration builder, and a …
turmelclem ea9a8fb
feature(aggregator): implement dependency injection for ProtocolConfi…
turmelclem ab0a1c7
feature(protocol-config): implement a ConfigurationComputerFromMarker…
turmelclem 0654986
feature(aggregator, common): implementing verification between user i…
turmelclem 57fb6e5
feature(protocol-config, aggregator): use ciborium encoding/decoding for
turmelclem 18165d7
feature(common, aggregator): check protocol parameters and configurat…
turmelclem 2845a30
feature(aggregator): wiring on chain verification and datum size veri…
turmelclem 65bc61b
feature(aggregator, protocol-config): cleanning builder adapter mecan…
turmelclem b343558
feature(protocol-config, aggregator): simplify PrototolConfigurationR…
turmelclem c13a4a7
refactor: move ciborium to workspace dependencies
turmelclem 7182d4a
feature(aggregator): implement export protocol configurations command
turmelclem 7141c8e
feature(aggregagor): add a default option for the export markers command
turmelclem 4ca0494
refactor: rename ConfigurationComputerFromMarkers to ConfigurationRes…
turmelclem a4b4cb9
refactor(protocol-config): remove unused Deserialize, Serialize from …
turmelclem a134e72
refactor(aggregator) move HumanReadableProtocolConfiguration into tools
turmelclem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 223 additions & 0 deletions
223
internal/mithril-protocol-config/src/cardano_chain/message.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| //! Messages representing Protocol Configurations converted into CBOR HEX format, for Cardano chain datum | ||
|
|
||
| use anyhow::Context; | ||
| use fixed::types::U8F24; | ||
| use hex::FromHex; | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::collections::BTreeSet; | ||
| use thiserror::Error; | ||
|
|
||
| use mithril_common::{ | ||
| StdError, | ||
| entities::{ | ||
| BlockNumber, BlockNumberOffset, CardanoBlocksTransactionsSigningConfig, | ||
| CardanoTransactionsSigningConfig, Epoch, ProtocolParameters, | ||
| }, | ||
| messages::SignedEntityTypeDiscriminantsMessage, | ||
| }; | ||
|
|
||
| /// The CBOR HEX representation of a [ProtocolConfigurationForEpochMessage] | ||
| pub type CborHexProtocolConfigurationForEpochMessage = String; | ||
|
|
||
| /// Value object that represents a tag of Protocol Configuration. | ||
| #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
| pub struct ProtocolConfigurationMarker { | ||
| /// Epoch | ||
| pub epoch: Epoch, | ||
|
|
||
| /// Protocol parameters | ||
| pub configuration: CborHexProtocolConfigurationForEpochMessage, | ||
| } | ||
|
|
||
| impl ProtocolConfigurationMarker { | ||
| /// instantiate a new [ProtocolConfigurationMarker]. | ||
| pub fn new( | ||
| epoch: Epoch, | ||
| protocol_configuration: CborHexProtocolConfigurationForEpochMessage, | ||
| ) -> Self { | ||
| ProtocolConfigurationMarker { | ||
| epoch, | ||
| configuration: protocol_configuration, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Parse error | ||
| #[derive(Error, Debug)] | ||
| #[error("Codec parse error")] | ||
| pub struct ProtocolConfigurationForEpochMessageParseError(#[source] StdError); | ||
|
|
||
| /// Protocol cryptographic parameters Message | ||
| /// | ||
| /// used for the CBOR HEX representation of [ProtocolConfigurationForEpochMessage] | ||
| #[derive(Clone, Debug, Serialize, Deserialize)] | ||
| pub struct ProtocolParametersMessage { | ||
| /// Quorum parameter | ||
| pub k: u64, | ||
|
|
||
| /// Security parameter (number of lotteries) | ||
| pub m: u64, | ||
|
|
||
| /// f in phi(w) = 1 - (1 - f)^w, where w is the stake of a participant | ||
| pub phi_f: f64, | ||
| } | ||
|
|
||
| impl ProtocolParametersMessage { | ||
| /// phi_f_fixed is a fixed decimal representation of phi_f | ||
| /// used for PartialEq and Hash implementation | ||
| pub fn phi_f_fixed(&self) -> U8F24 { | ||
| U8F24::from_num(self.phi_f) | ||
| } | ||
| } | ||
|
|
||
| impl PartialEq<ProtocolParametersMessage> for ProtocolParametersMessage { | ||
| fn eq(&self, other: &ProtocolParametersMessage) -> bool { | ||
| self.k == other.k && self.m == other.m && self.phi_f_fixed() == other.phi_f_fixed() | ||
| } | ||
| } | ||
|
|
||
| impl From<ProtocolParameters> for ProtocolParametersMessage { | ||
| fn from(params: ProtocolParameters) -> Self { | ||
| ProtocolParametersMessage { | ||
| k: params.k, | ||
| m: params.m, | ||
| phi_f: params.phi_f, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Configuration for the signing of Cardano transactions | ||
| /// | ||
| /// used for the CBOR HEX representation of [ProtocolConfigurationForEpochMessage] | ||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct CardanoTransactionsSigningConfigMessage { | ||
| /// Number of blocks to discard from the tip of the chain when importing transactions. | ||
| pub security_parameter: BlockNumberOffset, | ||
|
|
||
| /// The number of blocks between signature of the transactions. | ||
| pub step: BlockNumber, | ||
| } | ||
|
|
||
| impl From<CardanoTransactionsSigningConfig> for CardanoTransactionsSigningConfigMessage { | ||
| fn from(config: CardanoTransactionsSigningConfig) -> Self { | ||
| CardanoTransactionsSigningConfigMessage { | ||
| security_parameter: config.security_parameter, | ||
| step: config.step, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Configuration for the signing of Cardano blocks and transactions | ||
| /// | ||
| /// used for the CBOR HEX representation of [ProtocolConfigurationForEpochMessage] | ||
| #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] | ||
| pub struct CardanoBlocksTransactionsSigningConfigMessage { | ||
| /// Number of blocks to discard from the tip of the chain when importing blocks and transactions. | ||
| pub security_parameter: BlockNumberOffset, | ||
|
|
||
| /// The number of blocks between signature of the blocks and transactions. | ||
| pub step: BlockNumber, | ||
| } | ||
|
|
||
| impl From<CardanoBlocksTransactionsSigningConfig> | ||
| for CardanoBlocksTransactionsSigningConfigMessage | ||
| { | ||
| fn from(config: CardanoBlocksTransactionsSigningConfig) -> Self { | ||
| CardanoBlocksTransactionsSigningConfigMessage { | ||
| security_parameter: config.security_parameter, | ||
| step: config.step, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //A epoch configuration used for the CBOR HEX representation in the [ProtocolConfigurationMarker] | ||
| #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] | ||
| /// A network configuration available for an epoch | ||
| pub struct ProtocolConfigurationForEpochMessage { | ||
| /// Cryptographic protocol parameters (`k`, `m` and `phi_f`) | ||
| pub protocol_parameters: ProtocolParametersMessage, | ||
|
|
||
| /// List of available types of certifications | ||
| pub enabled_signed_entity_types: BTreeSet<SignedEntityTypeDiscriminantsMessage>, | ||
|
|
||
| /// Signing configuration for Cardano transactions | ||
| pub cardano_transactions: Option<CardanoTransactionsSigningConfigMessage>, | ||
|
|
||
| /// Signing configuration for Cardano blocks and transactions | ||
| pub cardano_blocks_transactions: Option<CardanoBlocksTransactionsSigningConfigMessage>, | ||
| } | ||
|
|
||
| impl ProtocolConfigurationForEpochMessage { | ||
| /// Serialize the structure to a CBOR bytes representation. | ||
| fn to_cbor_bytes(&self) -> Result<Vec<u8>, ProtocolConfigurationForEpochMessageParseError> { | ||
| let mut cursor = std::io::Cursor::new(Vec::new()); | ||
| ciborium::ser::into_writer(&self, &mut cursor) | ||
| .with_context(|| "ProtocolConfigurationForEpoch can not serialize data to cbor") | ||
| .map_err(ProtocolConfigurationForEpochMessageParseError)?; | ||
|
|
||
| Ok(cursor.into_inner()) | ||
| } | ||
|
|
||
| /// Serialize the structure to a CBOR HEX representation. | ||
| pub fn to_cbor_hex(&self) -> Result<String, ProtocolConfigurationForEpochMessageParseError> { | ||
| Ok(hex::encode(self.to_cbor_bytes()?)) | ||
| } | ||
|
|
||
| /// Deserialize a ProtocolConfigurationForEpochMessage from CBOR bytes representation. | ||
| fn from_cbor_bytes( | ||
| bytes: &[u8], | ||
| ) -> Result<Self, ProtocolConfigurationForEpochMessageParseError> { | ||
| let mut cursor = std::io::Cursor::new(&bytes); | ||
| let a: Self = ciborium::de::from_reader(&mut cursor) | ||
| .with_context(|| "ProtocolConfigurationForEpoch can not unserialize cbor data") | ||
| .map_err(ProtocolConfigurationForEpochMessageParseError)?; | ||
|
|
||
| Ok(a) | ||
| } | ||
|
|
||
| /// Deserialize a ProtocolConfigurationForEpochMessage from CBOR HEX representation. | ||
| pub fn from_cbor_hex( | ||
| hex: &str, | ||
| ) -> Result<Self, ProtocolConfigurationForEpochMessageParseError> { | ||
| let hex_vector = Vec::from_hex(hex) | ||
| .with_context(|| "ProtocolConfigurationForEpochMessage can not unserialize HEX data") | ||
| .map_err(ProtocolConfigurationForEpochMessageParseError)?; | ||
|
|
||
| Self::from_cbor_bytes(&hex_vector) | ||
| .with_context(|| "ProtocolConfigurationForEpochMessage can not unserialize CBOR data") | ||
| .map_err(ProtocolConfigurationForEpochMessageParseError) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use mithril_common::test::double::Dummy; | ||
|
|
||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn golden_master_cbor_hex_conversion() { | ||
| const EXPECTED_JSON_HEX: &str = "a47370726f746f636f6c5f706172616d6574657273a3616b01616d02657068695f66fb3fd3333333333333781b656e61626c65645f7369676e65645f656e746974795f74797065738578184d69746872696c5374616b65446973747269627574696f6e781843617264616e6f5374616b65446973747269627574696f6e6f43617264616e6f44617461626173657343617264616e6f5472616e73616374696f6e73781943617264616e6f426c6f636b735472616e73616374696f6e737463617264616e6f5f7472616e73616374696f6e73a27273656375726974795f706172616d657465720a647374657005781b63617264616e6f5f626c6f636b735f7472616e73616374696f6e73a27273656375726974795f706172616d657465720b647374657007"; | ||
|
|
||
| let mithril_network_configuration_for_epoch = ProtocolConfigurationForEpochMessage::dummy(); | ||
| let mithril_network_configuration_for_epoch_from_cbor_hex = | ||
| ProtocolConfigurationForEpochMessage::from_cbor_hex(EXPECTED_JSON_HEX).unwrap(); | ||
|
|
||
| assert_eq!( | ||
| mithril_network_configuration_for_epoch, | ||
| mithril_network_configuration_for_epoch_from_cbor_hex | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn to_cbor_hex_from_cbor_hex_conversion() { | ||
| let mithril_network_configuration_for_epoch = ProtocolConfigurationForEpochMessage::dummy(); | ||
| let cbor_hex = mithril_network_configuration_for_epoch.to_cbor_hex().unwrap(); | ||
| let mithril_network_configuration_for_epoch_from_cbor_hex = | ||
| ProtocolConfigurationForEpochMessage::from_cbor_hex(&cbor_hex).unwrap(); | ||
| assert_eq!( | ||
| mithril_network_configuration_for_epoch, | ||
| mithril_network_configuration_for_epoch_from_cbor_hex | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| //! Cardano Chain module to read protocol configuration markers | ||
| pub mod message; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| pub mod payload; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| pub mod protocol_configuration_reader; | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| pub use payload::{ | ||
| ProtocolConfigurationMarkersPayload as ProtocolConfigurationMarkersPayloadCardanoChain, | ||
| SignedProtocolConfigurationMarkersPayload as SignedProtocolConfigurationMarkersPayloadCardanoChain, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.