Skip to content

Commit

Permalink
moved strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Sep 26, 2024
1 parent 0137e00 commit 407ceb7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
32 changes: 16 additions & 16 deletions zk_toolbox/crates/zk_inception/src/commands/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ impl TxSet {
let status = PendingTransaction::new(h, provider)
.await
.context("await")?
.context("receipt missing")?
.context(messages::MSG_RECEIPT_MISSING)?
.status
.context("status missing")?;
anyhow::ensure!(status == 1.into(), "transaction failed");
.context(messages::MSG_STATUS_MISSING)?;
anyhow::ensure!(status == 1.into(), messages::MSG_TRANSACTION_FAILED);
Ok(())
}
.await
Expand Down Expand Up @@ -133,7 +133,7 @@ impl Setup {
.general
.api_config
.as_ref()
.context("api_config missing")?
.context(messages::MSG_API_CONFIG_MISSING)?
.web3_json_rpc
.http_url;
Provider::try_from(l2_url).with_context(|| format!("Provider::try_from({l2_url})"))
Expand All @@ -148,7 +148,7 @@ impl Setup {
.context("get_contracts_config()")?
.l2
.multicall3
.context("multicall3 contract not configured")?,
.context(messages::MSG_MULTICALL3_CONTRACT_NOT_CONFIGURED)?,
),
Some(self.genesis.l2_chain_id.as_u64()),
)?)
Expand All @@ -158,10 +158,10 @@ impl Setup {
let governor = self
.chain
.get_wallets_config()
.context("get_secrets_config()")?
.context("get_wallets_config()")?
.governor
.private_key
.context("governor private key not set")?;
.context(messages::MSG_GOVERNOR_PRIVATE_KEY_NOT_SET)?;
let governor = LocalWallet::from_bytes(governor.as_bytes())
.context("LocalWallet::from_bytes()")?
.with_chain_id(self.genesis.l2_chain_id.as_u64());
Expand Down Expand Up @@ -199,14 +199,14 @@ impl Setup {
.contracts
.l2
.consensus_registry
.context("consensus_registry address not configured")?;
.context(messages::MSG_CONSENSUS_REGISTRY_ADDRESS_NOT_CONFIGURED)?;
Ok(abi::ConsensusRegistry::new(addr, m))
}

async fn last_block(&self, m: &(impl 'static + Middleware)) -> anyhow::Result<BlockId> {
Ok(m.get_block_number()
.await
.context("get_block_number")?
.context("get_block_number()")?
.into())
}

Expand All @@ -224,7 +224,7 @@ impl Setup {
.iter()
.map(decode_weighted_attester)
.collect::<Result<_, _>>()
.context("decode_weighted_attester")?;
.context("decode_weighted_attester()")?;
attester::Committee::new(attesters.into_iter()).context("attester::Committee::new()")
}

Expand All @@ -241,15 +241,15 @@ impl Setup {
.attesters,
)
})()
.context("consensus.genesis_spec.attesters missing in general.yaml")?;
.context(messages::MSG_CONSENSUS_GENESIS_SPEC_ATTESTERS_MISSING_IN_GENERAL_YAML)?;
let want = parse_attester_committee(want).context("parse_attester_committee()")?;

let provider = self.provider().context("provider()")?;
let block_id = self.last_block(&provider).await.context("last_block()")?;
let governor = self.governor().context("governor()")?;
let consensus_registry = self
.consensus_registry(governor.clone())
.context("consensus_registry")?;
.context("consensus_registry()")?;
let mut multicall = self.multicall(governor.clone()).context("multicall()")?;

// Fetch contract state.
Expand All @@ -261,7 +261,7 @@ impl Setup {
.context("num_nodes()")?
.try_into()
.ok()
.context("overflow")?;
.context("num_nodes() overflow")?;

multicall.block = Some(block_id);
let node_owners: Vec<Address> = multicall
Expand Down Expand Up @@ -294,7 +294,7 @@ impl Setup {
}
let got = attester::WeightedAttester {
key: decode_attester_key(&node.attester_latest.pub_key)
.context("decode_attester_key")?,
.context("decode_attester_key()")?,
weight: node.attester_latest.weight.into(),
};
if let Some(weight) = to_insert.remove(&got.key) {
Expand All @@ -303,7 +303,7 @@ impl Setup {
"changed_attester_weight",
consensus_registry.change_attester_weight(
node_owners[i],
weight.try_into().context("overflow")?,
weight.try_into().context("weight overflow")?,
),
)
.await?;
Expand Down Expand Up @@ -351,7 +351,7 @@ impl Command {
let got = setup.get_attester_committee().await?;
anyhow::ensure!(
got == want,
"setting attester committee failed: got {got:?}, want {want:?}"
messages::msg_setting_attester_committee_failed(&got, &want)
);
print_attesters(&got);
}
Expand Down
20 changes: 20 additions & 0 deletions zk_toolbox/crates/zk_inception/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ethers::{
types::{H160, U256},
utils::format_ether,
};
use zksync_consensus_roles::attester;

pub(super) const MSG_SETUP_KEYS_DOWNLOAD_SELECTION_PROMPT: &str =
"Do you want to download the setup keys or generate them?";
Expand Down Expand Up @@ -481,3 +482,22 @@ pub(super) fn msg_diff_secrets(
pub(super) fn msg_updating_chain(chain: &str) -> String {
format!("Updating chain: {}", chain)
}

/// consensus command messages
pub(super) const MSG_RECEIPT_MISSING: &str = "receipt missing";
pub(super) const MSG_STATUS_MISSING: &str = "status missing";
pub(super) const MSG_TRANSACTION_FAILED: &str = "transaction failed";
pub(super) const MSG_API_CONFIG_MISSING: &str = "api config missing";
pub(super) const MSG_MULTICALL3_CONTRACT_NOT_CONFIGURED: &str =
"multicall3 contract not configured";
pub(super) const MSG_GOVERNOR_PRIVATE_KEY_NOT_SET: &str = "governor private key not set";
pub(super) const MSG_CONSENSUS_REGISTRY_ADDRESS_NOT_CONFIGURED: &str =
"consensus registry address not configured";
pub(super) const MSG_CONSENSUS_GENESIS_SPEC_ATTESTERS_MISSING_IN_GENERAL_YAML: &str =
"consensus.genesis_spec.attesters missing in general.yaml";
pub(super) fn msg_setting_attester_committee_failed(
got: &attester::Committee,
want: &attester::Committee,
) -> String {
format!("setting attester committee failed: got {got:?}, want {want:?}")
}

0 comments on commit 407ceb7

Please sign in to comment.