mirror of
https://github.com/d0zingcat/ore.git
synced 2026-06-06 23:26:46 +00:00
remove admin stuff
This commit is contained in:
@@ -5,8 +5,11 @@ use solana_program::{pubkey, pubkey::Pubkey};
|
|||||||
/// The reward rate to intialize the program with.
|
/// The reward rate to intialize the program with.
|
||||||
pub const INITIAL_BASE_REWARD_RATE: u64 = 10u64.pow(3u32);
|
pub const INITIAL_BASE_REWARD_RATE: u64 = 10u64.pow(3u32);
|
||||||
|
|
||||||
/// The spam/liveness tolerance to initialize the program with.
|
/// The admin allowed to initialize the program.
|
||||||
pub const INITIAL_TOLERANCE: i64 = 5;
|
pub const INITIAL_ADMIN: Pubkey = pubkey!("HBUh9g46wk2X89CvaNN15UmsznP59rh6od1h8JwYAopk");
|
||||||
|
|
||||||
|
/// The spam/liveness tolerance in seconds.
|
||||||
|
pub const TOLERANCE: i64 = 5;
|
||||||
|
|
||||||
/// The minimum difficulty required of all submitted hashes.
|
/// The minimum difficulty required of all submitted hashes.
|
||||||
pub const MIN_DIFFICULTY: u32 = 8; // 12;
|
pub const MIN_DIFFICULTY: u32 = 8; // 12;
|
||||||
|
|||||||
@@ -108,11 +108,6 @@ pub enum OreInstruction {
|
|||||||
#[account(1, name = "signer", desc = "Admin signer", signer)]
|
#[account(1, name = "signer", desc = "Admin signer", signer)]
|
||||||
#[account(2, name = "config", desc = "Ore config account", writable)]
|
#[account(2, name = "config", desc = "Ore config account", writable)]
|
||||||
UpdateAdmin = 101,
|
UpdateAdmin = 101,
|
||||||
|
|
||||||
#[account(0, name = "ore_program", desc = "Ore program")]
|
|
||||||
#[account(1, name = "signer", desc = "Admin signer", signer)]
|
|
||||||
#[account(2, name = "config", desc = "Ore config account", writable)]
|
|
||||||
UpdateTolerance = 102,
|
|
||||||
|
|
||||||
#[account(0, name = "ore_program", desc = "Ore program")]
|
#[account(0, name = "ore_program", desc = "Ore program")]
|
||||||
#[account(1, name = "signer", desc = "Admin signer", signer)]
|
#[account(1, name = "signer", desc = "Admin signer", signer)]
|
||||||
@@ -180,13 +175,6 @@ pub struct UpdateAdminArgs {
|
|||||||
pub new_admin: Pubkey,
|
pub new_admin: Pubkey,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
|
||||||
pub struct UpdateToleranceArgs {
|
|
||||||
pub tolerance_liveness: u64,
|
|
||||||
pub tolerance_spam: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||||
pub struct PauseArgs {
|
pub struct PauseArgs {
|
||||||
@@ -200,7 +188,6 @@ impl_to_bytes!(ClaimArgs);
|
|||||||
impl_to_bytes!(StakeArgs);
|
impl_to_bytes!(StakeArgs);
|
||||||
impl_to_bytes!(UpgradeArgs);
|
impl_to_bytes!(UpgradeArgs);
|
||||||
impl_to_bytes!(UpdateAdminArgs);
|
impl_to_bytes!(UpdateAdminArgs);
|
||||||
impl_to_bytes!(UpdateToleranceArgs);
|
|
||||||
impl_to_bytes!(PauseArgs);
|
impl_to_bytes!(PauseArgs);
|
||||||
|
|
||||||
impl_instruction_from_bytes!(InitializeArgs);
|
impl_instruction_from_bytes!(InitializeArgs);
|
||||||
@@ -210,7 +197,6 @@ impl_instruction_from_bytes!(ClaimArgs);
|
|||||||
impl_instruction_from_bytes!(StakeArgs);
|
impl_instruction_from_bytes!(StakeArgs);
|
||||||
impl_instruction_from_bytes!(UpgradeArgs);
|
impl_instruction_from_bytes!(UpgradeArgs);
|
||||||
impl_instruction_from_bytes!(UpdateAdminArgs);
|
impl_instruction_from_bytes!(UpdateAdminArgs);
|
||||||
impl_instruction_from_bytes!(UpdateToleranceArgs);
|
|
||||||
impl_instruction_from_bytes!(PauseArgs);
|
impl_instruction_from_bytes!(PauseArgs);
|
||||||
|
|
||||||
/// Builds a reset instruction.
|
/// Builds a reset instruction.
|
||||||
@@ -445,31 +431,6 @@ pub fn update_admin(signer: Pubkey, new_admin: Pubkey) -> Instruction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build an update_tolerance instruction.
|
|
||||||
pub fn update_tolerance(
|
|
||||||
signer: Pubkey,
|
|
||||||
new_liveness_tolerance: u64,
|
|
||||||
new_spam_tolerance: u64,
|
|
||||||
) -> Instruction {
|
|
||||||
Instruction {
|
|
||||||
program_id: crate::id(),
|
|
||||||
accounts: vec![
|
|
||||||
AccountMeta::new(signer, true),
|
|
||||||
AccountMeta::new(CONFIG_ADDRESS, false),
|
|
||||||
],
|
|
||||||
data: [
|
|
||||||
OreInstruction::UpdateTolerance.to_vec(),
|
|
||||||
UpdateToleranceArgs {
|
|
||||||
tolerance_liveness: new_liveness_tolerance,
|
|
||||||
tolerance_spam: new_spam_tolerance,
|
|
||||||
}
|
|
||||||
.to_bytes()
|
|
||||||
.to_vec(),
|
|
||||||
]
|
|
||||||
.concat(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Build a pause instruction.
|
/// Build a pause instruction.
|
||||||
pub fn pause(signer: Pubkey, paused: bool) -> Instruction {
|
pub fn pause(signer: Pubkey, paused: bool) -> Instruction {
|
||||||
Instruction {
|
Instruction {
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ pub fn process_instruction(
|
|||||||
OreInstruction::Upgrade => process_upgrade(program_id, accounts, data)?,
|
OreInstruction::Upgrade => process_upgrade(program_id, accounts, data)?,
|
||||||
OreInstruction::Initialize => process_initialize(program_id, accounts, data)?,
|
OreInstruction::Initialize => process_initialize(program_id, accounts, data)?,
|
||||||
OreInstruction::UpdateAdmin => process_update_admin(program_id, accounts, data)?,
|
OreInstruction::UpdateAdmin => process_update_admin(program_id, accounts, data)?,
|
||||||
OreInstruction::UpdateTolerance => process_update_tolerance(program_id, accounts, data)?,
|
|
||||||
OreInstruction::Pause => process_pause(program_id, accounts, data)?,
|
OreInstruction::Pause => process_pause(program_id, accounts, data)?,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use solana_program::{
|
|||||||
entrypoint::ProgramResult,
|
entrypoint::ProgramResult,
|
||||||
program_error::ProgramError,
|
program_error::ProgramError,
|
||||||
program_pack::Pack,
|
program_pack::Pack,
|
||||||
pubkey,
|
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
system_program, {self, sysvar},
|
system_program, {self, sysvar},
|
||||||
};
|
};
|
||||||
@@ -18,13 +17,10 @@ use crate::{
|
|||||||
utils::create_pda,
|
utils::create_pda,
|
||||||
utils::AccountDeserialize,
|
utils::AccountDeserialize,
|
||||||
utils::Discriminator,
|
utils::Discriminator,
|
||||||
BUS, BUS_COUNT, CONFIG, INITIAL_BASE_REWARD_RATE, INITIAL_TOLERANCE, METADATA, METADATA_NAME,
|
BUS, BUS_COUNT, CONFIG, INITIAL_ADMIN, INITIAL_BASE_REWARD_RATE, METADATA, METADATA_NAME,
|
||||||
METADATA_SYMBOL, METADATA_URI, MINT, MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY,
|
METADATA_SYMBOL, METADATA_URI, MINT, MINT_ADDRESS, MINT_NOISE, TOKEN_DECIMALS, TREASURY,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The address to allow for initialization.
|
|
||||||
const AUTHORIZED_INITIALIZER: Pubkey = pubkey!("HBUh9g46wk2X89CvaNN15UmsznP59rh6od1h8JwYAopk");
|
|
||||||
|
|
||||||
/// Initialize sets up the Ore program. Its responsibilities include:
|
/// Initialize sets up the Ore program. Its responsibilities include:
|
||||||
/// 1. Initialize the 8 bus accounts.
|
/// 1. Initialize the 8 bus accounts.
|
||||||
/// 2. Initialize the treasury account.
|
/// 2. Initialize the treasury account.
|
||||||
@@ -92,7 +88,7 @@ pub fn process_initialize<'a, 'info>(
|
|||||||
load_sysvar(rent_sysvar, sysvar::rent::id())?;
|
load_sysvar(rent_sysvar, sysvar::rent::id())?;
|
||||||
|
|
||||||
// Check signer
|
// Check signer
|
||||||
if signer.key.ne(&AUTHORIZED_INITIALIZER) {
|
if signer.key.ne(&INITIAL_ADMIN) {
|
||||||
return Err(ProgramError::MissingRequiredSignature);
|
return Err(ProgramError::MissingRequiredSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,8 +139,6 @@ pub fn process_initialize<'a, 'info>(
|
|||||||
config.base_reward_rate = INITIAL_BASE_REWARD_RATE;
|
config.base_reward_rate = INITIAL_BASE_REWARD_RATE;
|
||||||
config.last_reset_at = 0;
|
config.last_reset_at = 0;
|
||||||
config.paused = 1;
|
config.paused = 1;
|
||||||
config.tolerance_liveness = INITIAL_TOLERANCE;
|
|
||||||
config.tolerance_spam = INITIAL_TOLERANCE;
|
|
||||||
|
|
||||||
// Initialize treasury
|
// Initialize treasury
|
||||||
create_pda(
|
create_pda(
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use crate::{
|
|||||||
loaders::*,
|
loaders::*,
|
||||||
state::{Bus, Config, Proof},
|
state::{Bus, Config, Proof},
|
||||||
utils::{AccountDeserialize, MineEvent},
|
utils::{AccountDeserialize, MineEvent},
|
||||||
EPOCH_DURATION, MIN_DIFFICULTY, ONE_MINUTE, ONE_YEAR,
|
EPOCH_DURATION, MIN_DIFFICULTY, ONE_MINUTE, ONE_YEAR, TOLERANCE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Mine is the primary workhorse instruction of the Ore program. Its responsibilities include:
|
/// Mine is the primary workhorse instruction of the Ore program. Its responsibilities include:
|
||||||
@@ -128,14 +128,14 @@ pub fn process_mine<'a, 'info>(
|
|||||||
// Apply spam penalty
|
// Apply spam penalty
|
||||||
let t = clock.unix_timestamp;
|
let t = clock.unix_timestamp;
|
||||||
let t_target = proof.last_hash_at.saturating_add(ONE_MINUTE);
|
let t_target = proof.last_hash_at.saturating_add(ONE_MINUTE);
|
||||||
let t_spam = t_target.saturating_sub(config.tolerance_spam);
|
let t_spam = t_target.saturating_sub(TOLERANCE);
|
||||||
if t.lt(&t_spam) {
|
if t.lt(&t_spam) {
|
||||||
sol_log("Spam penalty");
|
sol_log("Spam penalty");
|
||||||
return Err(OreError::Spam.into());
|
return Err(OreError::Spam.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply liveness penalty
|
// Apply liveness penalty
|
||||||
let t_liveness = t_target.saturating_add(config.tolerance_liveness);
|
let t_liveness = t_target.saturating_add(TOLERANCE);
|
||||||
if t.gt(&t_liveness) {
|
if t.gt(&t_liveness) {
|
||||||
reward = reward.saturating_sub(
|
reward = reward.saturating_sub(
|
||||||
reward
|
reward
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ mod register;
|
|||||||
mod reset;
|
mod reset;
|
||||||
mod stake;
|
mod stake;
|
||||||
mod update_admin;
|
mod update_admin;
|
||||||
mod update_tolerance;
|
|
||||||
mod upgrade;
|
mod upgrade;
|
||||||
|
|
||||||
pub use claim::*;
|
pub use claim::*;
|
||||||
@@ -19,5 +18,4 @@ pub use register::*;
|
|||||||
pub use reset::*;
|
pub use reset::*;
|
||||||
pub use stake::*;
|
pub use stake::*;
|
||||||
pub use update_admin::*;
|
pub use update_admin::*;
|
||||||
pub use update_tolerance::*;
|
|
||||||
pub use upgrade::*;
|
pub use upgrade::*;
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
use solana_program::{
|
|
||||||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError,
|
|
||||||
pubkey::Pubkey,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
error::OreError, instruction::UpdateToleranceArgs, loaders::*, state::Config,
|
|
||||||
utils::AccountDeserialize, ONE_MINUTE,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// UpdateTolerance updates the program's tolerance settings. Its responsibilities include:
|
|
||||||
/// 1. Update the liveness tolerance.
|
|
||||||
/// 2. Update the spam tolerance.
|
|
||||||
///
|
|
||||||
/// Safety requirements:
|
|
||||||
/// - Can only succeed if the signer is the program admin.
|
|
||||||
/// - Can only succeed if the provided config is valid.
|
|
||||||
/// - Can only succeed if the tolerances pass sanity tests.
|
|
||||||
pub fn process_update_tolerance<'a, 'info>(
|
|
||||||
_program_id: &Pubkey,
|
|
||||||
accounts: &'a [AccountInfo<'info>],
|
|
||||||
data: &[u8],
|
|
||||||
) -> ProgramResult {
|
|
||||||
// Parse args
|
|
||||||
let args = UpdateToleranceArgs::try_from_bytes(data)?;
|
|
||||||
|
|
||||||
// Load accounts
|
|
||||||
let [signer, config_info] = accounts else {
|
|
||||||
return Err(ProgramError::NotEnoughAccountKeys);
|
|
||||||
};
|
|
||||||
load_signer(signer)?;
|
|
||||||
load_config(config_info, true)?;
|
|
||||||
|
|
||||||
// Validate signer is admin
|
|
||||||
let mut config_data = config_info.data.borrow_mut();
|
|
||||||
let config = Config::try_from_bytes_mut(&mut config_data)?;
|
|
||||||
if config.admin.ne(&signer.key) {
|
|
||||||
return Err(ProgramError::MissingRequiredSignature);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sanity checks
|
|
||||||
if args.tolerance_liveness.ge(&(ONE_MINUTE as u64)) {
|
|
||||||
return Err(OreError::ToleranceOverflow.into());
|
|
||||||
}
|
|
||||||
if args.tolerance_spam.ge(&(ONE_MINUTE as u64)) {
|
|
||||||
return Err(OreError::ToleranceOverflow.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update tolerances
|
|
||||||
config.tolerance_liveness = args.tolerance_liveness as i64;
|
|
||||||
config.tolerance_spam = args.tolerance_spam as i64;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -22,12 +22,6 @@ pub struct Config {
|
|||||||
|
|
||||||
/// Is mining paused.
|
/// Is mining paused.
|
||||||
pub paused: u64,
|
pub paused: u64,
|
||||||
|
|
||||||
/// Seconds prior to a miner's target time during which their hashes will not be penalized.
|
|
||||||
pub tolerance_spam: i64,
|
|
||||||
|
|
||||||
/// Seconds after a miner's target time during which their hashes will not be penalized.
|
|
||||||
pub tolerance_liveness: i64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Discriminator for Config {
|
impl Discriminator for Config {
|
||||||
|
|||||||
Reference in New Issue
Block a user