diff --git a/keepers/validator-keeper/src/stake.rs b/keepers/validator-keeper/src/stake.rs index a3bb5a86..803039bc 100644 --- a/keepers/validator-keeper/src/stake.rs +++ b/keepers/validator-keeper/src/stake.rs @@ -131,7 +131,7 @@ impl UpdateInstruction for StakeHistoryEntry { validator_history_account: self.address, vote_account: self.vote_account, config: self.config_address, - stake_authority: self.signer, + oracle_authority: self.signer, } .to_account_metas(None), data: validator_history::instruction::UpdateStakeHistory { diff --git a/programs/validator-history/src/instructions/initialize_config.rs b/programs/validator-history/src/instructions/initialize_config.rs index d763c9aa..68a17f71 100644 --- a/programs/validator-history/src/instructions/initialize_config.rs +++ b/programs/validator-history/src/instructions/initialize_config.rs @@ -18,8 +18,8 @@ pub struct InitializeConfig<'info> { } pub fn handler(ctx: Context, authority: Pubkey) -> Result<()> { - ctx.accounts.config.stake_authority = authority; - ctx.accounts.config.tip_distribution_authority = authority; + ctx.accounts.config.oracle_authority = authority; + ctx.accounts.config.admin = authority; ctx.accounts.config.bump = *ctx.bumps.get("config").unwrap(); ctx.accounts.config.counter = 0; Ok(()) diff --git a/programs/validator-history/src/instructions/mod.rs b/programs/validator-history/src/instructions/mod.rs index 5d932c4d..9995550e 100644 --- a/programs/validator-history/src/instructions/mod.rs +++ b/programs/validator-history/src/instructions/mod.rs @@ -4,8 +4,8 @@ pub mod copy_vote_account; pub mod initialize_config; pub mod initialize_validator_history_account; pub mod realloc_validator_history_account; -pub mod set_new_stake_authority; -pub mod set_new_tip_distribution_authority; +pub mod set_new_admin; +pub mod set_new_oracle_authority; pub mod set_new_tip_distribution_program; pub mod update_mev_commission; pub mod update_stake_history; @@ -15,8 +15,8 @@ pub use copy_vote_account::*; pub use initialize_config::*; pub use initialize_validator_history_account::*; pub use realloc_validator_history_account::*; -pub use set_new_stake_authority::*; -pub use set_new_tip_distribution_authority::*; +pub use set_new_admin::*; +pub use set_new_oracle_authority::*; pub use set_new_tip_distribution_program::*; pub use update_mev_commission::*; pub use update_stake_history::*; diff --git a/programs/validator-history/src/instructions/set_new_admin.rs b/programs/validator-history/src/instructions/set_new_admin.rs new file mode 100644 index 00000000..54823ddd --- /dev/null +++ b/programs/validator-history/src/instructions/set_new_admin.rs @@ -0,0 +1,22 @@ +use anchor_lang::prelude::*; + +use crate::state::Config; + +#[derive(Accounts)] +pub struct SetNewAdmin<'info> { + #[account( + mut, + seeds = [Config::SEED], + bump = config.bump, + has_one = admin, + )] + pub config: Account<'info, Config>, + /// CHECK: fine since we are not deserializing account + pub new_admin: AccountInfo<'info>, + pub admin: Signer<'info>, +} + +pub fn handler(ctx: Context) -> Result<()> { + ctx.accounts.config.admin = ctx.accounts.new_admin.key(); + Ok(()) +} diff --git a/programs/validator-history/src/instructions/set_new_oracle_authority.rs b/programs/validator-history/src/instructions/set_new_oracle_authority.rs new file mode 100644 index 00000000..6fd5dd4a --- /dev/null +++ b/programs/validator-history/src/instructions/set_new_oracle_authority.rs @@ -0,0 +1,22 @@ +use anchor_lang::prelude::*; + +use crate::state::Config; + +#[derive(Accounts)] +pub struct SetNewOracleAuthority<'info> { + #[account( + mut, + seeds = [Config::SEED], + bump = config.bump, + has_one = admin, + )] + pub config: Account<'info, Config>, + /// CHECK: fine since we are not deserializing account + pub new_oracle_authority: AccountInfo<'info>, + pub admin: Signer<'info>, +} + +pub fn handler(ctx: Context) -> Result<()> { + ctx.accounts.config.oracle_authority = ctx.accounts.new_oracle_authority.key(); + Ok(()) +} diff --git a/programs/validator-history/src/instructions/set_new_stake_authority.rs b/programs/validator-history/src/instructions/set_new_stake_authority.rs deleted file mode 100644 index 0e9f3066..00000000 --- a/programs/validator-history/src/instructions/set_new_stake_authority.rs +++ /dev/null @@ -1,22 +0,0 @@ -use anchor_lang::prelude::*; - -use crate::state::Config; - -#[derive(Accounts)] -pub struct SetNewStakeAuthority<'info> { - #[account( - mut, - seeds = [Config::SEED], - bump = config.bump, - has_one = stake_authority, - )] - pub config: Account<'info, Config>, - /// CHECK: fine since we are not deserializing account - pub new_authority: AccountInfo<'info>, - pub stake_authority: Signer<'info>, -} - -pub fn handler(ctx: Context) -> Result<()> { - ctx.accounts.config.stake_authority = ctx.accounts.new_authority.key(); - Ok(()) -} diff --git a/programs/validator-history/src/instructions/set_new_tip_distribution_authority.rs b/programs/validator-history/src/instructions/set_new_tip_distribution_authority.rs deleted file mode 100644 index 50ef8e53..00000000 --- a/programs/validator-history/src/instructions/set_new_tip_distribution_authority.rs +++ /dev/null @@ -1,22 +0,0 @@ -use anchor_lang::prelude::*; - -use crate::state::Config; - -#[derive(Accounts)] -pub struct SetNewTipDistributionAuthority<'info> { - #[account( - mut, - seeds = [Config::SEED], - bump = config.bump, - has_one = tip_distribution_authority, - )] - pub config: Account<'info, Config>, - /// CHECK: fine since we are not deserializing account - pub new_authority: AccountInfo<'info>, - pub tip_distribution_authority: Signer<'info>, -} - -pub fn handler(ctx: Context) -> Result<()> { - ctx.accounts.config.tip_distribution_authority = ctx.accounts.new_authority.key(); - Ok(()) -} diff --git a/programs/validator-history/src/instructions/set_new_tip_distribution_program.rs b/programs/validator-history/src/instructions/set_new_tip_distribution_program.rs index e3288003..bdd66a6f 100644 --- a/programs/validator-history/src/instructions/set_new_tip_distribution_program.rs +++ b/programs/validator-history/src/instructions/set_new_tip_distribution_program.rs @@ -8,13 +8,13 @@ pub struct SetNewTipDistributionProgram<'info> { mut, seeds = [Config::SEED], bump = config.bump, - has_one = tip_distribution_authority, + has_one = admin, )] pub config: Account<'info, Config>, /// CHECK: fine since we are not deserializing account #[account(executable)] pub new_tip_distribution_program: AccountInfo<'info>, - pub tip_distribution_authority: Signer<'info>, + pub admin: Signer<'info>, } pub fn handler(ctx: Context) -> Result<()> { diff --git a/programs/validator-history/src/instructions/update_stake_history.rs b/programs/validator-history/src/instructions/update_stake_history.rs index 0fa6dd5b..756394b8 100644 --- a/programs/validator-history/src/instructions/update_stake_history.rs +++ b/programs/validator-history/src/instructions/update_stake_history.rs @@ -21,12 +21,12 @@ pub struct UpdateStakeHistory<'info> { #[account( seeds = [Config::SEED], bump = config.bump, - has_one = stake_authority + has_one = oracle_authority )] pub config: Account<'info, Config>, #[account(mut)] - pub stake_authority: Signer<'info>, + pub oracle_authority: Signer<'info>, } pub fn handler( diff --git a/programs/validator-history/src/lib.rs b/programs/validator-history/src/lib.rs index cf7c01fb..ab0a9591 100644 --- a/programs/validator-history/src/lib.rs +++ b/programs/validator-history/src/lib.rs @@ -71,14 +71,12 @@ pub mod validator_history { instructions::set_new_tip_distribution_program::handler(ctx) } - pub fn set_new_tip_distribution_authority( - ctx: Context, - ) -> Result<()> { - instructions::set_new_tip_distribution_authority::handler(ctx) + pub fn set_new_admin(ctx: Context) -> Result<()> { + instructions::set_new_admin::handler(ctx) } - pub fn set_new_stake_authority(ctx: Context) -> Result<()> { - instructions::set_new_stake_authority::handler(ctx) + pub fn set_new_oracle_authority(ctx: Context) -> Result<()> { + instructions::set_new_oracle_authority::handler(ctx) } pub fn update_stake_history( diff --git a/programs/validator-history/src/state.rs b/programs/validator-history/src/state.rs index 1a9ca52a..7258f6fc 100644 --- a/programs/validator-history/src/state.rs +++ b/programs/validator-history/src/state.rs @@ -19,10 +19,10 @@ pub struct Config { pub tip_distribution_program: Pubkey, // Has the ability to upgrade the tip_distribution_program in case of a program upgrade - pub tip_distribution_authority: Pubkey, + pub admin: Pubkey, // Has the ability to publish stake amounts per validator - pub stake_authority: Pubkey, + pub oracle_authority: Pubkey, // Tracks number of initialized ValidatorHistory accounts pub counter: u32, diff --git a/tests/src/fixtures.rs b/tests/src/fixtures.rs index 3a3e3584..fb4c39fb 100644 --- a/tests/src/fixtures.rs +++ b/tests/src/fixtures.rs @@ -78,6 +78,7 @@ impl TestFixture { new_vote_account(identity_pubkey, vote_account, 1, Some(vec![(0, 0, 0); 10])), ); program.add_account(keypair.pubkey(), system_account(100_000_000_000)); + program.add_account(identity_pubkey, system_account(100_000_000_000)); let ctx = Rc::new(RefCell::new(program.start_with_context().await)); @@ -127,7 +128,7 @@ impl TestFixture { accounts: validator_history::accounts::SetNewTipDistributionProgram { config: self.validator_history_config, new_tip_distribution_program: jito_tip_distribution::id(), - tip_distribution_authority: self.keypair.pubkey(), + admin: self.keypair.pubkey(), } .to_account_metas(None), data: validator_history::instruction::SetNewTipDistributionProgram {}.data(), diff --git a/tests/tests/test_initialize.rs b/tests/tests/test_initialize.rs index d85c9836..8020faef 100644 --- a/tests/tests/test_initialize.rs +++ b/tests/tests/test_initialize.rs @@ -38,8 +38,8 @@ async fn test_initialize() { .await; assert!(config.counter == 0); - assert!(config.stake_authority == test.keypair.pubkey()); - assert!(config.tip_distribution_authority == test.keypair.pubkey()); + assert!(config.oracle_authority == test.keypair.pubkey()); + assert!(config.admin == test.keypair.pubkey()); // Initialize validator history account @@ -170,7 +170,7 @@ async fn test_extra_realloc() { validator_history_account: fixture.validator_history_account, vote_account: fixture.vote_account, config: fixture.validator_history_config, - stake_authority: fixture.keypair.pubkey(), + oracle_authority: fixture.keypair.pubkey(), } .to_account_metas(None), }; diff --git a/tests/tests/test_mev_commission.rs b/tests/tests/test_mev_commission.rs index 9915bdef..7f41a098 100644 --- a/tests/tests/test_mev_commission.rs +++ b/tests/tests/test_mev_commission.rs @@ -203,13 +203,13 @@ async fn test_change_tip_distribution_authority() { // Change tip distribution authority let instruction = Instruction { program_id: validator_history::id(), - accounts: validator_history::accounts::SetNewTipDistributionAuthority { + accounts: validator_history::accounts::SetNewAdmin { config: fixture.validator_history_config, - new_authority, - tip_distribution_authority: fixture.keypair.pubkey(), + new_admin: new_authority, + admin: fixture.keypair.pubkey(), } .to_account_metas(None), - data: validator_history::instruction::SetNewTipDistributionAuthority {}.data(), + data: validator_history::instruction::SetNewAdmin {}.data(), }; let transaction = Transaction::new_signed_with_payer( &[instruction], @@ -224,18 +224,18 @@ async fn test_change_tip_distribution_authority() { .load_and_deserialize(&fixture.validator_history_config) .await; - assert!(config.tip_distribution_authority == new_authority); + assert!(config.admin == new_authority); // Change tip distribution authority let instruction = Instruction { program_id: validator_history::id(), - accounts: validator_history::accounts::SetNewTipDistributionAuthority { + accounts: validator_history::accounts::SetNewAdmin { config: fixture.validator_history_config, - new_authority: fixture.keypair.pubkey(), - tip_distribution_authority: fixture.keypair.pubkey(), + new_admin: fixture.keypair.pubkey(), + admin: fixture.keypair.pubkey(), } .to_account_metas(None), - data: validator_history::instruction::SetNewTipDistributionAuthority {}.data(), + data: validator_history::instruction::SetNewAdmin {}.data(), }; let transaction = Transaction::new_signed_with_payer( diff --git a/tests/tests/test_stake.rs b/tests/tests/test_stake.rs index 04dc200c..412768d7 100644 --- a/tests/tests/test_stake.rs +++ b/tests/tests/test_stake.rs @@ -32,7 +32,7 @@ async fn test_stake_history_basic_update() { validator_history_account: fixture.validator_history_account, vote_account: fixture.vote_account, config: fixture.validator_history_config, - stake_authority: fixture.keypair.pubkey(), + oracle_authority: fixture.keypair.pubkey(), } .to_account_metas(None), }; @@ -70,7 +70,7 @@ async fn test_stake_history_basic_update() { validator_history_account: fixture.validator_history_account, vote_account: fixture.vote_account, config: fixture.validator_history_config, - stake_authority: fixture.keypair.pubkey(), + oracle_authority: fixture.keypair.pubkey(), } .to_account_metas(None), }; @@ -122,7 +122,7 @@ async fn test_stake_history_wrong_authority() { validator_history_account: fixture.validator_history_account, vote_account: fixture.vote_account, config: fixture.validator_history_config, - stake_authority: new_authority.pubkey(), + oracle_authority: new_authority.pubkey(), } .to_account_metas(None), }; @@ -169,7 +169,7 @@ async fn test_stake_history_future_epoch() { validator_history_account: fixture.validator_history_account, vote_account: fixture.vote_account, config: fixture.validator_history_config, - stake_authority: fixture.keypair.pubkey(), + oracle_authority: fixture.keypair.pubkey(), } .to_account_metas(None), }; @@ -185,7 +185,7 @@ async fn test_stake_history_future_epoch() { } #[tokio::test] -async fn test_change_stake_authority() { +async fn test_change_oracle_authority() { let test = TestFixture::new().await; let ctx = &test.ctx; @@ -196,13 +196,13 @@ async fn test_change_stake_authority() { // Change stake authority let instruction = Instruction { program_id: validator_history::id(), - accounts: validator_history::accounts::SetNewStakeAuthority { + accounts: validator_history::accounts::SetNewOracleAuthority { config: test.validator_history_config, - new_authority, - stake_authority: test.keypair.pubkey(), + new_oracle_authority: new_authority, + admin: test.keypair.pubkey(), } .to_account_metas(None), - data: validator_history::instruction::SetNewStakeAuthority {}.data(), + data: validator_history::instruction::SetNewOracleAuthority {}.data(), }; let transaction = Transaction::new_signed_with_payer( &[instruction], @@ -217,23 +217,23 @@ async fn test_change_stake_authority() { .load_and_deserialize(&test.validator_history_config) .await; - assert!(config.stake_authority == new_authority); + assert!(config.oracle_authority == new_authority); // Try to change it back with wrong signer let instruction = Instruction { program_id: validator_history::id(), - accounts: validator_history::accounts::SetNewStakeAuthority { + accounts: validator_history::accounts::SetNewOracleAuthority { config: test.validator_history_config, - new_authority: test.keypair.pubkey(), - stake_authority: test.keypair.pubkey(), + new_oracle_authority: test.keypair.pubkey(), + admin: test.identity_keypair.pubkey(), } .to_account_metas(None), - data: validator_history::instruction::SetNewStakeAuthority {}.data(), + data: validator_history::instruction::SetNewOracleAuthority {}.data(), }; let transaction = Transaction::new_signed_with_payer( &[instruction], - Some(&test.keypair.pubkey()), - &[&test.keypair], + Some(&test.identity_keypair.pubkey()), + &[&test.identity_keypair], ctx.borrow().last_blockhash, ); diff --git a/utils/validator-history-cli/src/main.rs b/utils/validator-history-cli/src/main.rs index 5c4dc22d..fce8c5e0 100644 --- a/utils/validator-history-cli/src/main.rs +++ b/utils/validator-history-cli/src/main.rs @@ -104,7 +104,7 @@ fn command_init_config(args: InitConfig, client: RpcClient) { accounts: validator_history::accounts::SetNewTipDistributionProgram { config: config_pda, new_tip_distribution_program: args.tip_distribution_program_id, - tip_distribution_authority: keypair.pubkey(), + admin: keypair.pubkey(), } .to_account_metas(None), data: validator_history::instruction::SetNewTipDistributionProgram {}.data(), @@ -113,26 +113,26 @@ fn command_init_config(args: InitConfig, client: RpcClient) { if let Some(new_authority) = args.tip_distribution_authority { instructions.push(Instruction { program_id: validator_history::ID, - accounts: validator_history::accounts::SetNewTipDistributionAuthority { + accounts: validator_history::accounts::SetNewAdmin { config: config_pda, - new_authority, - tip_distribution_authority: keypair.pubkey(), + new_admin: new_authority, + admin: keypair.pubkey(), } .to_account_metas(None), - data: validator_history::instruction::SetNewTipDistributionAuthority {}.data(), + data: validator_history::instruction::SetNewAdmin {}.data(), }); } if let Some(new_authority) = args.stake_authority { instructions.push(Instruction { program_id: validator_history::ID, - accounts: validator_history::accounts::SetNewStakeAuthority { + accounts: validator_history::accounts::SetNewOracleAuthority { config: config_pda, - new_authority, - stake_authority: keypair.pubkey(), + new_oracle_authority: new_authority, + admin: keypair.pubkey(), } .to_account_metas(None), - data: validator_history::instruction::SetNewStakeAuthority {}.data(), + data: validator_history::instruction::SetNewOracleAuthority {}.data(), }); }