Skip to content

Commit c471323

Browse files
committed
Merge remote-tracking branch 'origin/main' into 3857-attestation-storage-delta
2 parents 6b4cbeb + 38df3e6 commit c471323

57 files changed

Lines changed: 837 additions & 600 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/backup-cli/src/adapters/contract_state_fixture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn get_keyset_from_contract_state(
7575
mod tests {
7676
use std::path::PathBuf;
7777

78-
use near_mpc_contract_interface::types::{ProtocolContractState, Threshold};
78+
use near_mpc_contract_interface::types::{GovernanceThreshold, ProtocolContractState};
7979

8080
use crate::{
8181
adapters::contract_state_fixture::ContractStateFixture, ports::ContractStateReader,
@@ -95,7 +95,7 @@ mod tests {
9595
let ProtocolContractState::Running(state) = &contract_state else {
9696
panic!("expected Running state, got {contract_state:?}");
9797
};
98-
assert_eq!(state.parameters.threshold, Threshold::new(7));
98+
assert_eq!(state.parameters.threshold, GovernanceThreshold::new(7));
9999
assert_eq!(state.domains.domains.len(), 2);
100100
}
101101
}

crates/contract/src/dto_mapping.rs

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::{
2424
domain::{AddDomainsVotes, DomainRegistry},
2525
key_state::{AuthenticatedAccountId, AuthenticatedParticipantId, KeyForDomain, Keyset},
2626
participants::{ParticipantInfo, Participants},
27-
threshold_votes::ThresholdParametersVotes,
28-
thresholds::{ProposedThresholdParameters, ThresholdParameters},
27+
threshold_votes::GovernanceThresholdParametersVotes,
28+
thresholds::{GovernanceThresholdParameters, ProposedGovernanceThresholdParameters},
2929
},
3030
state::{
3131
ProtocolContractState,
@@ -214,21 +214,23 @@ impl IntoContractType<Participants> for dtos::Participants {
214214
}
215215
}
216216

217-
impl TryIntoContractType<ThresholdParameters> for dtos::ThresholdParameters {
217+
impl TryIntoContractType<GovernanceThresholdParameters> for dtos::GovernanceThresholdParameters {
218218
type Error = Error;
219219

220-
fn try_into_contract_type(self) -> Result<ThresholdParameters, Self::Error> {
220+
fn try_into_contract_type(self) -> Result<GovernanceThresholdParameters, Self::Error> {
221221
// Validate eagerly at the DTO boundary so invalid proposal parameters are rejected here.
222-
ThresholdParameters::new(self.participants.into_contract_type(), self.threshold)
222+
GovernanceThresholdParameters::new(self.participants.into_contract_type(), self.threshold)
223223
}
224224
}
225225

226-
impl TryIntoContractType<ProposedThresholdParameters> for dtos::ProposedThresholdParameters {
226+
impl TryIntoContractType<ProposedGovernanceThresholdParameters>
227+
for dtos::ProposedGovernanceThresholdParameters
228+
{
227229
type Error = Error;
228230

229-
fn try_into_contract_type(self) -> Result<ProposedThresholdParameters, Self::Error> {
231+
fn try_into_contract_type(self) -> Result<ProposedGovernanceThresholdParameters, Self::Error> {
230232
// Validates the inner threshold parameters; see the conversion above.
231-
Ok(ProposedThresholdParameters::new(
233+
Ok(ProposedGovernanceThresholdParameters::new(
232234
self.parameters.try_into_contract_type()?,
233235
self.per_domain_thresholds,
234236
))
@@ -584,14 +586,14 @@ mod test_conversions {
584586
}
585587
}
586588

587-
impl From<ThresholdParameters> for dtos::ThresholdParameters {
588-
fn from(params: ThresholdParameters) -> Self {
589+
impl From<GovernanceThresholdParameters> for dtos::GovernanceThresholdParameters {
590+
fn from(params: GovernanceThresholdParameters) -> Self {
589591
(&params).into_dto_type()
590592
}
591593
}
592594

593-
impl From<ProposedThresholdParameters> for dtos::ProposedThresholdParameters {
594-
fn from(params: ProposedThresholdParameters) -> Self {
595+
impl From<ProposedGovernanceThresholdParameters> for dtos::ProposedGovernanceThresholdParameters {
596+
fn from(params: ProposedGovernanceThresholdParameters) -> Self {
595597
(&params).into_dto_type()
596598
}
597599
}
@@ -686,18 +688,20 @@ impl IntoInterfaceType<dtos::Participants> for &Participants {
686688
}
687689
}
688690

689-
impl IntoInterfaceType<dtos::ThresholdParameters> for &ThresholdParameters {
690-
fn into_dto_type(self) -> dtos::ThresholdParameters {
691-
dtos::ThresholdParameters {
691+
impl IntoInterfaceType<dtos::GovernanceThresholdParameters> for &GovernanceThresholdParameters {
692+
fn into_dto_type(self) -> dtos::GovernanceThresholdParameters {
693+
dtos::GovernanceThresholdParameters {
692694
participants: self.participants().into_dto_type(),
693695
threshold: self.threshold(),
694696
}
695697
}
696698
}
697699

698-
impl IntoInterfaceType<dtos::ProposedThresholdParameters> for &ProposedThresholdParameters {
699-
fn into_dto_type(self) -> dtos::ProposedThresholdParameters {
700-
dtos::ProposedThresholdParameters {
700+
impl IntoInterfaceType<dtos::ProposedGovernanceThresholdParameters>
701+
for &ProposedGovernanceThresholdParameters
702+
{
703+
fn into_dto_type(self) -> dtos::ProposedGovernanceThresholdParameters {
704+
dtos::ProposedGovernanceThresholdParameters {
701705
parameters: self.parameters().into_dto_type(),
702706
per_domain_thresholds: self.per_domain_thresholds().clone(),
703707
}
@@ -706,14 +710,16 @@ impl IntoInterfaceType<dtos::ProposedThresholdParameters> for &ProposedThreshold
706710

707711
// --- Voting types ---
708712

709-
impl IntoInterfaceType<dtos::ThresholdParametersVotes> for &ThresholdParametersVotes {
710-
fn into_dto_type(self) -> dtos::ThresholdParametersVotes {
713+
impl IntoInterfaceType<dtos::GovernanceThresholdParametersVotes>
714+
for &GovernanceThresholdParametersVotes
715+
{
716+
fn into_dto_type(self) -> dtos::GovernanceThresholdParametersVotes {
711717
let proposal_by_account = self
712718
.proposal_by_account
713719
.iter()
714720
.map(|(account, params)| (account.into_dto_type(), params.into_dto_type()))
715721
.collect();
716-
dtos::ThresholdParametersVotes {
722+
dtos::GovernanceThresholdParametersVotes {
717723
proposal_by_account,
718724
}
719725
}
@@ -868,7 +874,7 @@ mod tests {
868874
use super::*;
869875
use crate::errors::InvalidThreshold;
870876
use crate::primitives::test_utils::gen_participants;
871-
use crate::primitives::thresholds::Threshold;
877+
use crate::primitives::thresholds::GovernanceThreshold;
872878
use assert_matches::assert_matches;
873879

874880
const TEST_THRESHOLD: u64 = 2;
@@ -921,33 +927,40 @@ mod tests {
921927
}
922928

923929
/// Ensures that the JSON produced by serializing the internal
924-
/// [`ThresholdParameters`] type can be deserialized into the DTO
925-
/// [`dtos::ThresholdParameters`] type and vice versa, producing identical
930+
/// [`GovernanceThresholdParameters`] type can be deserialized into the DTO
931+
/// [`dtos::GovernanceThresholdParameters`] type and vice versa, producing identical
926932
/// JSON in both directions.
927933
#[test]
928934
fn threshold_parameters_serde_is_compatible_with_dto() {
929-
let internal =
930-
ThresholdParameters::new(test_participants(), Threshold::new(TEST_THRESHOLD)).unwrap();
935+
let internal = GovernanceThresholdParameters::new(
936+
test_participants(),
937+
GovernanceThreshold::new(TEST_THRESHOLD),
938+
)
939+
.unwrap();
931940
let json = serde_json::to_value(&internal).unwrap();
932941

933-
let dto: dtos::ThresholdParameters = serde_json::from_value(json.clone()).unwrap();
942+
let dto: dtos::GovernanceThresholdParameters =
943+
serde_json::from_value(json.clone()).unwrap();
934944

935945
let dto_json = serde_json::to_value(&dto).unwrap();
936946
assert_eq!(json, dto_json, "Internal and DTO JSON must be identical");
937947

938-
let roundtrip: ThresholdParameters = serde_json::from_value(dto_json).unwrap();
948+
let roundtrip: GovernanceThresholdParameters = serde_json::from_value(dto_json).unwrap();
939949
assert_eq!(internal, roundtrip);
940950
}
941951

942952
/// Verify that [`IntoInterfaceType::into_dto_type`] produces a DTO whose
943953
/// serialization matches the internal type's serialization.
944954
#[test]
945955
fn into_dto_type_preserves_serialization() {
946-
let internal =
947-
ThresholdParameters::new(test_participants(), Threshold::new(TEST_THRESHOLD)).unwrap();
956+
let internal = GovernanceThresholdParameters::new(
957+
test_participants(),
958+
GovernanceThreshold::new(TEST_THRESHOLD),
959+
)
960+
.unwrap();
948961
let internal_json = serde_json::to_value(&internal).unwrap();
949962

950-
let dto: dtos::ThresholdParameters = (&internal).into_dto_type();
963+
let dto: dtos::GovernanceThresholdParameters = (&internal).into_dto_type();
951964
let dto_json = serde_json::to_value(&dto).unwrap();
952965

953966
assert_eq!(internal_json, dto_json);
@@ -958,13 +971,13 @@ mod tests {
958971
#[test]
959972
fn try_into_contract_type__should_reject_threshold_below_relative_requirement() {
960973
// Given a DTO with 5 participants and a threshold of 2 (below the 60% bound of 3).
961-
let dto = dtos::ThresholdParameters {
974+
let dto = dtos::GovernanceThresholdParameters {
962975
participants: (&gen_participants(5)).into_dto_type(),
963-
threshold: Threshold::new(2),
976+
threshold: GovernanceThreshold::new(2),
964977
};
965978

966979
// When converting the DTO into the contract type.
967-
let result: Result<ThresholdParameters, Error> = dto.try_into_contract_type();
980+
let result: Result<GovernanceThresholdParameters, Error> = dto.try_into_contract_type();
968981

969982
// Then conversion fails with the relative-threshold error.
970983
assert_matches!(

crates/contract/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ pub enum InvalidState {
184184

185185
#[derive(Debug, PartialEq, Eq, Clone, thiserror::Error)]
186186
pub enum InvalidThreshold {
187-
#[error("Threshold does not meet the minimum absolute requirement")]
187+
#[error("GovernanceThreshold does not meet the minimum absolute requirement")]
188188
MinAbsRequirementFailed,
189189
#[error(
190190
"GovernanceThreshold is below the minimum required relative to the participant count: require at least {required}, found {found}"
191191
)]
192192
MinRelRequirementFailed { required: u64, found: u64 },
193-
#[error("Threshold must not exceed number of participants: max {max}, found {found}")]
193+
#[error("GovernanceThreshold must not exceed number of participants: max {max}, found {found}")]
194194
MaxRequirementFailed { max: u64, found: u64 },
195195
#[error(
196196
"GovernanceThreshold exceeds the maximum allowed relative to the participant count: max {max}, found {found}"

crates/contract/src/foreign_chain_rpc.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use near_sdk::near;
2020
use near_sdk::store::IterableMap;
2121

2222
use crate::errors::{ChainEntryValidationError, ConversionError, Error, InvalidParameters};
23-
use crate::primitives::thresholds::ThresholdParameters;
23+
use crate::primitives::thresholds::GovernanceThresholdParameters;
2424
use crate::primitives::votes::{ProposalHash, ProposalHashEncoding, Votes};
2525
use crate::primitives::{key_state::AuthenticatedParticipantId, participants::Participants};
2626
use crate::storage_keys::StorageKey;
@@ -174,7 +174,7 @@ impl ProviderVotes {
174174
chain: ForeignChain,
175175
hash: ProposalHash,
176176
participant: AuthenticatedParticipantId,
177-
threshold_parameters: &ThresholdParameters,
177+
threshold_parameters: &GovernanceThresholdParameters,
178178
) -> Result<bool, Error> {
179179
let protocol_threshold = threshold_parameters.threshold().value();
180180
let participants = threshold_parameters.participants();
@@ -223,7 +223,7 @@ impl ForeignChainRpcWhitelist {
223223
&mut self,
224224
participant: AuthenticatedParticipantId,
225225
votes: NonEmptyBTreeMap<ForeignChain, dtos::ChainEntry>,
226-
threshold_parameters: &ThresholdParameters,
226+
threshold_parameters: &GovernanceThresholdParameters,
227227
) -> Result<Vec<ForeignChain>, Error> {
228228
let mut applied: Vec<ForeignChain> = Vec::new();
229229
let votes: BTreeMap<ForeignChain, dtos::ChainEntry> = votes.into();
@@ -250,15 +250,18 @@ mod tests {
250250
key_state::AuthenticatedParticipantId, test_utils::gen_authenticated_participants,
251251
};
252252
use assert_matches::assert_matches;
253-
use mpc_primitives::Threshold;
253+
use mpc_primitives::GovernanceThreshold;
254254
use near_mpc_contract_interface::types::AuthScheme;
255255

256-
/// Build a `ThresholdParameters` for tests, bypassing the relative-threshold
256+
/// Build a `GovernanceThresholdParameters` for tests, bypassing the relative-threshold
257257
/// validation so tests can express edge-case combinations (e.g. the stale-votes
258258
/// test deliberately uses a threshold > current participant count to assert
259259
/// the count_for predicate filters out non-participant rows).
260-
fn tp(participants: &Participants, n: u64) -> ThresholdParameters {
261-
ThresholdParameters::new_unvalidated(participants.clone(), Threshold::new(n))
260+
fn tp(participants: &Participants, n: u64) -> GovernanceThresholdParameters {
261+
GovernanceThresholdParameters::new_unvalidated(
262+
participants.clone(),
263+
GovernanceThreshold::new(n),
264+
)
262265
}
263266

264267
fn provider(id: &str) -> (ProviderId, ProviderConfig) {

0 commit comments

Comments
 (0)