From ffdaa45010173392ebebd796f44bf362fef25711 Mon Sep 17 00:00:00 2001 From: bowenyang007 Date: Sun, 24 Mar 2024 11:50:18 -0700 Subject: [PATCH] fix panic where coin type is too long --- .../v2_fungible_asset_activities.rs | 21 +++++++++++-------- .../v2_fungible_asset_balances.rs | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_activities.rs b/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_activities.rs index a2566892..acf2a6b9 100644 --- a/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_activities.rs +++ b/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_activities.rs @@ -146,15 +146,18 @@ impl FungibleAssetActivity { addr: standardize_address(event_key.account_address.as_str()), creation_num: event_key.creation_number as i64, }; - let coin_type = - event_to_coin_type - .get(&event_move_guid) - .unwrap_or_else(|| { - panic!( - "Could not find event in resources (CoinStore), version: {}, event guid: {:?}, mapping: {:?}", - txn_version, event_move_guid, event_to_coin_type - ) - }).clone(); + // Given this mapping only contains coin type < 1000 length, we should not assume that the mapping exists. + // If it doesn't exist, skip. + let coin_type = match event_to_coin_type.get(&event_move_guid) { + Some(coin_type) => coin_type.clone(), + None => { + tracing::warn!( + "Could not find event in resources (CoinStore), version: {}, event guid: {:?}, mapping: {:?}", + txn_version, event_move_guid, event_to_coin_type + ); + return Ok(None); + }, + }; let storage_id = CoinInfoType::get_storage_id(coin_type.as_str(), event_move_guid.addr.as_str()); Ok(Some(Self { diff --git a/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_balances.rs b/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_balances.rs index 0da57d55..744518d4 100644 --- a/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_balances.rs +++ b/rust/processor/src/models/fungible_asset_models/v2_fungible_asset_balances.rs @@ -125,6 +125,7 @@ impl FungibleAssetBalance { } /// Getting coin balances from resources for v1 + /// If the fully qualified coin type is too long (currently 1000 length), we exclude from indexing pub fn get_v1_from_write_resource( write_resource: &WriteResource, write_set_change_index: i64,