From 78f52cdacbd296146f2e3507cc1205b01f85742f Mon Sep 17 00:00:00 2001 From: canonbrother Date: Tue, 5 Nov 2024 16:35:34 +0800 Subject: [PATCH] rev invalidate loop --- lib/ain-ocean/src/indexer/loan_token.rs | 2 +- lib/ain-ocean/src/indexer/mod.rs | 16 ++++++++-------- lib/ain-ocean/src/indexer/oracle.rs | 12 ++++++------ lib/ain-ocean/src/indexer/poolswap.rs | 8 ++++---- lib/ain-ocean/src/indexer/transaction.rs | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/ain-ocean/src/indexer/loan_token.rs b/lib/ain-ocean/src/indexer/loan_token.rs index 4c6dafe2bf..3ae78b1e21 100644 --- a/lib/ain-ocean/src/indexer/loan_token.rs +++ b/lib/ain-ocean/src/indexer/loan_token.rs @@ -153,7 +153,7 @@ pub fn invalidate_active_price(services: &Arc, block: &BlockContext) - .flatten() .collect::>(); - for ((token, currency), _) in price_tickers { + for ((token, currency), _) in price_tickers.into_iter().rev() { services .oracle_price_active .by_id diff --git a/lib/ain-ocean/src/indexer/mod.rs b/lib/ain-ocean/src/indexer/mod.rs index d20a19ab2e..eea99999f9 100644 --- a/lib/ain-ocean/src/indexer/mod.rs +++ b/lib/ain-ocean/src/indexer/mod.rs @@ -298,7 +298,7 @@ fn index_script(services: &Arc, ctx: &Context, txs: &[Transaction]) -> return Err(Error::NotFoundIndex { action: IndexAction::Index, - r#type: "Index script TransactionVout".to_string(), + r#type: "index_script TransactionVout".to_string(), id: format!("{}-{}", vin.txid, vin.vout), }); }; @@ -369,7 +369,7 @@ fn invalidate_script(services: &Arc, ctx: &Context, txs: &[Transaction let mut hid_set = HashSet::new(); - for vin in tx.vin.iter() { + for vin in tx.vin.iter().rev() { if is_evm_tx { continue; } @@ -386,8 +386,8 @@ fn invalidate_script(services: &Arc, ctx: &Context, txs: &[Transaction }; return Err(Error::NotFoundIndex { - action: IndexAction::Index, - r#type: "Index script TransactionVout".to_string(), + action: IndexAction::Invalidate, + r#type: "invalidate_script TransactionVout".to_string(), id: format!("{}-{}", vin.txid, vin.vout), }); }; @@ -397,7 +397,7 @@ fn invalidate_script(services: &Arc, ctx: &Context, txs: &[Transaction hid_set.insert(as_sha256(&vout.script.hex)); // part of invalidate_script_aggregation } - for vout in tx.vout.iter() { + for vout in tx.vout.iter().rev() { invalidate_script_unspent_vout(services, ctx, vout)?; if vout.script_pub_key.hex.starts_with(&[0x6a]) { @@ -428,7 +428,7 @@ fn invalidate_script_unspent_vin( let Some(transaction) = services.transaction.by_id.get(&vin.txid)? else { return Err(Error::NotFoundIndex { action: IndexAction::Invalidate, - r#type: "Transaction".to_string(), + r#type: "invalidate_script_unspent_vin Transaction".to_string(), id: vin.txid.to_string(), }); }; @@ -436,7 +436,7 @@ fn invalidate_script_unspent_vin( let Some(vout) = services.transaction.vout_by_id.get(&(vin.txid, vin.vout))? else { return Err(Error::NotFoundIndex { action: IndexAction::Invalidate, - r#type: "TransactionVout".to_string(), + r#type: "invalidate_script_unspent_vin TransactionVout".to_string(), id: format!("{}{}", vin.txid, vin.vout), }); }; @@ -664,7 +664,7 @@ pub fn invalidate_block(services: &Arc, block: Block) -> let mut dftxs = Vec::new(); - for (tx_idx, tx) in block.tx.clone().into_iter().enumerate() { + for (tx_idx, tx) in block.tx.clone().into_iter().rev().enumerate() { if is_skipped_tx(&tx.txid) { continue; } diff --git a/lib/ain-ocean/src/indexer/oracle.rs b/lib/ain-ocean/src/indexer/oracle.rs index ca6f652003..e33a91cc28 100644 --- a/lib/ain-ocean/src/indexer/oracle.rs +++ b/lib/ain-ocean/src/indexer/oracle.rs @@ -89,7 +89,7 @@ impl Index for AppointOracle { .by_id .delete(&(oracle_id, context.block.height))?; - for currency_pair in self.price_feeds.as_ref() { + for currency_pair in self.price_feeds.iter().rev() { let token_currency_id = ( currency_pair.token.clone(), currency_pair.currency.clone(), @@ -136,7 +136,7 @@ impl Index for RemoveOracle { services.oracle.by_id.put(&oracle_id, &oracle)?; - for price_feed in previous.price_feeds { + for price_feed in previous.price_feeds.into_iter().rev() { let oracle_token_currency = OracleTokenCurrency { weightage: oracle.weightage, block: oracle.block.clone(), @@ -208,7 +208,7 @@ impl Index for UpdateOracle { .delete(&(oracle_id, context.block.height))?; let price_feeds = self.price_feeds.as_ref(); - for pair in price_feeds { + for pair in price_feeds.iter().rev() { services.oracle_token_currency.by_id.delete(&( pair.token.clone(), pair.currency.clone(), @@ -225,7 +225,7 @@ impl Index for UpdateOracle { }; services.oracle.by_id.put(&(prev_oracle_id), &prev_oracle)?; - for price_feed in &previous.price_feeds { + for price_feed in previous.price_feeds.iter().rev() { let oracle_token_currency = OracleTokenCurrency { weightage: previous.weightage, block: previous.block.clone(), @@ -427,7 +427,7 @@ impl Index for SetOracleData { let feeds = map_price_feeds(self, context); - for ((token, currency, _, _), _) in &feeds { + for ((token, currency, _, _), _) in feeds.iter().rev() { let id = (token.clone(), currency.clone(), context.block.height); let aggregated = oracle_repo.by_id.get(&id)?; @@ -436,7 +436,7 @@ impl Index for SetOracleData { continue; }; - for interval in AGGREGATED_INTERVALS { + for interval in AGGREGATED_INTERVALS.into_iter().rev() { invalidate_oracle_interval( services, &context.block, diff --git a/lib/ain-ocean/src/indexer/poolswap.rs b/lib/ain-ocean/src/indexer/poolswap.rs index d371ab74e1..3141afefdb 100644 --- a/lib/ain-ocean/src/indexer/poolswap.rs +++ b/lib/ain-ocean/src/indexer/poolswap.rs @@ -99,7 +99,7 @@ fn invalidate_swap_aggregated( from_amount: i64, txid: Txid, ) -> Result<()> { - for interval in AGGREGATED_INTERVALS { + for interval in AGGREGATED_INTERVALS.into_iter().rev() { let repo = &services.pool_swap_aggregated; let prevs = repo .by_key @@ -231,8 +231,8 @@ impl IndexBlockStart for PoolSwap { let mut pool_pairs = ain_cpp_imports::get_pool_pairs(); pool_pairs.sort_by(|a, b| b.creation_height.cmp(&a.creation_height)); - for interval in AGGREGATED_INTERVALS { - for pool_pair in &pool_pairs { + for interval in AGGREGATED_INTERVALS.into_iter().rev() { + for pool_pair in pool_pairs.iter().rev() { let pool_swap_aggregated_id = (pool_pair.id, interval, block.hash); services .pool_swap_aggregated @@ -400,7 +400,7 @@ impl Index for CompositeSwap { let from_token_id = self.pool_swap.from_token_id.0; let from_amount = self.pool_swap.from_amount; let txid = ctx.tx.txid; - for pool in self.pools.as_ref() { + for pool in self.pools.iter().rev() { let pool_id = pool.id.0 as u32; services .pool diff --git a/lib/ain-ocean/src/indexer/transaction.rs b/lib/ain-ocean/src/indexer/transaction.rs index ab39c1070a..43d9ace500 100644 --- a/lib/ain-ocean/src/indexer/transaction.rs +++ b/lib/ain-ocean/src/indexer/transaction.rs @@ -117,7 +117,7 @@ pub fn invalidate_transaction(services: &Arc, ctx: &Context) -> Result services.transaction.by_id.delete(&ctx.tx.txid)?; let is_evm = check_if_evm_tx(&ctx.tx); - for vin in ctx.tx.vin.clone().into_iter() { + for vin in ctx.tx.vin.clone().into_iter().rev() { if is_evm { continue; } @@ -133,7 +133,7 @@ pub fn invalidate_transaction(services: &Arc, ctx: &Context) -> Result } } - for vout in ctx.tx.vout.clone().into_iter() { + for vout in ctx.tx.vout.clone().into_iter().rev() { services .transaction .vout_by_id