diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 08191dd51..07675f22f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -30,17 +30,20 @@ Please select the branch type you are merging and fill in the relevant template. - [ ] 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 -- [ ] 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. +- [ ] `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 @@ -54,3 +57,4 @@ Please select the branch type you are merging and fill in the relevant template. - [ ] Crate version has been updated. - [ ] Spec version has been updated. - [ ] Transaction version has been updated if required. +- [ ] All CI checks have been passed successfully diff --git a/CHANGELOG.md b/CHANGELOG.md index 64a5041ef..cf19a96d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,12 +13,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- [C,D] Introduce new events to the DDC Payouts Pallet - [C,D] `pallet-ddc-clusters-gov`: Introduction of the Cluster Governance pallet for managing clusters protocol parameters. ## [5.3.0] -### Changed - - [C,D] Updated Substrate to polkadot-v1.1.0 - [C,D] Introduction of the OpenGov - [C,D] `pallet-ddc-clusters`: Added Erasure coding and Replication in cluster params diff --git a/pallets/ddc-payouts/src/lib.rs b/pallets/ddc-payouts/src/lib.rs index 1b7955ab1..f543db269 100644 --- a/pallets/ddc-payouts/src/lib.rs +++ b/pallets/ddc-payouts/src/lib.rs @@ -198,14 +198,24 @@ pub mod pallet { cluster_id: ClusterId, era: DdcEra, }, - Rewarded { + ProviderRewarded { cluster_id: ClusterId, era: DdcEra, batch_index: BatchIndex, + stored_bytes: u64, + transferred_bytes: u64, + number_of_puts: u64, + number_of_gets: u64, node_provider_id: T::AccountId, rewarded: u128, expected_to_reward: u128, }, + ValidatorRewarded { + cluster_id: ClusterId, + era: DdcEra, + validator_id: T::AccountId, + amount: u128, + }, NotDistributedReward { cluster_id: ClusterId, era: DdcEra, @@ -632,7 +642,7 @@ pub mod pallet { } if validators_fee > 0 { - charge_validator_fees::(validators_fee, &billing_report.vault)?; + charge_validator_fees::(validators_fee, &billing_report.vault, cluster_id, era)?; Self::deposit_event(Event::::ValidatorFeesCollected { cluster_id, era, @@ -785,10 +795,14 @@ pub mod pallet { .ok_or(Error::::ArithmeticOverflow)?; } - Self::deposit_event(Event::::Rewarded { + Self::deposit_event(Event::::ProviderRewarded { cluster_id, era, batch_index, + stored_bytes: payee.1.stored_bytes, + transferred_bytes: payee.1.transferred_bytes, + number_of_puts: payee.1.number_of_puts, + number_of_gets: payee.1.number_of_gets, node_provider_id, rewarded: reward_, expected_to_reward: amount_to_reward, @@ -935,6 +949,8 @@ pub mod pallet { fn charge_validator_fees( validators_fee: u128, vault: &T::AccountId, + cluster_id: ClusterId, + era: DdcEra, ) -> DispatchResult { let stakers = get_current_exposure_ratios::()?; @@ -947,6 +963,13 @@ pub mod pallet { amount_to_deduct.saturated_into::>(), ExistenceRequirement::AllowDeath, )?; + + pallet::Pallet::deposit_event(Event::::ValidatorRewarded { + cluster_id, + era, + validator_id: staker_id.clone(), + amount: amount_to_deduct, + }); } Ok(()) diff --git a/pallets/ddc-payouts/src/tests.rs b/pallets/ddc-payouts/src/tests.rs index af8fe2d30..9d50196ef 100644 --- a/pallets/ddc-payouts/src/tests.rs +++ b/pallets/ddc-payouts/src/tests.rs @@ -2519,7 +2519,7 @@ fn end_charging_customers_works() { Event::ValidatorFeesCollected { cluster_id, era, amount: validator_fee }.into(), ); - let transfers = 3 + 3 + 3 * 3; // for Currency::transfer + let transfers = 3 + 3 + 3 + 3 * 3; // for Currency::transfer assert_eq!(System::events().len(), 5 + 1 + 3 + transfers); let report_after = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); @@ -2531,31 +2531,63 @@ fn end_charging_customers_works() { .left_from_one(); balance = Balances::free_balance(TREASURY_ACCOUNT_ID); - assert_eq!(balance, get_fees(&cluster_id).treasury_share * charge); + let mut expected_fees = get_fees(&cluster_id).treasury_share * charge; + assert_eq!(balance, expected_fees); balance = Balances::free_balance(RESERVE_ACCOUNT_ID); - assert_eq!(balance, get_fees(&cluster_id).cluster_reserve_share * charge); + expected_fees = get_fees(&cluster_id).cluster_reserve_share * charge; + assert_eq!(balance, expected_fees); balance = Balances::free_balance(VALIDATOR1_ACCOUNT_ID); let mut ratio = Perquintill::from_rational( VALIDATOR1_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, ); - assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); + expected_fees = get_fees(&cluster_id).validators_share * ratio * charge; + assert_eq!(balance, expected_fees); + System::assert_has_event( + Event::ValidatorRewarded { + cluster_id, + era, + validator_id: VALIDATOR1_ACCOUNT_ID, + amount: expected_fees, + } + .into(), + ); balance = Balances::free_balance(VALIDATOR2_ACCOUNT_ID); ratio = Perquintill::from_rational( VALIDATOR2_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, ); - assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); + expected_fees = get_fees(&cluster_id).validators_share * ratio * charge; + assert_eq!(balance, expected_fees); + System::assert_has_event( + Event::ValidatorRewarded { + cluster_id, + era, + validator_id: VALIDATOR2_ACCOUNT_ID, + amount: expected_fees, + } + .into(), + ); balance = Balances::free_balance(VALIDATOR3_ACCOUNT_ID); ratio = Perquintill::from_rational( VALIDATOR3_SCORE, VALIDATOR1_SCORE + VALIDATOR2_SCORE + VALIDATOR3_SCORE, ); - assert_eq!(balance, get_fees(&cluster_id).validators_share * ratio * charge); + expected_fees = get_fees(&cluster_id).validators_share * ratio * charge; + assert_eq!(balance, expected_fees); + System::assert_has_event( + Event::ValidatorRewarded { + cluster_id, + era, + validator_id: VALIDATOR3_ACCOUNT_ID, + amount: expected_fees, + } + .into(), + ); assert_eq!( report_after.total_customer_charge.transfer, @@ -3216,11 +3248,15 @@ fn send_rewarding_providers_batch_works() { let mut report_reward = DdcPayouts::active_billing_reports(cluster_id, era).unwrap(); System::assert_has_event( - Event::Rewarded { + Event::ProviderRewarded { cluster_id, era, node_provider_id: node1, batch_index: batch_node_index, + stored_bytes: node_usage1.stored_bytes, + transferred_bytes: node_usage1.transferred_bytes, + number_of_puts: node_usage1.number_of_puts, + number_of_gets: node_usage1.number_of_gets, rewarded: balance_node1, expected_to_reward: balance_node1, } @@ -3254,11 +3290,15 @@ fn send_rewarding_providers_batch_works() { assert_eq!(report_reward.total_distributed_reward, balance_node1 + balance_node2); System::assert_has_event( - Event::Rewarded { + Event::ProviderRewarded { cluster_id, era, node_provider_id: node2, batch_index: batch_node_index, + stored_bytes: node_usage2.stored_bytes, + transferred_bytes: node_usage2.transferred_bytes, + number_of_puts: node_usage2.number_of_puts, + number_of_gets: node_usage2.number_of_gets, rewarded: balance_node2, expected_to_reward: balance_node2, } @@ -3301,11 +3341,15 @@ fn send_rewarding_providers_batch_works() { assert_eq!(balance_node3, transfer_charge + storage_charge + puts_charge + gets_charge); System::assert_has_event( - Event::Rewarded { + Event::ProviderRewarded { cluster_id, era, node_provider_id: node3, batch_index: batch_node_index + 1, + stored_bytes: node_usage3.stored_bytes, + transferred_bytes: node_usage3.transferred_bytes, + number_of_puts: node_usage3.number_of_puts, + number_of_gets: node_usage3.number_of_gets, rewarded: balance_node3, expected_to_reward: balance_node3, }