Skip to content

Commit

Permalink
flags, udeps
Browse files Browse the repository at this point in the history
  • Loading branch information
Longarithm committed Jul 10, 2024
1 parent 8fa854c commit 169eab2
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ len_zero = "deny"
or_fun_call = "deny"
unnecessary_lazy_evaluations = "deny"

[workspace.lints.rust]
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(enable_const_type_id)'] }

[workspace.dependencies]
actix = "0.13.0"
Expand Down
5 changes: 5 additions & 0 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ nightly_protocol = [
]

statelessnet_protocol = []

protocol_schema = [
"near-structs-checker/protocol_schema",
"near-structs-checker-core",
"inventory",
]

[package.metadata.cargo-udeps.ignore]
# Protocol schema checks require external dependencies for sanity checker tool.
normal = ["near-structs-checker-core", "inventory"]
2 changes: 1 addition & 1 deletion core/primitives-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(protocol_schema, feature(const_type_id))]
#![cfg_attr(enable_const_type_id, feature(const_type_id))]

pub use borsh;
pub use num_rational;
Expand Down
8 changes: 6 additions & 2 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ statelessnet_protocol = ["near-primitives-core/statelessnet_protocol"]

new_epoch_sync = []
default = ["near-primitives/rand"]
calimero_zero_storage = []

protocol_schema = [
"near-primitives-core/protocol_schema",
"near-structs-checker-core",
"inventory"
]

calimero_zero_storage = []

[dev-dependencies]
chrono = { workspace = true, features = ["clock"] }
near-primitives = { workspace = true, features = ["clock", "solomon", "rand"] }
Expand All @@ -117,3 +117,7 @@ regex.workspace = true
[[bench]]
name = "serialization"
harness = false

[package.metadata.cargo-udeps.ignore]
# Protocol schema checks require external dependencies for sanity checker tool.
normal = ["near-structs-checker-core", "inventory"]
2 changes: 1 addition & 1 deletion core/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(const_type_id, feature(const_type_id))]
#![cfg_attr(enable_const_type_id, feature(const_type_id))]

pub use near_primitives_core::account;
pub use near_primitives_core::apply;
Expand Down
5 changes: 5 additions & 0 deletions core/structs-checker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ syn = { workspace = true, optional = true }
near-structs-checker-core = { path = "../structs-checker-core" }

[features]

protocol_schema = [
"near-structs-checker-core/protocol_schema",
"proc-macro2",
"syn",
"quote"
]

[package.metadata.cargo-udeps.ignore]
# Protocol schema checks require external dependencies for sanity checker tool.
normal = ["proc-macro2", "syn", "quote"]
4 changes: 2 additions & 2 deletions core/structs-checker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn protocol_struct(input: TokenStream) -> TokenStream {
helper::protocol_struct_impl(input)
}

#[cfg(all(const_type_id, feature = "protocol_schema"))]
#[cfg(all(enable_const_type_id, feature = "protocol_schema"))]
mod helper {
use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
Expand Down Expand Up @@ -118,7 +118,7 @@ mod helper {
}
}

#[cfg(not(all(const_type_id, feature = "protocol_schema")))]
#[cfg(not(all(enable_const_type_id, feature = "protocol_schema")))]
mod helper {
use proc_macro::TokenStream;

Expand Down
2 changes: 1 addition & 1 deletion tools/protocol-schema-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ For context on why this tool is necessary, refer to [this pull request](https://
## Usage

Run the tool locally using:
`cargo +nightly run -p protocol-schema-check`
`RUSTFLAGS="--cfg enable_const_type_id" cargo +nightly run -p protocol-schema-check`

## What To Do If It Fails

Expand Down
3 changes: 0 additions & 3 deletions tools/protocol-schema-check/build.rs

This file was deleted.

6 changes: 6 additions & 0 deletions tools/protocol-schema-check/res/protocol_structs.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
AccessKey = 3914867406
Account = 3785422552
AccountV2 = 3850278944
CryptoHash = 1506996321
LegacyAccount = 1274590952
ValidatorKickoutReason = 1209594351
14 changes: 6 additions & 8 deletions tools/protocol-schema-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ fn compute_hash(
) -> u32 {
let mut hasher = DefaultHasher::new();
match info {
ProtocolStructInfo::Struct { name, type_id, fields } => {
ProtocolStructInfo::Struct { name, type_id: _, fields } => {
name.hash(&mut hasher);
type_id.hash(&mut hasher);
// type_id.hash(&mut hasher);
for (field_name, field_type_id) in *fields {
field_name.hash(&mut hasher);
compute_type_hash(*field_type_id, structs, &mut hasher);
}
}
ProtocolStructInfo::Enum { name, type_id, variants } => {
ProtocolStructInfo::Enum { name, type_id: _, variants } => {
name.hash(&mut hasher);
type_id.hash(&mut hasher);
// type_id.hash(&mut hasher);
for (variant_name, variant_fields) in *variants {
variant_name.hash(&mut hasher);
if let Some(fields) = variant_fields {
Expand All @@ -61,14 +61,12 @@ fn compute_type_hash(
// Likely a primitive or external type, hash the type_id directly.
// TODO (#11755): proper implementation for generics. Or require a
// separate type for them.
type_id.hash(hasher);
// type_id.hash(hasher);
0.hash(hasher);
}
}

fn main() {
#[cfg(all(const_type_id, feature = "protocol_schema"))]
println!("CONST TYPE ID ON");

let file_path = Path::new(env!("CARGO_MANIFEST_DIR")).join("res").join("protocol_structs.toml");

let stored_hashes: BTreeMap<String, u32> = if file_path.exists() {
Expand Down

0 comments on commit 169eab2

Please sign in to comment.