Skip to content

Commit

Permalink
[move] clear bloat from stake.move (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Aug 8, 2024
1 parent aed64b1 commit c7fbb82
Show file tree
Hide file tree
Showing 14 changed files with 2,427 additions and 1,328 deletions.
122 changes: 16 additions & 106 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,29 +484,9 @@ pub enum EntryFunctionCall {
fullnode_addresses: Vec<u8>,
},

/// Unlock from active delegation, it's moved to pending_inactive if locked_until_secs < current_time or
/// directly inactive if it's not from an active validator.
/// This can only called by the operator of the validator/staking pool.
StakeJoinValidatorSet {
pool_address: AccountAddress,
},

/// Similar to unlock_with_cap but will use ownership capability from the signing account.
/// Unlock `amount` from the active stake. Only possible if the lockup has expired.
/// Request to have `pool_address` leave the validator set. The validator is only actually removed from the set when
/// the next epoch starts.
/// The last validator in the set cannot leave. This is an edge case that should never happen as long as the network
/// is still operational.
///
/// Can only be called by the operator of the validator/staking pool.
StakeLeaveValidatorSet {
pool_address: AccountAddress,
},

/// Add `amount` of coins from the `account` owning the StakePool.
/// Rotate the consensus key of the validator, it'll take effect in next epoch.
StakeRotateConsensusKey {
pool_address: AccountAddress,
validator_address: AccountAddress,
new_consensus_pubkey: Vec<u8>,
proof_of_possession: Vec<u8>,
},
Expand All @@ -518,7 +498,7 @@ pub enum EntryFunctionCall {

/// Update the network and full node addresses of the validator. This only takes effect in the next epoch.
StakeUpdateNetworkAndFullnodeAddresses {
pool_address: AccountAddress,
validator_address: AccountAddress,
new_network_addresses: Vec<u8>,
new_fullnode_addresses: Vec<u8>,
},
Expand Down Expand Up @@ -847,22 +827,22 @@ impl EntryFunctionCall {
network_addresses,
fullnode_addresses,
),
StakeJoinValidatorSet { pool_address } => stake_join_validator_set(pool_address),
StakeLeaveValidatorSet { pool_address } => stake_leave_validator_set(pool_address),
StakeRotateConsensusKey {
pool_address,
validator_address,
new_consensus_pubkey,
proof_of_possession,
} => {
stake_rotate_consensus_key(pool_address, new_consensus_pubkey, proof_of_possession)
}
} => stake_rotate_consensus_key(
validator_address,
new_consensus_pubkey,
proof_of_possession,
),
StakeSetOperator { new_operator } => stake_set_operator(new_operator),
StakeUpdateNetworkAndFullnodeAddresses {
pool_address,
validator_address,
new_network_addresses,
new_fullnode_addresses,
} => stake_update_network_and_fullnode_addresses(
pool_address,
validator_address,
new_network_addresses,
new_fullnode_addresses,
),
Expand Down Expand Up @@ -2204,51 +2184,9 @@ pub fn stake_initialize_validator(
))
}

/// Unlock from active delegation, it's moved to pending_inactive if locked_until_secs < current_time or
/// directly inactive if it's not from an active validator.
/// This can only called by the operator of the validator/staking pool.
pub fn stake_join_validator_set(pool_address: AccountAddress) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("stake").to_owned(),
),
ident_str!("join_validator_set").to_owned(),
vec![],
vec![bcs::to_bytes(&pool_address).unwrap()],
))
}

/// Similar to unlock_with_cap but will use ownership capability from the signing account.
/// Unlock `amount` from the active stake. Only possible if the lockup has expired.
/// Request to have `pool_address` leave the validator set. The validator is only actually removed from the set when
/// the next epoch starts.
/// The last validator in the set cannot leave. This is an edge case that should never happen as long as the network
/// is still operational.
///
/// Can only be called by the operator of the validator/staking pool.
pub fn stake_leave_validator_set(pool_address: AccountAddress) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("stake").to_owned(),
),
ident_str!("leave_validator_set").to_owned(),
vec![],
vec![bcs::to_bytes(&pool_address).unwrap()],
))
}

