Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocean fix invalidate flow by reverse loop #3111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 7 additions & 7 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: "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 @@ -387,7 +387,7 @@ fn invalidate_script(services: &Arc<Services>, ctx: &Context, txs: &[Transaction

return Err(Error::NotFoundIndex {
action: IndexAction::Invalidate,
r#type: "Script TransactionVout".to_string(),
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: "ScriptUnspentVin 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: "ScriptUnspentVin 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 @@ -90,7 +90,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 @@ -146,7 +146,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 @@ -223,7 +223,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 @@ -245,7 +245,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 @@ -447,7 +447,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 @@ -456,7 +456,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
10 changes: 5 additions & 5 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 @@ -184,7 +184,7 @@ fn create_new_bucket(

impl IndexBlockStart for PoolSwap {
fn index_block_start(self, services: &Arc<Services>, block: &BlockContext) -> Result<()> {
let mut pool_pairs = ain_cpp_imports::get_pool_pairs();
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 {
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
Loading