Skip to content

Commit

Permalink
refactor: rename function and clarify some comments after review
Browse files Browse the repository at this point in the history
- Rename function 'allow_unparsable_block' to 'compute_allow_unparsable_block' and clarify its comment
- Add reference to pre-production network in 'allow_unparsable_block' comments
  • Loading branch information
dlachaume committed Apr 19, 2024
1 parent 5d06859 commit 0b35797
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ inputs:
description: CExplorer url of the list of pools that is used by the mithril aggregator.
required: false
mithril_aggregator_allow_unparsable_block:
description: If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on production networks.
description: If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on (pre)production networks.
required: false
default: "false"
prometheus_auth_username:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Here is a list of the available parameters:
| `signed_entity_types` | `--signed-entity-types` | - | `SIGNED_ENTITY_TYPES` | Signed entity types parameters (discriminants names in an ordered comma separated list) | - | `MithrilStakeDistribution,CardanoImmutableFilesFull,CardanoStakeDistribution` | - |
| `snapshot_compression_algorithm` | `--snapshot-compression-algorithm` | - | `SNAPSHOT_COMPRESSION_ALGORITHM` | Compression algorithm of the snapshot archive | `zstandard` | `gzip` or `zstandard` | - |
| `zstandard_parameters` | - | - | `ZSTANDARD_PARAMETERS__LEVEL` and `ZSTANDARD_PARAMETERS__NUMBER_OF_WORKERS` | Zstandard specific parameters | - | `{ level: 9, number_of_workers: 4 }` | - |
| `allow_unparsable_block` | `--allow-unparsable-block` | - | `ALLOW_UNPARSABLE_BLOCK` | If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on production networks. | `false` | - | - |
| `allow_unparsable_block` | `--allow-unparsable-block` | - | `ALLOW_UNPARSABLE_BLOCK` | If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on (pre)production networks. | `false` | - | - |

`genesis bootstrap` command:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Options:
--allow-unparsable-block
If set no error is returned in case of unparsable block and an error log is written instead.

Will be ignored on production networks.
Will be ignored on (pre)production networks.

-h, --help
Print help (see a summary with '-h')
Expand Down Expand Up @@ -251,4 +251,4 @@ Here is a list of the available parameters:
| `enable_metrics_server` | `--enable-metrics-server` | - | `ENABLE_METRICS_SERVER` | Enable metrics HTTP server (Prometheus endpoint on /metrics) | `false` | - | - |
| `metrics_server_ip` | `--metrics-server-ip` | - | `METRICS_SERVER_IP` | Metrics HTTP server IP | `0.0.0.0` | - | - |
| `metrics_server_port` | `--metrics-server-port` | - | `METRICS_SERVER_PORT` | Metrics HTTP server listening port | `9090` | - | - |
| `allow_unparsable_block` | `--allow-unparsable-block` | - | `ALLOW_UNPARSABLE_BLOCK` | If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on production networks. | `false` | - | - |
| `allow_unparsable_block` | `--allow-unparsable-block` | - | `ALLOW_UNPARSABLE_BLOCK` | If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on (pre)production networks. | `false` | - | - |
2 changes: 1 addition & 1 deletion mithril-aggregator/src/commands/serve_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct ServeCommand {

/// If set no error is returned in case of unparsable block and an error log is written instead.
///
/// Will be ignored on production networks.
/// Will be ignored on (pre)production networks.
#[clap(long)]
allow_unparsable_block: bool,
}
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub struct Configuration {

/// If set no error is returned in case of unparsable block and an error log is written instead.
///
/// Will be ignored on production networks.
/// Will be ignored on (pre)production networks.
pub allow_unparsable_block: bool,
}

Expand Down Expand Up @@ -357,7 +357,7 @@ pub struct DefaultConfiguration {

/// If set no error is returned in case of unparsable block and an error log is written instead.
///
/// Will be ignored on production networks.
/// Will be ignored on (pre)production networks.
pub allow_unparsable_block: String,
}

Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ impl DependenciesBuilder {
self.get_logger().await?,
self.configuration
.get_network()?
.allow_unparsable_block(self.configuration.allow_unparsable_block)?,
.compute_allow_unparsable_block(self.configuration.allow_unparsable_block)?,
);

Ok(Arc::new(transaction_parser))
Expand Down
29 changes: 14 additions & 15 deletions mithril-common/src/entities/cardano_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ impl CardanoNetwork {
}
}

