Skip to content

Commit

Permalink
Fix Era activity issue (#383)
Browse files Browse the repository at this point in the history
## Description
<!-- Describe what change this PR is implementing -->

## Types of Changes
Please select the branch type you are merging and fill in the relevant
template.
<!--- Check the following box with an x if the following applies: -->
- [ ] Hotfix
- [ ] Release
- [ ] Fix or Feature

## Fix or Feature
<!--- Check the following box with an x if the following applies: -->

### Types of Changes
<!--- What types of changes does your code introduce? -->
- [ ] 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
<!--- Check the following box with an x if the following applies: -->
- [ ] This change requires a runtime migration.
- [ ] Modifies `on_initialize`
- [ ] Modifies `on_finalize`

### Checklist for Fix or Feature
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] 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
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] 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
<!--- All boxes need to be checked. Follow this checklist before
requiring PR review -->
- [ ] 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
  • Loading branch information
ayushmishra2005 authored Jul 2, 2024
1 parent aac18ae commit 7ef5b3c
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pallets/ddc-verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
pub(crate) fn process_dac_data(
cluster_id: &ClusterId,
era_id_to_process: Option<DdcEra>,
era_id_to_process: Option<EraActivity>,
dac_nodes: &[(NodePubKey, StorageNodeParams)],
min_nodes: u16,
batch_size: usize,
Expand All @@ -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,
Expand All @@ -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),
)
Expand All @@ -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])?;

Expand Down Expand Up @@ -2167,13 +2173,18 @@ pub mod pallet {
let sender = ensure_signed(origin)?;
//ensure!(Self::is_ocw_validator(sender.clone()), Error::<T>::Unauthorised); // todo!
// need to refactor this

T::PayoutVisitor::begin_billing_report(sender, cluster_id, era_id, start_era, end_era)?;

EraValidations::<T>::mutate(cluster_id, era_id, |maybe_era_validations| {
if let Some(ref mut era_validation) = maybe_era_validations {
era_validation.status = EraValidationStatus::PayoutInProgress
}
});
EraValidations::<T>::try_mutate(
cluster_id,
era_id,
|maybe_era_validations| -> DispatchResult {
maybe_era_validations.as_mut().ok_or(Error::<T>::NoEraValidation)?.status =
EraValidationStatus::PayoutInProgress;
Ok(())
},
)?;

Ok(())
}
Expand Down

0 comments on commit 7ef5b3c

Please sign in to comment.