From 842108c7578f6dba6f6340384e47eedb4c2e5165 Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 26 May 2025 08:24:26 +0800 Subject: [PATCH 1/3] allow axon ip as 0 --- pallets/subtensor/src/subnets/serving.rs | 18 +++++----------- pallets/subtensor/src/tests/serving.rs | 27 ++++++++++++++++-------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pallets/subtensor/src/subnets/serving.rs b/pallets/subtensor/src/subnets/serving.rs index c8c89bc011..bee81bfae6 100644 --- a/pallets/subtensor/src/subnets/serving.rs +++ b/pallets/subtensor/src/subnets/serving.rs @@ -172,7 +172,7 @@ impl Pallet { // Check the ip signature validity. ensure!(Self::is_valid_ip_type(ip_type), Error::::InvalidIpType); ensure!( - Self::is_valid_ip_address(ip_type, ip), + Self::is_valid_ip_address(ip_type, ip, false), Error::::InvalidIpAddress ); @@ -276,17 +276,11 @@ impl Pallet { } // @todo (Parallax 2-1-2021) : Implement exclusion of private IP ranges - pub fn is_valid_ip_address(ip_type: u8, addr: u128) -> bool { - if !Self::is_valid_ip_type(ip_type) { - return false; - } - if addr == 0 { + pub fn is_valid_ip_address(ip_type: u8, addr: u128, allow_zero: bool) -> bool { + if !allow_zero && addr == 0 { return false; } if ip_type == 4 { - if addr == 0 { - return false; - } if addr >= u32::MAX as u128 { return false; } @@ -295,9 +289,6 @@ impl Pallet { } // Localhost } if ip_type == 6 { - if addr == 0x0 { - return false; - } if addr == u128::MAX { return false; } @@ -346,7 +337,8 @@ impl Pallet { // Check the ip signature validity. ensure!(Self::is_valid_ip_type(ip_type), Error::::InvalidIpType); ensure!( - Self::is_valid_ip_address(ip_type, ip), + // allow axon to be served with a zero ip address for testing purposes + Self::is_valid_ip_address(ip_type, ip, true), Error::::InvalidIpAddress ); diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index 251dde2078..269d70485b 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -555,7 +555,8 @@ fn test_serving_is_valid_ip_address_ipv4() { new_test_ext(1).execute_with(|| { assert!(SubtensorModule::is_valid_ip_address( 4, - test::ipv4(8, 8, 8, 8) + test::ipv4(8, 8, 8, 8), + false )); }); } @@ -565,11 +566,13 @@ fn test_serving_is_valid_ip_address_ipv6() { new_test_ext(1).execute_with(|| { assert!(SubtensorModule::is_valid_ip_address( 6, - test::ipv6(1, 2, 3, 4, 5, 6, 7, 8) + test::ipv6(1, 2, 3, 4, 5, 6, 7, 8), + false )); assert!(SubtensorModule::is_valid_ip_address( 6, - test::ipv6(1, 2, 3, 4, 5, 6, 7, 8) + test::ipv6(1, 2, 3, 4, 5, 6, 7, 8), + false )); }); } @@ -579,19 +582,23 @@ fn test_serving_is_invalid_ipv4_address() { new_test_ext(1).execute_with(|| { assert!(!SubtensorModule::is_valid_ip_address( 4, - test::ipv4(0, 0, 0, 0) + test::ipv4(0, 0, 0, 0), + false )); assert!(!SubtensorModule::is_valid_ip_address( 4, - test::ipv4(255, 255, 255, 255) + test::ipv4(255, 255, 255, 255), + false )); assert!(!SubtensorModule::is_valid_ip_address( 4, - test::ipv4(127, 0, 0, 1) + test::ipv4(127, 0, 0, 1), + false )); assert!(!SubtensorModule::is_valid_ip_address( 4, - test::ipv6(0xffff, 2, 3, 4, 5, 6, 7, 8) + test::ipv6(0xffff, 2, 3, 4, 5, 6, 7, 8), + false )); }); } @@ -601,13 +608,15 @@ fn test_serving_is_invalid_ipv6_address() { new_test_ext(1).execute_with(|| { assert!(!SubtensorModule::is_valid_ip_address( 6, - test::ipv6(0, 0, 0, 0, 0, 0, 0, 0) + test::ipv6(0, 0, 0, 0, 0, 0, 0, 0), + false )); assert!(!SubtensorModule::is_valid_ip_address( 4, test::ipv6( 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff - ) + ), + false )); }); } From 493832fd6891e5bb9eb4756a160b9308eeb18f5d Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 26 May 2025 08:38:08 +0800 Subject: [PATCH 2/3] add more tests --- pallets/subtensor/src/tests/serving.rs | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pallets/subtensor/src/tests/serving.rs b/pallets/subtensor/src/tests/serving.rs index 269d70485b..6711862a6b 100644 --- a/pallets/subtensor/src/tests/serving.rs +++ b/pallets/subtensor/src/tests/serving.rs @@ -558,6 +558,12 @@ fn test_serving_is_valid_ip_address_ipv4() { test::ipv4(8, 8, 8, 8), false )); + + assert!(SubtensorModule::is_valid_ip_address( + 4, + test::ipv4(0, 0, 0, 0), + true + )); }); } @@ -574,6 +580,11 @@ fn test_serving_is_valid_ip_address_ipv6() { test::ipv6(1, 2, 3, 4, 5, 6, 7, 8), false )); + assert!(SubtensorModule::is_valid_ip_address( + 6, + test::ipv6(0, 0, 0, 0, 0, 0, 0, 0), + true + )); }); } @@ -600,6 +611,21 @@ fn test_serving_is_invalid_ipv4_address() { test::ipv6(0xffff, 2, 3, 4, 5, 6, 7, 8), false )); + assert!(!SubtensorModule::is_valid_ip_address( + 4, + test::ipv4(255, 255, 255, 255), + true + )); + assert!(!SubtensorModule::is_valid_ip_address( + 4, + test::ipv4(127, 0, 0, 1), + true + )); + assert!(!SubtensorModule::is_valid_ip_address( + 4, + test::ipv6(0xffff, 2, 3, 4, 5, 6, 7, 8), + true + )); }); } @@ -618,6 +644,13 @@ fn test_serving_is_invalid_ipv6_address() { ), false )); + assert!(!SubtensorModule::is_valid_ip_address( + 4, + test::ipv6( + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff + ), + true + )); }); } From f27d15565434ecfc8beb2929503c03e59e91f6f5 Mon Sep 17 00:00:00 2001 From: open-junius Date: Mon, 26 May 2025 13:18:15 +0800 Subject: [PATCH 3/3] update version --- runtime/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 95b032f9e6..5e099d1ce2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -209,7 +209,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { // `spec_version`, and `authoring_version` are the same between Wasm and native. // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use // the compatible custom types. - spec_version: 272, + spec_version: 273, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1,