update postgres fields

This commit is contained in:
aniketfuryrocks 2023-01-31 14:42:23 +05:30
parent e0e42e9187
commit 21595caa06
No known key found for this signature in database
GPG Key ID: FA6BFCFAA7D4B764
3 changed files with 121 additions and 63 deletions

112
Cargo.lock generated
View File

@ -269,7 +269,7 @@ name = "bench"
version = "0.1.0"
dependencies = [
"anyhow",
"clap 4.1.1",
"clap 4.1.4",
"csv",
"dirs",
"log",
@ -579,9 +579,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.1.1"
version = "4.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec7a4128863c188deefe750ac1d1dfe66c236909f845af04beed823638dc1b2"
checksum = "f13b9c79b5d1dd500d20ef541215a6423c75829ef43117e1b4d17fd8af0b5d76"
dependencies = [
"bitflags",
"clap_derive",
@ -2102,7 +2102,7 @@ dependencies = [
"bincode",
"bs58",
"bytes",
"clap 4.1.1",
"clap 4.1.4",
"const_env",
"dashmap",
"futures",
@ -3527,9 +3527,9 @@ dependencies = [
[[package]]
name = "solana-account-decoder"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87b4533fe4abfd4c540ece335ad767cc91e93a5263069e2e59225be555c5c839"
checksum = "b04c1316932017ae5f947e83d77cc0356c4a395130a480cdc17ffb0570a0c115"
dependencies = [
"Inflector",
"base64 0.13.1",
@ -3552,9 +3552,9 @@ dependencies = [
[[package]]
name = "solana-address-lookup-table-program"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ceb299cd9df79f4c1abda6f140813f1e451a9a8810d18b84ff9dc3b81f1593c6"
checksum = "5be490ed850c99286a4e4ba169ce20695336fe666c56bd823bfd8db689d23a58"
dependencies = [
"bincode",
"bytemuck",
@ -3573,9 +3573,9 @@ dependencies = [
[[package]]
name = "solana-clap-utils"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dde26cacc87164747988cf1cef8e701155188a8d51ed45a7d1be268bc49c41c2"
checksum = "36228e03e14bc7d7707189b66f625981993f1a000b0b192d5b42367349901d91"
dependencies = [
"chrono",
"clap 2.34.0",
@ -3591,9 +3591,9 @@ dependencies = [
[[package]]
name = "solana-cli-config"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aad3cc2faa1721149f1af05b8f10daed33c68b7523bcc82bc7f2835f2ed51746"
checksum = "6c43b08f24fd605eaeaafe0e834dc9b209137ac253bc874d32a5bdd791cbd318"
dependencies = [
"dirs-next",
"lazy_static",
@ -3607,9 +3607,9 @@ dependencies = [
[[package]]
name = "solana-client"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2d59b69ee79e5b32f41b381d0e54d81e3a89e3ebe35335a586241dc000e8374"
checksum = "a3e270b1afd0b360c2aec42ae302ae7980ebb226017275b32a6156ab2ccbdad9"
dependencies = [
"async-mutex",
"async-trait",
@ -3661,9 +3661,9 @@ dependencies = [
[[package]]
name = "solana-config-program"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b80b3dd0cd746511a4bbf9a64a8ddb2b528800437928dd90a1a16ef0e1b95be3"
checksum = "fb275d80a482134f0f0c5439b0c40ba3f04bef70dbc46c0e47f6107f6ae482a8"
dependencies = [
"bincode",
"chrono",
@ -3675,9 +3675,9 @@ dependencies = [
[[package]]
name = "solana-faucet"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e0634db95537eeb77d78f402ea70b513b8bc12ed926b379eca53a1ba5038bbc"
checksum = "b3ef95ad1f87b8c011d0e4d85a46f4a703e9dd7e722459659b395ed70d6ba924"
dependencies = [
"bincode",
"byteorder",
@ -3699,9 +3699,9 @@ dependencies = [
[[package]]
name = "solana-frozen-abi"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c39813ee5b249cb8ccb325d3639323eb3616e7bb9a2b1502936d7ea20530097"
checksum = "f44a019070a6cec4d3ad8605c5caa65bdaa13f00b5f1849340f44ffea63b625b"
dependencies = [
"ahash",
"blake3",
@ -3733,9 +3733,9 @@ dependencies = [
[[package]]
name = "solana-frozen-abi-macro"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dad43ac27c4b8d7a3ce0e2cb8642a7e3b8ea5e3c29ecea38045a8518519adccf"
checksum = "be23cc7a382f54dfe1348edb94610e5cc146b8eb21563cdd04062a403c75ba62"
dependencies = [
"proc-macro2 1.0.50",
"quote 1.0.23",
@ -3745,9 +3745,9 @@ dependencies = [
[[package]]
name = "solana-logger"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13a18f8d7490f712a4340998fca2b0d35afcdef671320a0e51f40b537363d592"
checksum = "447d16a70a1b5383736ef44801050c0e1affd022303b22ed899352f958c2de4b"
dependencies = [
"env_logger",
"lazy_static",
@ -3756,9 +3756,9 @@ dependencies = [
[[package]]
name = "solana-measure"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e365647d451d2b124d9705e92fcfc6e90790ae317495ff20043b6812eb8c41"
checksum = "2400d2534a19f7605c5059060edea0499600a223f1a1f6a4b172666c04946a77"
dependencies = [
"log",
"solana-sdk",
@ -3766,9 +3766,9 @@ dependencies = [
[[package]]
name = "solana-metrics"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c4630a427e772ad5a4a64ca43f0d80848af19a1057084c9611a1e71bf027fce"
checksum = "68aaa3d683945dc3b6ca38923ef952ca1f96a27b61f898a1ddf9f4cd79f2df92"
dependencies = [
"crossbeam-channel",
"gethostname",
@ -3780,9 +3780,9 @@ dependencies = [
[[package]]
name = "solana-net-utils"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "740fb87bea9d7b9eee070244441c9079b44fa223224fb1d6bd23da1b8ec0f2b3"
checksum = "d6d7093739e143d5e2edf3e81e523d47228adb802b847d66f4ab819be7ad6dc8"
dependencies = [
"bincode",
"clap 3.2.23",
@ -3802,9 +3802,9 @@ dependencies = [
[[package]]
name = "solana-perf"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "079105b92b89a0e0b3f238f1c2c40ebffd2171d632236c20f59abac79a8aa978"
checksum = "cbc742f8d53f0a6e6f3a27ed11c1d0764b5486813c721d625c56094fcd14e984"
dependencies = [
"ahash",
"bincode",
@ -3829,9 +3829,9 @@ dependencies = [
[[package]]
name = "solana-program"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dafff676128fe508ab83147b6fb19534fc33f43ec14789da1f1867e9ea06887"
checksum = "d0937481f080f5dd495fae456c94718a7bacf30fb5fdabb02dcb8a9622e446d5"
dependencies = [
"base64 0.13.1",
"bincode",
@ -3878,9 +3878,9 @@ dependencies = [
[[package]]
name = "solana-program-runtime"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17865dc487a5f38e8f64a8ff3ff14e92a8a71be87ca6ee958ad07f5d1fa4cdf4"
checksum = "b4d12047608bac77fca000e18f7a2df3c7fa90656d7c7d387b1cd7faf18b238c"
dependencies = [
"base64 0.13.1",
"bincode",
@ -3905,9 +3905,9 @@ dependencies = [
[[package]]
name = "solana-rayon-threadlimit"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f82e4deecbe820847c88f091f9b721fad46276575fcfdf177bbc2743731dc25b"
checksum = "b6eca67181e0381532db4bc69a625b1f96a047be461ff9050c451add0165424f"
dependencies = [
"lazy_static",
"num_cpus",
@ -3915,9 +3915,9 @@ dependencies = [
[[package]]
name = "solana-remote-wallet"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09863751b4d9ca46297f0662293561c4a3846abc9cab7b691b091ea9ae3c9340"
checksum = "9b83d035ee90035ebcb07ec73672fdc0272e5b98899846dd29fcb31f856ac78c"
dependencies = [
"console",
"dialoguer",
@ -3934,9 +3934,9 @@ dependencies = [
[[package]]
name = "solana-sdk"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c702cc57432bc16eab54ad7b5668c2a3cdc72b0f820175972b4857e26ac4f49"
checksum = "390e7481c56dda2ceab2652beeda30a533e9667b34861a2eb4eec92fa1d826d7"
dependencies = [
"assert_matches",
"base64 0.13.1",
@ -3985,9 +3985,9 @@ dependencies = [
[[package]]
name = "solana-sdk-macro"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f89a14a8f1e7708fe19ee3140125e9d8279945ead74cb09e65c94dd5cf0640c3"
checksum = "33d0acbad862093ea123f3a27364336dcb0c8373522cd6810496a34e932c56c1"
dependencies = [
"bs58",
"proc-macro2 1.0.50",
@ -3998,9 +3998,9 @@ dependencies = [
[[package]]
name = "solana-streamer"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7116f13d20003e99f3f8fb5b1b20cb638a8c797ec8fe40dc4840a284bab1e53c"
checksum = "853b0187fdf233c13e8b7ba76e61d0c7cb49ca92c5fdb3b7568ad5ca30e2cf88"
dependencies = [
"crossbeam-channel",
"futures-util",
@ -4027,9 +4027,9 @@ dependencies = [
[[package]]
name = "solana-transaction-status"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff48b27221d728dd907400711aa42d07d5fe78c6bf9e35f850c78e89ee800e97"
checksum = "3c5bbdaed99403e4a17763bee60c1e0e3418524503c72b514ebff62efbcc9d33"
dependencies = [
"Inflector",
"base64 0.13.1",
@ -4056,9 +4056,9 @@ dependencies = [
[[package]]
name = "solana-version"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18f9c97e7d62d3e0ef04426cd7731689f5c675e0b4540fa5dca172ab261b57a3"
checksum = "5a46c9ecb15ccd5388511cec0c5bfb989589425f8286ce432ff64b55dc7bf61e"
dependencies = [
"log",
"rustc_version 0.4.0",
@ -4072,9 +4072,9 @@ dependencies = [
[[package]]
name = "solana-vote-program"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "694e6ecff6764540b555224308fa3cbccb59135e6029761febdba49d8197faaf"
checksum = "81ab9ff8928282cb42871a370435dd4713f700854801afb476cf63066f1337db"
dependencies = [
"bincode",
"log",
@ -4093,9 +4093,9 @@ dependencies = [
[[package]]
name = "solana-zk-token-sdk"
version = "1.14.12"
version = "1.14.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32395c4561673f7b4aa1f3a5b5a654eaa363041f67d92f5d680de72293ef7d1b"
checksum = "cebca4083e982ae01583d1a590c4d679e6f648a4761364ddfb43026d2c433142"
dependencies = [
"aes-gcm-siv",
"arrayref",
@ -4399,9 +4399,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.24.2"
version = "1.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb"
checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af"
dependencies = [
"autocfg",
"bytes",

View File

@ -14,14 +14,15 @@ use solana_client::{
use solana_sdk::commitment_config::{CommitmentConfig, CommitmentLevel};
use solana_transaction_status::{
TransactionConfirmationStatus, TransactionStatus, UiConfirmedBlock, UiTransactionStatusMeta,
option_serializer::OptionSerializer, TransactionConfirmationStatus, TransactionStatus,
UiConfirmedBlock, UiTransactionStatusMeta,
};
use tokio::{
sync::{mpsc::Sender, RwLock},
task::JoinHandle,
};
use crate::workers::{PostgresBlock, PostgresMsg};
use crate::workers::{PostgresBlock, PostgresMsg, PostgresUpdateTx};
use super::{PostgresMpscSend, TxProps, TxSender};
@ -185,7 +186,7 @@ impl BlockListener {
}
for tx in transactions {
let Some(UiTransactionStatusMeta { err, status, .. }) = tx.meta else {
let Some(UiTransactionStatusMeta { err, status, compute_units_consumed ,.. }) = tx.meta else {
info!("tx with no meta");
continue;
};
@ -218,6 +219,25 @@ impl BlockListener {
value: serde_json::json!({ "err": err }),
})?;
}
let cu_consumed = match compute_units_consumed {
OptionSerializer::Some(cu_consumed) => Some(cu_consumed as i64),
_ => None,
};
// write to postgres
if let Some(postgres) = &postgres {
postgres
.send(PostgresMsg::PostgresUpdateTx(
PostgresUpdateTx {
processed_slot: slot as i64,
cu_consumed,
cu_requested: None, //TODO: cu requested
},
sig,
))
.unwrap();
}
}
}

View File

@ -31,6 +31,13 @@ pub struct PostgresTx {
pub quic_response: i16,
}
#[derive(Debug)]
pub struct PostgresUpdateTx {
pub processed_slot: i64,
pub cu_consumed: Option<i64>,
pub cu_requested: Option<i64>,
}
#[derive(Debug)]
pub struct PostgresBlock {
pub slot: i64,
@ -49,6 +56,7 @@ pub enum PostgresMsg {
PostgresTx(PostgresTx),
PostgresBlock(PostgresBlock),
PostgreAccountAddr(PostgreAccountAddr),
PostgresUpdateTx(PostgresUpdateTx, String),
}
pub type PostgresMpscRecv = UnboundedReceiver<PostgresMsg>;
@ -62,11 +70,17 @@ impl Postgres {
pub async fn new(
porstgres_config: String,
) -> anyhow::Result<(JoinHandle<anyhow::Result<()>>, Self)> {
let ca_pem = fs::read("ca.pem").await?;
// let ca_pem = BinaryEncoding::Base64
// .decode(ca_pem_b64)
// .context("ca pem decode")?;
let client_pks = fs::read("client.pks").await?;
// let client_pks = BinaryEncoding::Base64.decode(client_pks_b64).context("client pks decode")?;
let connector = TlsConnector::builder()
.add_root_certificate(Certificate::from_pem(&fs::read("ca.pem").await?)?)
.identity(
Identity::from_pkcs12(&fs::read("client.pks").await?, "p").context("Identity")?,
)
.add_root_certificate(Certificate::from_pem(&ca_pem)?)
.identity(Identity::from_pkcs12(&client_pks, "p").context("Identity")?)
.danger_accept_invalid_hostnames(true)
.danger_accept_invalid_certs(true)
.build()?;
@ -151,6 +165,29 @@ impl Postgres {
Ok(())
}
pub async fn update_tx(&self, tx: PostgresUpdateTx, signature: &str) -> anyhow::Result<()> {
let PostgresUpdateTx {
processed_slot,
cu_consumed,
cu_requested,
} = tx;
self.client
.read()
.await
.execute(
r#"
UPDATE lite_rpc.Txs
SET processed_slot = $1, cu_consumed = $2, cu_requested = $3
WHERE signature = $4
"#,
&[&processed_slot, &cu_consumed, &cu_requested, &signature],
)
.await?;
Ok(())
}
pub fn start(self, mut recv: PostgresMpscRecv) -> JoinHandle<anyhow::Result<()>> {
tokio::spawn(async move {
info!("Writing to postgres");
@ -159,6 +196,7 @@ impl Postgres {
let Err(err) = (
match msg {
PostgresMsg::PostgresTx(tx) => self.send_tx(tx).await,
PostgresMsg::PostgresUpdateTx(tx, sig) => self.update_tx(tx, &sig).await,
PostgresMsg::PostgresBlock(block) => self.send_block(block).await,
PostgresMsg::PostgreAccountAddr(_) => todo!(),
} ) else {