Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(staking): 🎽 IdentityKey is internally represented as bytes #4151

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/bin/pcli/src/command/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ impl ValidatorCmd {

match self {
ValidatorCmd::Identity { base64 } => {
let ik = IdentityKey(fvk.spend_verification_key().clone());
let ik: IdentityKey = fvk.spend_verification_key().into();

if *base64 {
use base64::{display::Base64Display, engine::general_purpose::STANDARD};
println!("{}", Base64Display::new(&ik.0.to_bytes(), &STANDARD));
println!("{}", Base64Display::new(ik.as_bytes(), &STANDARD));
} else {
println!("{ik}");
}
Expand Down Expand Up @@ -276,7 +276,7 @@ impl ValidatorCmd {
reason,
signature_file,
}) => {
let identity_key = IdentityKey(fvk.spend_verification_key().clone());
let identity_key = fvk.spend_verification_key().into();
let governance_key = app.config.governance_key();

let (proposal, vote): (u64, Vote) = (*vote).into();
Expand Down Expand Up @@ -323,7 +323,7 @@ impl ValidatorCmd {
reason,
signature,
}) => {
let identity_key = IdentityKey(fvk.spend_verification_key().clone());
let identity_key = fvk.spend_verification_key().into();
let governance_key = app.config.governance_key();

let (proposal, vote): (u64, Vote) = (*vote).into();
Expand Down Expand Up @@ -385,7 +385,7 @@ impl ValidatorCmd {
tendermint_validator_keyfile,
}) => {
let (address, _dtk) = fvk.incoming().payment_address(0u32.into());
let identity_key = IdentityKey(fvk.spend_verification_key().clone());
let identity_key = fvk.spend_verification_key().into();
// By default, the template sets the governance key to the same verification key as
// the identity key, but a validator can change this if they want to use different
// key material.
Expand Down Expand Up @@ -473,7 +473,7 @@ impl ValidatorCmd {
}
}
ValidatorCmd::Definition(DefinitionCmd::Fetch { file }) => {
let identity_key = IdentityKey(fvk.spend_verification_key().clone());
let identity_key = fvk.spend_verification_key().into();
super::query::ValidatorCmd::Definition {
file: file.clone(),
identity_key: identity_key.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions crates/bin/pd/src/testnet/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ impl TestnetValidator {
let ivk = fvk.incoming();
let (dest, _dtk_d) = ivk.payment_address(0u32.into());

let identity_key: IdentityKey = IdentityKey(fvk.spend_verification_key().clone());
let delegation_denom = DelegationToken::from(&identity_key).denom();
let identity_key: IdentityKey = fvk.spend_verification_key().into();
let delegation_denom = DelegationToken::from(identity_key).denom();
Ok(Allocation {
address: dest,
// Add an initial allocation of 25,000 delegation tokens,
Expand Down Expand Up @@ -540,7 +540,7 @@ impl TryFrom<&TestnetValidator> for Validator {
// Currently there's no way to set validator keys beyond
// manually editing the genesis.json. Otherwise they
// will be randomly generated keys.
identity_key: IdentityKey(tv.keys.validator_id_vk),
identity_key: tv.keys.validator_id_vk.into(),
governance_key: GovernanceKey(tv.keys.validator_id_vk),
consensus_key: tv.keys.validator_cons_pk,
name: tv.name.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
unexpected => panic!("there should be one validator, got: {unexpected:?}"),
};

let existing_validator_id = existing_validator.identity_key;
let existing_validator_id = existing_validator.identity_key.clone();

// Check that we are now in a new epoch.
{
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
use penumbra_stake::component::ConsensusIndexRead;
let start = snapshot_start.get_consensus_set().await?;
let end = snapshot_end.get_consensus_set().await?;
let expected = [existing_validator_id];
let expected = [existing_validator_id.clone()];
assert_eq!(
start, expected,
"validator should start in the consensus set"
Expand All @@ -116,7 +116,7 @@ async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
// To define a validator, we need to define two keypairs: an identity key
// for the Penumbra application and a consensus key for cometbft.
let new_validator_id_sk = SigningKey::<SpendAuth>::new(OsRng);
let new_validator_id = IdentityKey(new_validator_id_sk.into());
let new_validator_id = IdentityKey::from(new_validator_id_sk);
let new_validator_consensus_sk = ed25519_consensus::SigningKey::new(OsRng);
let new_validator_consensus = new_validator_consensus_sk.verification_key();

Expand Down Expand Up @@ -405,7 +405,7 @@ async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
.ok_or(anyhow!("new validator has a rate"))?
.tap(|rate| tracing::info!(?rate, "got new validator rate"));

let undelegation_id = DelegationToken::new(new_validator_id).id();
let undelegation_id = DelegationToken::new(new_validator_id.clone()).id();
let note = client
.notes
.values()
Expand Down
4 changes: 2 additions & 2 deletions crates/core/app/tests/app_can_undelegate_from_a_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async fn app_can_undelegate_from_a_validator() -> anyhow::Result<()> {
[v] => v.clone(),
unexpected => panic!("there should be one validator, got: {unexpected:?}"),
}; // ..and note the asset id for delegation tokens tied to this validator.
let delegate_token_id = penumbra_stake::DelegationToken::new(identity_key).id();
let delegate_token_id = penumbra_stake::DelegationToken::new(identity_key.clone()).id();

// Sync the mock client, using the test wallet's spend key, to the latest snapshot.
let mut client = MockClient::new(test_keys::SPEND_KEY.clone())
Expand Down Expand Up @@ -228,7 +228,7 @@ async fn app_can_undelegate_from_a_validator() -> anyhow::Result<()> {
};
let snapshot = storage.latest_snapshot();
client.sync_to_latest(snapshot.clone()).await?;
let undelegation_id = DelegationToken::new(identity_key).id();
let undelegation_id = DelegationToken::new(identity_key.clone()).id();
let note = client
.notes
.values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(
let mut client = MockClient::new(test_keys::SPEND_KEY.clone());

/// Helper function, retrieve a validator's [`Uptime`].
async fn get_uptime(storage: &TempStorage, id: IdentityKey) -> Option<Uptime> {
async fn get_uptime(storage: &TempStorage, id: &IdentityKey) -> Option<Uptime> {
storage
.latest_snapshot()
.get_validator_uptime(&id)
.get_validator_uptime(id)
.await
.expect("should be able to get a validator uptime")
}
Expand All @@ -83,15 +83,15 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(
.tap(|_| info!("getting validator definitions"))
.await?;
match validators.as_slice() {
[Validator { identity_key, .. }] => *identity_key,
[Validator { identity_key, .. }] => identity_key.clone(),
unexpected => panic!("there should be one validator, got: {unexpected:?}"),
}
};

// To define a validator, we need to define two keypairs: an identity key
// for the Penumbra application and a consensus key for cometbft.
let new_validator_id_sk = SigningKey::<SpendAuth>::new(OsRng);
let new_validator_id = IdentityKey(new_validator_id_sk.into());
let new_validator_id: IdentityKey = new_validator_id_sk.into();
let new_validator_consensus_sk = ed25519_consensus::SigningKey::new(OsRng);
let new_validator_consensus = new_validator_consensus_sk.verification_key();

Expand All @@ -111,11 +111,11 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(
description: String::default(),
funding_streams: FundingStreams::default(),
};
let new_validator_id = new_validator.identity_key;
let new_validator_id = new_validator.identity_key.clone();

// Helper functions, retrieve validators' [`Uptime`].
let existing_validator_uptime = || get_uptime(&storage, existing_validator_id);
let new_validator_uptime = || get_uptime(&storage, new_validator_id);
let existing_validator_uptime = || get_uptime(&storage, &existing_validator_id);
let new_validator_uptime = || get_uptime(&storage, &new_validator_id);

// Make a transaction that defines the new validator.
let plan = {
Expand Down Expand Up @@ -310,7 +310,7 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(
.ok_or(anyhow::anyhow!("new validator has a rate"))?
.tap(|rate| tracing::info!(?rate, "got new validator rate"));

let undelegation_id = DelegationToken::new(new_validator_id).id();
let undelegation_id = DelegationToken::new(new_validator_id.clone()).id();
let note = client
.notes
.values()
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/tests/common/test_node_builder_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn generate_penumbra_validator(
.incoming()
.payment_address(0u32.into());

let ik = penumbra_stake::IdentityKey(validator_id_vk);
let ik = penumbra_stake::IdentityKey::from(validator_id_vk);
let delegation_denom = DelegationToken::from(ik).denom();

let allocation = Allocation {
Expand Down
3 changes: 1 addition & 2 deletions crates/core/app/tests/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ async fn mock_consensus_can_define_a_genesis_validator() -> anyhow::Result<()> {
.await?;
match validators.as_slice() {
[v] => {
let identity_key = v.identity_key;
let status = snapshot
.get_validator_state(&identity_key)
.get_validator_state(&v.identity_key)
.await?
.ok_or_else(|| anyhow!("could not find validator status"))?;
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl ActionHandler for DelegatorVote {
.await;
let identity_key = state.validator_by_delegation_asset(value.asset_id).await?;
state
.cast_delegator_vote(*proposal, identity_key, *vote, nullifier, *unbonded_amount)
.cast_delegator_vote(*proposal, &identity_key, *vote, nullifier, *unbonded_amount)
.await?;

state.record_proto(event::delegator_vote(self));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl ActionHandler for ValidatorVote {
}

tracing::debug!(validator_identity = %identity_key, proposal = %proposal, "cast validator vote");
state.cast_validator_vote(*proposal, *identity_key, *vote, reason.clone());
state.cast_validator_vote(*proposal, identity_key, *vote, reason.clone());

// Emergency proposals are passed immediately after receiving +2/3 of
// validator votes. These include the eponymous `Emergency` proposal but
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/governance/src/component/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl QueryService for Server {
let voting_power = state
.get_proto::<u64>(&state_key::voting_power_at_proposal_start(
proposal_id,
identity_key,
&identity_key,
))
.await
.map_err(|e| tonic::Status::internal(format!("error accessing storage: {}", e)))?;
Expand Down
26 changes: 13 additions & 13 deletions crates/core/component/governance/src/component/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub trait StateReadExt: StateRead + penumbra_stake::StateReadExt {
async fn validator_vote(
&self,
proposal_id: u64,
identity_key: IdentityKey,
identity_key: &IdentityKey,
) -> Result<Option<Vote>> {
Ok(self
.get::<Vote>(&state_key::validator_vote(proposal_id, identity_key))
Expand Down Expand Up @@ -193,7 +193,7 @@ pub trait StateReadExt: StateRead + penumbra_stake::StateReadExt {
async fn rate_data_at_proposal_start(
&self,
proposal_id: u64,
identity_key: IdentityKey,
identity_key: &IdentityKey,
) -> Result<Option<RateData>> {
self.get(&state_key::rate_data_at_proposal_start(
proposal_id,
Expand Down Expand Up @@ -278,7 +278,7 @@ pub trait StateReadExt: StateRead + penumbra_stake::StateReadExt {

// Attempt to find the validator identity for the specified denom, failing if it is not a
// delegation token
let validator_identity = DelegationToken::try_from(denom)?.validator();
let validator_identity = DelegationToken::try_from(denom)?.validator().to_owned();

Ok(validator_identity)
}
Expand All @@ -295,7 +295,7 @@ pub trait StateReadExt: StateRead + penumbra_stake::StateReadExt {

// Attempt to look up the snapshotted `RateData` for the validator at the start of the proposal
let Some(rate_data) = self
.rate_data_at_proposal_start(proposal_id, validator_identity)
.rate_data_at_proposal_start(proposal_id, &validator_identity)
.await?
else {
anyhow::bail!(
Expand Down Expand Up @@ -341,7 +341,7 @@ pub trait StateReadExt: StateRead + penumbra_stake::StateReadExt {
proposal_id: u64,
identity_key: &IdentityKey,
) -> Result<()> {
if let Some(_vote) = self.validator_vote(proposal_id, *identity_key).await? {
if let Some(_vote) = self.validator_vote(proposal_id, identity_key).await? {
anyhow::bail!(
"validator {} has already voted on proposal {}",
identity_key,
Expand Down Expand Up @@ -461,7 +461,7 @@ pub trait StateReadExt: StateRead + penumbra_stake::StateReadExt {
if self
.get_proto::<u64>(&state_key::voting_power_at_proposal_start(
proposal_id,
*identity_key,
identity_key,
))
.await?
.is_none()
Expand Down Expand Up @@ -661,11 +661,11 @@ pub trait StateWriteExt: StateWrite + penumbra_ibc::component::ConnectionStateWr
while let Some(per_validator) = js.join_next().await.transpose()? {
if let Some((identity_key, rate_data, power)) = per_validator? {
self.put(
state_key::rate_data_at_proposal_start(proposal_id, identity_key),
state_key::rate_data_at_proposal_start(proposal_id, &identity_key),
rate_data,
);
self.put(
state_key::voting_power_at_proposal_start(proposal_id, identity_key),
state_key::voting_power_at_proposal_start(proposal_id, &identity_key),
power,
)
}
Expand Down Expand Up @@ -727,7 +727,7 @@ pub trait StateWriteExt: StateWrite + penumbra_ibc::component::ConnectionStateWr
fn cast_validator_vote(
&mut self,
proposal_id: u64,
identity_key: IdentityKey,
identity_key: &IdentityKey,
vote: Vote,
reason: ValidatorVoteReason,
) {
Expand Down Expand Up @@ -776,7 +776,7 @@ pub trait StateWriteExt: StateWrite + penumbra_ibc::component::ConnectionStateWr
async fn cast_delegator_vote(
&mut self,
proposal_id: u64,
identity_key: IdentityKey,
identity_key: &IdentityKey,
vote: Vote,
nullifier: &Nullifier,
unbonded_amount: Amount,
Expand Down Expand Up @@ -819,7 +819,7 @@ pub trait StateWriteExt: StateWrite + penumbra_ibc::component::ConnectionStateWr
.ok_or_else(|| {
anyhow::anyhow!("unexpected key format for untallied delegator vote")
})?
.parse()?;
.parse::<IdentityKey>()?;
let proposal_id = reverse_path_elements
.next()
.ok_or_else(|| {
Expand All @@ -831,7 +831,7 @@ pub trait StateWriteExt: StateWrite + penumbra_ibc::component::ConnectionStateWr
let mut current_tally = self
.get::<Tally>(&state_key::tallied_delegator_votes(
proposal_id,
identity_key,
&identity_key,
))
.await?
.unwrap_or_default();
Expand Down Expand Up @@ -869,7 +869,7 @@ pub trait StateWriteExt: StateWrite + penumbra_ibc::component::ConnectionStateWr
"tallying delegator votes"
);
self.put(
state_key::tallied_delegator_votes(proposal_id, identity_key),
state_key::tallied_delegator_votes(proposal_id, &identity_key),
tally,
);
}
Expand Down
12 changes: 6 additions & 6 deletions crates/core/component/governance/src/state_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn voted_nullifier_lookup_for_proposal(proposal_id: u64, nullifier: &Nullifi
format!("governance/proposal/{proposal_id:020}/voted_nullifiers/{nullifier}")
}

pub fn rate_data_at_proposal_start(proposal_id: u64, identity_key: IdentityKey) -> String {
pub fn rate_data_at_proposal_start(proposal_id: u64, identity_key: &IdentityKey) -> String {
format!("governance/proposal/{proposal_id:020}/rate_data_at_start/{identity_key}")
}

Expand All @@ -59,7 +59,7 @@ pub fn all_rate_data_at_proposal_start(proposal_id: u64) -> String {
format!("governance/proposal/{proposal_id:020}/rate_data_at_start/")
}

pub fn voting_power_at_proposal_start(proposal_id: u64, identity_key: IdentityKey) -> String {
pub fn voting_power_at_proposal_start(proposal_id: u64, identity_key: &IdentityKey) -> String {
format!("governance/proposal/{proposal_id:020}/voting_power_at_start/{identity_key}")
}

Expand All @@ -68,11 +68,11 @@ pub fn all_voting_power_at_proposal_start(proposal_id: u64) -> String {
format!("governance/proposal/{proposal_id:020}/voting_power_at_start/")
}

pub fn validator_vote(proposal_id: u64, identity_key: IdentityKey) -> String {
pub fn validator_vote(proposal_id: u64, identity_key: &IdentityKey) -> String {
format!("governance/validator_vote/{proposal_id:020}/{identity_key}")
}

pub fn validator_vote_reason(proposal_id: u64, identity_key: IdentityKey) -> String {
pub fn validator_vote_reason(proposal_id: u64, identity_key: &IdentityKey) -> String {
format!("governance/validator_vote_reason/{proposal_id:020}/{identity_key}")
}

Expand All @@ -81,7 +81,7 @@ pub fn all_validator_votes_for_proposal(proposal_id: u64) -> String {
format!("governance/validator_vote/{proposal_id:020}/")
}

pub fn tallied_delegator_votes(proposal_id: u64, identity_key: IdentityKey) -> String {
pub fn tallied_delegator_votes(proposal_id: u64, identity_key: &IdentityKey) -> String {
format!("governance/tallied_delegator_votes/{proposal_id:020}/{identity_key}")
}

Expand All @@ -92,7 +92,7 @@ pub fn all_tallied_delegator_votes_for_proposal(proposal_id: u64) -> String {

pub fn untallied_delegator_vote(
proposal_id: u64,
identity_key: IdentityKey,
identity_key: &IdentityKey,
nullifier: &Nullifier,
) -> String {
format!("governance/untallied_delegator_vote/{proposal_id:020}/{identity_key}/{nullifier}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl ActionHandler for Delegate {

// (end of former check_historical checks)

let validator = self.validator_identity;
let validator = &self.validator_identity;
let unbonded_delegation = self.unbonded_amount;

// This action is executed in two phases:
Expand Down
Loading
Loading