From 7ef5b3cfacce1507a9976e9362652ff3272d93aa Mon Sep 17 00:00:00 2001 From: Ayush Mishra Date: Tue, 2 Jul 2024 21:13:51 +0530 Subject: [PATCH] Fix Era activity issue (#383) ## Description ## Types of Changes Please select the branch type you are merging and fill in the relevant template. - [ ] Hotfix - [ ] Release - [ ] Fix or Feature ## Fix or Feature ### Types of Changes - [ ] Tech Debt (Code improvements) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Dependency upgrade (A change in substrate or any 3rd party crate version) ### Migrations and Hooks - [ ] This change requires a runtime migration. - [ ] Modifies `on_initialize` - [ ] Modifies `on_finalize` ### Checklist for Fix or Feature - [ ] Change has been tested locally. - [ ] Change adds / updates tests if applicable. - [ ] Changelog doc updated. - [ ] `spec_version` has been incremented. - [ ] `network-relayer`'s [events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go) have been updated according to the blockchain events if applicable. - [ ] All CI checks have been passed successfully ## Checklist for Hotfix - [ ] Changelog has been updated. - [ ] Crate version has been updated. - [ ] `spec_version` has been incremented. - [ ] Transaction version has been updated if required. - [ ] Pull Request to `dev` has been created. - [ ] Pull Request to `staging` has been created. - [ ] `network-relayer`'s [events](https://github.com/Cerebellum-Network/network-relayer/blob/dev-cere/shared/substrate/events.go) have been updated according to the blockchain events if applicable. - [ ] All CI checks have been passed successfully ## Checklist for Release - [ ] Change has been deployed to Devnet. - [ ] Change has been tested in Devnet. - [ ] Change has been deployed to Qanet. - [ ] Change has been tested in Qanet. - [ ] Change has been deployed to Testnet. - [ ] Change has been tested in Testnet. - [ ] Changelog has been updated. - [ ] Crate version has been updated. - [ ] Spec version has been updated. - [ ] Transaction version has been updated if required. - [ ] All CI checks have been passed successfully --- pallets/ddc-verification/src/lib.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/pallets/ddc-verification/src/lib.rs b/pallets/ddc-verification/src/lib.rs index b64c977e5..f5d24596e 100644 --- a/pallets/ddc-verification/src/lib.rs +++ b/pallets/ddc-verification/src/lib.rs @@ -968,7 +968,7 @@ pub mod pallet { impl Pallet { pub(crate) fn process_dac_data( cluster_id: &ClusterId, - era_id_to_process: Option, + era_id_to_process: Option, dac_nodes: &[(NodePubKey, StorageNodeParams)], min_nodes: u16, batch_size: usize, @@ -978,8 +978,12 @@ pub mod pallet { return Err(vec![OCWError::NotEnoughDACNodes { num_nodes: min_nodes }]); } - let era_activity = if let Some(era_id) = era_id_to_process { - EraActivity { id: era_id, start: Default::default(), end: Default::default() } + let era_activity = if let Some(era_activity) = era_id_to_process { + EraActivity { + id: era_activity.id, + start: era_activity.start, + end: era_activity.end, + } } else { match Self::get_era_for_validation(cluster_id, dac_nodes) { Ok(Some(era_activity)) => era_activity, @@ -1003,6 +1007,7 @@ pub mod pallet { Percent::from_percent(T::MAJORITY), )?; + log::info!("🪅 customers_activity_in_consensus executed successfully. "); let customers_activity_batch_roots = Self::convert_to_batch_merkle_roots( Self::split_to_batches(&customers_activity_in_consensus, batch_size), ) @@ -1019,8 +1024,9 @@ pub mod pallet { Percent::from_percent(T::MAJORITY), )?; + log::info!("🪅 nodes_activity_in_consensus executed successfully. "); let nodes_activity_batch_roots = Self::convert_to_batch_merkle_roots( - Self::split_to_batches(&customers_activity_in_consensus, batch_size), + Self::split_to_batches(&nodes_activity_in_consensus, batch_size), ) .map_err(|err| vec![err])?; @@ -2167,13 +2173,18 @@ pub mod pallet { let sender = ensure_signed(origin)?; //ensure!(Self::is_ocw_validator(sender.clone()), Error::::Unauthorised); // todo! // need to refactor this + T::PayoutVisitor::begin_billing_report(sender, cluster_id, era_id, start_era, end_era)?; - EraValidations::::mutate(cluster_id, era_id, |maybe_era_validations| { - if let Some(ref mut era_validation) = maybe_era_validations { - era_validation.status = EraValidationStatus::PayoutInProgress - } - }); + EraValidations::::try_mutate( + cluster_id, + era_id, + |maybe_era_validations| -> DispatchResult { + maybe_era_validations.as_mut().ok_or(Error::::NoEraValidation)?.status = + EraValidationStatus::PayoutInProgress; + Ok(()) + }, + )?; Ok(()) }