Skip to content

Commit

Permalink
Merge pull request #476 from Cerebellum-Network/feat/dac-payout-bench…
Browse files Browse the repository at this point in the history
…marks

Verification + Payout benchmarks
  • Loading branch information
yahortsaryk authored Nov 18, 2024
2 parents f2ea45b + beaea12 commit 20ee149
Show file tree
Hide file tree
Showing 42 changed files with 2,655 additions and 2,912 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion node/service/chain-specs/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@
},
"ddcPayouts": {
"feederAccount": null,
"authorisedCaller": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
"debtorCustomers": [
[
"0x0000000000000000000000000000000000000001",
Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-clusters-gov/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn create_cluster_with_nodes<T: Config>(
p2p_port: 9070_u16,
});

T::NodeCreator::create_node(node_pub_key.clone(), node_provider.clone(), node_params)
T::NodeManager::create_node(node_pub_key.clone(), node_provider.clone(), node_params)
.expect("Node is not created");

T::StakerCreator::bond_stake_and_participate(
Expand Down
12 changes: 5 additions & 7 deletions pallets/ddc-clusters-gov/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

use codec::{Decode, Encode};
#[cfg(feature = "runtime-benchmarks")]
use ddc_primitives::traits::{node::NodeCreator, staking::StakerCreator};
use ddc_primitives::traits::staking::StakerCreator;
use ddc_primitives::{
traits::{
cluster::{ClusterCreator, ClusterManager, ClusterProtocol, ClusterQuery},
cluster_gov::{DefaultVote, MemberCount, SeatsConsensus},
node::NodeVisitor,
node::NodeManager,
pallet::GetDdcOrigin,
},
ClusterId, ClusterNodeStatus, ClusterProtocolParams, ClusterStatus, NodePubKey,
Expand Down Expand Up @@ -138,14 +138,12 @@ pub mod pallet {
type ClusterCreator: ClusterCreator<Self, BalanceOf<Self>>;
type ClusterManager: ClusterManager<Self>;
type ClusterProtocol: ClusterProtocol<Self, BalanceOf<Self>>;
type NodeVisitor: NodeVisitor<Self>;
type NodeManager: NodeManager<Self>;
type SeatsConsensus: SeatsConsensus;
type DefaultVote: DefaultVote;
type MinValidatedNodesCount: Get<u16>;
type ReferendumEnactmentDuration: Get<BlockNumberFor<Self>>;
#[cfg(feature = "runtime-benchmarks")]
type NodeCreator: NodeCreator<Self>;
#[cfg(feature = "runtime-benchmarks")]
type StakerCreator: StakerCreator<Self, BalanceOf<Self>>;
}

Expand Down Expand Up @@ -488,7 +486,7 @@ pub mod pallet {
if !is_validated_node {
Err(Error::<T>::NotValidatedNode.into())
} else {
let node_provider = T::NodeVisitor::get_node_provider_id(&node_pub_key)?;
let node_provider = T::NodeManager::get_node_provider_id(&node_pub_key)?;
if origin == node_provider {
Ok(())
} else {
Expand All @@ -512,7 +510,7 @@ pub mod pallet {
if node_state.status != ClusterNodeStatus::ValidationSucceeded {
Err(Error::<T>::NotValidatedNode.into())
} else {
let node_provider = T::NodeVisitor::get_node_provider_id(&node_pub_key)?;
let node_provider = T::NodeManager::get_node_provider_id(&node_pub_key)?;
if origin == node_provider {
let voting = ClusterProposalVoting::<T>::get(cluster_id)
.ok_or(Error::<T>::ProposalMissing)?;
Expand Down
7 changes: 2 additions & 5 deletions pallets/ddc-clusters-gov/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ impl pallet_ddc_staking::Config for Test {
type ClusterProtocol = pallet_ddc_clusters::Pallet<Test>;
type ClusterCreator = pallet_ddc_clusters::Pallet<Test>;
type ClusterManager = pallet_ddc_clusters::Pallet<Test>;
type NodeVisitor = pallet_ddc_nodes::Pallet<Test>;
type NodeCreator = pallet_ddc_nodes::Pallet<Test>;
type NodeManager = pallet_ddc_nodes::Pallet<Test>;
type ClusterBondingAmount = ClusterBondingAmount;
type ClusterUnboningDelay = ClusterUnboningDelay;
}
Expand Down Expand Up @@ -322,14 +321,12 @@ impl crate::pallet::Config for Test {
type ClusterManager = pallet_ddc_clusters::Pallet<Test>;
type ClusterCreator = pallet_ddc_clusters::Pallet<Test>;
type ClusterProtocol = pallet_ddc_clusters::Pallet<Test>;
type NodeVisitor = pallet_ddc_nodes::Pallet<Test>;
type NodeManager = pallet_ddc_nodes::Pallet<Test>;
type SeatsConsensus = MockedSeatsConsensus;
type DefaultVote = MockedDefaultVote; // pallet_ddc_clusters_gov::PrimeDefaultVote;
type MinValidatedNodesCount = MinValidatedNodesCount;
type ReferendumEnactmentDuration = ReferendumEnactmentDuration;
#[cfg(feature = "runtime-benchmarks")]
type NodeCreator = pallet_ddc_nodes::Pallet<Test>;
#[cfg(feature = "runtime-benchmarks")]
type StakerCreator = pallet_ddc_staking::Pallet<Test>;
}

Expand Down
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,7 +15,7 @@ pub struct Cluster<AccountId> {
pub reserve_id: AccountId,
pub props: ClusterProps<AccountId>,
pub status: ClusterStatus,
pub last_validated_era_id: DdcEra,
pub last_paid_era: DdcEra,
}

#[derive(Clone, Encode, Decode, RuntimeDebug, TypeInfo, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -44,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
18 changes: 6 additions & 12 deletions pallets/ddc-clusters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub mod pallet {
ClusterUnbonding { cluster_id: ClusterId },
ClusterUnbonded { cluster_id: ClusterId },
ClusterNodeValidated { cluster_id: ClusterId, node_pub_key: NodePubKey, succeeded: bool },
ClusterEraValidated { cluster_id: ClusterId, era_id: DdcEra },
ClusterEraPaid { cluster_id: ClusterId, era_id: DdcEra },
}

#[pallet::error]
Expand Down Expand Up @@ -890,28 +890,22 @@ pub mod pallet {
}
}
impl<T: Config> ClusterValidator<T> for Pallet<T> {
fn set_last_validated_era(
cluster_id: &ClusterId,
era_id: DdcEra,
) -> Result<(), DispatchError> {
fn set_last_paid_era(cluster_id: &ClusterId, era_id: DdcEra) -> Result<(), DispatchError> {
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>::ClusterEraValidated {
cluster_id: *cluster_id,
era_id,
});
Self::deposit_event(Event::<T>::ClusterEraPaid { cluster_id: *cluster_id, era_id });

Ok(())
}

fn get_last_validated_era(cluster_id: &ClusterId) -> Result<DdcEra, DispatchError> {
fn get_last_paid_era(cluster_id: &ClusterId) -> Result<DdcEra, DispatchError> {
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
8 changes: 4 additions & 4 deletions pallets/ddc-clusters/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ fn set_last_validated_era_works() {

// Cluster doesn't exist
assert_noop!(
DdcClusters::set_last_validated_era(&cluster_id, era_id),
DdcClusters::set_last_paid_era(&cluster_id, era_id),
Error::<Test>::ClusterDoesNotExist
);

Expand Down Expand Up @@ -619,14 +619,14 @@ fn set_last_validated_era_works() {
}
));

assert_ok!(DdcClusters::set_last_validated_era(&cluster_id, era_id));
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);
System::assert_last_event(Event::ClusterEraValidated { cluster_id, era_id }.into())
System::assert_last_event(Event::ClusterEraPaid { cluster_id, era_id }.into())
})
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-customers/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! DdcStaking pallet benchmarking.
#![cfg(feature = "runtime-benchmarks")]

use ddc_primitives::{ClusterId, ClusterParams, ClusterProtocolParams};
use ddc_primitives::{BucketParams, ClusterId, ClusterParams, ClusterProtocolParams};
use frame_benchmarking::{account, benchmarks, whitelist_account};
use frame_support::traits::Currency;
use sp_runtime::Perquintill;
Expand Down
Loading

0 comments on commit 20ee149

Please sign in to comment.