Skip to content

Commit

Permalink
println progress
Browse files Browse the repository at this point in the history
  • Loading branch information
grooviegermanikus committed Aug 14, 2024
1 parent 53965b1 commit 47eedfe
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions chaindata_standalone/src/replay_slot_account_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ use std::io;
use std::io::BufRead;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Instant;
use csv::ReaderBuilder;
use itertools::Itertools;
use log::trace;
use solana_sdk::account::AccountSharedData;

Check warning on line 10 in chaindata_standalone/src/replay_slot_account_stream.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/chaindata_standalone/src/replay_slot_account_stream.rs
use solana_sdk::clock::Slot;
use solana_sdk::commitment_config::CommitmentLevel;
use solana_sdk::pubkey::Pubkey;

Check warning on line 13 in chaindata_standalone/src/replay_slot_account_stream.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/chaindata_standalone/src/replay_slot_account_stream.rs
use tracing_subscriber::EnvFilter;
use tracing_subscriber::fmt::format::FmtSpan;
use mango_feeds_connector::chain_data::{ChainData, SlotData, SlotStatus};
use mango_feeds_connector::chain_data::{AccountData, ChainData, SlotData, SlotStatus};

const RAYDIUM_AMM_PUBKEY: &'static str = "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8";

pub fn main() {
tracing_subscriber::fmt()
Expand All @@ -20,6 +25,10 @@ pub fn main() {

let slot_stream_dump_file = PathBuf::from_str("/Users/stefan/mango/projects/mango-feeds-connector/dump-slot-acccounts-fsn4-mixed.csv").unwrap();

let mut chain_data = ChainData::new();
let mut slot_cnt = 0;
let mut account_cnt = 0;
let started_at = Instant::now();
// read lins
let file = File::open(slot_stream_dump_file).unwrap();
let lines = io::BufReader::new(file).lines();
Expand All @@ -31,32 +40,58 @@ pub fn main() {
if rows[0] == "MIXSLOT" {
let slot: u64 = rows[1].parse().unwrap();
let parent: Option<u64> = rows[2].parse().ok().and_then(|v| if v == 0 { None } else { Some(v) });
let status = match rows[3].to_string().as_str() {
let commitment_level = match rows[3].to_string().as_str() {
"P" => CommitmentLevel::Processed,
"C" => CommitmentLevel::Confirmed,
"F" => CommitmentLevel::Finalized,
_ => panic!("invalid commitment level"),
};
let since_epoch_ms: u64 = rows[4].trim().parse().unwrap();

let status = match status {
let slot_status = match commitment_level {
CommitmentLevel::Processed => SlotStatus::Processed,
CommitmentLevel::Confirmed => SlotStatus::Confirmed,
CommitmentLevel::Finalized => SlotStatus::Rooted,
_ => panic!("invalid commitment level"),

Check warning on line 55 in chaindata_standalone/src/replay_slot_account_stream.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/chaindata_standalone/src/replay_slot_account_stream.rs
};
const INIT_CHAIN: Slot = 0;
println!("MIXSLOT slot: {}, parent: {:?}, status: {:?}, since_epoch_ms: {}", slot, parent, status, since_epoch_ms);
trace!("MIXSLOT slot: {}, parent: {:?}, status: {:?}, since_epoch_ms: {}", slot, parent, slot_status, since_epoch_ms);
let slot_data = SlotData {
slot,
parent,
status: slot_status,
chain: INIT_CHAIN,
};

Check warning on line 64 in chaindata_standalone/src/replay_slot_account_stream.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/chaindata_standalone/src/replay_slot_account_stream.rs
slot_cnt += 1;
chain_data.update_slot(slot_data);

} else if rows[0] == "MIXACCOUNT" {
let slot: u64 = rows[1].parse().unwrap();
let account_pk: String = rows[2].parse().unwrap();
let account_pk = Pubkey::from_str(&account_pk).unwrap();
let write_version: u64 = rows[3].parse().unwrap();
let data_len: u64 = rows[4].parse().unwrap();
let since_epoch_ms: u64 = rows[5].trim().parse().unwrap();
println!("MIXACCOUNT slot: {}, account_pk: {}, write_version: {}, data_len: {}, since_epoch_ms: {}", slot, account_pk, write_version, data_len, since_epoch_ms);
trace!("MIXACCOUNT slot: {}, account_pk: {}, write_version: {}, data_len: {}, since_epoch_ms: {}", slot, account_pk, write_version, data_len, since_epoch_ms);

let account_data = AccountData {

Check warning on line 77 in chaindata_standalone/src/replay_slot_account_stream.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/chaindata_standalone/src/replay_slot_account_stream.rs
slot,
write_version,
account: AccountSharedData::new(slot, data_len as usize, &Pubkey::from_str(RAYDIUM_AMM_PUBKEY).unwrap())
};

account_cnt += 1;
chain_data.update_account(account_pk, account_data);
}

Check warning on line 86 in chaindata_standalone/src/replay_slot_account_stream.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/chaindata_standalone/src/replay_slot_account_stream.rs
if (slot_cnt + account_cnt) % 100_000 == 0 {
let elapsed = started_at.elapsed();
println!("progress .. slot_cnt: {}, account_cnt: {}, elapsed: {:?}", slot_cnt, account_cnt, elapsed);
}
}

let elapsed = started_at.elapsed();

Check warning on line 93 in chaindata_standalone/src/replay_slot_account_stream.rs

View workflow job for this annotation

GitHub Actions / test

Diff in /home/runner/work/mango-feeds/mango-feeds/chaindata_standalone/src/replay_slot_account_stream.rs

println!("slot_cnt: {}, account_cnt: {}, elapsed: {:?}", slot_cnt, account_cnt, elapsed);

}

0 comments on commit 47eedfe

Please sign in to comment.