-
Notifications
You must be signed in to change notification settings - Fork 52
Implement chain adapter to read on chain protocol configurations #3482
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
Merged
turmelclem
merged 19 commits into
main
from
ctl/3393-implement-chain-adapater-to-read-on-chain-protocol-configurations-2
Aug 27, 2026
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
098e3ea
feature(protocol-config): Implement on-chain reader for protocol conf…
turmelclem 8126da9
refactor(protocol-config): moving mechanism checking configuration co…
turmelclem 5bacf4c
feature(protocol-config): add markers implementation of MithrilNetwor…
turmelclem 37a4768
feature(protocol-config): Implement a protocol configuration builder
turmelclem 5b63d91
feature(signer): Wiring MarkersMithrilNetworkConfigurationProvider
turmelclem b33e27c
feature(aggregator, protocol-config): Wiring MarkersMithrilNetworkCon…
turmelclem 6f656e9
refactor(aggregator): refactor usage of parameters for protocol-confi…
turmelclem ad58e5f
refactor(signer): make protocol_configuration_reader_adapter_config o…
turmelclem e9c5825
refactor(aggregator): Make aggregator follower use on-chain protocol …
turmelclem 1733474
refactor(end-to-end): improve environement variables mecanism
turmelclem bc99845
refactor(end-to-end): use a dedicated protocol configuration reader a…
turmelclem 9d6e9b9
refactor(protocol-config, aggregator, e2e): improve FakeConfig with c…
turmelclem 65e41db
refactor(protocol-config): simplify SignedProtocolConfigurationMarker…
turmelclem cc7d95c
feature(ci): add a e2e test running signer with HTTP adapter for prot…
turmelclem ec4a623
refactor(end-to-end): mutualize cardano chain command for funds and d…
turmelclem c9d10f1
refactor(aggregator): make protocol_configuration_reader_adapter_conf…
turmelclem 3005ee4
refactor(cardano-node-chain): ensure a deterministic order when retri…
turmelclem 4fbf349
docs: update changelog
turmelclem f9f5aac
chore: upgrade crate versions and `mithril-test-lab/cardano-devnet/VE…
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
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
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
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
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
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,157 @@ | ||
| //! Builder for creating a ProtocolConfigurationMarkersReader based on AdapterConfig. | ||
|
|
||
| use std::{str::FromStr, sync::Arc}; | ||
|
|
||
| use serde::Deserialize; | ||
|
|
||
| use mithril_cardano_node_chain::{chain_observer::ChainObserver, entities::ChainAddress}; | ||
| use mithril_common::{ | ||
| crypto_helper::ProtocolConfigurationMarkersVerifierVerificationKey, | ||
| entities::ProtocolParameters, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| cardano_chain::protocol_configuration_reader::CardanoChainProtocolConfigurationMarkersReader, | ||
| interface::ProtocolConfigurationMarkersReader, | ||
| test::double::FakeProtocolConfigurationMarkersReader, | ||
| }; | ||
|
|
||
| /// Configuration of Protocol Configuration Adapter | ||
| #[derive(Debug, Clone, Deserialize, PartialEq)] | ||
| #[serde(rename_all = "kebab-case", tag = "type")] | ||
| pub enum AdapterConfig { | ||
| /// Cardano chain protocol configuration adapter | ||
| CardanoChain { | ||
| /// Cardano chain address | ||
| address: ChainAddress, | ||
|
|
||
| /// Verification key | ||
| verification_key: Box<ProtocolConfigurationMarkersVerifierVerificationKey>, | ||
| }, | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| /// Fake protocol configuration adapter with given protocol parameters and default value, at epoch 0 (for test usage) | ||
| Fake { | ||
| /// Protocol parameters | ||
| protocol_parameters: ProtocolParameters, | ||
| }, | ||
| } | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| impl FromStr for AdapterConfig { | ||
| type Err = serde_json::Error; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| serde_json::from_str(s) | ||
| } | ||
| } | ||
|
|
||
| /// Build a ProtocolConfigurationMarkersReader from configuration settings. | ||
| pub fn build_protocol_configuration_adapter( | ||
| adapter_config: AdapterConfig, | ||
| chain_observer: Arc<dyn ChainObserver>, | ||
| ) -> Arc<dyn ProtocolConfigurationMarkersReader> { | ||
| match adapter_config { | ||
| AdapterConfig::CardanoChain { | ||
| address, | ||
| verification_key, | ||
| } => Arc::new(CardanoChainProtocolConfigurationMarkersReader::new( | ||
| address, | ||
| chain_observer, | ||
| *verification_key, | ||
| )), | ||
| AdapterConfig::Fake { | ||
| protocol_parameters, | ||
| } => Arc::new( | ||
| FakeProtocolConfigurationMarkersReader::default_with_protocol_parameters( | ||
| protocol_parameters, | ||
| ), | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod test { | ||
|
|
||
| use super::*; | ||
|
|
||
| static VERIFICATION_KEY: &str = "5b35352c3232382c3134342c38372c3133382c3133362c34382c382c31342c3138372c38352c3134382c39372c3233322c3235352c3232392c33382c3234342c3234372c3230342c3139382c31332c33312c3232322c32352c3136342c35322c3130322c39312c3132302c3230382c3134375d"; | ||
|
|
||
| #[test] | ||
| fn deserialize_cardano_chain_adapter_config_from_json() { | ||
| let serialized_json = serde_json::json!({ | ||
| "type": "cardano-chain", | ||
| "address": "my_address", | ||
| "verification_key": VERIFICATION_KEY, | ||
| }); | ||
|
|
||
| let payload = serde_json::to_string(&serialized_json).unwrap(); | ||
| let deserialized: AdapterConfig = serde_json::from_str(&payload).unwrap(); | ||
|
|
||
| assert_eq!( | ||
| deserialized, | ||
| AdapterConfig::CardanoChain { | ||
| address: "my_address".to_string(), | ||
| verification_key: Box::new(VERIFICATION_KEY.try_into().expect("should not fail")) | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn deserialize_fake_adapter_config_from_json() { | ||
| let serialized_json = serde_json::json!({ | ||
| "type": "fake", | ||
| "protocol_parameters": { | ||
| "k": 1944, | ||
| "m": 16948, | ||
| "phi_f": 0.2 | ||
| }, | ||
| }); | ||
|
|
||
| let payload = serde_json::to_string(&serialized_json).unwrap(); | ||
| let deserialized: AdapterConfig = serde_json::from_str(&payload).unwrap(); | ||
|
|
||
| assert_eq!( | ||
| deserialized, | ||
| AdapterConfig::Fake { | ||
| protocol_parameters: ProtocolParameters { | ||
| k: 1944, | ||
| m: 16948, | ||
| phi_f: 0.2 | ||
| } | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn rejects_adapter_config_with_invalid_verification_key() { | ||
| let invalid_verification_key = "invalid_verification_key"; | ||
|
|
||
| let serialized_json = serde_json::json!({ | ||
| "type": "cardano-chain", | ||
| "address": "my_address", | ||
| "verification_key": invalid_verification_key, | ||
| }); | ||
|
|
||
| let payload = serde_json::to_string(&serialized_json).unwrap(); | ||
| let result = serde_json::from_str::<AdapterConfig>(&payload); | ||
| assert!(result.is_err()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn rejects_adapter_config_with_unknown_type() { | ||
| let serialized_json = serde_json::json!({ | ||
| "type": "invalid-type", | ||
| "address": "A", | ||
| "verification_key": "B", | ||
| }); | ||
|
|
||
| let payload = serde_json::to_string(&serialized_json).unwrap(); | ||
| let result = serde_json::from_str::<AdapterConfig>(&payload); | ||
| assert!(result.is_err()); | ||
| assert!( | ||
| result | ||
| .unwrap_err() | ||
| .to_string() | ||
| .contains("unknown variant `invalid-type`") | ||
| ); | ||
| } | ||
| } | ||
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.