Skip to content

Commit

Permalink
chore: addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yahortsaryk committed Nov 18, 2024
1 parent e494bb7 commit beaea12
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 29 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.

6 changes: 2 additions & 4 deletions pallets/ddc-clusters/src/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ pub struct Cluster<AccountId> {
pub reserve_id: AccountId,
pub props: ClusterProps<AccountId>,
pub status: ClusterStatus,
// 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,
pub last_paid_era: DdcEra,
}

#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -46,7 +44,7 @@ impl<AccountId> Cluster<AccountId> {
replication_total: cluster_params.replication_total,
},
status: ClusterStatus::Unbonded,
last_validated_era_id: DdcEra::default(),
last_paid_era: DdcEra::default(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/ddc-clusters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ pub mod pallet {
let mut cluster =
Clusters::<T>::try_get(cluster_id).map_err(|_| Error::<T>::ClusterDoesNotExist)?;

cluster.last_validated_era_id = era_id;
cluster.last_paid_era = era_id;
Clusters::<T>::insert(cluster_id, cluster);
Self::deposit_event(Event::<T>::ClusterEraPaid { cluster_id: *cluster_id, era_id });

Expand All @@ -905,7 +905,7 @@ pub mod pallet {
let cluster =
Clusters::<T>::try_get(cluster_id).map_err(|_| Error::<T>::ClusterDoesNotExist)?;

Ok(cluster.last_validated_era_id)
Ok(cluster.last_paid_era)
}
}

Expand Down
14 changes: 7 additions & 7 deletions pallets/ddc-clusters/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ pub mod v3 {
pub reserve_id: AccountId,
pub props: ClusterProps<AccountId>,
pub status: ClusterStatus,
pub last_validated_era_id: DdcEra, // new field
pub last_paid_era: DdcEra, // new field
}

#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -521,7 +521,7 @@ pub mod v3 {
replication_total: old_cluster.props.replication_total,
},
status: old_cluster.status,
last_validated_era_id: 0,
last_paid_era: 0,
})
},
);
Expand Down Expand Up @@ -610,7 +610,7 @@ pub mod v3 {
erasure_coding_total: 48,
replication_total: 20,
},
last_validated_era_id: 0,
last_paid_era: 0,
status: ClusterStatus::Activated,
};

Expand All @@ -625,7 +625,7 @@ pub mod v3 {
erasure_coding_total: 48,
replication_total: 20,
},
last_validated_era_id: 0,
last_paid_era: 0,
status: ClusterStatus::Activated,
};

Expand All @@ -647,21 +647,21 @@ pub mod v3 {
);
assert_eq!(Clusters::<T>::get(cluster_id0).unwrap().props.erasure_coding_total, 48);
assert_eq!(Clusters::<T>::get(cluster_id0).unwrap().props.replication_total, 20);
assert_eq!(Clusters::<T>::get(cluster_id0).unwrap().last_validated_era_id, 0);
assert_eq!(Clusters::<T>::get(cluster_id0).unwrap().last_paid_era, 0);
assert_eq!(
Clusters::<T>::get(cluster_id1).unwrap().props.erasure_coding_required,
16
);
assert_eq!(Clusters::<T>::get(cluster_id1).unwrap().props.erasure_coding_total, 48);
assert_eq!(Clusters::<T>::get(cluster_id1).unwrap().props.replication_total, 20);
assert_eq!(Clusters::<T>::get(cluster_id1).unwrap().last_validated_era_id, 0);
assert_eq!(Clusters::<T>::get(cluster_id1).unwrap().last_paid_era, 0);
assert_eq!(
Clusters::<T>::get(cluster_id2).unwrap().props.erasure_coding_required,
16
);
assert_eq!(Clusters::<T>::get(cluster_id2).unwrap().props.erasure_coding_total, 48);
assert_eq!(Clusters::<T>::get(cluster_id2).unwrap().props.replication_total, 20);
assert_eq!(Clusters::<T>::get(cluster_id2).unwrap().last_validated_era_id, 0);
assert_eq!(Clusters::<T>::get(cluster_id2).unwrap().last_paid_era, 0);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-clusters/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ fn set_last_validated_era_works() {
assert_ok!(DdcClusters::set_last_paid_era(&cluster_id, era_id));

let updated_cluster = DdcClusters::clusters(cluster_id).unwrap();
assert_eq!(updated_cluster.last_validated_era_id, era_id);
assert_eq!(updated_cluster.last_paid_era, era_id);

// Checking that event was emitted
assert_eq!(System::events().len(), 3);
Expand Down
2 changes: 0 additions & 2 deletions pallets/ddc-payouts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ sp-std = { workspace = true }

# Cere dependencies
ddc-primitives = { workspace = true }
polkadot-ckb-merkle-mountain-range = { workspace = true }

[dev-dependencies]
chrono = { workspace = true, default-features = true }
Expand All @@ -42,7 +41,6 @@ substrate-test-utils = { workspace = true, default-features = true }
[features]
default = ["std"]
std = [
"polkadot-ckb-merkle-mountain-range/std",
"hex/std",
"codec/std",
"ddc-primitives/std",
Expand Down
10 changes: 5 additions & 5 deletions pallets/ddc-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ fn bond_cluster_works() {
replication_total: 0
},
status: ClusterStatus::Bonded,
last_validated_era_id: DdcEra::default()
last_paid_era: DdcEra::default()
})
);

