Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tool: Add checker object count #1626

Merged
merged 6 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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