adding keeper for root bank
This commit is contained in:
parent
5ecece370e
commit
8344b08983
|
@ -102,7 +102,8 @@ pub fn build_args<'a, 'b>(version: &'b str) -> App<'a, 'b> {
|
|||
.long("identity")
|
||||
.value_name("FILEPATH")
|
||||
.takes_value(true)
|
||||
.help("Identity used to connect with QUIC connection, identity with lot of stakes have better chances to send transaction to the leader"),
|
||||
.help("Identity used in the QUIC connection. Identity with a lot of stake has a \
|
||||
better chance to send transaction to the leader"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("duration")
|
||||
|
|
|
@ -2,6 +2,7 @@ use {
|
|||
crate::{helpers::to_sdk_instruction, states::PerpMarketCache},
|
||||
iter_tools::Itertools,
|
||||
solana_client::tpu_client::TpuClient,
|
||||
solana_program::pubkey::Pubkey,
|
||||
solana_quic_client::{QuicConfig, QuicConnectionManager, QuicPool},
|
||||
solana_sdk::{
|
||||
hash::Hash, instruction::Instruction, message::Message, signature::Keypair, signer::Signer,
|
||||
|
@ -110,12 +111,41 @@ pub fn send_transaction(
|
|||
tpu_client.send_transaction(&tx);
|
||||
}
|
||||
|
||||
pub fn create_update_and_cache_quote_banks(
|
||||
perp_markets: &[PerpMarketCache],
|
||||
quote_root_bank: Pubkey,
|
||||
quote_node_banks: Vec<Pubkey>,
|
||||
) -> Vec<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 ix_update = mango::instruction::update_root_bank(
|
||||
&mango_program_pk,
|
||||
&mango_group_pk,
|
||||
&mango_cache_pk,
|
||||
"e_root_bank,
|
||||
quote_node_banks.as_slice(),
|
||||
)
|
||||
.unwrap();
|
||||
let ix_cache = mango::instruction::cache_root_banks(
|
||||
&mango_program_pk,
|
||||
&mango_group_pk,
|
||||
&mango_cache_pk,
|
||||
&[quote_root_bank],
|
||||
)
|
||||
.unwrap();
|
||||
vec![to_sdk_instruction(ix_update), to_sdk_instruction(ix_cache)]
|
||||
}
|
||||
|
||||
pub fn start_keepers(
|
||||
exit_signal: Arc<AtomicBool>,
|
||||
tpu_client: Arc<TpuClient<QuicPool, QuicConnectionManager, QuicConfig>>,
|
||||
perp_markets: Vec<PerpMarketCache>,
|
||||
blockhash: Arc<RwLock<Hash>>,
|
||||
authority: &Keypair,
|
||||
quote_root_bank: Pubkey,
|
||||
quote_node_banks: Vec<Pubkey>,
|
||||
) -> JoinHandle<()> {
|
||||
let authority = Keypair::from_bytes(&authority.to_bytes()).unwrap();
|
||||
Builder::new()
|
||||
|
@ -126,6 +156,11 @@ pub fn start_keepers(
|
|||
let update_perp_cache = create_cache_perp_markets_instructions(&perp_markets);
|
||||
let cache_root_bank_ix = create_cache_root_bank_instruction(&perp_markets);
|
||||
let update_funding_ix = create_update_fundings_instructions(&perp_markets);
|
||||
let quote_root_bank_ix = create_update_and_cache_quote_banks(
|
||||
&perp_markets,
|
||||
quote_root_bank,
|
||||
quote_node_banks,
|
||||
);
|
||||
|
||||
let blockhash = blockhash.clone();
|
||||
|
||||
|
@ -143,17 +178,14 @@ pub fn start_keepers(
|
|||
|
||||
send_transaction(
|
||||
tpu_client.clone(),
|
||||
&[cache_root_bank_ix.clone()],
|
||||
quote_root_bank_ix.as_slice(),
|
||||
blockhash.clone(),
|
||||
&authority,
|
||||
);
|
||||
|
||||
send_transaction(
|
||||
tpu_client.clone(),
|
||||
update_funding_ix.as_slice(),
|
||||
blockhash.clone(),
|
||||
&authority,
|
||||
);
|
||||
for updates in update_funding_ix.chunks(3) {
|
||||
send_transaction(tpu_client.clone(), updates, blockhash.clone(), &authority);
|
||||
}
|
||||
|
||||
send_transaction(
|
||||
tpu_client.clone(),
|
||||
|
@ -171,14 +203,7 @@ pub fn start_keepers(
|
|||
|
||||
send_transaction(
|
||||
tpu_client.clone(),
|
||||
&[update_perp_cache.clone()],
|
||||
blockhash.clone(),
|
||||
&authority,
|
||||
);
|
||||
|
||||
send_transaction(
|
||||
tpu_client.clone(),
|
||||
&[update_perp_cache.clone()],
|
||||
&[cache_root_bank_ix.clone()],
|
||||
blockhash.clone(),
|
||||
&authority,
|
||||
);
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -16,10 +16,12 @@ use {
|
|||
solana_client::{
|
||||
connection_cache::ConnectionCache, rpc_client::RpcClient, tpu_client::TpuClient,
|
||||
},
|
||||
solana_program::pubkey::Pubkey,
|
||||
solana_sdk::commitment_config::CommitmentConfig,
|
||||
std::{
|
||||
fs,
|
||||
net::{IpAddr, Ipv4Addr},
|
||||
str::FromStr,
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
Arc, RwLock,
|
||||
|
@ -131,6 +133,12 @@ fn main() {
|
|||
let perp_market_caches: Vec<PerpMarketCache> =
|
||||
get_mango_market_perps_cache(rpc_client.clone(), &mango_group_config);
|
||||
|
||||
let quote_root_bank = Pubkey::from_str(mango_group_config.tokens.last().unwrap().root_key.as_str()).unwrap();
|
||||
let quote_node_banks = mango_group_config.tokens.last().unwrap()
|
||||
.node_keys
|
||||
.iter()
|
||||
.map(|x| Pubkey::from_str(x.as_str()).unwrap())
|
||||
.collect();
|
||||
// start keeper if keeper authority is present
|
||||
let keepers_jl = if let Some(keeper_authority) = keeper_authority {
|
||||
let jl = start_keepers(
|
||||
|
@ -139,6 +147,8 @@ fn main() {
|
|||
perp_market_caches.clone(),
|
||||
blockhash.clone(),
|
||||
keeper_authority,
|
||||
quote_root_bank,
|
||||
quote_node_banks,
|
||||
);
|
||||
Some(jl)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue