Skip to content

Commit f0bb79d

Browse files
committed
refactor: rename allowed_delta to be weight_reduction_allowed_delta
1 parent 25c9d55 commit f0bb79d

File tree

13 files changed

+85
-63
lines changed

13 files changed

+85
-63
lines changed

crates/e2e-tests/src/e2e_flow.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,11 +1378,11 @@ mod tests {
13781378
.current_committee()
13791379
.unwrap();
13801380
assert_eq!(
1381-
epoch1_committee.threshold_basis_points(),
1381+
epoch1_committee.mpc_threshold_basis_points(),
13821382
DEFAULT_MPC_THRESHOLD_BASIS_POINTS
13831383
);
13841384
assert_eq!(
1385-
epoch1_committee.allowed_delta(),
1385+
epoch1_committee.mpc_weight_reduction_allowed_delta(),
13861386
DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA
13871387
);
13881388

@@ -1397,7 +1397,7 @@ mod tests {
13971397
hashi_types::move_types::ConfigValue::U64(new_threshold),
13981398
),
13991399
(
1400-
"mpc_allowed_delta".into(),
1400+
"mpc_weight_reduction_allowed_delta".into(),
14011401
hashi_types::move_types::ConfigValue::U64(new_delta),
14021402
),
14031403
],
@@ -1444,25 +1444,25 @@ mod tests {
14441444
};
14451445
let epoch1 = committees.get(&initial_epoch).expect("epoch 1 committee");
14461446
assert_eq!(
1447-
epoch1.threshold_basis_points(),
1447+
epoch1.mpc_threshold_basis_points(),
14481448
DEFAULT_MPC_THRESHOLD_BASIS_POINTS,
14491449
"epoch {initial_epoch} committee should retain original threshold_basis_points"
14501450
);
14511451
assert_eq!(
1452-
epoch1.allowed_delta(),
1452+
epoch1.mpc_weight_reduction_allowed_delta(),
14531453
DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA,
14541454
"epoch {initial_epoch} committee should retain original allowed_delta"
14551455
);
14561456

14571457
// Epoch 2 committee has new values.
14581458
let epoch2 = committees.get(&target_epoch).expect("epoch 2 committee");
14591459
assert_eq!(
1460-
epoch2.threshold_basis_points(),
1460+
epoch2.mpc_threshold_basis_points(),
14611461
new_threshold as u16,
14621462
"epoch {target_epoch} committee should have updated threshold_basis_points"
14631463
);
14641464
assert_eq!(
1465-
epoch2.allowed_delta(),
1465+
epoch2.mpc_weight_reduction_allowed_delta(),
14661466
new_delta as u16,
14671467
"epoch {target_epoch} committee should have updated allowed_delta"
14681468
);

crates/hashi-types/proto/sui/hashi/v1alpha/signature.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ message Committee {
66
optional uint64 epoch = 1;
77
repeated CommitteeMember members = 2;
88
optional uint64 total_weight = 3;
9-
optional uint64 threshold_basis_points = 4;
10-
optional uint64 allowed_delta = 5;
9+
optional uint64 mpc_threshold_basis_points = 4;
10+
optional uint64 mpc_weight_reduction_allowed_delta = 5;
1111
}
1212

