Skip to content

Commit

Permalink
refactor: 'CustomerUsage' is renamed to 'BucketUsage'
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Nov 15, 2024
1 parent 512c385 commit 411b1b7
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 115 deletions.
4 changes: 2 additions & 2 deletions pallets/ddc-clusters/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub struct Cluster<AccountId> {
pub reserve_id: AccountId,
pub props: ClusterProps<AccountId>,
pub status: ClusterStatus,
// todo(yahortsaryk): this should be renamed to `last_paid_era` to eliminate ambiguity,
// as the validation step is decoupled from payout step.
// todo(yahortsaryk): `last_validated_era_id` should be renamed to `last_paid_era` to eliminate
// ambiguity, as the validation step is decoupled from payout step.
pub last_validated_era_id: DdcEra,
}

Expand Down
14 changes: 8 additions & 6 deletions pallets/ddc-customers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use ddc_primitives::{
cluster::{ClusterCreator, ClusterProtocol, ClusterQuery},
customer::{CustomerCharger, CustomerDepositor, CustomerVisitor},
},
BucketId, BucketParams, ClusterId, CustomerUsage,
BucketId, BucketParams, BucketUsage, ClusterId,
};
use frame_support::{
parameter_types,
Expand Down Expand Up @@ -67,7 +67,9 @@ pub struct Bucket<T: Config> {
cluster_id: ClusterId,
is_public: bool,
is_removed: bool,
total_customers_usage: Option<CustomerUsage>,
// todo(yahortsaryk): `total_customers_usage` should be renamed to `total_usage` to eliminate
// ambiguity, as the bucket owner is the only customer of the bucket who pays for its usage.
total_customers_usage: Option<BucketUsage>,
}

#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
Expand Down Expand Up @@ -665,7 +667,7 @@ pub mod pallet {
cluster_id: &ClusterId,
bucket_id: BucketId,
content_owner: &T::AccountId,
) -> Result<Option<CustomerUsage>, DispatchError> {
) -> Result<Option<BucketUsage>, DispatchError> {
let bucket = Self::buckets(bucket_id).ok_or(Error::<T>::NoBucketWithId)?;
ensure!(bucket.owner_id == *content_owner, Error::<T>::NotBucketOwner);
ensure!(bucket.cluster_id == *cluster_id, Error::<T>::ClusterMismatch);
Expand All @@ -677,7 +679,7 @@ pub mod pallet {
cluster_id: &ClusterId,
bucket_id: BucketId,
content_owner: T::AccountId,
customer_usage: &CustomerUsage,
customer_usage: &BucketUsage,
) -> DispatchResult {
let mut bucket = Self::buckets(bucket_id).ok_or(Error::<T>::NoBucketWithId)?;
ensure!(bucket.owner_id == content_owner, Error::<T>::NotBucketOwner);
Expand All @@ -691,7 +693,7 @@ pub mod pallet {
total_customers_usage.number_of_gets += customer_usage.number_of_gets;
},
None => {
bucket.total_customers_usage = Some(CustomerUsage {
bucket.total_customers_usage = Some(BucketUsage {
transferred_bytes: customer_usage.transferred_bytes,
stored_bytes: customer_usage.stored_bytes,
number_of_puts: customer_usage.number_of_puts,
Expand Down Expand Up @@ -730,7 +732,7 @@ pub mod pallet {
bucket_id: BucketId,
content_owner: T::AccountId,
billing_vault: T::AccountId,
customer_usage: &CustomerUsage,
customer_usage: &BucketUsage,
amount: u128,
) -> Result<u128, DispatchError> {
let actually_charged: BalanceOf<T>;
Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-customers/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub mod v2 {
cluster_id: ClusterId,
is_public: bool,
is_removed: bool,
total_customers_usage: Option<CustomerUsage>, // new field
total_customers_usage: Option<BucketUsage>, // new field
}

#[storage_alias]
Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-customers/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn charge_content_owner_works() {
let bucket_id2: BucketId = 2;
let cluster_id = ClusterId::from([1; 20]);
let bucket_1_params = BucketParams { is_public: false };
let customer_usage = CustomerUsage {
let customer_usage = BucketUsage {
transferred_bytes: 1,
stored_bytes: 2,
number_of_puts: 3,
Expand Down
14 changes: 7 additions & 7 deletions pallets/ddc-payouts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ use ddc_primitives::{
customer::CustomerCharger as CustomerChargerType, node::NodeManager,
pallet::PalletVisitor as PalletVisitorType, payout::PayoutProcessor,
},
BatchIndex, BucketId, ClusterId, CustomerCharge, CustomerUsage, DdcEra, MMRProof, NodePubKey,
NodeReward, NodeUsage, PayoutError, PayoutState, MAX_PAYOUT_BATCH_COUNT, MAX_PAYOUT_BATCH_SIZE,
MILLICENTS,
BatchIndex, BucketId, BucketUsage, ClusterId, CustomerCharge, DdcEra, MMRProof, NodePubKey,
NodeUsage, PayoutError, PayoutState, ProviderReward, MAX_PAYOUT_BATCH_COUNT,
MAX_PAYOUT_BATCH_SIZE, MILLICENTS,
};
use frame_election_provider_support::SortedListProvider;
use frame_support::{
Expand Down Expand Up @@ -392,8 +392,8 @@ pub mod pallet {
node_usage: &NodeUsage,
total_nodes_usage: &NodeUsage,
total_customer_charge: &CustomerCharge,
) -> Option<NodeReward> {
let mut node_reward = NodeReward::default();
) -> Option<ProviderReward> {
let mut node_reward = ProviderReward::default();

let mut ratio = Perquintill::from_rational(
node_usage.transferred_bytes as u128,
Expand Down Expand Up @@ -422,7 +422,7 @@ pub mod pallet {

fn get_customer_charge<T: Config>(
cluster_id: &ClusterId,
usage: &CustomerUsage,
usage: &BucketUsage,
bucket_id: BucketId,
customer_id: &T::AccountId,
start_era: i64,
Expand Down Expand Up @@ -609,7 +609,7 @@ pub mod pallet {
cluster_id: ClusterId,
era: DdcEra,
batch_index: BatchIndex,
payers: &[(NodePubKey, BucketId, CustomerUsage)],
payers: &[(NodePubKey, BucketId, BucketUsage)],
batch_proof: MMRProof,
) -> DispatchResult {
ensure!(
Expand Down
8 changes: 4 additions & 4 deletions pallets/ddc-payouts/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ where
_era: DdcEra,
_batch_index: BatchIndex,
_max_batch_index: BatchIndex,
_payers: &[(NodePubKey, BucketId, CustomerUsage)],
_payers: &[(NodePubKey, BucketId, BucketUsage)],
_batch_proof: &MMRProof,
) -> bool {
true
Expand Down Expand Up @@ -258,15 +258,15 @@ where
_cluster_id: &ClusterId,
_bucket_id: BucketId,
_content_owner: &T::AccountId,
) -> Result<Option<CustomerUsage>, DispatchError> {
) -> Result<Option<BucketUsage>, DispatchError> {
Ok(None)
}

fn inc_total_bucket_usage(
_cluster_id: &ClusterId,
_bucket_id: BucketId,
_content_owner: T::AccountId,
_customer_usage: &CustomerUsage,
_customer_usage: &BucketUsage,
) -> DispatchResult {
unimplemented!()
}
Expand All @@ -292,7 +292,7 @@ where
_bucket_id: BucketId,
content_owner: T::AccountId,
billing_vault: T::AccountId,
_customer_usage: &CustomerUsage,
_customer_usage: &BucketUsage,
amount: u128,
) -> Result<u128, DispatchError> {
let mut amount_to_charge = amount;
Expand Down
Loading

0 comments on commit 411b1b7

Please sign in to comment.