Expand Down Expand Up @@ -922,7 +922,7 @@ fn unbond_bonded_cluster_works() {
replication_total: 0
},
status: ClusterStatus::Unbonding,
last_validated_era_id: DdcEra::default()
last_paid_era: DdcEra::default()
})
);

Expand Down Expand Up @@ -1002,7 +1002,7 @@ fn unbond_activated_cluster_works() {
replication_total: 0
},
status: ClusterStatus::Unbonding,
last_validated_era_id: DdcEra::default()
last_paid_era: DdcEra::default()
})
);

Expand Down Expand Up @@ -1097,7 +1097,7 @@ fn withdraw_unbonded_cluster_works() {
replication_total: 0
},
status: ClusterStatus::Unbonded,
last_validated_era_id: DdcEra::default()
last_paid_era: DdcEra::default()
})
);
});
Expand Down Expand Up @@ -1184,7 +1184,7 @@ fn withdraw_activated_cluster_works() {
replication_total: 0
},
status: ClusterStatus::Unbonded,
last_validated_era_id: DdcEra::default()
last_paid_era: DdcEra::default()
})
);
});
Expand Down
14 changes: 7 additions & 7 deletions primitives/src/traits/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ pub trait ClusterManager<T: Config>: ClusterQuery<T> {
fn get_clusters(status: ClusterStatus) -> Result<Vec<ClusterId>, DispatchError>;
}
pub trait ClusterValidator<T: Config> {
/// Updates the `last_validated_era_id` for the given cluster and emits an event indicating the
/// Updates the `last_paid_era` for the given cluster and emits an event indicating the
/// update.
///
/// # Parameters
///
/// - `cluster_id`: A reference to the unique identifier of the cluster that needs its last
/// validated era updated.
/// - `era_id`: The new era identifier to be set as the last validated era for the cluster.
/// - `cluster_id`: A reference to the unique identifier of the cluster that needs its last paid
/// era updated.
/// - `era_id`: The new era identifier to be set as the last paid era for the cluster.
///
/// # Returns
///
Expand All @@ -116,13 +116,13 @@ pub trait ClusterValidator<T: Config> {
/// Emits `ClusterEraPaid` event if the operation is successful.
fn set_last_paid_era(cluster_id: &ClusterId, era_id: DdcEra) -> Result<(), DispatchError>;

/// Retrieves the `last_validated_era_id` for the given cluster
/// Retrieves the `last_paid_era` for the given cluster
/// update.
///
/// # Parameters
///
/// - `cluster_id`: A reference to the unique identifier of the cluster the
/// `last_validated_era_id` is being retrieved for
/// - `cluster_id`: A reference to the unique identifier of the cluster the `last_paid_era` is
/// being retrieved for
///
/// # Returns
///
Expand Down

0 comments on commit beaea12

Please sign in to comment.