Skip to content

Commit

Permalink
Merge pull request #1626 from radixdlt/feature/checker-object-count
Browse files Browse the repository at this point in the history
Tool: Add checker object count
  • Loading branch information
talekhinezh authored Oct 16, 2023
2 parents 8875755 + 15e4a35 commit 593240d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion radix-engine-interface/src/types/blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct KeyValueStoreInfo {
pub generic_substitutions: KeyValueStoreGenericSubstitutions,
}

#[derive(Clone, PartialEq, Eq, Hash, ScryptoSbor, ManifestSbor)]
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, ScryptoSbor, ManifestSbor)]
pub struct BlueprintId {
pub package_address: PackageAddress,
pub blueprint_name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where
value: &Vec<u8>,
) {
// Ignore if the module id is not the royalty module.
if module_id == ModuleId::Royalty {
if module_id != ModuleId::Royalty {
return;
}

Expand Down
37 changes: 36 additions & 1 deletion radix-engine/src/system/checkers/system_db_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub struct NodeCounts {
pub interior_node_count: usize,
pub package_count: usize,
pub blueprint_count: usize,
pub scrypto_global_component_count: usize,
pub native_global_component_count: usize,
pub object_count: BTreeMap<PackageAddress, BTreeMap<String, usize>>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -166,12 +169,18 @@ impl ApplicationChecker for () {

pub struct SystemDatabaseChecker<A: ApplicationChecker> {
application_checker: A,
scrypto_global_component_count: usize,
native_global_component_count: usize,
object_count: BTreeMap<PackageAddress, BTreeMap<String, usize>>,
}

impl<A: ApplicationChecker> SystemDatabaseChecker<A> {
pub fn new(checker: A) -> SystemDatabaseChecker<A> {
SystemDatabaseChecker {
application_checker: checker,
scrypto_global_component_count: 0usize,
native_global_component_count: 0usize,
object_count: btreemap!(),
}
}
}
Expand All @@ -183,6 +192,9 @@ where
fn default() -> Self {
Self {
application_checker: A::default(),
scrypto_global_component_count: 0usize,
native_global_component_count: 0usize,
object_count: btreemap!(),
}
}
}
Expand Down Expand Up @@ -253,6 +265,10 @@ impl<A: ApplicationChecker> SystemDatabaseChecker<A> {
.map_err(SystemDatabaseCheckError::NodeError)?;
}

node_counts.scrypto_global_component_count = self.scrypto_global_component_count;
node_counts.native_global_component_count = self.native_global_component_count;
node_counts.object_count.extend(self.object_count.clone());

let system_checker_results = SystemDatabaseCheckerResults {
node_counts,
partition_count,
Expand All @@ -265,7 +281,7 @@ impl<A: ApplicationChecker> SystemDatabaseChecker<A> {
}

fn check_node<S: SubstateDatabase + ListableSubstateDatabase>(
&self,
&mut self,
reader: &SystemDatabaseReader<S>,
node_id: &NodeId,
node_counts: &mut NodeCounts,
Expand Down Expand Up @@ -388,6 +404,25 @@ impl<A: ApplicationChecker> SystemDatabaseChecker<A> {
ObjectType::Owned => {}
}

if node_id.entity_type().unwrap() == EntityType::GlobalGenericComponent {
self.scrypto_global_component_count += 1;
} else if node_id.is_global_component() {
self.native_global_component_count += 1;
}

self.object_count
.entry(object_info.blueprint_info.blueprint_id.package_address)
.or_default()
.entry(
object_info
.blueprint_info
.blueprint_id
.blueprint_name
.clone(),
)
.or_default()
.add_assign(&1);

SystemNodeCheckerState {
node_id: *node_id,
node_type: SystemNodeType::Object {
Expand Down

0 comments on commit 593240d

Please sign in to comment.