Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8c3ec67
try dissolve_network benchmark
open-junius Feb 10, 2026
9030e64
remove collect
open-junius Feb 10, 2026
f6293d7
add on idle
open-junius Feb 11, 2026
fb3dc04
add weight meter
open-junius Feb 12, 2026
e7d60f1
on_idle hook
open-junius Feb 13, 2026
860d84d
add macro
open-junius Feb 13, 2026
5161299
need handle remove all lp
open-junius Feb 13, 2026
890f685
fix typo
open-junius Feb 13, 2026
07da3b5
update interface
open-junius Feb 13, 2026
7b0cca7
merge devnet-ready
open-junius Feb 13, 2026
4b9a6a0
cargo clippy
open-junius Feb 13, 2026
e9a67b8
add weigth for all db ops
open-junius Feb 16, 2026
8f17e84
commit Cargo.lock
open-junius Feb 16, 2026
f932ae6
commit Cargo.lock
open-junius Feb 16, 2026
71668de
commit Cargo.lock
open-junius Feb 16, 2026
85d33d6
commit Cargo.lock
open-junius Feb 16, 2026
dc8b744
commit Cargo.lock
open-junius Feb 16, 2026
08d2d34
optimize some db ops
open-junius Feb 16, 2026
50cd88c
add unit test for macro
open-junius Feb 16, 2026
2dc8630
cargo clippy
open-junius Feb 16, 2026
f3eb5bd
commit Cargo.lock
open-junius Feb 16, 2026
cc033e6
exclude the dissolved network id when registration
open-junius Feb 16, 2026
8f2add8
fix unit test
open-junius Feb 16, 2026
c9c66d8
Merge branch 'devnet-ready' into benchmark-dissolve-network
open-junius Feb 24, 2026
cbc441b
fix unit test
open-junius Feb 25, 2026
21d8e4f
fix clippy
open-junius Feb 25, 2026
f2ed907
reduce benchmark for dissolve_network
open-junius Feb 25, 2026
d489382
fix unit test
open-junius Feb 25, 2026
aabec8c
update purge netuid in mock
open-junius Feb 25, 2026
06f5cdc
fix bug, missed bonds removal
open-junius Feb 25, 2026
203628c
correct weights for dissolve network
open-junius Feb 25, 2026
984f14c
fix benchmark
open-junius Feb 26, 2026
39205fd
merge with devnet ready
open-junius Feb 26, 2026
9361813
commit Cargo.lock
open-junius Feb 26, 2026
694b833
commit Cargo.lock
open-junius Feb 26, 2026
ed7b2e3
commit Cargo.lock
open-junius Feb 26, 2026
951d04a
commit Cargo.lock
open-junius Feb 26, 2026
453db3f
fix unit test
open-junius Feb 26, 2026
7639d7e
Merge branch 'devnet-ready' into benchmark-dissolve-network
open-junius Feb 27, 2026
a861672
add subnet exist check in admin util
open-junius Feb 27, 2026
b8eac0c
add netuid exist check
open-junius Mar 2, 2026
f407896
check all clean up function
open-junius Mar 2, 2026
0ec605f
cargo clippy
open-junius Mar 2, 2026
f30093e
fix unit test
open-junius Mar 2, 2026
9cca3c6
increase balance diff
open-junius Mar 3, 2026
3c524f8
update yarn lock file
open-junius Mar 3, 2026
9eb810c
not lock yarn dep
open-junius Mar 3, 2026
ebee8a9
upgrade polkadot-api
open-junius Mar 3, 2026
7fbca9a
fix low tx fee
open-junius Mar 3, 2026
f9191d6
correct weigth in on_idle
open-junius Mar 3, 2026
3adb0b8
add batch size parameter
open-junius Mar 6, 2026
7fa4030
merge devnet ready
open-junius Mar 6, 2026
ff91f52
fix benchmark
open-junius Mar 6, 2026
807ce96
auto-update benchmark weights
github-actions[bot] Mar 6, 2026
124db65
Merge branch 'devnet-ready' into benchmark-dissolve-network
open-junius Mar 9, 2026
4c025b0
fix meter compute
open-junius Mar 9, 2026
6e59f7a
optimize a data remove
open-junius Mar 9, 2026
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
34 changes: 20 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion chain-extensions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ impl PrivilegeCmp<OriginCaller> for OriginPrivilegeCmp {

pub struct CommitmentsI;
impl CommitmentsInterface for CommitmentsI {
fn purge_netuid(_netuid: NetUid) {}
fn purge_netuid(_netuid: NetUid, remaining_weight: Weight) -> Weight {
remaining_weight
}
}

parameter_types! {
Expand Down
159 changes: 159 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,171 @@ impl TypeInfo for NetUidStorageIndex {
}
}

#[macro_export]
macro_rules! WeightMeterWrapper {
( $meter:expr, $weight:expr ) => {{
if !$meter.can_consume($weight) {
return $meter.consumed();
}
$meter.consume($weight);
}};
}

pub const BATCH_SIZE: u32 = 1024;

#[macro_export]
macro_rules! LoopRemovePrefixWithWeightMeter {
( $meter:expr, $weight:expr, $batch_size:expr, $body:expr ) => {{
loop {
if !$meter.can_consume($weight.saturating_mul($batch_size as u64)) {
return $meter.consumed();
}
let result = $body;

$meter.consume($weight.saturating_mul(result.backend as u64));
if result.maybe_cursor.is_none() {
break;
}
}
$meter.consumed()
}};
}

#[cfg(test)]
mod tests {
use super::*;
use frame_support::weights::WeightMeter;
const REF_TIME_WEIGHT: u64 = 100;
const PROOF_SIZE_WEIGHT: u64 = 100;
const BATCH_SIZE_U64: u64 = BATCH_SIZE as u64;

struct TestBody {
count: u64,
}

struct TestResult {
backend: u64,
maybe_cursor: Option<()>,
}

impl TestBody {
fn new(count: u64) -> Self {
Self { count }
}

fn execute(&mut self, number: u64) -> TestResult {
if self.count >= number {
self.count = self.count.saturating_sub(number);
TestResult {
backend: number,
maybe_cursor: Some(()),
}
} else {
let tmp = self.count;
self.count = 0;
TestResult {
backend: tmp,
maybe_cursor: None,
}
}
}
}

#[test]
fn netuid_has_u16_bin_repr() {
assert_eq!(NetUid(5).encode(), 5u16.encode());
}

fn test_weight(remaining_weight: Weight, weight: Weight) -> Weight {
let mut weight_meter = WeightMeter::with_limit(remaining_weight);
WeightMeterWrapper!(weight_meter, weight);
weight_meter.consumed()
}

fn test_loop(
remaining_weight: Weight,
weight: Weight,
body: &mut TestBody,
number: u64,
) -> Weight {
let mut weight_meter = WeightMeter::with_limit(remaining_weight);
LoopRemovePrefixWithWeightMeter!(weight_meter, weight, BATCH_SIZE, body.execute(number));
weight_meter.consumed()
}

#[test]
fn test_weight_meter_wrapper() {
// enough to consume one ref and one proof
let remaining_weight = Weight::from_parts(REF_TIME_WEIGHT * 2, PROOF_SIZE_WEIGHT * 2);
let used_weight = test_weight(
remaining_weight,
Weight::from_parts(REF_TIME_WEIGHT, PROOF_SIZE_WEIGHT),
);
assert_eq!(used_weight, Weight::from_parts(100, 100));

// not enough to consume three ref and three proof
let used_weight = test_weight(
remaining_weight,
Weight::from_parts(REF_TIME_WEIGHT * 3, PROOF_SIZE_WEIGHT * 3),
);
assert_eq!(used_weight, Weight::from_parts(0, 0));
}

#[test]
fn test_loop_remove_prefix_with_weight_meter() {
// remaining weight matches the body count
let mut body = TestBody::new(BATCH_SIZE as u64);
let remaining_weight = Weight::from_parts(
REF_TIME_WEIGHT * BATCH_SIZE as u64,
PROOF_SIZE_WEIGHT * BATCH_SIZE as u64,
);
let used_weight = test_loop(
remaining_weight,
Weight::from_parts(REF_TIME_WEIGHT, PROOF_SIZE_WEIGHT),
&mut body,
BATCH_SIZE as u64,
);
assert_eq!(
used_weight,
Weight::from_parts(REF_TIME_WEIGHT, PROOF_SIZE_WEIGHT) * BATCH_SIZE as u64
);
assert_eq!(body.count, 0);

// remaining weight is less than the body count
let count = BATCH_SIZE_U64 + 1;
let mut body = TestBody::new(count);
let remaining_weight = Weight::from_parts(
REF_TIME_WEIGHT * BATCH_SIZE_U64,
PROOF_SIZE_WEIGHT * BATCH_SIZE_U64,
);
let used_weight = test_loop(
remaining_weight,
Weight::from_parts(REF_TIME_WEIGHT, PROOF_SIZE_WEIGHT),
&mut body,
BATCH_SIZE_U64,
);
assert_eq!(
used_weight,
Weight::from_parts(REF_TIME_WEIGHT, PROOF_SIZE_WEIGHT) * BATCH_SIZE_U64
);
assert_eq!(body.count, 1);

// remaining weight is more than the body count
let mut body = TestBody::new(count);
let remaining_weight = Weight::from_parts(
REF_TIME_WEIGHT * BATCH_SIZE_U64 * 2,
PROOF_SIZE_WEIGHT * BATCH_SIZE_U64 * 2,
);
let used_weight = test_loop(
remaining_weight,
Weight::from_parts(REF_TIME_WEIGHT, PROOF_SIZE_WEIGHT),
&mut body,
BATCH_SIZE_U64,
);
assert_eq!(
used_weight,
Weight::from_parts(REF_TIME_WEIGHT, PROOF_SIZE_WEIGHT) * count
);
assert_eq!(body.count, 0);
}
}
2 changes: 1 addition & 1 deletion contract-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dotenv": "17.2.1",
"ethers": "^6.13.5",
"mocha": "^11.1.0",
"polkadot-api": "^1.22.0",
"polkadot-api": "^1.23.3",
"rxjs": "^7.8.2",
"scale-ts": "^1.6.1",
"viem": "2.23.4",
Expand Down
Loading
Loading