implement parsing of compute budget instructions (#123)
* implement parsing of compute budget instructions * add parser for legacy compute budget
This commit is contained in:
parent
ed56f1231a
commit
30555ea712
|
@ -9,6 +9,7 @@ CREATE TABLE lite_rpc.Txs (
|
||||||
processed_slot BIGINT,
|
processed_slot BIGINT,
|
||||||
cu_consumed BIGINT,
|
cu_consumed BIGINT,
|
||||||
cu_requested BIGINT,
|
cu_requested BIGINT,
|
||||||
|
cu_price BIGINT,
|
||||||
quic_response SMALLINT
|
quic_response SMALLINT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,9 @@ use solana_rpc_client_api::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
borsh::try_from_slice_unchecked,
|
||||||
commitment_config::{CommitmentConfig, CommitmentLevel},
|
commitment_config::{CommitmentConfig, CommitmentLevel},
|
||||||
|
compute_budget::{self, ComputeBudgetInstruction},
|
||||||
slot_history::Slot,
|
slot_history::Slot,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -270,11 +272,60 @@ impl BlockListener {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let legacy_compute_budget = tx.message.instructions().iter().find_map(|i| {
|
||||||
|
if i.program_id(tx.message.static_account_keys())
|
||||||
|
.eq(&compute_budget::id())
|
||||||
|
{
|
||||||
|
if let Ok(ComputeBudgetInstruction::RequestUnitsDeprecated {
|
||||||
|
units,
|
||||||
|
additional_fee,
|
||||||
|
}) = try_from_slice_unchecked(i.data.as_slice())
|
||||||
|
{
|
||||||
|
return Some((units as i64, additional_fee as i64));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut cu_requested = tx.message.instructions().iter().find_map(|i| {
|
||||||
|
if i.program_id(tx.message.static_account_keys())
|
||||||
|
.eq(&compute_budget::id())
|
||||||
|
{
|
||||||
|
if let Ok(ComputeBudgetInstruction::SetComputeUnitLimit(limit)) =
|
||||||
|
try_from_slice_unchecked(i.data.as_slice())
|
||||||
|
{
|
||||||
|
return Some(limit as i64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut cu_price = tx.message.instructions().iter().find_map(|i| {
|
||||||
|
if i.program_id(tx.message.static_account_keys())
|
||||||
|
.eq(&compute_budget::id())
|
||||||
|
{
|
||||||
|
if let Ok(ComputeBudgetInstruction::SetComputeUnitPrice(price)) =
|
||||||
|
try_from_slice_unchecked(i.data.as_slice())
|
||||||
|
{
|
||||||
|
return Some(price as i64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some((units, additional_fee)) = legacy_compute_budget {
|
||||||
|
cu_requested = Some(units);
|
||||||
|
if additional_fee > 0 {
|
||||||
|
cu_price = Some((units * 1000) / additional_fee)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
transactions_to_update.push(PostgresUpdateTx {
|
transactions_to_update.push(PostgresUpdateTx {
|
||||||
signature: sig.clone(),
|
signature: sig.clone(),
|
||||||
processed_slot: slot as i64,
|
processed_slot: slot as i64,
|
||||||
cu_consumed,
|
cu_consumed,
|
||||||
cu_requested: None, //TODO: cu requested
|
cu_requested,
|
||||||
|
cu_price,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -299,7 +350,9 @@ impl BlockListener {
|
||||||
// Write to postgres
|
// Write to postgres
|
||||||
//
|
//
|
||||||
if let Some(postgres) = &postgres {
|
if let Some(postgres) = &postgres {
|
||||||
postgres.send(PostgresMsg::PostgresUpdateTx(transactions_to_update)).unwrap();
|
postgres
|
||||||
|
.send(PostgresMsg::PostgresUpdateTx(transactions_to_update))
|
||||||
|
.unwrap();
|
||||||
MESSAGES_IN_POSTGRES_CHANNEL.inc();
|
MESSAGES_IN_POSTGRES_CHANNEL.inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,11 +70,12 @@ pub struct PostgresUpdateTx {
|
||||||
pub processed_slot: i64, // 8 bytes
|
pub processed_slot: i64, // 8 bytes
|
||||||
pub cu_consumed: Option<i64>,
|
pub cu_consumed: Option<i64>,
|
||||||
pub cu_requested: Option<i64>,
|
pub cu_requested: Option<i64>,
|
||||||
|
pub cu_price: Option<i64>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SchemaSize for PostgresUpdateTx {
|
impl SchemaSize for PostgresUpdateTx {
|
||||||
const DEFAULT_SIZE: usize = 88 + 8;
|
const DEFAULT_SIZE: usize = 88 + 8;
|
||||||
const MAX_SIZE: usize = Self::DEFAULT_SIZE + (2 * 8);
|
const MAX_SIZE: usize = Self::DEFAULT_SIZE + (3 * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -299,7 +300,7 @@ impl PostgresSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_txs(&self, txs: &[PostgresUpdateTx]) -> anyhow::Result<()> {
|
pub async fn update_txs(&self, txs: &[PostgresUpdateTx]) -> anyhow::Result<()> {
|
||||||
const NUMBER_OF_ARGS: usize = 4;
|
const NUMBER_OF_ARGS: usize = 5;
|
||||||
|
|
||||||
if txs.is_empty() {
|
if txs.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -313,12 +314,14 @@ impl PostgresSession {
|
||||||
processed_slot,
|
processed_slot,
|
||||||
cu_consumed,
|
cu_consumed,
|
||||||
cu_requested,
|
cu_requested,
|
||||||
|
cu_price
|
||||||
} = tx;
|
} = tx;
|
||||||
|
|
||||||
args.push(signature);
|
args.push(signature);
|
||||||
args.push(processed_slot);
|
args.push(processed_slot);
|
||||||
args.push(cu_consumed);
|
args.push(cu_consumed);
|
||||||
args.push(cu_requested);
|
args.push(cu_requested);
|
||||||
|
args.push(cu_price);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut query = String::from(
|
let mut query = String::from(
|
||||||
|
@ -327,6 +330,7 @@ impl PostgresSession {
|
||||||
processed_slot = t2.processed_slot,
|
processed_slot = t2.processed_slot,
|
||||||
cu_consumed = t2.cu_consumed,
|
cu_consumed = t2.cu_consumed,
|
||||||
cu_requested = t2.cu_requested
|
cu_requested = t2.cu_requested
|
||||||
|
cu_price = t2.cu_price
|
||||||
FROM (VALUES
|
FROM (VALUES
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
@ -340,7 +344,7 @@ impl PostgresSession {
|
||||||
|
|
||||||
query.push_str(
|
query.push_str(
|
||||||
r#"
|
r#"
|
||||||
) AS t2(signature, processed_slot, cu_consumed, cu_requested)
|
) AS t2(signature, processed_slot, cu_consumed, cu_requested, cu_price)
|
||||||
WHERE t1.signature = t2.signature
|
WHERE t1.signature = t2.signature
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue