diff --git a/pallets/ddc-verification/src/lib.rs b/pallets/ddc-verification/src/lib.rs index 9812ab3f1..19f7ceac4 100644 --- a/pallets/ddc-verification/src/lib.rs +++ b/pallets/ddc-verification/src/lib.rs @@ -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, @@ -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, @@ -1186,6 +1199,10 @@ pub mod pallet { ) -> Result<(), Vec> { let mut errors: Vec = 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); } @@ -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, @@ -1876,7 +1918,7 @@ pub mod pallet { pub(crate) fn prepare_commit_billing_fingerprint( cluster_id: &ClusterId, - ) -> Result, Vec> { + ) -> Result, Vec> { if let Some((era_id, start, end)) = Self::get_era_for_payout(cluster_id, EraValidationStatus::ReadyForPayout) { @@ -1884,7 +1926,7 @@ pub mod pallet { 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) } @@ -3791,6 +3833,31 @@ pub mod pallet { #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::begin_billing_report())] + pub fn commit_billing_fingerprint( + origin: OriginFor, + 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::::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(::WeightInfo::begin_billing_report())] pub fn begin_billing_report( origin: OriginFor, cluster_id: ClusterId, @@ -3815,7 +3882,7 @@ pub mod pallet { Ok(()) } - #[pallet::call_index(3)] + #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::begin_charging_customers())] pub fn begin_charging_customers( origin: OriginFor, @@ -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(::WeightInfo::send_charging_customers_batch(payers.len() as u32))] pub fn send_charging_customers_batch( origin: OriginFor, @@ -3849,7 +3916,7 @@ pub mod pallet { ) } - #[pallet::call_index(5)] + #[pallet::call_index(6)] #[pallet::weight(::WeightInfo::end_charging_customers())] pub fn end_charging_customers( origin: OriginFor, @@ -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(::WeightInfo::begin_rewarding_providers())] pub fn begin_rewarding_providers( origin: OriginFor, @@ -3880,7 +3947,7 @@ pub mod pallet { ) } - #[pallet::call_index(7)] + #[pallet::call_index(8)] #[pallet::weight(::WeightInfo::send_rewarding_providers_batch(payees.len() as u32))] pub fn send_rewarding_providers_batch( origin: OriginFor, @@ -3901,7 +3968,7 @@ pub mod pallet { ) } - #[pallet::call_index(8)] + #[pallet::call_index(9)] #[pallet::weight(::WeightInfo::end_rewarding_providers())] pub fn end_rewarding_providers( origin: OriginFor, @@ -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(::WeightInfo::end_billing_report())] pub fn end_billing_report( origin: OriginFor, @@ -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(::WeightInfo::emit_consensus_errors(errors.len() as u32))] pub fn emit_consensus_errors( origin: OriginFor, @@ -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, @@ -4195,7 +4276,7 @@ pub mod pallet { /// nothing. /// /// Emits `EraValidationReady`. - #[pallet::call_index(11)] + #[pallet::call_index(12)] #[pallet::weight(::WeightInfo::set_era_validations())] pub fn set_era_validations( origin: OriginFor, @@ -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(::WeightInfo::skip_dac_validation_to_era())] pub fn skip_dac_validation_to_era( origin: OriginFor, diff --git a/runtime/cere-dev/src/lib.rs b/runtime/cere-dev/src/lib.rs index 86d7ec32c..f44f9a15d 100644 --- a/runtime/cere-dev/src/lib.rs +++ b/runtime/cere-dev/src/lib.rs @@ -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; diff --git a/runtime/cere/src/lib.rs b/runtime/cere/src/lib.rs index 1539d985d..4f45a1821 100644 --- a/runtime/cere/src/lib.rs +++ b/runtime/cere/src/lib.rs @@ -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;