Skip to content

Commit 2245824

Browse files
kodemartinalexsporn
authored andcommitted
refactor(iota): use new system-state summary type (#5502)
1 parent 27068cf commit 2245824

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

crates/iota/src/fire_drill.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use iota_types::{
3434
base_types::{IotaAddress, ObjectRef},
3535
committee::EpochId,
3636
crypto::{IotaKeyPair, generate_proof_of_possession, get_authority_key_pair, get_key_pair},
37+
iota_system_state::iota_system_state_summary::IotaSystemStateSummary,
3738
multiaddr::{Multiaddr, Protocol},
3839
transaction::{CallArg, TEST_ONLY_GAS_UNIT_FOR_GENERIC, Transaction, TransactionData},
3940
};
@@ -160,11 +161,16 @@ async fn update_next_epoch_metadata(
160161
new_config.protocol_key_pair =
161162
KeyPairWithPath::new(IotaKeyPair::Ed25519(new_protocol_key_pair));
162163

163-
let validators = iota_client
164+
let iota_system_state = iota_client
164165
.governance_api()
165166
.get_latest_iota_system_state()
166-
.await?
167-
.active_validators;
167+
.await?;
168+
let validators = match iota_system_state {
169+
IotaSystemStateSummary::V1(v1) => v1.active_validators,
170+
IotaSystemStateSummary::V2(v2) => v2.active_validators,
171+
_ => panic!("unsupported IotaSystemStateSummary"),
172+
};
173+
168174
let self_validator = validators
169175
.iter()
170176
.find(|v| v.iota_address == iota_address)

crates/iota/src/validator_commands.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,16 @@ impl IotaValidatorCommand {
550550
)?;
551551
// Make sure the address is a validator
552552
let iota_client = context.get_client().await?;
553-
let active_validators = iota_client
553+
let iota_system_state = iota_client
554554
.governance_api()
555555
.get_latest_iota_system_state()
556-
.await?
557-
.active_validators;
556+
.await?;
557+
let active_validators = match iota_system_state {
558+
IotaSystemStateSummary::V1(v1) => v1.active_validators,
559+
IotaSystemStateSummary::V2(v2) => v2.active_validators,
560+
_ => panic!("unsupported IotaSystemStateSummary"),
561+
};
562+
558563
if !active_validators
559564
.into_iter()
560565
.any(|s| s.iota_address == address)
@@ -686,11 +691,15 @@ impl IotaValidatorCommand {
686691
IotaValidatorCommand::List => {
687692
let client = context.get_client().await?;
688693

689-
let active_validators = client
694+
let iota_system_state = client
690695
.governance_api()
691696
.get_latest_iota_system_state()
692-
.await?
693-
.active_validators;
697+
.await?;
698+
let active_validators = match iota_system_state {
699+
IotaSystemStateSummary::V1(v1) => v1.active_validators,
700+
IotaSystemStateSummary::V2(v2) => v2.active_validators,
701+
_ => panic!("unsupported IotaSystemStateSummary"),
702+
};
694703

695704
let mut builder = Builder::default();
696705

@@ -1070,14 +1079,16 @@ pub async fn get_validator_summary(
10701079
client: &IotaClient,
10711080
validator_address: IotaAddress,
10721081
) -> anyhow::Result<Option<(ValidatorStatus, IotaValidatorSummary)>> {
1073-
let IotaSystemStateSummary {
1074-
active_validators,
1075-
pending_active_validators_id,
1076-
..
1077-
} = client
1082+
let iota_system_state = client
10781083
.governance_api()
10791084
.get_latest_iota_system_state()
10801085
.await?;
1086+
let (active_validators, pending_active_validators_id) = match iota_system_state {
1087+
IotaSystemStateSummary::V1(v1) => (v1.active_validators, v1.pending_active_validators_id),
1088+
IotaSystemStateSummary::V2(v2) => (v2.active_validators, v2.pending_active_validators_id),
1089+
_ => panic!("unsupported IotaSystemStateSummary"),
1090+
};
1091+
10811092
let mut status = None;
10821093
let mut active_validators = active_validators
10831094
.into_iter()

crates/iota/tests/cli_tests.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ use iota_types::{
6060
},
6161
error::IotaObjectResponseError,
6262
gas_coin::GasCoin,
63+
iota_system_state::iota_system_state_summary::IotaSystemStateSummary,
6364
object::Owner,
6465
transaction::{
6566
TEST_ONLY_GAS_UNIT_FOR_GENERIC, TEST_ONLY_GAS_UNIT_FOR_OBJECT_BASICS,
@@ -3029,12 +3030,17 @@ async fn test_stake_with_none_amount() -> Result<(), anyhow::Error> {
30293030
.data;
30303031

30313032
let config_path = test_cluster.swarm.dir().join(IOTA_CLIENT_CONFIG);
3032-
let validator_addr = client
3033+
let iota_system_state = client
30333034
.governance_api()
30343035
.get_latest_iota_system_state()
3035-
.await?
3036-
.active_validators[0]
3037-
.iota_address;
3036+
.await?;
3037+
let active_validators = match iota_system_state {
3038+
IotaSystemStateSummary::V1(v1) => v1.active_validators,
3039+
IotaSystemStateSummary::V2(v2) => v2.active_validators,
3040+
_ => panic!("unsupported IotaSystemStateSummary"),
3041+
};
3042+
3043+
let validator_addr = active_validators[0].iota_address;
30383044

30393045
test_with_iota_binary(&[
30403046
"client",
@@ -3081,12 +3087,17 @@ async fn test_stake_with_u64_amount() -> Result<(), anyhow::Error> {
30813087
.data;
30823088

30833089
let config_path = test_cluster.swarm.dir().join(IOTA_CLIENT_CONFIG);
3084-
let validator_addr = client
3090+
let iota_system_state = client
30853091
.governance_api()
30863092
.get_latest_iota_system_state()
3087-
.await?
3088-
.active_validators[0]
3089-
.iota_address;
3093+
.await?;
3094+
let active_validators = match iota_system_state {
3095+
IotaSystemStateSummary::V1(v1) => v1.active_validators,
3096+
IotaSystemStateSummary::V2(v2) => v2.active_validators,
3097+
_ => panic!("unsupported IotaSystemStateSummary"),
3098+
};
3099+
3100+
let validator_addr = active_validators[0].iota_address;
30903101

30913102
test_with_iota_binary(&[
30923103
"client",

0 commit comments

Comments
 (0)