Skip to content

Commit

Permalink
chore: sending billing fingerprint on behalf validator
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Nov 28, 2024
1 parent 850b8cf commit 9a5b96e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 14 deletions.
105 changes: 93 additions & 12 deletions pallets/ddc-verification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ pub mod pallet {
payees_merkle_root_hash: ActivityHash,
validator: T::AccountId,
},
CommitBillingFingerprintTransactionError {
cluster_id: ClusterId,
era_id: DdcEra,
payers_root: PayableUsageHash,
payees_root: PayableUsageHash,
validator: T::AccountId,
},
BeginBillingReportTransactionError {
cluster_id: ClusterId,
era_id: DdcEra,
Expand Down Expand Up @@ -431,6 +438,12 @@ pub mod pallet {
payers_merkle_root_hash: ActivityHash,
payees_merkle_root_hash: ActivityHash,
},
CommitBillingFingerprintTransactionError {
cluster_id: ClusterId,
era_id: DdcEra,
payers_root: PayableUsageHash,
payees_root: PayableUsageHash,
},
BeginBillingReportTransactionError {
cluster_id: ClusterId,
era_id: DdcEra,
Expand Down Expand Up @@ -1186,6 +1199,10 @@ pub mod pallet {
) -> Result<(), Vec<OCWError>> {
let mut errors: Vec<OCWError> = Vec::new();

if let Err(errs) = Self::step_commit_billing_fingerprint(cluster_id, account, signer) {
errors.extend(errs);
}

if let Err(errs) = Self::step_begin_billing_report(cluster_id, account, signer) {
errors.extend(errs);
}
Expand Down Expand Up @@ -1225,6 +1242,31 @@ pub mod pallet {
}
}

define_payout_step_function!(
step_commit_billing_fingerprint,
prepare_commit_billing_fingerprint,
|cluster_id: &ClusterId, (era, payable_usage): (EraActivity, PayableEraUsage)| {
Call::commit_billing_fingerprint {
cluster_id: *cluster_id,
era_id: era.id,
start_era: era.start,
end_era: era.end,
payers_root: payable_usage.payers_root,
payees_root: payable_usage.payees_root,
}
},
|prepared_data: &(EraActivity, PayableEraUsage)| prepared_data.0.id,
"🔑",
|cluster_id: &ClusterId, (era, payable_usage): (EraActivity, PayableEraUsage)| {
OCWError::CommitBillingFingerprintTransactionError {
cluster_id: *cluster_id,
era_id: era.id,
payers_root: payable_usage.payers_root,
payees_root: payable_usage.payees_root,
}
}
);

define_payout_step_function!(
step_begin_billing_report,
prepare_begin_billing_report,
Expand Down Expand Up @@ -1876,15 +1918,15 @@ pub mod pallet {

pub(crate) fn prepare_commit_billing_fingerprint(
cluster_id: &ClusterId,
) -> Result<Option<PayableEraUsage>, Vec<OCWError>> {
) -> Result<Option<(EraActivity, PayableEraUsage)>, Vec<OCWError>> {
if let Some((era_id, start, end)) =
Self::get_era_for_payout(cluster_id, EraValidationStatus::ReadyForPayout)
{
let era = EraActivity { id: era_id, start, end };
if let Ok(payable_usage) =
Self::fetch_payable_delta_usage_or_retry(&cluster_id, era)
{
Ok(Some(payable_usage))
Ok(Some((era, payable_usage)))
} else {
Ok(None)
}
Expand Down Expand Up @@ -3791,6 +3833,31 @@ pub mod pallet {

#[pallet::call_index(2)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::begin_billing_report())]
pub fn commit_billing_fingerprint(
origin: OriginFor<T>,
cluster_id: ClusterId,
era_id: DdcEra,
start_era: i64,
end_era: i64,
payers_root: PayableUsageHash,
payees_root: PayableUsageHash,
) -> DispatchResult {
let sender = ensure_signed(origin.clone())?;
ensure!(Self::is_ocw_validator(sender.clone()), Error::<T>::Unauthorized);

T::PayoutProcessor::commit_billing_fingerprint(
sender,
cluster_id,
era_id,
start_era,
end_era,
payers_root,
payees_root,
)
}

#[pallet::call_index(3)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::begin_billing_report())]
pub fn begin_billing_report(
origin: OriginFor<T>,
cluster_id: ClusterId,
Expand All @@ -3815,7 +3882,7 @@ pub mod pallet {
Ok(())
}

#[pallet::call_index(3)]
#[pallet::call_index(4)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::begin_charging_customers())]
pub fn begin_charging_customers(
origin: OriginFor<T>,
Expand All @@ -3828,7 +3895,7 @@ pub mod pallet {
T::PayoutProcessor::begin_charging_customers(cluster_id, era_id, max_batch_index)
}

#[pallet::call_index(4)]
#[pallet::call_index(5)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::send_charging_customers_batch(payers.len() as u32))]
pub fn send_charging_customers_batch(
origin: OriginFor<T>,
Expand All @@ -3849,7 +3916,7 @@ pub mod pallet {
)
}

#[pallet::call_index(5)]
#[pallet::call_index(6)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::end_charging_customers())]
pub fn end_charging_customers(
origin: OriginFor<T>,
Expand All @@ -3861,7 +3928,7 @@ pub mod pallet {
T::PayoutProcessor::end_charging_customers(cluster_id, era_id)
}

#[pallet::call_index(6)]
#[pallet::call_index(7)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::begin_rewarding_providers())]
pub fn begin_rewarding_providers(
origin: OriginFor<T>,
Expand All @@ -3880,7 +3947,7 @@ pub mod pallet {
)
}

#[pallet::call_index(7)]
#[pallet::call_index(8)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::send_rewarding_providers_batch(payees.len() as u32))]
pub fn send_rewarding_providers_batch(
origin: OriginFor<T>,
Expand All @@ -3901,7 +3968,7 @@ pub mod pallet {
)
}

#[pallet::call_index(8)]
#[pallet::call_index(9)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::end_rewarding_providers())]
pub fn end_rewarding_providers(
origin: OriginFor<T>,
Expand All @@ -3913,7 +3980,7 @@ pub mod pallet {
T::PayoutProcessor::end_rewarding_providers(cluster_id, era_id)
}

#[pallet::call_index(9)]
#[pallet::call_index(10)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::end_billing_report())]
pub fn end_billing_report(
origin: OriginFor<T>,
Expand All @@ -3940,7 +4007,7 @@ pub mod pallet {
///
/// Emits `NotEnoughNodesForConsensus` OR `ActivityNotInConsensus` event depend of error
/// type, when successful.
#[pallet::call_index(10)]
#[pallet::call_index(11)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::emit_consensus_errors(errors.len() as u32))]
pub fn emit_consensus_errors(
origin: OriginFor<T>,
Expand Down Expand Up @@ -3992,6 +4059,20 @@ pub mod pallet {
validator: caller.clone(),
});
},
OCWError::CommitBillingFingerprintTransactionError {
cluster_id,
era_id,
payers_root,
payees_root,
} => {
Self::deposit_event(Event::CommitBillingFingerprintTransactionError {
cluster_id,
era_id,
payers_root,
payees_root,
validator: caller.clone(),
});
},
OCWError::BeginBillingReportTransactionError { cluster_id, era_id } => {
Self::deposit_event(Event::BeginBillingReportTransactionError {
cluster_id,
Expand Down Expand Up @@ -4195,7 +4276,7 @@ pub mod pallet {
/// nothing.
///
/// Emits `EraValidationReady`.
#[pallet::call_index(11)]
#[pallet::call_index(12)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::set_era_validations())]
pub fn set_era_validations(
origin: OriginFor<T>,
Expand All @@ -4213,7 +4294,7 @@ pub mod pallet {
/// Continue DAC validation from an era after a given one. It updates `last_paid_era` of a
/// given cluster, creates an empty billing report with a finalized state, and sets an empty
/// validation result on validators (in case it does not exist yet).
#[pallet::call_index(12)]
#[pallet::call_index(13)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::skip_dac_validation_to_era())]
pub fn skip_dac_validation_to_era(
origin: OriginFor<T>,
Expand Down
2 changes: 1 addition & 1 deletion runtime/cere-dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use sp_api::impl_runtime_apis;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_core::{
crypto::{AccountId32, KeyTypeId},
OpaqueMetadata, H256,
OpaqueMetadata,
};
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_io::hashing::blake2_128;
Expand Down
2 changes: 1 addition & 1 deletion runtime/cere/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use sp_api::impl_runtime_apis;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_core::{
crypto::{AccountId32, KeyTypeId},
OpaqueMetadata, H256,
OpaqueMetadata,
};
use sp_inherents::{CheckInherentsResult, InherentData};
use sp_io::hashing::blake2_128;
Expand Down

0 comments on commit 9a5b96e

Please sign in to comment.