correcting price cache
This commit is contained in:
parent
898059d81e
commit
e45a7d8802
|
@ -3,7 +3,6 @@ use std::{
|
|||
ops::Div,
|
||||
str::FromStr,
|
||||
sync::{
|
||||
atomic::{AtomicU64, Ordering},
|
||||
Arc, RwLock,
|
||||
},
|
||||
thread::{sleep, Builder},
|
||||
|
@ -201,19 +200,17 @@ pub fn confirmation_by_querying_rpc(
|
|||
|
||||
pub fn confirmations_by_blocks(
|
||||
client: Arc<RpcClient>,
|
||||
current_slot: &AtomicU64,
|
||||
recv_limit: usize,
|
||||
tx_record_rx: Receiver<TransactionSendRecord>,
|
||||
tx_confirm_records: Arc<RwLock<Vec<TransactionConfirmRecord>>>,
|
||||
tx_timeout_records: Arc<RwLock<Vec<TransactionSendRecord>>>,
|
||||
tx_block_data: Arc<RwLock<Vec<BlockData>>>,
|
||||
from_slot: u64,
|
||||
) {
|
||||
let mut recv_until_confirm = recv_limit;
|
||||
let transaction_map = Arc::new(RwLock::new(
|
||||
HashMap::<Signature, TransactionSendRecord>::new(),
|
||||
));
|
||||
let last_slot = current_slot.load(Ordering::Acquire);
|
||||
|
||||
while recv_until_confirm != 0 {
|
||||
match tx_record_rx.try_recv() {
|
||||
Ok(tx_record) => {
|
||||
|
@ -245,7 +242,7 @@ pub fn confirmations_by_blocks(
|
|||
commitment: CommitmentLevel::Confirmed,
|
||||
};
|
||||
let block_res = client
|
||||
.get_blocks_with_commitment(last_slot, None, commitment_confirmation)
|
||||
.get_blocks_with_commitment(from_slot, None, commitment_confirmation)
|
||||
.unwrap();
|
||||
|
||||
let nb_blocks = block_res.len();
|
||||
|
|
|
@ -252,6 +252,7 @@ pub fn get_mango_market_perps_cache(
|
|||
.iter()
|
||||
.map(|x| Pubkey::from_str(x.as_str()).unwrap())
|
||||
.collect();
|
||||
let price_oracle = Pubkey::from_str(mango_group_config.oracles[market_index].public_key.as_str()).unwrap();
|
||||
PerpMarketCache {
|
||||
order_base_lots,
|
||||
price,
|
||||
|
@ -263,6 +264,7 @@ pub fn get_mango_market_perps_cache(
|
|||
perp_market,
|
||||
root_bank,
|
||||
node_banks,
|
||||
price_oracle,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
|
|
@ -13,10 +13,9 @@ use {
|
|||
},
|
||||
thread::{Builder, JoinHandle},
|
||||
},
|
||||
crate::{helpers::to_sdk_instruction, states::PerpMarketCache},
|
||||
};
|
||||
|
||||
use crate::{helpers::to_sdk_instruction, states::PerpMarketCache};
|
||||
|
||||
fn create_root_bank_update_instructions(perp_markets: &[PerpMarketCache]) -> Vec<Instruction> {
|
||||
perp_markets
|
||||
.iter()
|
||||
|
@ -34,20 +33,19 @@ fn create_root_bank_update_instructions(perp_markets: &[PerpMarketCache]) -> Vec
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn create_update_price_cache_instructions(perp_markets: &[PerpMarketCache]) -> Vec<Instruction> {
|
||||
perp_markets
|
||||
.iter()
|
||||
.map(|perp_market| {
|
||||
let ix = mango::instruction::cache_prices(
|
||||
&perp_market.mango_program_pk,
|
||||
&perp_market.mango_group_pk,
|
||||
&perp_market.mango_cache_pk,
|
||||
perp_market.node_banks.as_slice(),
|
||||
)
|
||||
.unwrap();
|
||||
to_sdk_instruction(ix)
|
||||
})
|
||||
.collect()
|
||||
fn create_update_price_cache_instructions(perp_markets: &[PerpMarketCache]) -> Instruction {
|
||||
let mango_program_pk = perp_markets[0].mango_program_pk;
|
||||
let mango_group_pk = perp_markets[0].mango_group_pk;
|
||||
let mango_cache_pk = perp_markets[0].mango_cache_pk;
|
||||
let price_oracles = perp_markets.iter().map(|x| x.price_oracle).collect_vec();
|
||||
|
||||
let ix = mango::instruction::cache_prices(
|
||||
&mango_program_pk,
|
||||
&mango_group_pk,
|
||||
&mango_cache_pk,
|
||||
price_oracles.as_slice()
|
||||
).unwrap();
|
||||
to_sdk_instruction(ix)
|
||||
}
|
||||
|
||||
fn create_cache_perp_markets_instructions(perp_markets: &[PerpMarketCache]) -> Instruction {
|
||||
|
@ -89,7 +87,7 @@ pub fn start_keepers(
|
|||
.name("updating root bank keeper".to_string())
|
||||
.spawn(move || {
|
||||
let mut root_update_ixs = create_root_bank_update_instructions(&perp_markets);
|
||||
let mut cache_price = create_update_price_cache_instructions(&perp_markets);
|
||||
let cache_prices = create_update_price_cache_instructions(&perp_markets);
|
||||
let update_perp_cache = create_cache_perp_markets_instructions(&perp_markets);
|
||||
|
||||
let blockhash = blockhash.clone();
|
||||
|
@ -97,7 +95,7 @@ pub fn start_keepers(
|
|||
// add prioritization instruction
|
||||
let prioritization_ix = ComputeBudgetInstruction::set_compute_unit_price(10000);
|
||||
root_update_ixs.insert(0, prioritization_ix.clone());
|
||||
cache_price.insert(0, prioritization_ix.clone());
|
||||
|
||||
while !exit_signal.load(Ordering::Relaxed) {
|
||||
send_transaction(
|
||||
tpu_client.clone(),
|
||||
|
@ -107,7 +105,7 @@ pub fn start_keepers(
|
|||
);
|
||||
send_transaction(
|
||||
tpu_client.clone(),
|
||||
cache_price.as_slice(),
|
||||
&[prioritization_ix.clone(), cache_prices.clone(),],
|
||||
blockhash.clone(),
|
||||
&authority,
|
||||
);
|
||||
|
|
|
@ -146,6 +146,7 @@ fn main() {
|
|||
};
|
||||
|
||||
let (tx_record_sx, tx_record_rx) = crossbeam_channel::unbounded();
|
||||
let from_slot = current_slot.load(Ordering::Relaxed);
|
||||
|
||||
let mm_threads: Vec<JoinHandle<()>> = start_market_making_threads(
|
||||
account_keys_parsed.clone(),
|
||||
|
@ -181,12 +182,12 @@ fn main() {
|
|||
//confirmation_by_querying_rpc(recv_limit, rpc_client.clone(), &tx_record_rx, tx_confirm_records.clone(), tx_timeout_records.clone());
|
||||
confirmations_by_blocks(
|
||||
rpc_client.clone(),
|
||||
¤t_slot,
|
||||
recv_limit,
|
||||
tx_record_rx,
|
||||
tx_confirm_records.clone(),
|
||||
tx_timeout_records.clone(),
|
||||
tx_block_data.clone(),
|
||||
from_slot,
|
||||
);
|
||||
|
||||
let confirmed: Vec<TransactionConfirmRecord> = {
|
||||
|
|
|
@ -43,6 +43,7 @@ pub struct PerpMarketCache {
|
|||
pub mango_cache_pk: Pubkey,
|
||||
pub perp_market_pk: Pubkey,
|
||||
pub perp_market: PerpMarket,
|
||||
pub price_oracle: Pubkey,
|
||||
pub root_bank: Pubkey,
|
||||
pub node_banks: Vec<Pubkey>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue