Skip to content

Commit

Permalink
point to new jito-programs submod and invoke updated init tda instruc…
Browse files Browse the repository at this point in the history
…tion (#228)
  • Loading branch information
segfaultdoc authored and buffalu committed Feb 14, 2023
1 parent 917425f commit 1295da1
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 54 deletions.
1 change: 0 additions & 1 deletion core/src/bundle_sanitizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ mod tests {
tip_payment_program_id: Pubkey::new_unique(),
tip_distribution_program_id: Pubkey::new_unique(),
tip_distribution_account_config: TipDistributionAccountConfig {
payer: Arc::new(Keypair::new()),
merkle_root_upload_authority: Pubkey::new_unique(),
vote_account: Pubkey::new_unique(),
commission_bps: 0,
Expand Down
25 changes: 14 additions & 11 deletions core/src/bundle_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,23 +831,26 @@ impl BundleStage {
let maybe_init_tip_distro_config_tx =
if tip_manager.should_initialize_tip_distribution_config(bank) {
info!("building initialize_tip_distribution_config_tx");
Some(tip_manager.initialize_tip_distribution_config_tx(
Some(
tip_manager
.initialize_tip_distribution_config_tx(bank.last_blockhash(), cluster_info),
)
} else {
None
};

let maybe_init_tip_distro_account_tx =
if tip_manager.should_init_tip_distribution_account(bank) {
info!("building initialize_tip_distribution_account tx");
Some(tip_manager.initialize_tip_distribution_account_tx(
bank.last_blockhash(),
&cluster_info.keypair(),
bank.epoch(),
cluster_info,
))
} else {
None
};

let maybe_init_tip_distro_account_tx = if tip_manager
.should_init_tip_distribution_account(bank)
{
info!("building init_tip_distribution_account_tx");
Some(tip_manager.init_tip_distribution_account_tx(bank.last_blockhash(), bank.epoch()))
} else {
None
};

let transactions = [
maybe_init_tip_payment_config_tx,
maybe_init_tip_distro_config_tx,
Expand Down
47 changes: 23 additions & 24 deletions core/src/tip_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use {
solana_program::hash::Hash, AccountDeserialize, InstructionData, ToAccountMetas,
},
log::warn,
solana_gossip::cluster_info::ClusterInfo,
solana_runtime::bank::Bank,
solana_sdk::{
account::ReadableAccount,
Expand All @@ -22,8 +23,9 @@ use {
tip_distribution::sdk::{
derive_config_account_address, derive_tip_distribution_account_address,
instruction::{
init_tip_distribution_account_ix, initialize_ix, InitTipDistributionAccountAccounts,
InitTipDistributionAccountArgs, InitializeAccounts, InitializeArgs,
initialize_ix, initialize_tip_distribution_account_ix, InitializeAccounts,
InitializeArgs, InitializeTipDistributionAccountAccounts,
InitializeTipDistributionAccountArgs,
},
},
tip_payment::{
Expand Down Expand Up @@ -61,12 +63,9 @@ struct TipDistributionProgramInfo {
config_pda_and_bump: (Pubkey, u8),
}

/// This config is used on each invocation to the `init_tip_distribution_account` instruction.
/// This config is used on each invocation to the `initialize_tip_distribution_account` instruction.
#[derive(Debug, Clone)]
pub struct TipDistributionAccountConfig {
/// The keypair paying and signing each init tx.
pub payer: Arc<Keypair>,

/// The account with authority to upload merkle-roots to this validator's [TipDistributionAccount].
pub merkle_root_upload_authority: Pubkey,

Expand All @@ -80,7 +79,6 @@ pub struct TipDistributionAccountConfig {
impl Default for TipDistributionAccountConfig {
fn default() -> Self {
Self {
payer: Arc::new(Keypair::new()),
merkle_root_upload_authority: Pubkey::new_unique(),
vote_account: Pubkey::new_unique(),
commission_bps: 0,
Expand Down Expand Up @@ -302,67 +300,68 @@ impl TipManager {
pub fn initialize_tip_distribution_config_tx(
&self,
recent_blockhash: Hash,
my_keypair: &Keypair,
cluster_info: &Arc<ClusterInfo>,
) -> SanitizedTransaction {
let ix = initialize_ix(
self.tip_distribution_program_info.program_id,
InitializeArgs {
authority: my_keypair.pubkey(),
expired_funds_account: my_keypair.pubkey(),
num_epochs_valid: 3,
max_validator_commission_bps: 1000,
authority: cluster_info.id(),
expired_funds_account: cluster_info.id(),
num_epochs_valid: 10,
max_validator_commission_bps: 10_000,
bump: self.tip_distribution_program_info.config_pda_and_bump.1,
},
InitializeAccounts {
config: self.tip_distribution_program_info.config_pda_and_bump.0,
system_program: system_program::id(),
initializer: my_keypair.pubkey(),
initializer: cluster_info.id(),
},
);

SanitizedTransaction::try_from_legacy_transaction(Transaction::new_signed_with_payer(
&[ix],
Some(&my_keypair.pubkey()),
&[my_keypair],
Some(&cluster_info.id()),
&[cluster_info.keypair().as_ref()],
recent_blockhash,
))
.unwrap()
}

/// Creates an [InitTipDistributionAccount] transaction object using the provided Epoch.
pub fn init_tip_distribution_account_tx(
/// Creates an [InitializeTipDistributionAccount] transaction object using the provided Epoch.
pub fn initialize_tip_distribution_account_tx(
&self,
recent_blockhash: Hash,
epoch: Epoch,
cluster_info: &Arc<ClusterInfo>,
) -> SanitizedTransaction {
let (tip_distribution_account, bump) = derive_tip_distribution_account_address(
&self.tip_distribution_program_info.program_id,
&self.tip_distribution_account_config.vote_account,
epoch,
);

let ix = init_tip_distribution_account_ix(
let ix = initialize_tip_distribution_account_ix(
self.tip_distribution_program_info.program_id,
InitTipDistributionAccountArgs {
validator_vote_account: self.tip_distribution_account_config.vote_account,
InitializeTipDistributionAccountArgs {
merkle_root_upload_authority: self
.tip_distribution_account_config
.merkle_root_upload_authority,
validator_commission_bps: self.tip_distribution_account_config.commission_bps,
bump,
},
InitTipDistributionAccountAccounts {
InitializeTipDistributionAccountAccounts {
config: self.tip_distribution_program_info.config_pda_and_bump.0,
tip_distribution_account,
payer: self.tip_distribution_account_config.payer.pubkey(),
system_program: system_program::id(),
signer: cluster_info.id(),
validator_vote_account: self.tip_distribution_account_config.vote_account,
},
);

SanitizedTransaction::try_from_legacy_transaction(Transaction::new_signed_with_payer(
&[ix],
Some(&self.tip_distribution_account_config.payer.pubkey()),
&[self.tip_distribution_account_config.payer.as_ref()],
Some(&cluster_info.id()),
&[cluster_info.keypair().as_ref()],
recent_blockhash,
))
.unwrap()
Expand Down
18 changes: 0 additions & 18 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1907,13 +1907,6 @@ pub fn main() {
.takes_value(true)
.help("The public key of the tip-distribution program.")
)
.arg(
Arg::with_name("tip_distribution_account_payer")
.long("tip-distribution-account-payer")
.value_name("TIP_DISTRIBUTION_ACCOUNT_PAYER")
.takes_value(true)
.help("The payer of my tip distribution accounts.")
)
.arg(
Arg::with_name("merkle_root_upload_authority")
.long("merkle-root-upload-authority")
Expand Down Expand Up @@ -3463,17 +3456,6 @@ fn tip_manager_config_from_matches(
Pubkey::new_unique()
}),
tip_distribution_account_config: TipDistributionAccountConfig {
payer: {
let keypair =
keypair_of(matches, "tip_distribution_account_payer").unwrap_or_else(|| {
if !voting_disabled {
panic!("--tip-distribution-account-payer argument required when validator is voting");
}
Keypair::new()
});

Arc::new(keypair)
},
merkle_root_upload_authority: pubkey_of(matches, "merkle_root_upload_authority")
.unwrap_or_else(|| {
if !voting_disabled {
Expand Down

0 comments on commit 1295da1

Please sign in to comment.