Skip to content

Commit

Permalink
disallow ocw signatures after era status change (#394)
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)
- [x] 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
aie0 authored Jul 16, 2024
1 parent bcf7dc9 commit f06f760
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pallets/ddc-verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ pub mod pallet {
Unauthorised,
/// Already signed era.
AlreadySignedEra,
NotExpectedState,
/// Already signed payout batch.
AlreadySignedPayoutBatch,
/// Node Retrieval Error.
Expand Down Expand Up @@ -2192,6 +2193,8 @@ pub mod pallet {
.add(sp_runtime::offchain::Duration::from_millis(10000));
let pending = request.deadline(timeout).send().map_err(|_| http::Error::IoError)?;

// todo! filter by status == PROCESSED

let response =
pending.try_wait(timeout).map_err(|_| http::Error::DeadlineReached)??;
if response.code != 200 {
Expand Down Expand Up @@ -2429,6 +2432,12 @@ pub mod pallet {
}
};

// disallow signatures after era status change
ensure!(
era_validation.status == EraValidationStatus::ValidatingData,
Error::<T>::NotExpectedState
);

// Ensure the validators entry exists for the specified (payers_merkle_root_hash,
// payees_merkle_root_hash)
let signed_validators = era_validation
Expand All @@ -2448,7 +2457,7 @@ pub mod pallet {
// threshold
era_validation.payers_merkle_root_hash = payers_merkle_root_hash;
era_validation.payees_merkle_root_hash = payees_merkle_root_hash;
era_validation.start_era = era_activity.start;
era_validation.start_era = era_activity.start; // todo! start/end is set by the last validator and is not in consensus
era_validation.end_era = era_activity.end;

if payers_merkle_root_hash == ActivityHash::default() &&
Expand Down

0 comments on commit f06f760

Please sign in to comment.