successfully write to postgres

This commit is contained in:
aniketfuryrocks 2023-01-28 10:33:42 +05:30
parent 4fbef582e3
commit a90609576f
No known key found for this signature in database
GPG Key ID: FA6BFCFAA7D4B764
4 changed files with 31 additions and 23 deletions

View File

@ -1,12 +1,12 @@
CREATE TABLE lite_rpc.Txs ( CREATE TABLE lite_rpc.Txs (
id SERIAL NOT NULL PRIMARY KEY, id SERIAL NOT NULL PRIMARY KEY,
signature BINARY(64) NOT NULL, signature CHAR(88) NOT NULL,
recent_slot BIGINT NOT NULL, recent_slot BIGINT NOT NULL,
forwarded_slot BIGINT NOT NULL, forwarded_slot BIGINT NOT NULL,
processed_slot BIGINT, processed_slot BIGINT,
cu_consumed BIGINT, cu_consumed BIGINT,
cu_requested BIGINT, cu_requested BIGINT,
quic_response CHAR quic_response SMALLINT
); );

View File

@ -108,7 +108,7 @@ impl LiteBridge {
let confirmed_block_listenser = self let confirmed_block_listenser = self
.confirmed_block_listenser .confirmed_block_listenser
.clone() .clone()
.listen(Some(postgres.clone())); .listen(None);
let cleaner = Cleaner::new( let cleaner = Cleaner::new(
self.tx_sender.clone(), self.tx_sender.clone(),

View File

@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use anyhow::Context; use anyhow::Context;
use log::info; use log::{info, warn};
use postgres_native_tls::MakeTlsConnector; use postgres_native_tls::MakeTlsConnector;
use tokio::fs; use tokio::fs;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
@ -14,14 +14,14 @@ pub struct Postgres {
client: Arc<Client>, client: Arc<Client>,
} }
pub struct PostgresTx<'a> { pub struct PostgresTx {
pub signature: &'a [u8], pub signature: String,
pub recent_slot: i64, pub recent_slot: i64,
pub forwarded_slot: i64, pub forwarded_slot: i64,
pub processed_slot: Option<i64>, pub processed_slot: Option<i64>,
pub cu_consumed: Option<i64>, pub cu_consumed: Option<i64>,
pub cu_requested: Option<i64>, pub cu_requested: Option<i64>,
pub quic_response: u32, pub quic_response: i16,
} }
pub struct PostgresBlock { pub struct PostgresBlock {
@ -86,7 +86,7 @@ impl Postgres {
Ok(()) Ok(())
} }
pub async fn send_tx<'a>(&self, tx: PostgresTx<'a>) -> anyhow::Result<()> { pub async fn send_tx(&self, tx: PostgresTx) -> anyhow::Result<()> {
let PostgresTx { let PostgresTx {
signature, signature,
recent_slot, recent_slot,
@ -97,12 +97,14 @@ impl Postgres {
quic_response, quic_response,
} = tx; } = tx;
warn!("{}", signature.len());
self.client.execute( self.client.execute(
r#" r#"
INSERT INTO lite_rpc.Txs INSERT INTO lite_rpc.Txs
(signature, recent_slot, forwarded_slot, processed_slot, cu_consumed, cu_requested, quic_response) (signature, recent_slot, forwarded_slot, processed_slot, cu_consumed, cu_requested, quic_response)
VALUES VALUES
($1, $2, $3, $4, $5, $6) ($1, $2, $3, $4, $5, $6, $7)
"#, "#,
&[&signature, &recent_slot, &forwarded_slot, &processed_slot, &cu_consumed, &cu_requested, &quic_response], &[&signature, &recent_slot, &forwarded_slot, &processed_slot, &cu_consumed, &cu_requested, &quic_response],
).await?; ).await?;

View File

@ -153,11 +153,14 @@ impl BlockListener {
}; };
if let Some(postgres) = &postgres { if let Some(postgres) = &postgres {
postgres.send_block(PostgresBlock { postgres
slot: slot as i64, .send_block(PostgresBlock {
leader_id: 0, //FIX: slot: slot as i64,
parent_slot: 0, //FIX: leader_id: 0, //FIX:
}).await?; parent_slot: 0, //FIX:
})
.await
.unwrap();
} }
for tx in transactions { for tx in transactions {
@ -175,15 +178,18 @@ impl BlockListener {
if let Some(mut tx_status) = self.tx_sender.txs_sent.get_mut(&sig) { if let Some(mut tx_status) = self.tx_sender.txs_sent.get_mut(&sig) {
if let Some(postgres) = &postgres { if let Some(postgres) = &postgres {
postgres.send_tx(PostgresTx { postgres
signature: tx.get_signature().as_ref(), .send_tx(PostgresTx {
recent_slot: slot as i64, signature: sig.clone(),
forwarded_slot: 0, recent_slot: slot as i64,
processed_slot: None, forwarded_slot: 0,
cu_consumed: None, processed_slot: None,
cu_requested: None, cu_consumed: None,
quic_response: 0, cu_requested: None,
}).await?; quic_response: 0,
})
.await
.unwrap();
} }
tx_status.value_mut().status = Some(TransactionStatus { tx_status.value_mut().status = Some(TransactionStatus {