/// Evaluate the possibility of validating the request to allow unparsable block or not,
/// depending on the target Cardano network
pub fn allow_unparsable_block(&self, allow_unparsable_block: bool) -> StdResult<bool> {
/// Determines whether unparsable blocks should be allowed based on the specific Cardano network.
pub fn compute_allow_unparsable_block(&self, allow_unparsable_block: bool) -> StdResult<bool> {
let allow_unparsable_block = match self {
CardanoNetwork::MainNet => false,
CardanoNetwork::TestNet(id) if *id == PREPROD_MAGIC_ID => false,
Expand Down Expand Up @@ -160,22 +159,22 @@ mod tests {
#[test]
fn allow_unparsable_block_should_always_return_false_on_mainnet_and_preprod() {
let allow_unparsable_block = CardanoNetwork::MainNet
.allow_unparsable_block(false)
.compute_allow_unparsable_block(false)
.unwrap();
assert!(!allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::MainNet
.allow_unparsable_block(true)
.compute_allow_unparsable_block(true)
.unwrap();
assert!(!allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::TestNet(PREPROD_MAGIC_ID)
.allow_unparsable_block(false)
.compute_allow_unparsable_block(false)
.unwrap();
assert!(!allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::TestNet(PREPROD_MAGIC_ID)
.allow_unparsable_block(true)
.compute_allow_unparsable_block(true)
.unwrap();
assert!(!allow_unparsable_block);
}
Expand All @@ -184,42 +183,42 @@ mod tests {
fn allow_unparsable_block_should_return_value_passed_in_parameter_on_all_networks_other_than_mainnet_and_preprod(
) {
let allow_unparsable_block = CardanoNetwork::TestNet(PREVIEW_MAGIC_ID)
.allow_unparsable_block(false)
.compute_allow_unparsable_block(false)
.unwrap();
assert!(!allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::TestNet(PREVIEW_MAGIC_ID)
.allow_unparsable_block(true)
.compute_allow_unparsable_block(true)
.unwrap();
assert!(allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::TestNet(SANCHONET_MAGIC_ID)
.allow_unparsable_block(false)
.compute_allow_unparsable_block(false)
.unwrap();
assert!(!allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::TestNet(SANCHONET_MAGIC_ID)
.allow_unparsable_block(true)
.compute_allow_unparsable_block(true)
.unwrap();
assert!(allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::TestNet(TESTNET_MAGIC_ID)
.allow_unparsable_block(false)
.compute_allow_unparsable_block(false)
.unwrap();
assert!(!allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::TestNet(TESTNET_MAGIC_ID)
.allow_unparsable_block(true)
.compute_allow_unparsable_block(true)
.unwrap();
assert!(allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::DevNet(123)
.allow_unparsable_block(false)
.compute_allow_unparsable_block(false)
.unwrap();
assert!(!allow_unparsable_block);

let allow_unparsable_block = CardanoNetwork::DevNet(123)
.allow_unparsable_block(true)
.compute_allow_unparsable_block(true)
.unwrap();
assert!(allow_unparsable_block);
}
Expand Down
2 changes: 1 addition & 1 deletion mithril-infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ variable "mithril_aggregator_cexplorer_pools_url" {

variable "mithril_aggregator_allow_unparsable_block" {
type = bool
description = "If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on production networks."
description = "If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on (pre)production networks."
default = false
}

Expand Down
2 changes: 1 addition & 1 deletion mithril-signer/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub struct Configuration {

/// If set no error is returned in case of unparsable block and an error log is written instead.
///
/// Will be ignored on production networks.
/// Will be ignored on (pre)production networks.
pub allow_unparsable_block: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion mithril-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub struct Args {

/// If set no error is returned in case of unparsable block and an error log is written instead.
///
/// Will be ignored on production networks.
/// Will be ignored on (pre)production networks.
#[clap(long)]
allow_unparsable_block: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion mithril-signer/src/runtime/signer_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> {
slog_scope::logger(),
self.config
.get_network()?
.allow_unparsable_block(self.config.allow_unparsable_block)?,
.compute_allow_unparsable_block(self.config.allow_unparsable_block)?,
));
let transaction_store = Arc::new(CardanoTransactionRepository::new(
transaction_sqlite_connection,
Expand Down

0 comments on commit 0b35797

Please sign in to comment.