From 00ee8f5a8fb38dc9acb594c03f65c094777996a2 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Wed, 18 Sep 2024 02:05:01 +0200 Subject: [PATCH 01/16] bump deps in cargo --- Cargo.lock | 6 +++--- execution_engine/Cargo.toml | 6 +++--- execution_engine/src/runtime/wasm_prep.rs | 2 ++ resources/production/chainspec.toml | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37ee7ad599..7384a4c8b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -827,7 +827,7 @@ dependencies = [ [[package]] name = "casper-wasmi" -version = "0.13.2" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8357f19a7fd98073d8fe8df60f1bef1e677b7c623c1e6e2e07d2f8e59ceb87fc" dependencies = [ @@ -838,7 +838,7 @@ dependencies = [ [[package]] name = "casper-wasmi-core" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60089625560924f184cf91d59b0731373d5114b81224f1201c6a39ccc1d8388c" dependencies = [ @@ -851,7 +851,7 @@ dependencies = [ [[package]] name = "casper-wasmi-validation" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f669d385132ce321a57fdf453588d69c01654e75991bee3d22392a3aaaad80bb" dependencies = [ diff --git a/execution_engine/Cargo.toml b/execution_engine/Cargo.toml index 343bf42e85..5b617835e3 100644 --- a/execution_engine/Cargo.toml +++ b/execution_engine/Cargo.toml @@ -16,9 +16,9 @@ base16 = "0.2.1" bincode = "1.3.1" casper-storage = { version = "2.0.0", path = "../storage" } casper-types = { version = "5.0.0", path = "../types", default-features = false, features = ["datasize", "gens", "json-schema", "std"] } -casper-wasm = { version = "0.46.0", default-features = false } -casper-wasm-utils = "3.0.0" -casper-wasmi = "0.13.2" +casper-wasm = { version = "0.46.0", default-features = false, features = ["sign_ext"] } +casper-wasm-utils = { version = "3.0.0", default-features = false, features = ["sign_ext"] } +casper-wasmi = { version = "0.14.0" } datasize = "0.2.4" either = "1.8.1" hex-buffer-serde = "0.2.1" diff --git a/execution_engine/src/runtime/wasm_prep.rs b/execution_engine/src/runtime/wasm_prep.rs index e2191018ac..b5e7cf2648 100644 --- a/execution_engine/src/runtime/wasm_prep.rs +++ b/execution_engine/src/runtime/wasm_prep.rs @@ -686,6 +686,8 @@ impl Rules for RuledOpcodeCosts { | Instruction::F32ReinterpretI32 | Instruction::F64ReinterpretI64 => None, /* Unsupported reinterpretation operators * for floats. */ + + Instruction::SignExt(_) => Some(1) } } diff --git a/resources/production/chainspec.toml b/resources/production/chainspec.toml index ad9bdcabf2..9038f4eaa4 100644 --- a/resources/production/chainspec.toml +++ b/resources/production/chainspec.toml @@ -256,6 +256,7 @@ nop = 200 current_memory = 290 # Grow memory cost, per page (64kb). grow_memory = 240_000 +sign = 300 # Control flow operations multiplier. [wasm.opcode_costs.control_flow] From e4413190045a6767f3f4b187086684ef0d5aa156 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Thu, 19 Sep 2024 03:23:23 +0200 Subject: [PATCH 02/16] add sign op cost to chainspec --- Cargo.lock | 6 +++--- execution_engine/Cargo.toml | 2 +- .../tests/src/test/storage_costs.rs | 1 + .../tests/src/test/system_costs.rs | 1 + node/src/utils/chain_specification.rs | 1 + resources/local/chainspec.toml.in | 2 ++ resources/production/chainspec.toml | 1 + .../chainspec/vm_config/opcode_costs.txt | 7 +++++++ types/src/chainspec/vm_config/opcode_costs.rs | 17 +++++++++++++++++ 9 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 types/proptest-regressions/chainspec/vm_config/opcode_costs.txt diff --git a/Cargo.lock b/Cargo.lock index 7384a4c8b2..94095a7da3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -829,7 +829,7 @@ dependencies = [ name = "casper-wasmi" version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8357f19a7fd98073d8fe8df60f1bef1e677b7c623c1e6e2e07d2f8e59ceb87fc" +checksum = "0319f5a421cce8a5b87f441230607a53c57a065ddc45703ea1e355cd2831397e" dependencies = [ "casper-wasm", "casper-wasmi-core", @@ -840,7 +840,7 @@ dependencies = [ name = "casper-wasmi-core" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60089625560924f184cf91d59b0731373d5114b81224f1201c6a39ccc1d8388c" +checksum = "077494ae45ba9d6df93da1bc3e6e686c6f4cf8ea658f2a1152980edb2c0c60bd" dependencies = [ "downcast-rs", "libm", @@ -853,7 +853,7 @@ dependencies = [ name = "casper-wasmi-validation" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f669d385132ce321a57fdf453588d69c01654e75991bee3d22392a3aaaad80bb" +checksum = "218e1bb3693233149b6ac945cd26ea3e5fb5e50ac523cc87fb3ee6579a9eb789" dependencies = [ "casper-wasm", ] diff --git a/execution_engine/Cargo.toml b/execution_engine/Cargo.toml index 5b617835e3..ef639ce0a1 100644 --- a/execution_engine/Cargo.toml +++ b/execution_engine/Cargo.toml @@ -18,7 +18,7 @@ casper-storage = { version = "2.0.0", path = "../storage" } casper-types = { version = "5.0.0", path = "../types", default-features = false, features = ["datasize", "gens", "json-schema", "std"] } casper-wasm = { version = "0.46.0", default-features = false, features = ["sign_ext"] } casper-wasm-utils = { version = "3.0.0", default-features = false, features = ["sign_ext"] } -casper-wasmi = { version = "0.14.0" } +casper-wasmi = { version = "0.14.0", features=["sign_ext"] } datasize = "0.2.4" either = "1.8.1" hex-buffer-serde = "0.2.1" diff --git a/execution_engine_testing/tests/src/test/storage_costs.rs b/execution_engine_testing/tests/src/test/storage_costs.rs index a9f0588a75..776cffc53f 100644 --- a/execution_engine_testing/tests/src/test/storage_costs.rs +++ b/execution_engine_testing/tests/src/test/storage_costs.rs @@ -90,6 +90,7 @@ const NEW_OPCODE_COSTS: OpcodeCosts = OpcodeCosts { nop: 0, current_memory: 0, grow_memory: 0, + sign: 0, }; static NEW_HOST_FUNCTION_COSTS: Lazy = Lazy::new(HostFunctionCosts::zero); diff --git a/execution_engine_testing/tests/src/test/system_costs.rs b/execution_engine_testing/tests/src/test/system_costs.rs index d4bebb14ca..945eca473e 100644 --- a/execution_engine_testing/tests/src/test/system_costs.rs +++ b/execution_engine_testing/tests/src/test/system_costs.rs @@ -826,6 +826,7 @@ fn should_verify_wasm_add_bid_wasm_cost_is_not_recursive() { nop: 0, current_memory: 0, grow_memory: 0, + sign: 0, }; let new_storage_costs = StorageCosts::new(0); diff --git a/node/src/utils/chain_specification.rs b/node/src/utils/chain_specification.rs index 26e860192f..ec0a3edad2 100644 --- a/node/src/utils/chain_specification.rs +++ b/node/src/utils/chain_specification.rs @@ -199,6 +199,7 @@ mod tests { nop: 25, current_memory: 26, grow_memory: 27, + sign: 28, }; static EXPECTED_GENESIS_HOST_FUNCTION_COSTS: Lazy = Lazy::new(|| HostFunctionCosts { diff --git a/resources/local/chainspec.toml.in b/resources/local/chainspec.toml.in index 69c5b92b2a..174c9deb0b 100644 --- a/resources/local/chainspec.toml.in +++ b/resources/local/chainspec.toml.in @@ -246,6 +246,8 @@ nop = 200 current_memory = 290 # Grow memory cost, per page (64kb). grow_memory = 240_000 +# Sign extension operations cost +sign = 300 # Control flow operations multiplier. [wasm.opcode_costs.control_flow] diff --git a/resources/production/chainspec.toml b/resources/production/chainspec.toml index 9038f4eaa4..de899cf951 100644 --- a/resources/production/chainspec.toml +++ b/resources/production/chainspec.toml @@ -256,6 +256,7 @@ nop = 200 current_memory = 290 # Grow memory cost, per page (64kb). grow_memory = 240_000 +# Sign extension operations cost sign = 300 # Control flow operations multiplier. diff --git a/types/proptest-regressions/chainspec/vm_config/opcode_costs.txt b/types/proptest-regressions/chainspec/vm_config/opcode_costs.txt new file mode 100644 index 0000000000..a9d02952e2 --- /dev/null +++ b/types/proptest-regressions/chainspec/vm_config/opcode_costs.txt @@ -0,0 +1,7 @@ +# Seeds for failure cases proptest has generated in the past. It is +# automatically read and these particular cases re-run before any +# novel cases are generated. +# +# It is recommended to check this file in to source control so that +# everyone who runs the test benefits from these saved cases. +cc 1fdebefaf3095a3c7dc7503bcc0f213ed68263d760440653c3e7f6005cd8c7a0 # shrinks to opcode_costs = OpcodeCosts { bit: 0, add: 0, mul: 0, div: 0, load: 0, store: 0, op_const: 0, local: 0, global: 0, integer_comparison: 0, conversion: 0, unreachable: 0, nop: 0, current_memory: 0, grow_memory: 0, control_flow: ControlFlowCosts { block: 0, op_loop: 0, op_if: 0, op_else: 0, end: 0, br: 0, br_if: 0, op_return: 0, call: 0, call_indirect: 0, drop: 0, select: 0, br_table: BrTableCost { cost: 0, size_multiplier: 0 } }, sign: 0 } diff --git a/types/src/chainspec/vm_config/opcode_costs.rs b/types/src/chainspec/vm_config/opcode_costs.rs index d87caf0c04..fcc710817b 100644 --- a/types/src/chainspec/vm_config/opcode_costs.rs +++ b/types/src/chainspec/vm_config/opcode_costs.rs @@ -72,6 +72,8 @@ pub const DEFAULT_CONTROL_FLOW_DROP_OPCODE: u32 = 440; pub const DEFAULT_CONTROL_FLOW_BR_TABLE_OPCODE: u32 = 35_000; /// Default multiplier for the size of targets in `br_table` Wasm opcode. pub const DEFAULT_CONTROL_FLOW_BR_TABLE_MULTIPLIER: u32 = 100; +/// Default cost of the sign extension opcodes +pub const DEFAULT_SIGN_COST: u32 = 300; /// Definition of a cost table for a Wasm `br_table` opcode. /// @@ -438,6 +440,8 @@ pub struct OpcodeCosts { pub grow_memory: u32, /// Control flow operations multiplier. pub control_flow: ControlFlowCosts, + /// Sign ext operations costs + pub sign: u32, } impl Default for OpcodeCosts { @@ -459,6 +463,7 @@ impl Default for OpcodeCosts { current_memory: DEFAULT_CURRENT_MEMORY_COST, grow_memory: DEFAULT_GROW_MEMORY_COST, control_flow: ControlFlowCosts::default(), + sign: DEFAULT_SIGN_COST, } } } @@ -483,6 +488,7 @@ impl Distribution for Standard { current_memory: rng.gen(), grow_memory: rng.gen(), control_flow: rng.gen(), + sign: rng.gen(), } } } @@ -508,6 +514,7 @@ impl ToBytes for OpcodeCosts { current_memory, grow_memory, control_flow, + sign } = self; ret.append(&mut bit.to_bytes()?); @@ -526,6 +533,7 @@ impl ToBytes for OpcodeCosts { ret.append(&mut current_memory.to_bytes()?); ret.append(&mut grow_memory.to_bytes()?); ret.append(&mut control_flow.to_bytes()?); + ret.append(&mut sign.to_bytes()?); Ok(ret) } @@ -548,6 +556,7 @@ impl ToBytes for OpcodeCosts { current_memory, grow_memory, control_flow, + sign } = self; bit.serialized_length() + add.serialized_length() @@ -565,6 +574,7 @@ impl ToBytes for OpcodeCosts { + current_memory.serialized_length() + grow_memory.serialized_length() + control_flow.serialized_length() + + sign.serialized_length() } } @@ -586,6 +596,7 @@ impl FromBytes for OpcodeCosts { let (current_memory, bytes): (_, &[u8]) = FromBytes::from_bytes(bytes)?; let (grow_memory, bytes): (_, &[u8]) = FromBytes::from_bytes(bytes)?; let (control_flow, bytes): (_, &[u8]) = FromBytes::from_bytes(bytes)?; + let (sign, bytes): (_, &[u8]) = FromBytes::from_bytes(bytes)?; let opcode_costs = OpcodeCosts { bit, @@ -604,6 +615,7 @@ impl FromBytes for OpcodeCosts { current_memory, grow_memory, control_flow, + sign, }; Ok((opcode_costs, bytes)) } @@ -628,6 +640,7 @@ impl Zero for OpcodeCosts { current_memory: 0, grow_memory: 0, control_flow: ControlFlowCosts::zero(), + sign: 0 } } @@ -649,6 +662,7 @@ impl Zero for OpcodeCosts { current_memory, grow_memory, control_flow, + sign } = self; bit.is_zero() && add.is_zero() @@ -666,6 +680,7 @@ impl Zero for OpcodeCosts { && current_memory.is_zero() && grow_memory.is_zero() && control_flow.is_zero() + && sign.is_zero() } } @@ -738,6 +753,7 @@ pub mod gens { current_memory in num::u32::ANY, grow_memory in num::u32::ANY, control_flow in control_flow_cost_arb(), + sign in num::u32::ANY, ) -> OpcodeCosts { OpcodeCosts { bit, @@ -756,6 +772,7 @@ pub mod gens { current_memory, grow_memory, control_flow, + sign, } } } From 4f2e0550f6c97f02590ba7325b632b3882f82a01 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Thu, 19 Sep 2024 14:37:15 +0200 Subject: [PATCH 03/16] remove related sig-ext tests --- execution_engine/src/runtime/wasm_prep.rs | 214 +--------------------- 1 file changed, 2 insertions(+), 212 deletions(-) diff --git a/execution_engine/src/runtime/wasm_prep.rs b/execution_engine/src/runtime/wasm_prep.rs index b5e7cf2648..cef173c3d3 100644 --- a/execution_engine/src/runtime/wasm_prep.rs +++ b/execution_engine/src/runtime/wasm_prep.rs @@ -429,9 +429,9 @@ pub fn deserialize(module_bytes: &[u8]) -> Result { PreprocessingError::Deserialize("Atomic operations are not supported".to_string()) } casper_wasm::SerializationError::UnknownOpcode( - SIGN_EXT_OPCODE_START..=SIGN_EXT_OPCODE_END, + _, ) => PreprocessingError::Deserialize( - "Sign extension operations are not supported".to_string(), + "Encountered an unsupported operation".to_string(), ), casper_wasm::SerializationError::Other( "Enable the multi_value feature to deserialize more than one function result", @@ -1012,214 +1012,4 @@ mod tests { error, ); } - - #[test] - fn should_not_accept_sign_ext_i32_e8s_proposal_wasm() { - let module_bytes = { - let mut module = walrus::Module::with_config(ModuleConfig::new()); - - let _memory_id = module.memories.add_local(false, 11, None); - - let mut func_with_sign_ext = FunctionBuilder::new(&mut module.types, &[], &[]); - - func_with_sign_ext.func_body().i32_const(0); - - { - let mut body = func_with_sign_ext.func_body(); - let instructions = body.instrs_mut(); - let (instr, _) = instructions.get_mut(0).unwrap(); - *instr = Instr::Unop(Unop { - op: UnaryOp::I32Extend8S, - }); - } - - let func_with_sign_ext = func_with_sign_ext.finish(vec![], &mut module.funcs); - - let mut call_func = FunctionBuilder::new(&mut module.types, &[], &[]); - - call_func.func_body().call(func_with_sign_ext); - - let call = call_func.finish(Vec::new(), &mut module.funcs); - - module.exports.add(DEFAULT_ENTRY_POINT_NAME, call); - - module.emit_wasm() - }; - let error = preprocess(WasmConfig::default(), &module_bytes) - .expect_err("should fail with an error"); - assert!( - matches!(&error, PreprocessingError::Deserialize(msg) - if msg == "Sign extension operations are not supported"), - "{:?}", - error, - ); - } - - #[test] - fn should_not_accept_sign_ext_i32_e16s_proposal_wasm() { - let module_bytes = { - let mut module = walrus::Module::with_config(ModuleConfig::new()); - - let _memory_id = module.memories.add_local(false, 11, None); - - let mut func_with_sign_ext = FunctionBuilder::new(&mut module.types, &[], &[]); - - func_with_sign_ext.func_body().i32_const(0); - - { - let mut body = func_with_sign_ext.func_body(); - let instructions = body.instrs_mut(); - let (instr, _) = instructions.get_mut(0).unwrap(); - *instr = Instr::Unop(Unop { - op: UnaryOp::I32Extend16S, - }); - } - - let func_with_sign_ext = func_with_sign_ext.finish(vec![], &mut module.funcs); - - let mut call_func = FunctionBuilder::new(&mut module.types, &[], &[]); - - call_func.func_body().call(func_with_sign_ext); - - let call = call_func.finish(Vec::new(), &mut module.funcs); - - module.exports.add(DEFAULT_ENTRY_POINT_NAME, call); - - module.emit_wasm() - }; - let error = preprocess(WasmConfig::default(), &module_bytes) - .expect_err("should fail with an error"); - assert!( - matches!(&error, PreprocessingError::Deserialize(msg) - if msg == "Sign extension operations are not supported"), - "{:?}", - error, - ); - } - - #[test] - fn should_not_accept_sign_ext_i64_e8s_proposal_wasm() { - let module_bytes = { - let mut module = walrus::Module::with_config(ModuleConfig::new()); - - let _memory_id = module.memories.add_local(false, 11, None); - - let mut func_with_sign_ext = FunctionBuilder::new(&mut module.types, &[], &[]); - - func_with_sign_ext.func_body().i32_const(0); - - { - let mut body = func_with_sign_ext.func_body(); - let instructions = body.instrs_mut(); - let (instr, _) = instructions.get_mut(0).unwrap(); - *instr = Instr::Unop(Unop { - op: UnaryOp::I64Extend8S, - }); - } - - let func_with_sign_ext = func_with_sign_ext.finish(vec![], &mut module.funcs); - - let mut call_func = FunctionBuilder::new(&mut module.types, &[], &[]); - - call_func.func_body().call(func_with_sign_ext); - - let call = call_func.finish(Vec::new(), &mut module.funcs); - - module.exports.add(DEFAULT_ENTRY_POINT_NAME, call); - - module.emit_wasm() - }; - let error = preprocess(WasmConfig::default(), &module_bytes) - .expect_err("should fail with an error"); - assert!( - matches!(&error, PreprocessingError::Deserialize(msg) - if msg == "Sign extension operations are not supported"), - "{:?}", - error, - ); - } - - #[test] - fn should_not_accept_sign_ext_i64_e16s_proposal_wasm() { - let module_bytes = { - let mut module = walrus::Module::with_config(ModuleConfig::new()); - - let _memory_id = module.memories.add_local(false, 11, None); - - let mut func_with_sign_ext = FunctionBuilder::new(&mut module.types, &[], &[]); - - func_with_sign_ext.func_body().i32_const(0); - - { - let mut body = func_with_sign_ext.func_body(); - let instructions = body.instrs_mut(); - let (instr, _) = instructions.get_mut(0).unwrap(); - *instr = Instr::Unop(Unop { - op: UnaryOp::I64Extend16S, - }); - } - - let func_with_sign_ext = func_with_sign_ext.finish(vec![], &mut module.funcs); - - let mut call_func = FunctionBuilder::new(&mut module.types, &[], &[]); - - call_func.func_body().call(func_with_sign_ext); - - let call = call_func.finish(Vec::new(), &mut module.funcs); - - module.exports.add(DEFAULT_ENTRY_POINT_NAME, call); - - module.emit_wasm() - }; - let error = preprocess(WasmConfig::default(), &module_bytes) - .expect_err("should fail with an error"); - assert!( - matches!(&error, PreprocessingError::Deserialize(msg) - if msg == "Sign extension operations are not supported"), - "{:?}", - error, - ); - } - - #[test] - fn should_not_accept_sign_ext_i64_e32s_proposal_wasm() { - let module_bytes = { - let mut module = walrus::Module::with_config(ModuleConfig::new()); - - let _memory_id = module.memories.add_local(false, 11, None); - - let mut func_with_sign_ext = FunctionBuilder::new(&mut module.types, &[], &[]); - - func_with_sign_ext.func_body().i32_const(0); - - { - let mut body = func_with_sign_ext.func_body(); - let instructions = body.instrs_mut(); - let (instr, _) = instructions.get_mut(0).unwrap(); - *instr = Instr::Unop(Unop { - op: UnaryOp::I64Extend32S, - }); - } - - let func_with_sign_ext = func_with_sign_ext.finish(vec![], &mut module.funcs); - - let mut call_func = FunctionBuilder::new(&mut module.types, &[], &[]); - - call_func.func_body().call(func_with_sign_ext); - - let call = call_func.finish(Vec::new(), &mut module.funcs); - - module.exports.add(DEFAULT_ENTRY_POINT_NAME, call); - - module.emit_wasm() - }; - let error = preprocess(WasmConfig::default(), &module_bytes) - .expect_err("should fail with an error"); - assert!( - matches!(&error, PreprocessingError::Deserialize(msg) - if msg == "Sign extension operations are not supported"), - "{:?}", - error, - ); - } } From 9b2c592f32f4a7a3dbdd2ad59a7b7f33f1b14483 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Thu, 19 Sep 2024 17:51:50 +0200 Subject: [PATCH 04/16] use spec sign ext costs in Rules impl --- execution_engine/src/runtime/wasm_prep.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/execution_engine/src/runtime/wasm_prep.rs b/execution_engine/src/runtime/wasm_prep.rs index cef173c3d3..5b802d7c9b 100644 --- a/execution_engine/src/runtime/wasm_prep.rs +++ b/execution_engine/src/runtime/wasm_prep.rs @@ -17,8 +17,6 @@ use crate::execution::ExecError; const ATOMIC_OPCODE_PREFIX: u8 = 0xfe; const BULK_OPCODE_PREFIX: u8 = 0xfc; -const SIGN_EXT_OPCODE_START: u8 = 0xc0; -const SIGN_EXT_OPCODE_END: u8 = 0xc4; const SIMD_OPCODE_PREFIX: u8 = 0xfd; const DEFAULT_GAS_MODULE_NAME: &str = "env"; @@ -687,7 +685,7 @@ impl Rules for RuledOpcodeCosts { | Instruction::F64ReinterpretI64 => None, /* Unsupported reinterpretation operators * for floats. */ - Instruction::SignExt(_) => Some(1) + Instruction::SignExt(_) => Some(costs.sign) } } @@ -704,7 +702,6 @@ mod tests { elements::{CodeSection, Instructions}, }; use walrus::{ - ir::{Instr, UnaryOp, Unop}, FunctionBuilder, ModuleConfig, ValType, }; From 344109b3c7620e49c893c08429f84926295c7c22 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Thu, 19 Sep 2024 17:57:53 +0200 Subject: [PATCH 05/16] minor cleanup --- .../chainspec/vm_config/opcode_costs.txt | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 types/proptest-regressions/chainspec/vm_config/opcode_costs.txt diff --git a/types/proptest-regressions/chainspec/vm_config/opcode_costs.txt b/types/proptest-regressions/chainspec/vm_config/opcode_costs.txt deleted file mode 100644 index a9d02952e2..0000000000 --- a/types/proptest-regressions/chainspec/vm_config/opcode_costs.txt +++ /dev/null @@ -1,7 +0,0 @@ -# Seeds for failure cases proptest has generated in the past. It is -# automatically read and these particular cases re-run before any -# novel cases are generated. -# -# It is recommended to check this file in to source control so that -# everyone who runs the test benefits from these saved cases. -cc 1fdebefaf3095a3c7dc7503bcc0f213ed68263d760440653c3e7f6005cd8c7a0 # shrinks to opcode_costs = OpcodeCosts { bit: 0, add: 0, mul: 0, div: 0, load: 0, store: 0, op_const: 0, local: 0, global: 0, integer_comparison: 0, conversion: 0, unreachable: 0, nop: 0, current_memory: 0, grow_memory: 0, control_flow: ControlFlowCosts { block: 0, op_loop: 0, op_if: 0, op_else: 0, end: 0, br: 0, br_if: 0, op_return: 0, call: 0, call_indirect: 0, drop: 0, select: 0, br_table: BrTableCost { cost: 0, size_multiplier: 0 } }, sign: 0 } From b1e80f21fc89e37ca6bde295a2ba032d4714ba3b Mon Sep 17 00:00:00 2001 From: igor-casper Date: Fri, 20 Sep 2024 01:19:41 +0200 Subject: [PATCH 06/16] apply fmt suggestions --- execution_engine/src/runtime/wasm_prep.rs | 18 +++++++----------- types/src/chainspec/vm_config/opcode_costs.rs | 8 ++++---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/execution_engine/src/runtime/wasm_prep.rs b/execution_engine/src/runtime/wasm_prep.rs index 5b802d7c9b..a4b11e230e 100644 --- a/execution_engine/src/runtime/wasm_prep.rs +++ b/execution_engine/src/runtime/wasm_prep.rs @@ -426,11 +426,9 @@ pub fn deserialize(module_bytes: &[u8]) -> Result { casper_wasm::SerializationError::UnknownOpcode(ATOMIC_OPCODE_PREFIX) => { PreprocessingError::Deserialize("Atomic operations are not supported".to_string()) } - casper_wasm::SerializationError::UnknownOpcode( - _, - ) => PreprocessingError::Deserialize( - "Encountered an unsupported operation".to_string(), - ), + casper_wasm::SerializationError::UnknownOpcode(_) => { + PreprocessingError::Deserialize("Encountered an unsupported operation".to_string()) + } casper_wasm::SerializationError::Other( "Enable the multi_value feature to deserialize more than one function result", ) => { @@ -679,13 +677,13 @@ impl Rules for RuledOpcodeCosts { | Instruction::F64ConvertUI64 | Instruction::F64PromoteF32 => None, // Unsupported conversion operators for floats. + // Unsupported reinterpretation operators for floats. Instruction::I32ReinterpretF32 | Instruction::I64ReinterpretF64 | Instruction::F32ReinterpretI32 - | Instruction::F64ReinterpretI64 => None, /* Unsupported reinterpretation operators - * for floats. */ + | Instruction::F64ReinterpretI64 => None, - Instruction::SignExt(_) => Some(costs.sign) + Instruction::SignExt(_) => Some(costs.sign), } } @@ -701,9 +699,7 @@ mod tests { builder, elements::{CodeSection, Instructions}, }; - use walrus::{ - FunctionBuilder, ModuleConfig, ValType, - }; + use walrus::{FunctionBuilder, ModuleConfig, ValType}; use super::*; diff --git a/types/src/chainspec/vm_config/opcode_costs.rs b/types/src/chainspec/vm_config/opcode_costs.rs index fcc710817b..d17dcfcc37 100644 --- a/types/src/chainspec/vm_config/opcode_costs.rs +++ b/types/src/chainspec/vm_config/opcode_costs.rs @@ -514,7 +514,7 @@ impl ToBytes for OpcodeCosts { current_memory, grow_memory, control_flow, - sign + sign, } = self; ret.append(&mut bit.to_bytes()?); @@ -556,7 +556,7 @@ impl ToBytes for OpcodeCosts { current_memory, grow_memory, control_flow, - sign + sign, } = self; bit.serialized_length() + add.serialized_length() @@ -640,7 +640,7 @@ impl Zero for OpcodeCosts { current_memory: 0, grow_memory: 0, control_flow: ControlFlowCosts::zero(), - sign: 0 + sign: 0, } } @@ -662,7 +662,7 @@ impl Zero for OpcodeCosts { current_memory, grow_memory, control_flow, - sign + sign, } = self; bit.is_zero() && add.is_zero() From d89d00fb22859dd497fe765d55cdf463e4c88092 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Mon, 23 Sep 2024 16:43:34 +0200 Subject: [PATCH 07/16] bump smart contracts toolchain --- execution_engine/Cargo.toml | 2 +- .../tests/src/test/explorer/faucet.rs | 8 ++++---- .../regression/host_function_metrics_size_and_gas_cost.rs | 2 +- smart_contracts/rust-toolchain | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/execution_engine/Cargo.toml b/execution_engine/Cargo.toml index ef639ce0a1..dedfcc862d 100644 --- a/execution_engine/Cargo.toml +++ b/execution_engine/Cargo.toml @@ -18,7 +18,7 @@ casper-storage = { version = "2.0.0", path = "../storage" } casper-types = { version = "5.0.0", path = "../types", default-features = false, features = ["datasize", "gens", "json-schema", "std"] } casper-wasm = { version = "0.46.0", default-features = false, features = ["sign_ext"] } casper-wasm-utils = { version = "3.0.0", default-features = false, features = ["sign_ext"] } -casper-wasmi = { version = "0.14.0", features=["sign_ext"] } +casper-wasmi = { version = "0.14.0", features = ["sign_ext"] } datasize = "0.2.4" either = "1.8.1" hex-buffer-serde = "0.2.1" diff --git a/execution_engine_testing/tests/src/test/explorer/faucet.rs b/execution_engine_testing/tests/src/test/explorer/faucet.rs index a2b66a47d8..96676df354 100644 --- a/execution_engine_testing/tests/src/test/explorer/faucet.rs +++ b/execution_engine_testing/tests/src/test/explorer/faucet.rs @@ -660,11 +660,11 @@ fn faucet_costs() { // This test will fail if execution costs vary. The expected costs should not be updated // without understanding why the cost has changed. If the costs do change, it should be // reflected in the "Costs by Entry Point" section of the faucet crate's README.md. - const EXPECTED_FAUCET_INSTALL_COST: u64 = 160_995_706_637; + const EXPECTED_FAUCET_INSTALL_COST: u64 = 143_255_164_712; - const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 135_355_310; - const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_884_534_947; - const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_623_238_526; + const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 135_911_560; + const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_880_786_237; + const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_617_742_516; let installer_account = AccountHash::new([1u8; 32]); let user_account: AccountHash = AccountHash::new([2u8; 32]); diff --git a/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs b/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs index 1e65c06472..384cf4181e 100644 --- a/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs +++ b/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs @@ -16,7 +16,7 @@ const CONTRACT_TRANSFER_TO_ACCOUNT_U512: &str = "transfer_to_account_u512.wasm"; // This value is not systemic, as code is added the size of WASM will increase, // you can change this value to reflect the increase in WASM size. -const HOST_FUNCTION_METRICS_STANDARD_SIZE: usize = 122_154; +const HOST_FUNCTION_METRICS_STANDARD_SIZE: usize = 126_154; const HOST_FUNCTION_METRICS_STANDARD_GAS_COST: u64 = 422_402_224_490; /// Acceptable size regression/improvement in percentage. diff --git a/smart_contracts/rust-toolchain b/smart_contracts/rust-toolchain index f9e5e5e397..de4fb8f19f 100644 --- a/smart_contracts/rust-toolchain +++ b/smart_contracts/rust-toolchain @@ -1 +1 @@ -nightly-2023-03-25 +nightly-2024-04-20 From 4125adc208dfd3a3a0c54cf3519b653705878939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Papierski?= Date: Wed, 25 Sep 2024 16:58:33 +0200 Subject: [PATCH 08/16] Update rust-toolchain for smart contracts Uses most recent I could find that does not emit invalid table reference. --- execution_engine/src/engine_state/wasm_v1.rs | 5 ++++- .../tests/src/test/explorer/faucet.rs | 8 ++++---- ...host_function_metrics_size_and_gas_cost.rs | 2 +- .../consensus/highway_core/state/tests.rs | 10 +++++----- node/src/components/metrics.rs | 6 +++--- .../contract/src/contract_api/storage.rs | 2 +- smart_contracts/contract/src/ext_ffi.rs | 19 ++++++++++--------- smart_contracts/contract/src/lib.rs | 1 + .../test/deserialize-error/src/main.rs | 4 ++-- .../test/ee-966-regression/src/main.rs | 3 ++- .../contracts/test/storage-costs/src/main.rs | 2 +- smart_contracts/rust-toolchain | 2 +- storage/src/system/transfer.rs | 2 +- types/src/bytesrepr.rs | 2 +- types/src/stored_value.rs | 14 -------------- types/src/transaction/transaction_category.rs | 1 + 16 files changed, 38 insertions(+), 45 deletions(-) diff --git a/execution_engine/src/engine_state/wasm_v1.rs b/execution_engine/src/engine_state/wasm_v1.rs index 75196cc26e..634816ae61 100644 --- a/execution_engine/src/engine_state/wasm_v1.rs +++ b/execution_engine/src/engine_state/wasm_v1.rs @@ -496,7 +496,10 @@ impl TryFrom<&TransactionV1> for SessionInfo { } TransactionTarget::Stored { id, .. } => { let TransactionEntryPoint::Custom(entry_point) = v1_txn.entry_point() else { - return Err(InvalidRequest::InvalidEntryPoint(transaction_hash, v1_txn.entry_point().to_string())); + return Err(InvalidRequest::InvalidEntryPoint( + transaction_hash, + v1_txn.entry_point().to_string(), + )); }; let item = ExecutableItem::Invocation(id.clone()); ExecutableInfo { diff --git a/execution_engine_testing/tests/src/test/explorer/faucet.rs b/execution_engine_testing/tests/src/test/explorer/faucet.rs index 96676df354..679ecc3ae1 100644 --- a/execution_engine_testing/tests/src/test/explorer/faucet.rs +++ b/execution_engine_testing/tests/src/test/explorer/faucet.rs @@ -660,11 +660,11 @@ fn faucet_costs() { // This test will fail if execution costs vary. The expected costs should not be updated // without understanding why the cost has changed. If the costs do change, it should be // reflected in the "Costs by Entry Point" section of the faucet crate's README.md. - const EXPECTED_FAUCET_INSTALL_COST: u64 = 143_255_164_712; + const EXPECTED_FAUCET_INSTALL_COST: u64 = 142_379_864_303; - const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 135_911_560; - const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_880_786_237; - const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_617_742_516; + const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 134_259_210; + const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_879_594_967; + const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_615_492_876; let installer_account = AccountHash::new([1u8; 32]); let user_account: AccountHash = AccountHash::new([2u8; 32]); diff --git a/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs b/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs index 384cf4181e..02db172092 100644 --- a/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs +++ b/execution_engine_testing/tests/src/test/regression/host_function_metrics_size_and_gas_cost.rs @@ -16,7 +16,7 @@ const CONTRACT_TRANSFER_TO_ACCOUNT_U512: &str = "transfer_to_account_u512.wasm"; // This value is not systemic, as code is added the size of WASM will increase, // you can change this value to reflect the increase in WASM size. -const HOST_FUNCTION_METRICS_STANDARD_SIZE: usize = 126_154; +const HOST_FUNCTION_METRICS_STANDARD_SIZE: usize = 132_461; const HOST_FUNCTION_METRICS_STANDARD_GAS_COST: u64 = 422_402_224_490; /// Acceptable size regression/improvement in percentage. diff --git a/node/src/components/consensus/highway_core/state/tests.rs b/node/src/components/consensus/highway_core/state/tests.rs index adfdd46ab5..0566f4ef31 100644 --- a/node/src/components/consensus/highway_core/state/tests.rs +++ b/node/src/components/consensus/highway_core/state/tests.rs @@ -504,7 +504,7 @@ fn validate_lnc_mixed_citations() -> Result<(), AddUnitError> { // || | // || | // Bob b0<---------+ | - // + | | + // + | | // | | | // +c1<--+ | | // Carol c0<--+ | | @@ -545,12 +545,12 @@ fn validate_lnc_transitive_endorsement() -> Result<(), AddUnitError // c1 doesn't have to be endorsed, it is enough that c0 is. // // Alice a0<-----------+ - // + | + // + | // b0<----+ | // Bob | // | // b0'<---+ | - // + | + // + | // Carol c0<---+c1<----+ // | // | @@ -582,12 +582,12 @@ fn validate_lnc_cite_descendant_of_equivocation() -> Result<(), AddUnitError i32; - /// + /// This function loads a set of named keys from the host. The data will be available through + /// the host buffer and can be copied to Wasm memory through [`casper_read_host_buffer`]. pub fn casper_load_named_keys(total_keys: *mut usize, result_size: *mut usize) -> i32; /// This function causes a `Trap`, terminating the currently running module, /// but first copies the bytes from `value_ptr` to `value_ptr + value_size` to @@ -94,7 +95,7 @@ extern "C" { /// * `value_ptr`: pointer to bytes representing the value to return to the caller /// * `value_size`: size of the value (in bytes) pub fn casper_ret(value_ptr: *const u8, value_size: usize) -> !; - /// + /// Retrieves a key from the named keys by name and writes it to the output buffer. pub fn casper_get_key( name_ptr: *const u8, name_size: usize, @@ -102,16 +103,16 @@ extern "C" { output_size: usize, bytes_written_ptr: *mut usize, ) -> i32; - /// + /// This function checks if the key with the given name is present in the named keys. pub fn casper_has_key(name_ptr: *const u8, name_size: usize) -> i32; - /// + /// This function stores a key under the given name in the named keys. pub fn casper_put_key( name_ptr: *const u8, name_size: usize, key_ptr: *const u8, key_size: usize, ); - /// + /// This function removes a key with the given name from the named keys. pub fn casper_remove_key(name_ptr: *const u8, name_size: usize); /// This function causes a `Trap` which terminates the currently running /// module. Additionally, it signals that the current entire phase of @@ -198,8 +199,8 @@ extern "C" { /// /// # Arguments /// - /// * `public_key` - pointer to the bytes in wasm memory representing the - /// public key to update, presently only 32-byte public keys are supported + /// * `public_key` - pointer to the bytes in wasm memory representing the public key to update, + /// presently only 32-byte public keys are supported. /// * `weight` - the weight to assign to this public key pub fn casper_update_associated_key( account_hash_ptr: *const u8, @@ -404,13 +405,13 @@ extern "C" { /// /// * `dest_ptr` - pointer to position in wasm memory to write the result pub fn casper_get_phase(dest_ptr: *mut u8); - /// + /// Retrieves a system contract by index and writes it to the destination pointer. pub fn casper_get_system_contract( system_contract_index: u32, dest_ptr: *mut u8, dest_size: usize, ) -> i32; - /// + /// Retrieves the main purse and writes it to the destination pointer. pub fn casper_get_main_purse(dest_ptr: *mut u8); /// This function copies the contents of the current runtime buffer into the /// wasm memory, beginning at the provided offset. It is intended that this diff --git a/smart_contracts/contract/src/lib.rs b/smart_contracts/contract/src/lib.rs index a397ad60d8..62f4520d15 100644 --- a/smart_contracts/contract/src/lib.rs +++ b/smart_contracts/contract/src/lib.rs @@ -46,6 +46,7 @@ //! submodules. #![cfg_attr(not(test), no_std)] +#![cfg_attr(all(not(test), feature = "no-std-helpers"), allow(internal_features))] #![cfg_attr( all(not(test), feature = "no-std-helpers"), feature(alloc_error_handler, core_intrinsics, lang_items) diff --git a/smart_contracts/contracts/test/deserialize-error/src/main.rs b/smart_contracts/contracts/test/deserialize-error/src/main.rs index d10b7cb0d0..aceb9f4a79 100644 --- a/smart_contracts/contracts/test/deserialize-error/src/main.rs +++ b/smart_contracts/contracts/test/deserialize-error/src/main.rs @@ -3,7 +3,7 @@ extern crate alloc; -use alloc::{vec, vec::Vec}; +use alloc::vec::Vec; use casper_contract::{self, contract_api::storage, unwrap_or_revert::UnwrapOrRevert}; use casper_types::{ @@ -46,7 +46,7 @@ pub fn my_call_contract(contract_hash: AddressableEntityHash, entry_point_name: let (contract_hash_ptr, contract_hash_size, _bytes1) = to_ptr(contract_hash); let entry_point_name = ToBytes::to_bytes(entry_point_name).unwrap(); - let malicious_args = vec![255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + let malicious_args = [255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; { let mut bytes_written = 0usize; diff --git a/smart_contracts/contracts/test/ee-966-regression/src/main.rs b/smart_contracts/contracts/test/ee-966-regression/src/main.rs index 5c0889f714..efffe3a0da 100644 --- a/smart_contracts/contracts/test/ee-966-regression/src/main.rs +++ b/smart_contracts/contracts/test/ee-966-regression/src/main.rs @@ -1,5 +1,6 @@ #![no_std] #![no_main] +#![allow(internal_features)] #![feature(lang_items)] extern crate core; @@ -45,7 +46,7 @@ pub fn memory_size() -> usize { pub fn memory_grow(new_pages: usize) { let ptr = wasm32::memory_grow(DEFAULT_MEMORY_INDEX, new_pages); - if ptr == usize::max_value() { + if ptr == usize::MAX { revert(ApiError::OutOfMemory); } } diff --git a/smart_contracts/contracts/test/storage-costs/src/main.rs b/smart_contracts/contracts/test/storage-costs/src/main.rs index 7622190180..03a4b8dbd3 100644 --- a/smart_contracts/contracts/test/storage-costs/src/main.rs +++ b/smart_contracts/contracts/test/storage-costs/src/main.rs @@ -25,7 +25,7 @@ const WRITE_LARGE_VALUE: &[u8] = b"111111111111111111111111111111111111111111111 const HASH_KEY_NAME: &str = "contract_package"; const CONTRACT_KEY_NAME: &str = "contract"; const ADD_SMALL_VALUE: u64 = 1; -const ADD_LARGE_VALUE: u64 = u64::max_value(); +const ADD_LARGE_VALUE: u64 = u64::MAX; const NEW_UREF_FUNCTION: &str = "new_uref_function"; const PUT_KEY_FUNCTION: &str = "put_key_function"; const REMOVE_KEY_FUNCTION: &str = "remove_key_function"; diff --git a/smart_contracts/rust-toolchain b/smart_contracts/rust-toolchain index de4fb8f19f..63e221c849 100644 --- a/smart_contracts/rust-toolchain +++ b/smart_contracts/rust-toolchain @@ -1 +1 @@ -nightly-2024-04-20 +nightly-2024-07-31 diff --git a/storage/src/system/transfer.rs b/storage/src/system/transfer.rs index e0fb150aac..b5992a38ae 100644 --- a/storage/src/system/transfer.rs +++ b/storage/src/system/transfer.rs @@ -260,7 +260,7 @@ impl TransferRuntimeArgsBuilder { } Some(cl_value) if *cl_value.cl_type() == CLType::Option(CLType::URef.into()) => { let Some(uref): Option = self.map_cl_value(cl_value)? else { - return Ok(account.main_purse()) + return Ok(account.main_purse()); }; uref } diff --git a/types/src/bytesrepr.rs b/types/src/bytesrepr.rs index e44c67ef1f..a3622bf5ae 100644 --- a/types/src/bytesrepr.rs +++ b/types/src/bytesrepr.rs @@ -110,7 +110,7 @@ pub fn allocate_buffer(to_be_serialized: &T) -> Result, Erro /// Returns a `Vec` initialized with sufficient capacity to hold `expected_size` bytes, /// or an error if the capacity would exceed `u32::max_value()`. pub fn allocate_buffer_for_size(expected_size: usize) -> Result, Error> { - if expected_size > u32::max_value() as usize { + if expected_size > u32::MAX as usize { return Err(Error::OutOfMemory); } Ok(Vec::with_capacity(expected_size)) diff --git a/types/src/stored_value.rs b/types/src/stored_value.rs index 22fa15e15b..e6e6a0fe29 100644 --- a/types/src/stored_value.rs +++ b/types/src/stored_value.rs @@ -803,22 +803,8 @@ impl FromBytes for StoredValue { } mod serde_helpers { - use core::fmt; - use super::*; - pub struct InvalidHumanReadableDeser(String); - - impl fmt::Display for InvalidHumanReadableDeser { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "Couldn't deserialize StoredValue. Underlying error: {}", - self.0 - ) - } - } - #[derive(Serialize)] pub(super) enum HumanReadableSerHelper<'a> { CLValue(&'a CLValue), diff --git a/types/src/transaction/transaction_category.rs b/types/src/transaction/transaction_category.rs index c3ce0a678e..2c869b9475 100644 --- a/types/src/transaction/transaction_category.rs +++ b/types/src/transaction/transaction_category.rs @@ -32,6 +32,7 @@ use crate::{ schemars(description = "Session kind of a Transaction.") )] #[serde(deny_unknown_fields)] +#[allow(dead_code)] #[repr(u8)] pub(crate) enum TransactionCategory { /// The supported categories of transactions. This was not explicit in protocol 1.x From 80de62f26984a7bd4c3000a6b7412626f1ab1f89 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Thu, 26 Sep 2024 18:14:36 +0200 Subject: [PATCH 09/16] bump deps, fix lints --- Cargo.lock | 39 +++++++++++-------- .../tests/src/test/explorer/faucet.rs | 2 +- node/src/components/network.rs | 1 + node/src/components/transaction_buffer.rs | 2 +- node/src/effect.rs | 2 + node/src/reactor.rs | 2 + node/src/types/value_or_chunk.rs | 1 + node/src/utils.rs | 1 + .../contracts/explorer/faucet/README.md | 8 ++-- types/Cargo.toml | 4 +- 10 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 94095a7da3..0b209415ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -587,7 +587,7 @@ dependencies = [ "linked-hash-map", "log", "num", - "num-derive", + "num-derive 0.3.3", "num-rational", "num-traits", "num_cpus", @@ -648,7 +648,7 @@ dependencies = [ "log", "mio", "num", - "num-derive", + "num-derive 0.3.3", "num-rational", "num-traits", "num_cpus", @@ -718,7 +718,7 @@ dependencies = [ "linked-hash-map", "lmdb-rkv", "num", - "num-derive", + "num-derive 0.3.3", "num-rational", "num-traits", "once_cell", @@ -756,7 +756,7 @@ dependencies = [ "k256", "libc", "num", - "num-derive", + "num-derive 0.4.2", "num-integer", "num-rational", "num-traits", @@ -1468,16 +1468,15 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "4.0.0" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f711ade317dd348950a9910f81c5947e3d8907ebd2b83f76203ff1807e6a2bc2" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ "cfg-if 1.0.0", "cpufeatures", "curve25519-dalek-derive", "digest 0.10.7", "fiat-crypto", - "platforms", "rustc_version", "subtle", "zeroize", @@ -1730,14 +1729,15 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", "serde", "sha2", + "subtle", "zeroize", ] @@ -2124,9 +2124,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.1.20" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "filesize" @@ -3917,6 +3917,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2 1.0.86", + "quote 1.0.36", + "syn 2.0.72", +] + [[package]] name = "num-format" version = "0.4.4" @@ -4227,12 +4238,6 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" -[[package]] -name = "platforms" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d7ddaed09e0eb771a79ab0fd64609ba0afb0a8366421957936ad14cbd13630" - [[package]] name = "plotters" version = "0.3.5" diff --git a/execution_engine_testing/tests/src/test/explorer/faucet.rs b/execution_engine_testing/tests/src/test/explorer/faucet.rs index 679ecc3ae1..7d16b9f373 100644 --- a/execution_engine_testing/tests/src/test/explorer/faucet.rs +++ b/execution_engine_testing/tests/src/test/explorer/faucet.rs @@ -660,7 +660,7 @@ fn faucet_costs() { // This test will fail if execution costs vary. The expected costs should not be updated // without understanding why the cost has changed. If the costs do change, it should be // reflected in the "Costs by Entry Point" section of the faucet crate's README.md. - const EXPECTED_FAUCET_INSTALL_COST: u64 = 142_379_864_303; + const EXPECTED_FAUCET_INSTALL_COST: u64 = 142_640_262_074; const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 134_259_210; const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_879_594_967; diff --git a/node/src/components/network.rs b/node/src/components/network.rs index 51a8756075..bde7ff64be 100644 --- a/node/src/components/network.rs +++ b/node/src/components/network.rs @@ -203,6 +203,7 @@ where state: ComponentState, } +#[allow(dead_code)] #[derive(DataSize)] struct ChannelManagement { /// Channel signaling a shutdown of the network. diff --git a/node/src/components/transaction_buffer.rs b/node/src/components/transaction_buffer.rs index 8ac942ec50..f0587eb252 100644 --- a/node/src/components/transaction_buffer.rs +++ b/node/src/components/transaction_buffer.rs @@ -234,7 +234,7 @@ impl TransactionBuffer { where REv: From + Send, { - if self.prices.get(&era_id).is_none() { + if !self.prices.contains_key(&era_id) { info!("Empty prices field, requesting gas price from contract runtime"); return effect_builder .get_current_gas_price(era_id) diff --git a/node/src/effect.rs b/node/src/effect.rs index 55e801c460..6247718e6f 100644 --- a/node/src/effect.rs +++ b/node/src/effect.rs @@ -383,6 +383,7 @@ pub(crate) trait EffectExt: Future + Send { /// /// The function `f` is used to translate the returned value from an effect into an iterator of /// events. + #[allow(dead_code)] fn events(self, f: F) -> Effects where F: FnOnce(Self::Output) -> I + 'static + Send, @@ -415,6 +416,7 @@ pub(crate) trait EffectResultExt { /// Effect extension for futures, used to convert futures returning an `Option` into two different /// effects. +#[allow(dead_code)] pub(crate) trait EffectOptionExt { /// The type the future will return if `Some`. type Value; diff --git a/node/src/reactor.rs b/node/src/reactor.rs index a4a94cfa93..751f3af447 100644 --- a/node/src/reactor.rs +++ b/node/src/reactor.rs @@ -309,6 +309,7 @@ pub(crate) trait Reactor: Sized { /// /// May return `None` if the component cannot be found, or if the reactor does not support /// querying component states. + #[allow(dead_code)] #[cfg(test)] fn get_component_state(&self, _name: &str) -> Option<&ComponentState> { None @@ -334,6 +335,7 @@ pub(crate) trait ReactorEvent: Send + Debug + From + 'stati /// A drop-like trait for `async` compatible drop-and-wait. /// /// Shuts down a type by explicitly freeing resources, but allowing to wait on cleanup to complete. +#[allow(dead_code)] pub(crate) trait Finalize: Sized { /// Runs cleanup code and waits for a shutdown to complete. /// diff --git a/node/src/types/value_or_chunk.rs b/node/src/types/value_or_chunk.rs index b6381fba29..59646bf0f5 100644 --- a/node/src/types/value_or_chunk.rs +++ b/node/src/types/value_or_chunk.rs @@ -110,6 +110,7 @@ impl Display for ValueOrChunk> { /// Error type simply conveying that chunk validation failed. #[derive(Debug, Error)] #[error("Chunk validation failed")] +#[allow(dead_code)] pub(crate) struct ChunkValidationError; #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, DataSize)] diff --git a/node/src/utils.rs b/node/src/utils.rs index 42b124cefd..3c71b00104 100644 --- a/node/src/utils.rs +++ b/node/src/utils.rs @@ -359,6 +359,7 @@ pub(crate) fn xor(lhs: &mut [u8], rhs: &[u8]) { /// /// Using this function is usually a potential architectural issue and it should be used very /// sparingly. Consider introducing a different access pattern for the value under `Arc`. +#[allow(dead_code)] pub(crate) async fn wait_for_arc_drop( arc: Arc, attempts: usize, diff --git a/smart_contracts/contracts/explorer/faucet/README.md b/smart_contracts/contracts/explorer/faucet/README.md index bea61d656c..4829df7ff3 100644 --- a/smart_contracts/contracts/explorer/faucet/README.md +++ b/smart_contracts/contracts/explorer/faucet/README.md @@ -35,7 +35,7 @@ If you try to invoke the contract before these variables are set, then you'll ge | feature | cost | |--------------------------|-------------------| -| faucet install | `160_749_054_412` | -| faucet set variables | `135_343_030` | -| faucet call by installer | `2_884_513_067` | -| faucet call by user | `2_623_210_206` | +| faucet install | `142_640_262_074` | +| faucet set variables | `134_259_210` | +| faucet call by installer | `2_879_594_967` | +| faucet call by user | `2_615_492_876` | \ No newline at end of file diff --git a/types/Cargo.toml b/types/Cargo.toml index 5a684732fe..a799befa54 100644 --- a/types/Cargo.toml +++ b/types/Cargo.toml @@ -18,7 +18,7 @@ bincode = { version = "1.3.1", optional = true } blake2 = { version = "0.9.0", default-features = false } datasize = { version = "0.2.15", optional = true } derp = { version = "0.0.14", optional = true } -ed25519-dalek = { version = "2.0.0", default-features = false, features = ["alloc", "zeroize"] } +ed25519-dalek = { version = "2.1.1", default-features = false, features = ["alloc", "zeroize"] } getrandom = { version = "0.2.0", features = ["rdrand", "js"], optional = true } hex = { version = "0.4.2", default-features = false, features = ["alloc"] } hex_fmt = "0.3.0" @@ -27,7 +27,7 @@ itertools = { version = "0.10.3", default-features = false } libc = { version = "0.2.146", optional = true, default-features = false } k256 = { version = "0.13.1", default-features = false, features = ["ecdsa", "sha256"] } num = { version = "0.4.0", default-features = false, features = ["alloc"] } -num-derive = { version = "0.3.0", default-features = false } +num-derive = { version = "0.4.2", default-features = false } num-integer = { version = "0.1.42", default-features = false } num-rational = { version = "0.4.0", default-features = false, features = ["serde"] } num-traits = { version = "0.2.10", default-features = false } From d90b16ef9d2d3e40d29588a848fb53bf952bbc94 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Thu, 26 Sep 2024 18:29:01 +0200 Subject: [PATCH 10/16] remove unused code --- node/src/components/network.rs | 5 ----- node/src/types/value_or_chunk.rs | 6 ------ 2 files changed, 11 deletions(-) diff --git a/node/src/components/network.rs b/node/src/components/network.rs index bde7ff64be..119fae54d8 100644 --- a/node/src/components/network.rs +++ b/node/src/components/network.rs @@ -204,26 +204,21 @@ where } #[allow(dead_code)] -#[derive(DataSize)] struct ChannelManagement { /// Channel signaling a shutdown of the network. // Note: This channel is closed when `Network` is dropped, signalling the receivers that // they should cease operation. - #[data_size(skip)] shutdown_sender: Option>, /// Join handle for the server thread. - #[data_size(skip)] server_join_handle: Option>, /// Channel signaling a shutdown of the incoming connections. // Note: This channel is closed when we finished syncing, so the `Network` can close all // connections. When they are re-established, the proper value of the now updated `is_syncing` // flag will be exchanged on handshake. - #[data_size(skip)] close_incoming_sender: Option>, /// Handle used by the `message_reader` task to receive a notification that incoming /// connections should be closed. - #[data_size(skip)] close_incoming_receiver: watch::Receiver<()>, } diff --git a/node/src/types/value_or_chunk.rs b/node/src/types/value_or_chunk.rs index 59646bf0f5..d8d071ef0f 100644 --- a/node/src/types/value_or_chunk.rs +++ b/node/src/types/value_or_chunk.rs @@ -107,12 +107,6 @@ impl Display for ValueOrChunk> { } } -/// Error type simply conveying that chunk validation failed. -#[derive(Debug, Error)] -#[error("Chunk validation failed")] -#[allow(dead_code)] -pub(crate) struct ChunkValidationError; - #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, DataSize)] pub struct HashingTrieRaw { inner: TrieRaw, From ac278c78f363895a5ac6a8a5cdd73f1bf2eb9341 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Fri, 27 Sep 2024 00:43:31 +0200 Subject: [PATCH 11/16] bump time crate ver, allow skipping new lints --- Cargo.lock | 34 ++++++++++++++++++++++++++-------- Makefile | 9 +-------- binary_port/src/lib.rs | 2 ++ storage/src/lib.rs | 1 + 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b209415ad..f3d5ddce4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1552,9 +1552,12 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] [[package]] name = "derive_more" @@ -3906,6 +3909,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "num-derive" version = "0.3.3" @@ -4354,6 +4363,12 @@ dependencies = [ "pnet_sys", ] +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "pprof" version = "0.13.0" @@ -5756,14 +5771,16 @@ dependencies = [ [[package]] name = "time" -version = "0.3.25" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", "libc", + "num-conv", "num_threads", + "powerfmt", "serde", "time-core", "time-macros", @@ -5771,16 +5788,17 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.11" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb71511c991639bb078fd5bf97757e03914361c48100d52878b8e52b46fb92cd" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] diff --git a/Makefile b/Makefile index db90778235..907b328626 100644 --- a/Makefile +++ b/Makefile @@ -4,18 +4,11 @@ RUSTUP = $(or $(shell which rustup), $(HOME)/.cargo/bin/rustup) NPM = $(or $(shell which npm), /usr/bin/npm) PINNED_NIGHTLY := $(shell cat smart_contracts/rust-toolchain) -# TODO: When `PINNED_NIGHTLY` is updated to something reletively new, we can get rid -# of this specific 'NIGHTLY_FOR_DOC' variable and use `PINNED_NIGHTLY` in `make doc` instead. -# -# At the moment, we can't use STABLE for doc, due to 'doc_auto_cfg' feature being unstable. -# We also can't use the nightly version that is pinned for the contracts, because it is too old. -NIGHTLY_FOR_DOC = nightly-2024-01-01 PINNED_STABLE := $(shell sed -nr 's/channel *= *\"(.*)\"/\1/p' rust-toolchain.toml) WASM_STRIP_VERSION := $(shell wasm-strip --version) CARGO_OPTS := --locked CARGO_PINNED_NIGHTLY := $(CARGO) +$(PINNED_NIGHTLY) $(CARGO_OPTS) -CARGO_NIGHTLY_FOR_DOC := $(CARGO) +$(NIGHTLY_FOR_DOC) $(CARGO_OPTS) CARGO := $(CARGO) $(CARGO_OPTS) DISABLE_LOGGING = RUST_LOG=MatchesNothing @@ -164,7 +157,7 @@ audit: audit-rs .PHONY: doc doc: - RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(CARGO_NIGHTLY_FOR_DOC) doc --all-features $(CARGO_FLAGS) --no-deps + RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(CARGO_PINNED_NIGHTLY) doc --all-features $(CARGO_FLAGS) --no-deps cd smart_contracts/contract && RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(CARGO_PINNED_NIGHTLY) doc --all-features $(CARGO_FLAGS) --no-deps .PHONY: check-rs diff --git a/binary_port/src/lib.rs b/binary_port/src/lib.rs index ec0a173ccc..283753e084 100644 --- a/binary_port/src/lib.rs +++ b/binary_port/src/lib.rs @@ -1,5 +1,7 @@ //! A Rust library for types used by the binary port of a casper node. +#![allow(unexpected_cfgs)] + mod balance_response; mod binary_message; mod binary_request; diff --git a/storage/src/lib.rs b/storage/src/lib.rs index daa1c011ac..2609a054a9 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -6,6 +6,7 @@ html_logo_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Symbol_RGB.png" )] #![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![allow(unexpected_cfgs)] pub mod address_generator; pub mod block_store; From 97fd9ff5c74bd0223fb026da741be6aeb8d01466 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Tue, 1 Oct 2024 00:37:29 +0200 Subject: [PATCH 12/16] add cfg(test) attribs where appropriate --- node/src/components/binary_port.rs | 10 +++++++--- node/src/components/network.rs | 24 +++++++++++++++++------- node/src/components/rest_server.rs | 17 +++++++++++++---- node/src/effect.rs | 21 --------------------- node/src/reactor.rs | 6 ++++-- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/node/src/components/binary_port.rs b/node/src/components/binary_port.rs index 185bff496d..fb2d97b5bb 100644 --- a/node/src/components/binary_port.rs +++ b/node/src/components/binary_port.rs @@ -43,7 +43,7 @@ use casper_types::{ use datasize::DataSize; use either::Either; -use futures::{future::BoxFuture, FutureExt, SinkExt, StreamExt}; +use futures::{SinkExt, StreamExt}; use once_cell::sync::OnceCell; use prometheus::Registry; use tokio::{ @@ -54,6 +54,9 @@ use tokio::{ use tokio_util::codec::Framed; use tracing::{debug, error, info, warn}; +#[cfg(test)] +use futures::{future::BoxFuture, FutureExt}; + use crate::{ contract_runtime::SpeculativeExecutionResult, effect::{ @@ -64,7 +67,7 @@ use crate::{ }, EffectBuilder, EffectExt, Effects, }, - reactor::{main_reactor::MainEvent, Finalize, QueueKind}, + reactor::{main_reactor::MainEvent, QueueKind}, types::NodeRng, utils::{display_error, ListeningError}, }; @@ -1597,7 +1600,8 @@ async fn run_server( } } -impl Finalize for BinaryPort { +#[cfg(test)] +impl crate::reactor::Finalize for BinaryPort { fn finalize(mut self) -> BoxFuture<'static, ()> { self.shutdown_trigger.notify_one(); async move { diff --git a/node/src/components/network.rs b/node/src/components/network.rs index 7c77ec376d..6d16bef4ba 100644 --- a/node/src/components/network.rs +++ b/node/src/components/network.rs @@ -57,7 +57,6 @@ use std::{ }; use datasize::DataSize; -use futures::{future::BoxFuture, FutureExt}; use itertools::Itertools; use prometheus::Registry; use rand::{ @@ -77,6 +76,9 @@ use tokio_openssl::SslStream; use tokio_util::codec::LengthDelimitedCodec; use tracing::{debug, error, info, trace, warn, Instrument, Span}; +#[cfg(test)] +use futures::{future::BoxFuture, FutureExt}; + use casper_types::{EraId, PublicKey, SecretKey}; pub(crate) use self::{ @@ -113,7 +115,7 @@ use crate::{ requests::{BeginGossipRequest, NetworkInfoRequest, NetworkRequest, StorageRequest}, AutoClosingResponder, EffectBuilder, EffectExt, Effects, GossipTarget, }, - reactor::{Finalize, ReactorEvent}, + reactor::ReactorEvent, tls, types::{NodeId, ValidatorMatrix}, utils::{self, display_error, Source}, @@ -122,9 +124,6 @@ use crate::{ const COMPONENT_NAME: &str = "network"; -const MAX_METRICS_DROP_ATTEMPTS: usize = 25; -const DROP_RETRY_DELAY: Duration = Duration::from_millis(100); - /// How often to keep attempting to reconnect to a node before giving up. Note that reconnection /// delays increase exponentially! const RECONNECTION_ATTEMPTS: u8 = 8; @@ -206,20 +205,24 @@ where state: ComponentState, } -#[allow(dead_code)] struct ChannelManagement { /// Channel signaling a shutdown of the network. // Note: This channel is closed when `Network` is dropped, signalling the receivers that // they should cease operation. + #[allow(dead_code)] shutdown_sender: Option>, + /// Join handle for the server thread. + #[allow(dead_code)] server_join_handle: Option>, /// Channel signaling a shutdown of the incoming connections. // Note: This channel is closed when we finished syncing, so the `Network` can close all // connections. When they are re-established, the proper value of the now updated `is_syncing` // flag will be exchanged on handshake. + #[allow(dead_code)] close_incoming_sender: Option>, + /// Handle used by the `message_reader` task to receive a notification that incoming /// connections should be closed. close_incoming_receiver: watch::Receiver<()>, @@ -1027,7 +1030,14 @@ where } } -impl Finalize for Network +#[cfg(test)] +const MAX_METRICS_DROP_ATTEMPTS: usize = 25; + +#[cfg(test)] +const DROP_RETRY_DELAY: Duration = Duration::from_millis(100); + +#[cfg(test)] +impl crate::reactor::Finalize for Network where REv: Send + 'static, P: Payload, diff --git a/node/src/components/rest_server.rs b/node/src/components/rest_server.rs index d5c2d7bce4..a4650cad04 100644 --- a/node/src/components/rest_server.rs +++ b/node/src/components/rest_server.rs @@ -28,10 +28,16 @@ mod info; use std::{net::SocketAddr, sync::Arc}; use datasize::DataSize; -use futures::{future::BoxFuture, join, FutureExt}; +use futures::join; use once_cell::sync::OnceCell; use tokio::{sync::oneshot, task::JoinHandle}; -use tracing::{debug, error, info, warn}; +use tracing::{error, info, warn}; + +#[cfg(test)] +use futures::{future::BoxFuture, FutureExt}; + +#[cfg(test)] +use tracing::debug; use casper_types::ProtocolVersion; @@ -46,7 +52,7 @@ use crate::{ }, EffectBuilder, EffectExt, Effects, }, - reactor::{main_reactor::MainEvent, Finalize}, + reactor::{main_reactor::MainEvent}, types::{ChainspecInfo, StatusFeed}, utils::{self, ListeningError}, NodeRng, @@ -95,11 +101,13 @@ impl ReactorEventT for REv where pub(crate) struct InnerRestServer { /// When the message is sent, it signals the server loop to exit cleanly. #[data_size(skip)] + #[allow(dead_code)] shutdown_sender: oneshot::Sender<()>, /// The address the server is listening on. local_addr: Arc>, /// The task handle which will only join once the server loop has exited. #[data_size(skip)] + #[allow(dead_code)] server_join_handle: Option>, /// The network name, as specified in the chainspec network_name: String, @@ -321,7 +329,8 @@ where } } -impl Finalize for RestServer { +#[cfg(test)] +impl crate::reactor::Finalize for RestServer { fn finalize(self) -> BoxFuture<'static, ()> { async { if let Some(mut rest_server) = self.inner_rest { diff --git a/node/src/effect.rs b/node/src/effect.rs index 7b739e2f84..3e465e79c8 100644 --- a/node/src/effect.rs +++ b/node/src/effect.rs @@ -379,18 +379,6 @@ pub(crate) trait EffectExt: Future + Send { U: 'static, Self: Sized; - /// Finalizes a future into an effect that returns an iterator of events. - /// - /// The function `f` is used to translate the returned value from an effect into an iterator of - /// events. - #[allow(dead_code)] - fn events(self, f: F) -> Effects - where - F: FnOnce(Self::Output) -> I + 'static + Send, - U: 'static, - I: Iterator, - Self: Sized; - /// Finalizes a future into an effect that runs but drops the result. fn ignore(self) -> Effects; } @@ -453,15 +441,6 @@ where smallvec![self.map(f).map(|item| smallvec![item]).boxed()] } - fn events(self, f: F) -> Effects - where - F: FnOnce(Self::Output) -> I + 'static + Send, - U: 'static, - I: Iterator, - { - smallvec![self.map(f).map(|iter| iter.collect()).boxed()] - } - fn ignore(self) -> Effects { smallvec![self.map(|_| Multiple::new()).boxed()] } diff --git a/node/src/reactor.rs b/node/src/reactor.rs index ba0198c3fe..dbca754211 100644 --- a/node/src/reactor.rs +++ b/node/src/reactor.rs @@ -49,7 +49,9 @@ use datasize::DataSize; use erased_serde::Serialize as ErasedSerialize; #[cfg(test)] use fake_instant::FakeClock; -use futures::{future::BoxFuture, FutureExt}; +#[cfg(test)] +use futures::future::BoxFuture; +use futures::FutureExt; use once_cell::sync::Lazy; use prometheus::{self, Histogram, HistogramOpts, IntCounter, IntGauge, Registry}; use quanta::{Clock, IntoNanoseconds}; @@ -335,7 +337,7 @@ pub(crate) trait ReactorEvent: Send + Debug + From + 'stati /// A drop-like trait for `async` compatible drop-and-wait. /// /// Shuts down a type by explicitly freeing resources, but allowing to wait on cleanup to complete. -#[allow(dead_code)] +#[cfg(test)] pub(crate) trait Finalize: Sized { /// Runs cleanup code and waits for a shutdown to complete. /// From 4f3143e0a5287e89cfcc69007a4cedd846925976 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Tue, 1 Oct 2024 00:41:17 +0200 Subject: [PATCH 13/16] apply fmt suggestions --- node/src/components/rest_server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/src/components/rest_server.rs b/node/src/components/rest_server.rs index a4650cad04..e6b0d23d61 100644 --- a/node/src/components/rest_server.rs +++ b/node/src/components/rest_server.rs @@ -52,7 +52,7 @@ use crate::{ }, EffectBuilder, EffectExt, Effects, }, - reactor::{main_reactor::MainEvent}, + reactor::main_reactor::MainEvent, types::{ChainspecInfo, StatusFeed}, utils::{self, ListeningError}, NodeRng, From 6285c4db97d86be8b650cb60a19054f82f00aa8a Mon Sep 17 00:00:00 2001 From: igor-casper Date: Tue, 1 Oct 2024 19:39:48 +0200 Subject: [PATCH 14/16] remove anemic features --- binary_port/src/lib.rs | 2 +- binary_port/src/response_type.rs | 3 --- binary_port/src/type_wrappers.rs | 4 ---- node/src/components/binary_port.rs | 4 +++- storage/src/data_access_layer/genesis.rs | 4 ++-- storage/src/data_access_layer/key_prefix.rs | 7 +++---- storage/src/lib.rs | 1 - 7 files changed, 9 insertions(+), 16 deletions(-) diff --git a/binary_port/src/lib.rs b/binary_port/src/lib.rs index 283753e084..58a17d0f90 100644 --- a/binary_port/src/lib.rs +++ b/binary_port/src/lib.rs @@ -1,6 +1,6 @@ //! A Rust library for types used by the binary port of a casper node. -#![allow(unexpected_cfgs)] +// #![allow(unexpected_cfgs)] mod balance_response; mod binary_message; diff --git a/binary_port/src/response_type.rs b/binary_port/src/response_type.rs index 7f58f3869a..6be59c9b3e 100644 --- a/binary_port/src/response_type.rs +++ b/binary_port/src/response_type.rs @@ -4,8 +4,6 @@ use core::{convert::TryFrom, fmt}; #[cfg(test)] use rand::Rng; -#[cfg(feature = "json-schema")] -use schemars::JsonSchema; #[cfg(test)] use casper_types::testing::TestRng; @@ -32,7 +30,6 @@ use crate::{ /// A type of the payload being returned in a binary response. #[derive(Debug, Copy, Clone, PartialEq, Eq)] #[repr(u8)] -#[cfg_attr(feature = "json-schema", derive(JsonSchema))] pub enum ResponseType { /// Legacy version of the block header. BlockHeaderV1, diff --git a/binary_port/src/type_wrappers.rs b/binary_port/src/type_wrappers.rs index 11d4e40e37..89a14cbf78 100644 --- a/binary_port/src/type_wrappers.rs +++ b/binary_port/src/type_wrappers.rs @@ -1,9 +1,6 @@ use core::{convert::TryFrom, num::TryFromIntError, time::Duration}; use std::collections::BTreeMap; -#[cfg(feature = "datasize")] -use datasize::DataSize; - use casper_types::{ bytesrepr::{self, Bytes, FromBytes, ToBytes}, contracts::ContractHash, @@ -76,7 +73,6 @@ impl TryFrom for TimeDiff { /// Type representing changes in consensus validators. #[derive(Debug, PartialEq, Eq, Serialize)] -#[cfg_attr(feature = "datasize", derive(DataSize))] pub struct ConsensusValidatorChanges(BTreeMap>); impl ConsensusValidatorChanges { diff --git a/node/src/components/binary_port.rs b/node/src/components/binary_port.rs index fb2d97b5bb..519bf71db0 100644 --- a/node/src/components/binary_port.rs +++ b/node/src/components/binary_port.rs @@ -83,9 +83,11 @@ const COMPONENT_NAME: &str = "binary_port"; #[derive(Debug, DataSize)] pub(crate) struct BinaryPort { + #[data_size(skip)] state: ComponentState, + #[data_size(skip)] config: Arc, - /// The chainspec. + #[data_size(skip)] chainspec: Arc, #[data_size(skip)] connection_limit: Arc, diff --git a/storage/src/data_access_layer/genesis.rs b/storage/src/data_access_layer/genesis.rs index 163270c76f..7125c7d20f 100644 --- a/storage/src/data_access_layer/genesis.rs +++ b/storage/src/data_access_layer/genesis.rs @@ -1,4 +1,4 @@ -#[cfg(any(feature = "testing", test))] +#[cfg(test)] use rand::{ distributions::{Distribution, Standard}, Rng, @@ -54,7 +54,7 @@ impl GenesisRequest { } } -#[cfg(any(feature = "testing", test))] +#[cfg(test)] impl Distribution for Standard { fn sample(&self, rng: &mut R) -> GenesisRequest { let input: [u8; 32] = rng.gen(); diff --git a/storage/src/data_access_layer/key_prefix.rs b/storage/src/data_access_layer/key_prefix.rs index c6dbb75a8e..db1e82a099 100644 --- a/storage/src/data_access_layer/key_prefix.rs +++ b/storage/src/data_access_layer/key_prefix.rs @@ -1,5 +1,3 @@ -#[cfg(any(feature = "testing", test))] -use casper_types::testing::TestRng; use casper_types::{ account::AccountHash, bytesrepr::{self, FromBytes, ToBytes, U8_SERIALIZED_LENGTH}, @@ -7,8 +5,6 @@ use casper_types::{ system::{auction::BidAddrTag, mint::BalanceHoldAddrTag}, EntityAddr, KeyTag, URefAddr, }; -#[cfg(any(feature = "testing", test))] -use rand::Rng; /// Key prefixes used for querying the global state. #[derive(Debug, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)] @@ -172,6 +168,9 @@ impl FromBytes for KeyPrefix { #[cfg(test)] mod tests { + use casper_types::testing::TestRng; + use rand::Rng; + use casper_types::{ addressable_entity::NamedKeyAddr, contract_messages::MessageAddr, diff --git a/storage/src/lib.rs b/storage/src/lib.rs index 2609a054a9..daa1c011ac 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -6,7 +6,6 @@ html_logo_url = "https://raw.githubusercontent.com/CasperLabs/casper-node/master/images/CasperLabs_Logo_Symbol_RGB.png" )] #![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![allow(unexpected_cfgs)] pub mod address_generator; pub mod block_store; From 0b5a0f3b1d04bc54e25da64a247d8d307fee6ba6 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Wed, 2 Oct 2024 15:40:47 +0200 Subject: [PATCH 15/16] remove a dead trait --- node/src/effect.rs | 63 ---------------------------------------------- 1 file changed, 63 deletions(-) diff --git a/node/src/effect.rs b/node/src/effect.rs index 3e465e79c8..2017752aff 100644 --- a/node/src/effect.rs +++ b/node/src/effect.rs @@ -402,33 +402,6 @@ pub(crate) trait EffectResultExt { U: 'static; } -/// Effect extension for futures, used to convert futures returning an `Option` into two different -/// effects. -#[allow(dead_code)] -pub(crate) trait EffectOptionExt { - /// The type the future will return if `Some`. - type Value; - - /// Finalizes a future returning an `Option` into two different effects. - /// - /// The function `f_some` is used to translate the returned value from an effect into an event, - /// while the function `f_none` does the same for a returned `None`. - fn map_or_else(self, f_some: F, f_none: G) -> Effects - where - F: FnOnce(Self::Value) -> U + 'static + Send, - G: FnOnce() -> U + 'static + Send, - U: 'static; - - /// Finalizes a future returning an `Option` into two different effects. - /// - /// The function `f` is used to translate the returned value from an effect into an event, - /// In the case of `None`, empty vector of effects is returned. - fn map_some(self, f: F) -> Effects - where - F: FnOnce(Self::Value) -> U + 'static + Send, - U: 'static; -} - impl EffectExt for T where T: Future + Send + 'static + Sized, @@ -467,42 +440,6 @@ where } } -impl EffectOptionExt for T -where - T: Future> + Send + 'static + Sized, - T: ?Sized, -{ - type Value = V; - - fn map_or_else(self, f_some: F, f_none: G) -> Effects - where - F: FnOnce(V) -> U + 'static + Send, - G: FnOnce() -> U + 'static + Send, - U: 'static, - { - smallvec![self - .map(|option| option.map_or_else(f_none, f_some)) - .map(|item| smallvec![item]) - .boxed()] - } - - /// Finalizes a future returning an `Option`. - /// - /// The function `f` is used to translate the returned value from an effect into an event, - /// In the case of `None`, empty vector is returned. - fn map_some(self, f: F) -> Effects - where - F: FnOnce(Self::Value) -> U + 'static + Send, - U: 'static, - { - smallvec![self - .map(|option| option - .map(|el| smallvec![f(el)]) - .unwrap_or_else(|| smallvec![])) - .boxed()] - } -} - /// A builder for [`Effect`](type.Effect.html)s. /// /// Provides methods allowing the creation of effects which need to be scheduled on the reactor's From 55337d96537b172fe2c8f79ca0ede79eda230f93 Mon Sep 17 00:00:00 2001 From: igor-casper Date: Thu, 3 Oct 2024 14:35:29 +0200 Subject: [PATCH 16/16] remove comments, adjust attributes --- binary_port/src/lib.rs | 2 -- node/src/utils.rs | 13 ++++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/binary_port/src/lib.rs b/binary_port/src/lib.rs index 58a17d0f90..ec0a173ccc 100644 --- a/binary_port/src/lib.rs +++ b/binary_port/src/lib.rs @@ -1,7 +1,5 @@ //! A Rust library for types used by the binary port of a casper node. -// #![allow(unexpected_cfgs)] - mod balance_response; mod binary_message; mod binary_request; diff --git a/node/src/utils.rs b/node/src/utils.rs index 1e6d8bc432..93294fb097 100644 --- a/node/src/utils.rs +++ b/node/src/utils.rs @@ -16,19 +16,18 @@ pub(crate) mod umask; pub mod work_queue; use std::{ - any, fmt::{self, Debug, Display, Formatter}, io, net::{SocketAddr, ToSocketAddrs}, ops::{Add, BitXorAssign, Div}, path::{Path, PathBuf}, - sync::{ - atomic::{AtomicBool, Ordering}, - Arc, - }, - time::{Duration, Instant, SystemTime}, + sync::atomic::{AtomicBool, Ordering}, + time::{Instant, SystemTime}, }; +#[cfg(test)] +use std::{any, sync::Arc, time::Duration}; + use datasize::DataSize; use hyper::server::{conn::AddrIncoming, Builder, Server}; #[cfg(test)] @@ -360,7 +359,7 @@ pub(crate) fn xor(lhs: &mut [u8], rhs: &[u8]) { /// /// Using this function is usually a potential architectural issue and it should be used very /// sparingly. Consider introducing a different access pattern for the value under `Arc`. -#[allow(dead_code)] +#[cfg(test)] pub(crate) async fn wait_for_arc_drop( arc: Arc, attempts: usize,