no truncation logs

This commit is contained in:
Hardhat Chad
2025-07-10 08:42:32 -07:00
parent 6955c33aba
commit 8c5fcb02ce
12 changed files with 168 additions and 95 deletions

View File

@@ -8,16 +8,17 @@ pub enum OreInstruction {
Close = 1,
Commit = 2,
Deposit = 3,
Mine = 4,
Swap = 5,
Uncommit = 6,
Withdraw = 7,
Log = 4,
Mine = 5,
Swap = 6,
Uncommit = 7,
Withdraw = 8,
// Admin
SetAdmin = 8,
SetBlockLimit = 9,
SetFeeCollector = 10,
SetFeeRate = 11,
SetAdmin = 9,
SetBlockLimit = 10,
SetFeeCollector = 11,
SetFeeRate = 12,
}
#[repr(C)]
@@ -45,6 +46,10 @@ pub struct Deposit {
pub amount: [u8; 8],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Log {}
#[repr(C)]
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
pub struct Mine {
@@ -99,6 +104,7 @@ instruction!(OreInstruction, Open);
instruction!(OreInstruction, Close);
instruction!(OreInstruction, Commit);
instruction!(OreInstruction, Deposit);
instruction!(OreInstruction, Log);
instruction!(OreInstruction, Mine);
instruction!(OreInstruction, Swap);
instruction!(OreInstruction, Uncommit);

View File

@@ -2,7 +2,7 @@ use spl_associated_token_account::get_associated_token_address;
use steel::*;
use crate::{
consts::{MINT_ADDRESS, TREASURY_ADDRESS},
consts::{BLOCK, MINT_ADDRESS, TREASURY_ADDRESS},
instruction::*,
state::*,
};
@@ -87,6 +87,25 @@ pub fn close(
}
}
pub fn log(signer: Pubkey, msg: &[u8]) -> Instruction {
let mut data = Log {}.to_bytes();
data.extend_from_slice(msg);
Instruction {
program_id: crate::ID,
accounts: vec![AccountMeta::new(signer, true)],
data: data,
}
}
pub fn program_log(block_id: u64, block_info: AccountInfo, msg: &[u8]) -> Result<(), ProgramError> {
invoke_signed(
&log(*block_info.key, msg),
&[block_info.clone()],
&crate::ID,
&[BLOCK, &block_id.to_le_bytes()],
)
}
pub fn mine(signer: Pubkey, id: u64, amount: u64) -> Instruction {
let block_adddress = block_pda(id).0;
let market_address = market_pda(id).0;

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use steel::*;
/// Closes a block.
@@ -58,7 +58,6 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
if block.reward.lode_reward > 0 && block.reward.lode_authority != Pubkey::default() {
// Load recipient.
recipient_info.as_associated_token_account(&block.reward.lode_authority, &MINT_ADDRESS)?;
let miner = miner_info
.as_account_mut::<Miner>(&ore_api::ID)?
.assert_mut(|m| m.authority == block.reward.lode_authority)?;
@@ -173,14 +172,18 @@ pub fn process_close(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResul
market_info.close(opener_info)?;
// Emit event.
CloseEvent {
authority: *signer_info.key,
id: block.id,
burned_base: base_burned,
burned_quote: quote_burned,
ts: clock.unix_timestamp,
}
.log_return();
program_log(
block.id,
block_info.clone(),
&CloseEvent {
authority: *signer_info.key,
id: block.id,
burned_base: base_burned,
burned_quote: quote_burned,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use steel::*;
/// Commit to a block.
@@ -25,7 +25,6 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
.as_token_account()?
.assert(|t| t.mint() == *mint_info.key)?
.assert(|t| t.owner() == *block_info.key)?;
// commitment_info.as_associated_token_account(block_info.key, mint_info.key)?;
let market = market_info
.as_account::<Market>(&ore_api::ID)?
.assert(|m| m.id == block.id)?;
@@ -106,16 +105,20 @@ pub fn process_commit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResul
block.total_committed += amount;
// Emit event.
CommitEvent {
disc: OreEvent::Commit as u64,
authority: *signer_info.key,
block_id: block.id,
amount,
block_commitment: block.total_committed,
permit_commitment: permit.commitment,
ts: clock.unix_timestamp,
}
.log_return();
program_log(
block.id,
block_info.clone(),
&CommitEvent {
disc: OreEvent::Commit as u64,
authority: *signer_info.key,
block_id: block.id,
amount,
block_commitment: block.total_committed,
permit_commitment: permit.commitment,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use steel::*;
/// Deposits collateral.
@@ -67,15 +67,19 @@ pub fn process_deposit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResu
)?;
// Emit event.
DepositEvent {
disc: OreEvent::Deposit as u64,
authority: *signer_info.key,
block_id: block.id,
amount,
collateral: stake.collateral,
ts: clock.unix_timestamp,
}
.log_return();
program_log(
block.id,
block_info.clone(),
&DepositEvent {
disc: OreEvent::Deposit as u64,
authority: *signer_info.key,
block_id: block.id,
amount,
collateral: stake.collateral,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
Ok(())
}

View File

@@ -1,6 +1,7 @@
mod close;
mod commit;
mod deposit;
mod log;
mod mine;
mod open;
mod set_admin;
@@ -14,6 +15,7 @@ mod withdraw;
use close::*;
use commit::*;
use deposit::*;
use log::*;
use mine::*;
use open::*;
use set_admin::*;
@@ -39,6 +41,7 @@ pub fn process_instruction(
OreInstruction::Close => process_close(accounts, data)?,
OreInstruction::Commit => process_commit(accounts, data)?,
OreInstruction::Deposit => process_deposit(accounts, data)?,
OreInstruction::Log => process_log(accounts, data)?,
OreInstruction::Mine => process_mine(accounts, data)?,
OreInstruction::Swap => process_swap(accounts, data)?,
OreInstruction::Uncommit => process_uncommit(accounts, data)?,

15
program/src/log.rs Normal file
View File

@@ -0,0 +1,15 @@
use ore_api::prelude::*;
use steel::*;
/// No-op, use instruction data for logging w/o truncation.
pub fn process_log(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
// Load accounts.
let [signer_info] = accounts else {
return Err(ProgramError::NotEnoughAccountKeys);
};
signer_info.as_account::<Block>(&ore_api::ID)?;
// For data integrity, only a block can log messages.
Ok(())
}

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use solana_nostd_keccak::hash;
use solana_program::slot_hashes::SlotHashes;
use steel::*;
@@ -139,27 +139,35 @@ pub fn process_mine(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
)?;
// Emit event.
RewardEvent {
disc: OreEvent::Reward as u64,
amount: reward_amount,
authority: miner.authority,
block_id: block.id,
rewards_type: RewardsType::Nugget as u64,
ts: clock.unix_timestamp,
}
.log();
program_log(
block.id,
block_info.clone(),
&RewardEvent {
disc: OreEvent::Reward as u64,
amount: reward_amount,
authority: miner.authority,
block_id: block.id,
rewards_type: RewardsType::Nugget as u64,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
}
// Emit event.
MineEvent {
disc: OreEvent::Mine as u64,
authority: miner.authority,
block_id: block.id,
deployed: amount,
total_deployed: block.total_deployed,
ts: clock.unix_timestamp,
}
.log_return();
program_log(
block.id,
block_info.clone(),
&MineEvent {
disc: OreEvent::Mine as u64,
authority: miner.authority,
block_id: block.id,
deployed: amount,
total_deployed: block.total_deployed,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use solana_nostd_keccak::hash;
use solana_program::program_pack::Pack;
use spl_token_2022::instruction::AuthorityType;
@@ -313,17 +313,21 @@ pub fn process_open(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
)?;
// Emit event.
OpenEvent {
disc: OreEvent::Open as u64,
id,
start_slot,
signer: *signer_info.key,
reward_config: block.reward,
liquidity_base: market.base.liquidity() as u64,
liquidity_quote: market.quote.liquidity() as u64,
ts: clock.unix_timestamp,
}
.log_return();
program_log(
block.id,
block_info.clone(),
&OpenEvent {
disc: OreEvent::Open as u64,
id,
start_slot,
signer: *signer_info.key,
reward_config: block.reward,
liquidity_base: market.base.liquidity() as u64,
liquidity_quote: market.quote.liquidity() as u64,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use steel::*;
/// Swap in a hashpower market.
@@ -137,7 +137,7 @@ pub fn process_swap(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult
market.check_vaults(&vault_base, &vault_quote)?;
// Emit event.
swap_event.log_return();
program_log(block.id, block_info.clone(), &swap_event.to_bytes())?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use steel::*;
/// Uncommit from a block.
@@ -65,16 +65,20 @@ pub fn process_uncommit(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
}
// Emit event.
UncommitEvent {
disc: OreEvent::Uncommit as u64,
authority: *signer_info.key,
block_id: block.id,
block_commitment: block.total_committed,
permit_commitment: permit.commitment,
amount,
ts: clock.unix_timestamp,
}
.log_return();
program_log(
block.id,
block_info.clone(),
&UncommitEvent {
disc: OreEvent::Uncommit as u64,
authority: *signer_info.key,
block_id: block.id,
block_commitment: block.total_committed,
permit_commitment: permit.commitment,
amount,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
Ok(())
}

View File

@@ -1,4 +1,4 @@
use ore_api::prelude::*;
use ore_api::{prelude::*, sdk::program_log};
use steel::*;
/// Withdraws collateral.
@@ -57,15 +57,19 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
}
// Emit event.
WithdrawEvent {
disc: OreEvent::Withdraw as u64,
authority: *signer_info.key,
block_id: stake.block_id,
amount,
collateral: stake.collateral,
ts: clock.unix_timestamp,
}
.log_return();
program_log(
stake.block_id,
block_info.clone(),
&WithdrawEvent {
disc: OreEvent::Withdraw as u64,
authority: *signer_info.key,
block_id: stake.block_id,
amount,
collateral: stake.collateral,
ts: clock.unix_timestamp,
}
.to_bytes(),
)?;
Ok(())
}