Skip to content

Commit

Permalink
Ocw payout charging customers (#384)
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
- [x] 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? -->
- [x] 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
aie0 authored Jul 2, 2024
1 parent 7ef5b3c commit c1a57d2
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 325 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pallets/ddc-payouts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ repository.workspace = true
byte-unit = { workspace = true }
codec = { workspace = true }
log = { workspace = true }
polkadot-ckb-merkle-mountain-range = { workspace = true }
scale-info = { workspace = true }

# Substrate dependencies
Expand Down Expand Up @@ -52,7 +51,6 @@ std = [
"sp-std/std",
"sp-core/std",
"frame-election-provider-support/std",
"polkadot-ckb-merkle-mountain-range/std",
]
runtime-benchmarks = [
"ddc-primitives/runtime-benchmarks",
Expand Down
8 changes: 3 additions & 5 deletions pallets/ddc-payouts/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! DdcPayouts pallet benchmarking.

use ddc_primitives::{
traits::ValidatorVisitor, ActivityHash, ClusterId, ClusterParams, ClusterProtocolParams,
};
use ddc_primitives::{traits::ValidatorVisitor, ClusterId, ClusterParams, ClusterProtocolParams};
pub use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_system::RawOrigin;
use sp_runtime::Perquintill;
Expand Down Expand Up @@ -234,7 +232,7 @@ benchmarks! {
(customer, bucket_id, customer_usage)
}).collect();

}: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, batch_index, payers, 0, vec![], (0, ActivityHash::default()))
}: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, batch_index, payers, MMRProof::default())
verify {
assert!(ActiveBillingReports::<T>::contains_key(cluster_id, era));
let billing_report = ActiveBillingReports::<T>::get(cluster_id, era).unwrap();
Expand Down Expand Up @@ -398,7 +396,7 @@ benchmarks! {
(provider, bucket_id, node_usage)
}).collect();

}: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, batch_index, payees,0, vec![], (0, ActivityHash::default()))
}: _(RawOrigin::Signed(dac_account.clone()), cluster_id, era, batch_index, payees, MMRProof::default())
verify {
assert!(ActiveBillingReports::<T>::contains_key(cluster_id, era));
let billing_report = ActiveBillingReports::<T>::get(cluster_id, era).unwrap();
Expand Down
49 changes: 15 additions & 34 deletions pallets/ddc-payouts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#![recursion_limit = "256"]

pub mod weights;
use polkadot_ckb_merkle_mountain_range::MerkleProof;

use crate::weights::WeightInfo;

Expand All @@ -36,8 +35,8 @@ use ddc_primitives::{
pallet::PalletVisitor as PalletVisitorType,
payout::PayoutVisitor,
},
BatchIndex, BucketId, ClusterId, CustomerUsage, DdcEra, NodeUsage, PayoutError, PayoutState,
MAX_PAYOUT_BATCH_COUNT, MAX_PAYOUT_BATCH_SIZE, MILLICENTS,
BatchIndex, BucketId, ClusterId, CustomerUsage, DdcEra, MMRProof, NodeUsage, PayoutError,
PayoutState, MAX_PAYOUT_BATCH_COUNT, MAX_PAYOUT_BATCH_SIZE, MILLICENTS,
};
use frame_election_provider_support::SortedListProvider;
use frame_support::{
Expand Down Expand Up @@ -95,7 +94,7 @@ parameter_types! {

#[frame_support::pallet]
pub mod pallet {
use ddc_primitives::{traits::ValidatorVisitor, ActivityHash};
use ddc_primitives::traits::ValidatorVisitor;
use frame_support::PalletId;
use sp_io::hashing::blake2_128;
use sp_runtime::traits::{AccountIdConversion, Zero};
Expand Down Expand Up @@ -377,17 +376,13 @@ pub mod pallet {
// + pass values by reference PayoutProcessor trait
#[pallet::call_index(2)]
#[pallet::weight(T::WeightInfo::send_charging_customers_batch(payers.len().saturated_into()))]
// todo! remove clippy::too_many_arguments
#[allow(clippy::too_many_arguments)]
pub fn send_charging_customers_batch(
origin: OriginFor<T>,
cluster_id: ClusterId,
era: DdcEra,
batch_index: BatchIndex,
payers: Vec<(T::AccountId, BucketId, CustomerUsage)>,
mmr_size: u64,
proof: Vec<ActivityHash>,
leaf_with_position: (u64, ActivityHash),
batch_proof: MMRProof,
) -> DispatchResult {
let caller = ensure_signed(origin)?;
ensure!(T::ValidatorVisitor::is_ocw_validator(caller), Error::<T>::Unauthorised);
Expand Down Expand Up @@ -419,8 +414,7 @@ pub mod pallet {
era,
batch_index,
&payers,
MerkleProof::new(mmr_size, proof),
leaf_with_position
&batch_proof
),
Error::<T>::BatchValidationFailed
);
Expand Down Expand Up @@ -695,17 +689,13 @@ pub mod pallet {
// + pass values by reference PayoutProcessor trait
#[pallet::call_index(5)]
#[pallet::weight(T::WeightInfo::send_rewarding_providers_batch(payees.len().saturated_into()))]
// todo! remove clippy::too_many_arguments
#[allow(clippy::too_many_arguments)]
pub fn send_rewarding_providers_batch(
origin: OriginFor<T>,
cluster_id: ClusterId,
era: DdcEra,
batch_index: BatchIndex,
payees: Vec<(T::AccountId, BucketId, NodeUsage)>,
mmr_size: u64,
proof: Vec<ActivityHash>,
leaf_with_position: (u64, ActivityHash),
batch_proof: MMRProof,
) -> DispatchResult {
let caller = ensure_signed(origin)?;
ensure!(T::ValidatorVisitor::is_ocw_validator(caller), Error::<T>::Unauthorised);
Expand Down Expand Up @@ -737,8 +727,7 @@ pub mod pallet {
era,
batch_index,
&payees,
MerkleProof::new(mmr_size, proof),
leaf_with_position
&batch_proof
),
Error::<T>::BatchValidationFailed
);
Expand Down Expand Up @@ -1116,21 +1105,17 @@ pub mod pallet {
cluster_id: ClusterId,
era_id: DdcEra,
batch_index: BatchIndex,
payers: Vec<(T::AccountId, BucketId, CustomerUsage)>,
mmr_size: u64,
proof: Vec<ActivityHash>,
leaf_with_position: (u64, ActivityHash),
payers: &[(T::AccountId, BucketId, CustomerUsage)],
batch_proof: MMRProof,
) -> DispatchResult {
let origin = frame_system::RawOrigin::Signed(origin).into();
Self::send_charging_customers_batch(
origin,
cluster_id,
era_id,
batch_index,
payers,
mmr_size,
proof,
leaf_with_position,
(*payers).to_vec(),
batch_proof,
)
}

Expand Down Expand Up @@ -1165,21 +1150,17 @@ pub mod pallet {
cluster_id: ClusterId,
era_id: DdcEra,
batch_index: BatchIndex,
payees: Vec<(T::AccountId, BucketId, NodeUsage)>,
mmr_size: u64,
proof: Vec<ActivityHash>,
leaf_with_position: (u64, ActivityHash),
payees: &[(T::AccountId, BucketId, NodeUsage)],
batch_proof: MMRProof,
) -> DispatchResult {
let origin = frame_system::RawOrigin::Signed(origin).into();
Self::send_rewarding_providers_batch(
origin,
cluster_id,
era_id,
batch_index,
payees,
mmr_size,
proof,
leaf_with_position,
(*payees).to_vec(),
batch_proof,
)
}

Expand Down
10 changes: 4 additions & 6 deletions pallets/ddc-payouts/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use ddc_primitives::{
pallet::PalletVisitor,
ClusterQuery, ValidatorVisitor,
},
ActivityHash, ClusterBondingParams, ClusterFeesParams, ClusterParams, ClusterPricingParams,
ClusterProtocolParams, ClusterStatus, MergeActivityHash, NodeType, DOLLARS,
ClusterBondingParams, ClusterFeesParams, ClusterParams, ClusterPricingParams,
ClusterProtocolParams, ClusterStatus, NodeType, DOLLARS,
};
use frame_election_provider_support::SortedListProvider;
use frame_support::{
Expand Down Expand Up @@ -153,8 +153,7 @@ where
_era: DdcEra,
_batch_index: BatchIndex,
_payers: &[(T::AccountId, BucketId, CustomerUsage)],
_proof: MerkleProof<ActivityHash, MergeActivityHash>,
_leaf_with_position: (u64, ActivityHash),
_batch_proof: &MMRProof,
) -> bool {
true
}
Expand All @@ -164,8 +163,7 @@ where
_era: DdcEra,
_batch_index: BatchIndex,
_payees: &[(T::AccountId, BucketId, NodeUsage)],
_proof: MerkleProof<ActivityHash, MergeActivityHash>,
_leaf_with_position: (u64, ActivityHash),
_batch_proof: &MMRProof,
) -> bool {
true
}
Expand Down
Loading

0 comments on commit c1a57d2

Please sign in to comment.