keeper: cu limit when batching charge_collateral_fee ix
This commit is contained in:
parent
ab8393b52d
commit
d9f55c4c22
|
@ -98,6 +98,7 @@ pub async fn runner(
|
||||||
interval_update_funding: u64,
|
interval_update_funding: u64,
|
||||||
interval_check_for_changes_and_abort: u64,
|
interval_check_for_changes_and_abort: u64,
|
||||||
interval_charge_collateral_fees: u64,
|
interval_charge_collateral_fees: u64,
|
||||||
|
max_cu_when_batching: u32,
|
||||||
extra_jobs: Vec<JoinHandle<()>>,
|
extra_jobs: Vec<JoinHandle<()>>,
|
||||||
) -> Result<(), anyhow::Error> {
|
) -> Result<(), anyhow::Error> {
|
||||||
let handles1 = mango_client
|
let handles1 = mango_client
|
||||||
|
@ -157,7 +158,11 @@ pub async fn runner(
|
||||||
futures::future::join_all(handles1),
|
futures::future::join_all(handles1),
|
||||||
futures::future::join_all(handles2),
|
futures::future::join_all(handles2),
|
||||||
futures::future::join_all(handles3),
|
futures::future::join_all(handles3),
|
||||||
loop_charge_collateral_fees(mango_client.clone(), interval_charge_collateral_fees),
|
loop_charge_collateral_fees(
|
||||||
|
mango_client.clone(),
|
||||||
|
interval_charge_collateral_fees,
|
||||||
|
max_cu_when_batching
|
||||||
|
),
|
||||||
MangoClient::loop_check_for_context_changes_and_abort(
|
MangoClient::loop_check_for_context_changes_and_abort(
|
||||||
mango_client.clone(),
|
mango_client.clone(),
|
||||||
Duration::from_secs(interval_check_for_changes_and_abort),
|
Duration::from_secs(interval_check_for_changes_and_abort),
|
||||||
|
@ -431,7 +436,11 @@ pub async fn loop_update_funding(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn loop_charge_collateral_fees(mango_client: Arc<MangoClient>, interval: u64) {
|
pub async fn loop_charge_collateral_fees(
|
||||||
|
mango_client: Arc<MangoClient>,
|
||||||
|
interval: u64,
|
||||||
|
max_cu_when_batching: u32,
|
||||||
|
) {
|
||||||
if interval == 0 {
|
if interval == 0 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -451,7 +460,14 @@ pub async fn loop_charge_collateral_fees(mango_client: Arc<MangoClient>, interva
|
||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
|
|
||||||
match charge_collateral_fees_inner(&mango_client, &fetcher, collateral_fee_interval).await {
|
match charge_collateral_fees_inner(
|
||||||
|
&mango_client,
|
||||||
|
&fetcher,
|
||||||
|
collateral_fee_interval,
|
||||||
|
max_cu_when_batching,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("charge_collateral_fees error: {err:?}");
|
error!("charge_collateral_fees error: {err:?}");
|
||||||
|
@ -464,6 +480,7 @@ async fn charge_collateral_fees_inner(
|
||||||
client: &MangoClient,
|
client: &MangoClient,
|
||||||
fetcher: &RpcAccountFetcher,
|
fetcher: &RpcAccountFetcher,
|
||||||
collateral_fee_interval: u64,
|
collateral_fee_interval: u64,
|
||||||
|
max_cu_when_batching: u32,
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
let mango_accounts = fetcher
|
let mango_accounts = fetcher
|
||||||
.fetch_program_accounts(&mango_v4::id(), MangoAccount::DISCRIMINATOR)
|
.fetch_program_accounts(&mango_v4::id(), MangoAccount::DISCRIMINATOR)
|
||||||
|
@ -512,6 +529,7 @@ async fn charge_collateral_fees_inner(
|
||||||
client.transaction_builder().await?,
|
client.transaction_builder().await?,
|
||||||
&client.client,
|
&client.client,
|
||||||
&ix_to_send,
|
&ix_to_send,
|
||||||
|
max_cu_when_batching,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
info!("charge collateral fees: {:?}", txsigs);
|
info!("charge collateral fees: {:?}", txsigs);
|
||||||
|
@ -524,6 +542,7 @@ async fn send_batched_log_errors_no_confirm(
|
||||||
mut tx_builder: TransactionBuilder,
|
mut tx_builder: TransactionBuilder,
|
||||||
client: &mango_v4_client::Client,
|
client: &mango_v4_client::Client,
|
||||||
ixs_list: &[PreparedInstructions],
|
ixs_list: &[PreparedInstructions],
|
||||||
|
max_cu: u32,
|
||||||
) -> Vec<Signature> {
|
) -> Vec<Signature> {
|
||||||
let mut txsigs = Vec::new();
|
let mut txsigs = Vec::new();
|
||||||
|
|
||||||
|
@ -533,7 +552,7 @@ async fn send_batched_log_errors_no_confirm(
|
||||||
current_batch.append(ixs.clone());
|
current_batch.append(ixs.clone());
|
||||||
|
|
||||||
tx_builder.instructions = current_batch.clone().to_instructions();
|
tx_builder.instructions = current_batch.clone().to_instructions();
|
||||||
if !tx_builder.transaction_size().is_ok() {
|
if !tx_builder.transaction_size().is_ok() || current_batch.cu > max_cu {
|
||||||
tx_builder.instructions = previous_batch.to_instructions();
|
tx_builder.instructions = previous_batch.to_instructions();
|
||||||
match tx_builder.send(client).await {
|
match tx_builder.send(client).await {
|
||||||
Err(err) => error!("could not send transaction: {err:?}"),
|
Err(err) => error!("could not send transaction: {err:?}"),
|
||||||
|
|
|
@ -73,6 +73,11 @@ struct Cli {
|
||||||
/// url to the lite-rpc websocket, optional
|
/// url to the lite-rpc websocket, optional
|
||||||
#[clap(long, env, default_value = "")]
|
#[clap(long, env, default_value = "")]
|
||||||
lite_rpc_url: String,
|
lite_rpc_url: String,
|
||||||
|
|
||||||
|
/// When batching multiple instructions into a transaction, don't exceed
|
||||||
|
/// this compute unit limit.
|
||||||
|
#[clap(long, env, default_value_t = 1_000_000)]
|
||||||
|
max_cu_when_batching: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand, Debug, Clone)]
|
#[derive(Subcommand, Debug, Clone)]
|
||||||
|
@ -157,6 +162,7 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||||
cli.interval_update_funding,
|
cli.interval_update_funding,
|
||||||
cli.interval_check_new_listings_and_abort,
|
cli.interval_check_new_listings_and_abort,
|
||||||
cli.interval_charge_collateral_fees,
|
cli.interval_charge_collateral_fees,
|
||||||
|
cli.max_cu_when_batching,
|
||||||
prio_jobs,
|
prio_jobs,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
Loading…
Reference in New Issue