Skip to content

Commit

Permalink
rev invalidate loop
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Nov 5, 2024
1 parent e161cc4 commit 78f52cd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/indexer/loan_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn invalidate_active_price(services: &Arc<Services>, block: &BlockContext) -
.flatten()
.collect::<Vec<_>>();

for ((token, currency), _) in price_tickers {
for ((token, currency), _) in price_tickers.into_iter().rev() {
services
.oracle_price_active
.by_id
Expand Down
16 changes: 8 additions & 8 deletions lib/ain-ocean/src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ fn index_script(services: &Arc<Services>, 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),
});
};
Expand Down Expand Up @@ -369,7 +369,7 @@ fn invalidate_script(services: &Arc<Services>, 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;
}
Expand All @@ -386,8 +386,8 @@ fn invalidate_script(services: &Arc<Services>, 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),
});
};
Expand All @@ -397,7 +397,7 @@ fn invalidate_script(services: &Arc<Services>, 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]) {
Expand Down Expand Up @@ -428,15 +428,15 @@ 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(),
});
};

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),
});
};
Expand Down Expand Up @@ -664,7 +664,7 @@ pub fn invalidate_block(services: &Arc<Services>, block: Block<Transaction>) ->

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;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/ain-ocean/src/indexer/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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)?;
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/ain-ocean/src/indexer/poolswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/ain-ocean/src/indexer/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn invalidate_transaction(services: &Arc<Services>, 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;
}
Expand All @@ -133,7 +133,7 @@ pub fn invalidate_transaction(services: &Arc<Services>, 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
Expand Down

0 comments on commit 78f52cd

Please sign in to comment.