Skip to content

Commit 0fda68a

Browse files
muXxeralexsporn
authored andcommitted
feat(protocol): PCR-2 iota-proxy (#5461)
1 parent a50fcd6 commit 0fda68a

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

crates/iota-proxy/src/peers.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use futures::stream::{self, StreamExt};
1818
use iota_tls::Allower;
1919
use iota_types::{
2020
base_types::IotaAddress, bridge::BridgeSummary,
21-
iota_system_state::iota_system_state_summary::IotaSystemStateSummary,
21+
iota_system_state::iota_system_state_summary::IotaSystemStateSummaryV2,
2222
};
2323
use once_cell::sync::Lazy;
2424
use prometheus::{CounterVec, HistogramVec, register_counter_vec, register_histogram_vec};
@@ -134,7 +134,7 @@ impl IotaNodeProvider {
134134
}
135135

136136
/// get_validators will retrieve known validators
137-
async fn get_validators(url: String) -> Result<IotaSystemStateSummary> {
137+
async fn get_validators(url: String) -> Result<IotaSystemStateSummaryV2> {
138138
let rpc_method = "iotax_getLatestIotaSystemState";
139139
let observe = || {
140140
let timer = JSON_RPC_DURATION
@@ -174,7 +174,7 @@ impl IotaNodeProvider {
174174

175175
#[derive(Debug, Deserialize)]
176176
struct ResponseBody {
177-
result: IotaSystemStateSummary,
177+
result: IotaSystemStateSummaryV2,
178178
}
179179

180180
let body: ResponseBody = match serde_json::from_slice(&raw) {
@@ -335,7 +335,9 @@ impl IotaNodeProvider {
335335
/// This type comes from a full node rpc result. See get_validators for
336336
/// details. The key here, if extracted successfully, will ultimately be stored
337337
/// in the allow list and let us communicate with those actual peers via tls.
338-
fn extract(summary: IotaSystemStateSummary) -> impl Iterator<Item = (Ed25519PublicKey, IotaPeer)> {
338+
fn extract(
339+
summary: IotaSystemStateSummaryV2,
340+
) -> impl Iterator<Item = (Ed25519PublicKey, IotaPeer)> {
339341
summary.active_validators.into_iter().filter_map(|vm| {
340342
match Ed25519PublicKey::from_bytes(&vm.network_pubkey_bytes) {
341343
Ok(public_key) => {
@@ -544,9 +546,7 @@ mod tests {
544546
use iota_types::{
545547
base_types::IotaAddress,
546548
bridge::{BridgeCommitteeSummary, BridgeSummary, MoveTypeCommitteeMember},
547-
iota_system_state::iota_system_state_summary::{
548-
IotaSystemStateSummary, IotaValidatorSummary,
549-
},
549+
iota_system_state::iota_system_state_summary::IotaValidatorSummary,
550550
};
551551
use multiaddr::Multiaddr;
552552
use serde::Serialize;
@@ -566,7 +566,7 @@ mod tests {
566566
.expect("expected a multiaddr value");
567567
// all fields here just satisfy the field types, with exception to
568568
// active_validators, we use some of those.
569-
let depends_on = IotaSystemStateSummary {
569+
let depends_on = IotaSystemStateSummaryV2 {
570570
active_validators: vec![IotaValidatorSummary {
571571
network_pubkey_bytes: Vec::from(client_pub_key.as_bytes()),
572572
p2p_address: format!("{p2p_address}"),
@@ -578,14 +578,14 @@ mod tests {
578578

579579
#[derive(Debug, Serialize, Deserialize)]
580580
struct ResponseBody {
581-
result: IotaSystemStateSummary,
581+
result: IotaSystemStateSummaryV2,
582582
}
583583

584584
let r = serde_json::to_string(&ResponseBody { result: depends_on })
585-
.expect("expected to serialize ResponseBody{IotaSystemStateSummary}");
585+
.expect("expected to serialize ResponseBody{IotaSystemStateSummaryV2}");
586586

587587
let deserialized = serde_json::from_str::<ResponseBody>(&r)
588-
.expect("expected to deserialize ResponseBody{IotaSystemStateSummary}");
588+
.expect("expected to deserialize ResponseBody{IotaSystemStateSummaryV2}");
589589

590590
let peers = extract(deserialized.result);
591591
assert_eq!(peers.count(), 1, "peers should have been a length of 1");

crates/iota-types/src/iota_system_state/iota_system_state_summary.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,9 @@ pub struct IotaValidatorSummary {
711711
pub exchange_rates_size: u64,
712712
}
713713

714-
impl Default for IotaSystemStateSummary {
714+
impl Default for IotaSystemStateSummaryV2 {
715715
fn default() -> Self {
716-
Self::V2(IotaSystemStateSummaryV2 {
716+
IotaSystemStateSummaryV2 {
717717
epoch: 0,
718718
protocol_version: 1,
719719
system_state_version: 1,
@@ -749,7 +749,13 @@ impl Default for IotaSystemStateSummary {
749749
validator_candidates_size: 0,
750750
at_risk_validators: vec![],
751751
validator_report_records: vec![],
752-
})
752+
}
753+
}
754+
}
755+
756+
impl Default for IotaSystemStateSummary {
757+
fn default() -> Self {
758+
Self::V2(Default::default())
753759
}
754760
}
755761

0 commit comments

Comments
 (0)