0.7.27 +Refactor
This commit is contained in:
@@ -3,13 +3,13 @@
|
||||
//! Local pipeline replay from already persisted raw transaction data.
|
||||
//!
|
||||
//! This service does not fetch historical transactions from Solana RPC. It
|
||||
//! reuses rows already present in `kb_chain_transactions` and replays the
|
||||
//! reuses rows already present in `k_sol_chain_transactions` and replays the
|
||||
//! deterministic local pipeline over their signatures.
|
||||
|
||||
/// Configuration for a local pipeline replay pass.
|
||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct KbLocalPipelineReplayConfig {
|
||||
pub struct LocalPipelineReplayConfig {
|
||||
/// Maximum number of persisted transactions to replay.
|
||||
pub limit: std::option::Option<i64>,
|
||||
/// Whether token metadata backfill should run after local replay.
|
||||
@@ -18,7 +18,7 @@ pub struct KbLocalPipelineReplayConfig {
|
||||
pub token_metadata_limit: std::option::Option<i64>,
|
||||
}
|
||||
|
||||
impl Default for KbLocalPipelineReplayConfig {
|
||||
impl Default for LocalPipelineReplayConfig {
|
||||
fn default() -> Self {
|
||||
return Self {
|
||||
limit: Some(10_000),
|
||||
@@ -31,7 +31,7 @@ impl Default for KbLocalPipelineReplayConfig {
|
||||
/// Summary of a local pipeline replay pass.
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct KbLocalPipelineReplayResult {
|
||||
pub struct LocalPipelineReplayResult {
|
||||
/// Number of transaction signatures selected for replay.
|
||||
pub selected_transaction_count: usize,
|
||||
/// Number of transactions replayed without a fatal per-signature error.
|
||||
@@ -55,7 +55,7 @@ pub struct KbLocalPipelineReplayResult {
|
||||
/// Total candle upsert results returned by replayed candle calls.
|
||||
///
|
||||
/// This is a replay write/result counter, not the number of distinct rows
|
||||
/// currently persisted in `kb_pair_candles`. Use local diagnostics for the
|
||||
/// currently persisted in `k_sol_pair_candles`. Use local diagnostics for the
|
||||
/// persisted row count.
|
||||
pub pair_candle_upsert_count: usize,
|
||||
/// Total analytic signal upsert results returned by replayed analytic calls.
|
||||
@@ -73,15 +73,15 @@ pub struct KbLocalPipelineReplayResult {
|
||||
|
||||
/// Local pipeline replay service.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct KbLocalPipelineReplayService {
|
||||
database: std::sync::Arc<crate::KbDatabase>,
|
||||
pub struct LocalPipelineReplayService {
|
||||
database: std::sync::Arc<crate::Database>,
|
||||
http_pool: std::option::Option<std::sync::Arc<crate::HttpEndpointPool>>,
|
||||
http_role: std::string::String,
|
||||
}
|
||||
|
||||
impl KbLocalPipelineReplayService {
|
||||
impl LocalPipelineReplayService {
|
||||
/// Creates a new local-only pipeline replay service.
|
||||
pub fn new(database: std::sync::Arc<crate::KbDatabase>) -> Self {
|
||||
pub fn new(database: std::sync::Arc<crate::Database>) -> Self {
|
||||
return Self {
|
||||
database,
|
||||
http_pool: None,
|
||||
@@ -92,7 +92,7 @@ impl KbLocalPipelineReplayService {
|
||||
/// Creates a new pipeline replay service able to refresh token metadata over Solana HTTP RPC.
|
||||
pub fn new_with_http_pool(
|
||||
http_pool: std::sync::Arc<crate::HttpEndpointPool>,
|
||||
database: std::sync::Arc<crate::KbDatabase>,
|
||||
database: std::sync::Arc<crate::Database>,
|
||||
http_role: std::string::String,
|
||||
) -> Self {
|
||||
return Self {
|
||||
@@ -105,9 +105,9 @@ impl KbLocalPipelineReplayService {
|
||||
/// Replays the local pipeline from persisted raw chain transaction rows.
|
||||
pub async fn replay_local_pipeline(
|
||||
&self,
|
||||
config: &crate::KbLocalPipelineReplayConfig,
|
||||
) -> Result<crate::KbLocalPipelineReplayResult, crate::KbError> {
|
||||
let signatures_result = crate::list_chain_transaction_signatures_for_replay(
|
||||
config: &crate::LocalPipelineReplayConfig,
|
||||
) -> Result<crate::LocalPipelineReplayResult, crate::Error> {
|
||||
let signatures_result = crate::query_chain_transactions_list_signatures_for_replay(
|
||||
self.database.as_ref(),
|
||||
config.limit,
|
||||
)
|
||||
@@ -116,13 +116,13 @@ impl KbLocalPipelineReplayService {
|
||||
Ok(signatures) => signatures,
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let dex_decode = crate::KbDexDecodeService::new(self.database.clone());
|
||||
let dex_detect = crate::KbDexDetectService::new(self.database.clone());
|
||||
let trade_aggregation = crate::KbTradeAggregationService::new(self.database.clone());
|
||||
let dex_decode = crate::DexDecodeService::new(self.database.clone());
|
||||
let dex_detect = crate::DexDetectService::new(self.database.clone());
|
||||
let trade_aggregation = crate::TradeAggregationService::new(self.database.clone());
|
||||
let pair_candle_aggregation =
|
||||
crate::KbPairCandleAggregationService::new(self.database.clone());
|
||||
let pair_analytic_signal = crate::KbPairAnalyticSignalService::new(self.database.clone());
|
||||
let mut result = KbLocalPipelineReplayResult {
|
||||
crate::PairCandleAggregationService::new(self.database.clone());
|
||||
let pair_analytic_signal = crate::PairAnalyticSignalService::new(self.database.clone());
|
||||
let mut result = LocalPipelineReplayResult {
|
||||
selected_transaction_count: signatures.len(),
|
||||
..Default::default()
|
||||
};
|
||||
@@ -158,9 +158,8 @@ impl KbLocalPipelineReplayService {
|
||||
tracing::warn!(
|
||||
signature = %signature,
|
||||
error = %error,
|
||||
"local pipeline replay detect step failed"
|
||||
"local pipeline replay detect step failed; continuing with aggregation"
|
||||
);
|
||||
continue;
|
||||
},
|
||||
}
|
||||
let trade_result =
|
||||
@@ -214,12 +213,12 @@ impl KbLocalPipelineReplayService {
|
||||
}
|
||||
if config.refresh_missing_token_metadata {
|
||||
let metadata_service = match &self.http_pool {
|
||||
Some(http_pool) => crate::KbTokenMetadataBackfillService::new(
|
||||
Some(http_pool) => crate::TokenMetadataBackfillService::new(
|
||||
http_pool.clone(),
|
||||
self.database.clone(),
|
||||
self.http_role.clone(),
|
||||
),
|
||||
None => crate::KbTokenMetadataBackfillService::new_local(self.database.clone()),
|
||||
None => crate::TokenMetadataBackfillService::new_local(self.database.clone()),
|
||||
};
|
||||
let metadata_result = metadata_service
|
||||
.backfill_missing_token_metadata(config.token_metadata_limit)
|
||||
@@ -242,10 +241,10 @@ impl KbLocalPipelineReplayService {
|
||||
}
|
||||
|
||||
/// Replays the local pipeline from persisted raw chain transaction rows.
|
||||
pub async fn kb_replay_local_pipeline(
|
||||
database: std::sync::Arc<crate::KbDatabase>,
|
||||
config: &crate::KbLocalPipelineReplayConfig,
|
||||
) -> Result<crate::KbLocalPipelineReplayResult, crate::KbError> {
|
||||
let service = crate::KbLocalPipelineReplayService::new(database);
|
||||
pub async fn replay_local_pipeline(
|
||||
database: std::sync::Arc<crate::Database>,
|
||||
config: &crate::LocalPipelineReplayConfig,
|
||||
) -> Result<crate::LocalPipelineReplayResult, crate::Error> {
|
||||
let service = crate::LocalPipelineReplayService::new(database);
|
||||
return service.replay_local_pipeline(config).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user