/// Add `amount` of coins from the `account` owning the StakePool.
/// Rotate the consensus key of the validator, it'll take effect in next epoch.
pub fn stake_rotate_consensus_key(
pool_address: AccountAddress,
validator_address: AccountAddress,
new_consensus_pubkey: Vec<u8>,
proof_of_possession: Vec<u8>,
) -> TransactionPayload {
Expand All @@ -2263,7 +2201,7 @@ pub fn stake_rotate_consensus_key(
ident_str!("rotate_consensus_key").to_owned(),
vec![],
vec![
bcs::to_bytes(&pool_address).unwrap(),
bcs::to_bytes(&validator_address).unwrap(),
bcs::to_bytes(&new_consensus_pubkey).unwrap(),
bcs::to_bytes(&proof_of_possession).unwrap(),
],
Expand All @@ -2288,7 +2226,7 @@ pub fn stake_set_operator(new_operator: AccountAddress) -> TransactionPayload {

/// Update the network and full node addresses of the validator. This only takes effect in the next epoch.
pub fn stake_update_network_and_fullnode_addresses(
pool_address: AccountAddress,
validator_address: AccountAddress,
new_network_addresses: Vec<u8>,
new_fullnode_addresses: Vec<u8>,
) -> TransactionPayload {
Expand All @@ -2303,7 +2241,7 @@ pub fn stake_update_network_and_fullnode_addresses(
ident_str!("update_network_and_fullnode_addresses").to_owned(),
vec![],
vec![
bcs::to_bytes(&pool_address).unwrap(),
bcs::to_bytes(&validator_address).unwrap(),
bcs::to_bytes(&new_network_addresses).unwrap(),
bcs::to_bytes(&new_fullnode_addresses).unwrap(),
],
Expand Down Expand Up @@ -3170,30 +3108,10 @@ mod decoder {
}
}

pub fn stake_join_validator_set(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::StakeJoinValidatorSet {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
})
} else {
None
}
}

pub fn stake_leave_validator_set(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::StakeLeaveValidatorSet {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
})
} else {
None
}
}

pub fn stake_rotate_consensus_key(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::StakeRotateConsensusKey {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
validator_address: bcs::from_bytes(script.args().get(0)?).ok()?,
new_consensus_pubkey: bcs::from_bytes(script.args().get(1)?).ok()?,
proof_of_possession: bcs::from_bytes(script.args().get(2)?).ok()?,
})
Expand All @@ -3217,7 +3135,7 @@ mod decoder {
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::StakeUpdateNetworkAndFullnodeAddresses {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
validator_address: bcs::from_bytes(script.args().get(0)?).ok()?,
new_network_addresses: bcs::from_bytes(script.args().get(1)?).ok()?,
new_fullnode_addresses: bcs::from_bytes(script.args().get(2)?).ok()?,
})
Expand Down Expand Up @@ -3545,14 +3463,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"stake_initialize_validator".to_string(),
Box::new(decoder::stake_initialize_validator),
);
map.insert(
"stake_join_validator_set".to_string(),
Box::new(decoder::stake_join_validator_set),
);
map.insert(
"stake_leave_validator_set".to_string(),
Box::new(decoder::stake_leave_validator_set),
);
map.insert(
"stake_rotate_consensus_key".to_string(),
Box::new(decoder::stake_rotate_consensus_key),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ spec diem_framework::diem_governance {
/// The delegated voter under the resource StakePool of the stake_pool must be the proposer address.
/// Address @diem_framework must exist GovernanceEvents.
spec schema CreateProposalAbortsIf {
use diem_framework::stake;
// use diem_framework::stake;

proposer: &signer;
stake_pool: address;
Expand All @@ -150,14 +150,14 @@ spec diem_framework::diem_governance {

let proposer_address = signer::address_of(proposer);
let governance_config = global<GovernanceConfig>(@diem_framework);
let stake_pool_res = global<stake::StakePool>(stake_pool);
// let stake_pool_res = global<stake::StakePool>(stake_pool);
// aborts_if !exists<staking_config::StakingConfig>(@diem_framework);
aborts_if !exists<stake::StakePool>(stake_pool);
aborts_if global<stake::StakePool>(stake_pool).delegated_voter != proposer_address;
// aborts_if !exists<stake::StakePool>(stake_pool);
// aborts_if global<stake::StakePool>(stake_pool).delegated_voter != proposer_address;
include AbortsIfNotGovernanceConfig;
let current_time = timestamp::now_seconds();
let proposal_expiration = current_time + governance_config.voting_duration_secs;
aborts_if stake_pool_res.locked_until_secs < proposal_expiration;
// aborts_if stake_pool_res.locked_until_secs < proposal_expiration;
aborts_if !exists<GovernanceEvents>(@diem_framework);
// let allow_validator_set_change = global<staking_config::StakingConfig>(@diem_framework).allow_validator_set_change;
// aborts_if !allow_validator_set_change && !exists<stake::ValidatorSet>(@diem_framework);
Expand Down
Loading

0 comments on commit c7fbb82

Please sign in to comment.