1313
message CommitteeMember {

crates/hashi-types/src/committee.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pub struct Committee {
9393
members: Vec<CommitteeMember>,
9494
address_to_index: HashMap<Address, usize>,
9595
total_weight: u64,
96-
threshold_basis_points: u16,
97-
allowed_delta: u16,
96+
mpc_threshold_basis_points: u16,
97+
mpc_weight_reduction_allowed_delta: u16,
9898
}
9999

100100
#[derive(Clone, PartialEq)]
@@ -160,8 +160,8 @@ impl Committee {
160160
pub fn new(
161161
members: Vec<CommitteeMember>,
162162
epoch: u64,
163-
threshold_basis_points: u16,
164-
allowed_delta: u16,
163+
mpc_threshold_basis_points: u16,
164+
mpc_weight_reduction_allowed_delta: u16,
165165
) -> Self {
166166
let total_weight = members.iter().map(|member| member.weight).sum();
167167
let address_to_index = members
@@ -174,8 +174,8 @@ impl Committee {
174174
members,
175175
address_to_index,
176176
total_weight,
177-
threshold_basis_points,
178-
allowed_delta,
177+
mpc_threshold_basis_points,
178+
mpc_weight_reduction_allowed_delta,
179179
}
180180
}
181181

@@ -192,12 +192,12 @@ impl Committee {
192192
self.total_weight
193193
}
194194

195-
pub fn threshold_basis_points(&self) -> u16 {
196-
self.threshold_basis_points
195+
pub fn mpc_threshold_basis_points(&self) -> u16 {
196+
self.mpc_threshold_basis_points
197197
}
198198

199-
pub fn allowed_delta(&self) -> u16 {
200-
self.allowed_delta
199+
pub fn mpc_weight_reduction_allowed_delta(&self) -> u16 {
200+
self.mpc_weight_reduction_allowed_delta
201201
}
202202

203203
fn member(&self, address: &Address) -> Result<&CommitteeMember, SignatureError> {

crates/hashi-types/src/guardian/proto_conversions.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,19 @@ fn pb_to_hashi_committee(c: pb::Committee) -> GuardianResult<HashiCommittee> {
670670
let total_weight = c.total_weight.ok_or_else(|| missing("total_weight"))?;
671671

672672
let threshold_basis_points = c
673-
.threshold_basis_points
673+
.mpc_threshold_basis_points
674674
.map(|v| v as u16)
675675
.unwrap_or(DEFAULT_MPC_THRESHOLD_BASIS_POINTS);
676-
let allowed_delta = c
677-
.allowed_delta
676+
let weight_reduction_allowed_delta = c
677+
.mpc_weight_reduction_allowed_delta
678678
.map(|v| v as u16)
679679
.unwrap_or(DEFAULT_MPC_WEIGHT_REDUCTION_ALLOWED_DELTA);
680-
let committee = HashiCommittee::new(members, epoch, threshold_basis_points, allowed_delta);
680+
let committee = HashiCommittee::new(
681+
members,
682+
epoch,
683+
threshold_basis_points,
684+
weight_reduction_allowed_delta,
685+
);
681686

682687
if committee.total_weight() != total_weight {
683688
return Err(InvalidInputs(format!(
@@ -698,8 +703,8 @@ fn hashi_committee_to_pb(c: HashiCommittee) -> pb::Committee {
698703
.map(|m| hashi_committee_member_to_pb(m.clone()))
699704
.collect(),
700705
total_weight: Some(c.total_weight()),
701-
threshold_basis_points: Some(c.threshold_basis_points() as u64),
702-
allowed_delta: Some(c.allowed_delta() as u64),
706+
mpc_threshold_basis_points: Some(c.mpc_threshold_basis_points() as u64),
707+
mpc_weight_reduction_allowed_delta: Some(c.mpc_weight_reduction_allowed_delta() as u64),
703708
}
704709
}
705710

crates/hashi-types/src/move_types/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ pub struct Committee {
156156
pub members: Vec<CommitteeMember>,
157157
/// Total voting weight of the committee.
158158
pub total_weight: u64,
159-
/// MPC threshold in basis points
160-
pub threshold_basis_points: u64,
161-
/// Allowed delta for weight reduction
162-
pub allowed_delta: u64,
159+
pub mpc_threshold_basis_points: u64,
160+
pub mpc_weight_reduction_allowed_delta: u64,
163161
}
164162

165163
/// Rust version of the Move hashi::config::Config type.
@@ -1105,8 +1103,8 @@ impl From<&crate::committee::Committee> for Committee {
11051103
epoch: c.epoch(),
11061104
members: c.members().iter().map(Into::into).collect(),
11071105
total_weight: c.total_weight(),
1108-
threshold_basis_points: c.threshold_basis_points() as u64,
1109-
allowed_delta: c.allowed_delta() as u64,
1106+
mpc_threshold_basis_points: c.mpc_threshold_basis_points() as u64,
1107+
mpc_weight_reduction_allowed_delta: c.mpc_weight_reduction_allowed_delta() as u64,
11101108
}
11111109
}
11121110
}
@@ -1123,9 +1121,10 @@ impl TryFrom<Committee> for crate::committee::Committee {
11231121
Ok(crate::committee::Committee::new(
11241122
members,
11251123
c.epoch,
1126-
u16::try_from(c.threshold_basis_points)
1127-
.expect("threshold_basis_points exceeds u16::MAX"),
1128-
u16::try_from(c.allowed_delta).expect("allowed_delta exceeds u16::MAX"),
1124+
u16::try_from(c.mpc_threshold_basis_points)
1125+
.expect("mpc_threshold_basis_points exceeds u16::MAX"),
1126+
u16::try_from(c.mpc_weight_reduction_allowed_delta)
1127+
.expect("mpc_weight_reduction_allowed_delta exceeds u16::MAX"),
11291128
))
11301129
}
11311130
}
71 Bytes
Binary file not shown.

crates/hashi-types/src/proto/generated/sui.hashi.v1alpha.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,9 +2823,9 @@ pub struct Committee {
28232823
#[prost(uint64, optional, tag = "3")]
28242824
pub total_weight: ::core::option::Option<u64>,
28252825
#[prost(uint64, optional, tag = "4")]
2826-
pub threshold_basis_points: ::core::option::Option<u64>,
2826+
pub mpc_threshold_basis_points: ::core::option::Option<u64>,
28272827
#[prost(uint64, optional, tag = "5")]
2828-
pub allowed_delta: ::core::option::Option<u64>,
2828+
pub mpc_weight_reduction_allowed_delta: ::core::option::Option<u64>,
28292829
}
28302830
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
28312831
pub struct CommitteeMember {

crates/hashi/src/mpc/mpc_except_signing.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ impl MpcManager {
146146
.clone();
147147
let (nodes, threshold) = build_reduced_nodes(
148148
&committee,
149-
committee.threshold_basis_points(),
150-
committee.allowed_delta(),
149+
committee.mpc_threshold_basis_points(),
150+
committee.mpc_weight_reduction_allowed_delta(),
151151
weight_divisor,
152152
)?;
153153
let total_weight = nodes.total_weight();
@@ -205,8 +205,8 @@ impl MpcManager {
205205
Some(prev_committee) => {
206206
let (nodes, threshold) = build_reduced_nodes(
207207
prev_committee,
208-
prev_committee.threshold_basis_points(),
209-
prev_committee.allowed_delta(),
208+
prev_committee.mpc_threshold_basis_points(),
209+
prev_committee.mpc_weight_reduction_allowed_delta(),
210210
weight_divisor,
211211
)?;
212212
(Some(nodes), Some(threshold))

crates/hashi/src/onchain/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -994,10 +994,16 @@ fn convert_move_committee(c: move_types::Committee) -> Committee {
994994
.into_iter()
995995
.map(convert_move_committee_member)
996996
.collect();
997-
let threshold_basis_points =
998-
u16::try_from(c.threshold_basis_points).expect("threshold_basis_points exceeds u16::MAX");
999-
let allowed_delta = u16::try_from(c.allowed_delta).expect("allowed_delta exceeds u16::MAX");
1000-
Committee::new(members, c.epoch, threshold_basis_points, allowed_delta)
997+
let threshold_basis_points = u16::try_from(c.mpc_threshold_basis_points)
998+
.expect("mpc_threshold_basis_points exceeds u16::MAX");
999+
let weight_reduction_allowed_delta = u16::try_from(c.mpc_weight_reduction_allowed_delta)
1000+
.expect("mpc_weight_reduction_allowed_delta exceeds u16::MAX");
1001+
Committee::new(
1002+
members,
1003+
c.epoch,
1004+
threshold_basis_points,
1005+
weight_reduction_allowed_delta,
1006+
)
10011007
}
10021008

10031009
fn convert_move_uncompressed_g1_pubkey(uncompressed_g1: &[u8]) -> BLS12381PublicKey {

packages/hashi/sources/core/committee/committee.move

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,16 @@ public struct Committee has copy, drop, store {
3636
members: vector<CommitteeMember>,
3737
/// Total voting weight of the committee.
3838
total_weight: u64,
39-
/// MPC threshold in basis points
40-
threshold_basis_points: u64,
41-
/// Allowed delta for weight reduction
42-
allowed_delta: u64,
39+
mpc_threshold_basis_points: u64,
40+
mpc_weight_reduction_allowed_delta: u64,
4341
}
4442

4543
/// Constructor for committee.
4644
public(package) fun new_committee(
4745
epoch: u64,
4846
members: vector<CommitteeMember>,
49-
threshold_basis_points: u64,
50-
allowed_delta: u64,
47+
mpc_threshold_basis_points: u64,
48+
mpc_weight_reduction_allowed_delta: u64,
5149
): Committee {
5250
assert!(!members.is_empty());
5351

@@ -59,7 +57,13 @@ public(package) fun new_committee(
5957
total_weight = total_weight + weight;
6058
});
6159

62-
Committee { members, total_weight, epoch, threshold_basis_points, allowed_delta }
60+
Committee {
61+
members,
62+
total_weight,
63+
epoch,
64+
mpc_threshold_basis_points,
65+
mpc_weight_reduction_allowed_delta,
66+
}
6367
}
6468

6569
/// Constructor for committee member.

0 commit comments

Comments
 (0)