Skip to content

Commit

Permalink
[FA migration] When coinstore is deleted we miss the FA activities (#691
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bowenyang007 authored Jan 23, 2025
1 parent d68d37e commit 0764e6f
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 21 deletions.
25 changes: 18 additions & 7 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ anyhow = "1.0.86"
aptos-indexer-processor-sdk = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "b79ed8b5864b2a12a1f9c5fd01579462e029b2ae" }
aptos-indexer-processor-sdk-server-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "b79ed8b5864b2a12a1f9c5fd01579462e029b2ae" }
aptos-protos = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "1d8460a995503574ec4e9699d3442d0150d7f3b9" }
aptos-indexer-test-transactions = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "1d8460a995503574ec4e9699d3442d0150d7f3b9" }
aptos-indexer-test-transactions = { git = "https://github.com/aptos-labs/aptos-core.git", rev = "7cbfda27f78395104b5b5b2d5f7b52dd51069802" }
aptos-indexer-testing-framework = { git = "https://github.com/aptos-labs/aptos-indexer-processor-sdk.git", rev = "b79ed8b5864b2a12a1f9c5fd01579462e029b2ae" }
async-trait = "0.1.53"
backtrace = "0.3.58"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"transaction_version": 2186504987,
"coin_type_hash": "91ceb1308a98389691e05158b07ed5f079ab78461a6bb8d5a4054b1bb5cb8bb6",
"coin_type": "0x1::aptos_coin::AptosCoin",
"supply": "113534547660282355",
"transaction_timestamp": "2025-01-11T14:41:54",
"transaction_epoch": 9917
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[
{
"storage_id": "0x0c45a2c470e687bd011ead8c19f69b3c1cda9dad656c3f44947168d4ec62f1ee",
"owner_address": "0x9145f11536bda903471ac026c907b76ef0f957e81cfd2d443850362c52715b20",
"asset_type_v2": "0x000000000000000000000000000000000000000000000000000000000000000a",
"asset_type_v1": "0x1::aptos_coin::AptosCoin",
"is_primary": true,
"is_frozen": false,
"amount_v1": null,
"amount_v2": "1200000000",
"amount": "1200000000",
"last_transaction_version_v1": null,
"last_transaction_version_v2": 2186504987,
"last_transaction_version": 2186504987,
"last_transaction_timestamp_v1": null,
"last_transaction_timestamp_v2": "2025-01-11T14:41:54",
"last_transaction_timestamp": "2025-01-11T14:41:54",
"token_standard": "v1",
"asset_type": "0x1::aptos_coin::AptosCoin"
},
{
"storage_id": "0x2c87f6bda15c67be2791d1b084194cc322bb0e432ca49066c20d21de4a45957d",
"owner_address": "0xc5855db74d8b2a3b0cc62b5afa75f2d0bce471b47a5f90082336d00ae4289dd8",
"asset_type_v2": null,
"asset_type_v1": "0x1::aptos_coin::AptosCoin",
"is_primary": true,
"is_frozen": false,
"amount_v1": "1117884340",
"amount_v2": null,
"amount": "1117884340",
"last_transaction_version_v1": 2186504987,
"last_transaction_version_v2": null,
"last_transaction_version": 2186504987,
"last_transaction_timestamp_v1": "2025-01-11T14:41:54",
"last_transaction_timestamp_v2": null,
"last_transaction_timestamp": "2025-01-11T14:41:54",
"token_standard": "v1",
"asset_type": "0x1::aptos_coin::AptosCoin"
},
{
"storage_id": "0xe1d533aa4a76f9d711109c46d6830fee0da63d5bd63aeb53ad69f589bbd2e2ea",
"owner_address": "0x3e91d912e7c62dfd884fd8b9a2261fecd33c78cf4da1b1ef2e7452c585c6f30d",
"asset_type_v2": "0x000000000000000000000000000000000000000000000000000000000000000a",
"asset_type_v1": "0x1::aptos_coin::AptosCoin",
"is_primary": true,
"is_frozen": false,
"amount_v1": null,
"amount_v2": "116557238",
"amount": "116557238",
"last_transaction_version_v1": null,
"last_transaction_version_v2": 2186504987,
"last_transaction_version": 2186504987,
"last_transaction_timestamp_v1": null,
"last_transaction_timestamp_v2": "2025-01-11T14:41:54",
"last_transaction_timestamp": "2025-01-11T14:41:54",
"token_standard": "v1",
"asset_type": "0x1::aptos_coin::AptosCoin"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[
{
"transaction_version": 2186504987,
"event_index": -1,
"owner_address": "0x3e91d912e7c62dfd884fd8b9a2261fecd33c78cf4da1b1ef2e7452c585c6f30d",
"storage_id": "0xe1d533aa4a76f9d711109c46d6830fee0da63d5bd63aeb53ad69f589bbd2e2ea",
"asset_type": "0x1::aptos_coin::AptosCoin",
"is_frozen": null,
"amount": "284100",
"type_": "0x1::aptos_coin::GasFeeEvent",
"is_gas_fee": true,
"gas_fee_payer_address": "0xc5855db74d8b2a3b0cc62b5afa75f2d0bce471b47a5f90082336d00ae4289dd8",
"is_transaction_success": true,
"entry_function_id_str": "0xff5580c435e563ecb9ec27d2b8fa2fc4b09be38852ad96c1054849b0611005f3::red_envelope_entry::create_red_envelope_coin_by_multi_entry",
"block_height": 275903047,
"token_standard": "v1",
"transaction_timestamp": "2025-01-11T14:41:54",
"storage_refund_amount": "49640"
},
{
"transaction_version": 2186504987,
"event_index": 1,
"owner_address": "0x3e91d912e7c62dfd884fd8b9a2261fecd33c78cf4da1b1ef2e7452c585c6f30d",
"storage_id": "0xe1d533aa4a76f9d711109c46d6830fee0da63d5bd63aeb53ad69f589bbd2e2ea",
"asset_type": "0x1::aptos_coin::AptosCoin",
"is_frozen": null,
"amount": "641197548",
"type_": "0x1::coin::WithdrawEvent",
"is_gas_fee": false,
"gas_fee_payer_address": null,
"is_transaction_success": true,
"entry_function_id_str": "0xff5580c435e563ecb9ec27d2b8fa2fc4b09be38852ad96c1054849b0611005f3::red_envelope_entry::create_red_envelope_coin_by_multi_entry",
"block_height": 275903047,
"token_standard": "v1",
"transaction_timestamp": "2025-01-11T14:41:54",
"storage_refund_amount": "0"
},
{
"transaction_version": 2186504987,
"event_index": 2,
"owner_address": "0x3e91d912e7c62dfd884fd8b9a2261fecd33c78cf4da1b1ef2e7452c585c6f30d",
"storage_id": "0xe1d533aa4a76f9d711109c46d6830fee0da63d5bd63aeb53ad69f589bbd2e2ea",
"asset_type": "0x000000000000000000000000000000000000000000000000000000000000000a",
"is_frozen": null,
"amount": "641197548",
"type_": "0x1::fungible_asset::Deposit",
"is_gas_fee": false,
"gas_fee_payer_address": null,
"is_transaction_success": true,
"entry_function_id_str": "0xff5580c435e563ecb9ec27d2b8fa2fc4b09be38852ad96c1054849b0611005f3::red_envelope_entry::create_red_envelope_coin_by_multi_entry",
"block_height": 275903047,
"token_standard": "v2",
"transaction_timestamp": "2025-01-11T14:41:54",
"storage_refund_amount": "0"
},
{
"transaction_version": 2186504987,
"event_index": 3,
"owner_address": "0x3e91d912e7c62dfd884fd8b9a2261fecd33c78cf4da1b1ef2e7452c585c6f30d",
"storage_id": "0xe1d533aa4a76f9d711109c46d6830fee0da63d5bd63aeb53ad69f589bbd2e2ea",
"asset_type": "0x000000000000000000000000000000000000000000000000000000000000000a",
"is_frozen": null,
"amount": "1200000000",
"type_": "0x1::fungible_asset::Withdraw",
"is_gas_fee": false,
"gas_fee_payer_address": null,
"is_transaction_success": true,
"entry_function_id_str": "0xff5580c435e563ecb9ec27d2b8fa2fc4b09be38852ad96c1054849b0611005f3::red_envelope_entry::create_red_envelope_coin_by_multi_entry",
"block_height": 275903047,
"token_standard": "v2",
"transaction_timestamp": "2025-01-11T14:41:54",
"storage_refund_amount": "0"
},
{
"transaction_version": 2186504987,
"event_index": 4,
"owner_address": "0x9145f11536bda903471ac026c907b76ef0f957e81cfd2d443850362c52715b20",
"storage_id": "0x0c45a2c470e687bd011ead8c19f69b3c1cda9dad656c3f44947168d4ec62f1ee",
"asset_type": "0x000000000000000000000000000000000000000000000000000000000000000a",
"is_frozen": null,
"amount": "1200000000",
"type_": "0x1::fungible_asset::Deposit",
"is_gas_fee": false,
"gas_fee_payer_address": null,
"is_transaction_success": true,
"entry_function_id_str": "0xff5580c435e563ecb9ec27d2b8fa2fc4b09be38852ad96c1054849b0611005f3::red_envelope_entry::create_red_envelope_coin_by_multi_entry",
"block_height": 275903047,
"token_standard": "v2",
"transaction_timestamp": "2025-01-11T14:41:54",
"storage_refund_amount": "0"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"transaction_version": 2186504987,
"write_set_change_index": 6,
"storage_id": "0x0c45a2c470e687bd011ead8c19f69b3c1cda9dad656c3f44947168d4ec62f1ee",
"owner_address": "0x9145f11536bda903471ac026c907b76ef0f957e81cfd2d443850362c52715b20",
"asset_type": "0x000000000000000000000000000000000000000000000000000000000000000a",
"is_primary": true,
"is_frozen": false,
"amount": "1200000000",
"transaction_timestamp": "2025-01-11T14:41:54",
"token_standard": "v2"
},
{
"transaction_version": 2186504987,
"write_set_change_index": 8,
"storage_id": "0xe1d533aa4a76f9d711109c46d6830fee0da63d5bd63aeb53ad69f589bbd2e2ea",
"owner_address": "0x3e91d912e7c62dfd884fd8b9a2261fecd33c78cf4da1b1ef2e7452c585c6f30d",
"asset_type": "0x1::aptos_coin::AptosCoin",
"is_primary": true,
"is_frozen": false,
"amount": "0",
"transaction_timestamp": "2025-01-11T14:41:54",
"token_standard": "v1"
},
{
"transaction_version": 2186504987,
"write_set_change_index": 13,
"storage_id": "0x2c87f6bda15c67be2791d1b084194cc322bb0e432ca49066c20d21de4a45957d",
"owner_address": "0xc5855db74d8b2a3b0cc62b5afa75f2d0bce471b47a5f90082336d00ae4289dd8",
"asset_type": "0x1::aptos_coin::AptosCoin",
"is_primary": true,
"is_frozen": false,
"amount": "1117884340",
"transaction_timestamp": "2025-01-11T14:41:54",
"token_standard": "v1"
},
{
"transaction_version": 2186504987,
"write_set_change_index": 14,
"storage_id": "0xe1d533aa4a76f9d711109c46d6830fee0da63d5bd63aeb53ad69f589bbd2e2ea",
"owner_address": "0x3e91d912e7c62dfd884fd8b9a2261fecd33c78cf4da1b1ef2e7452c585c6f30d",
"asset_type": "0x000000000000000000000000000000000000000000000000000000000000000a",
"is_primary": true,
"is_frozen": false,
"amount": "116557238",
"transaction_timestamp": "2025-01-11T14:41:54",
"token_standard": "v2"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"asset_type": "0x000000000000000000000000000000000000000000000000000000000000000a",
"creator_address": "0x0000000000000000000000000000000000000000000000000000000000000001",
"name": "Aptos Coin",
"symbol": "APT",
"decimals": 8,
"icon_uri": "",
"project_uri": "",
"last_transaction_version": 2186504987,
"last_transaction_timestamp": "2025-01-11T14:41:54",
"supply_aggregator_table_handle_v1": null,
"supply_aggregator_table_key_v1": null,
"token_standard": "v2",
"maximum_v2": "340282366920938463463374607431768211455",
"is_token_v2": null,
"supply_v2": "20705635276853"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod sdk_fungible_asset_processor_tests {
};
use aptos_indexer_test_transactions::json_transactions::generated_transactions::{
IMPORTED_DEVNET_TXNS_78753811_COIN_TRANSFER_WITH_V2_EVENTS,
IMPORTED_MAINNET_TXNS_2186504987_COIN_STORE_DELETION_NO_EVENT,
IMPORTED_MAINNET_TXNS_508365567_FA_V1_EVENTS,
IMPORTED_MAINNET_TXNS_999929475_COIN_AND_FA_TRANSFERS,
IMPORTED_TESTNET_TXNS_1200394037_FA_V2_FROZEN_EVENT,
Expand Down Expand Up @@ -166,6 +167,15 @@ mod sdk_fungible_asset_processor_tests {
.await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_fungible_asset_processor_coin_store_deletion_no_event() {
process_single_testnet_fa_txns(
IMPORTED_MAINNET_TXNS_2186504987_COIN_STORE_DELETION_NO_EVENT,
Some("coin_store_deletion_no_event".to_string()),
)
.await;
}

// Helper function to abstract out the transaction processing
async fn process_single_testnet_fa_txns(txn: &[u8], test_case_name: Option<String>) {
let (diff_flag, custom_output_path) = get_test_config();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub type CoinType = String;
// Primary key of the current_coin_balances table, i.e. (owner_address, coin_type)
pub type CurrentCoinBalancePK = (OwnerAddress, CoinType);
pub type EventToCoinType = AHashMap<EventGuidResource, CoinType>;
pub type AddressToCoinType = AHashMap<String, String>;

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RawFungibleAssetActivity {
Expand Down Expand Up @@ -149,6 +150,7 @@ impl RawFungibleAssetActivity {
entry_function_id_str: &Option<String>,
event_to_coin_type: &EventToCoinType,
event_index: i64,
address_to_coin_type: &AddressToCoinType,
) -> anyhow::Result<Option<Self>> {
if let Some(inner) =
CoinEvent::from_event(event.type_str.as_str(), &event.data, txn_version)?
Expand Down Expand Up @@ -185,14 +187,23 @@ impl RawFungibleAssetActivity {
};
// Given this mapping only contains coin type < 1000 length, we should not assume that the mapping exists.
// If it doesn't exist, skip.
// First try to get from event_to_coin_type mapping
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);
// If not found, try to get from address_to_coin_type mapping
// This is temporary until we have a way to get the coin type from a new event
match address_to_coin_type.get(&event_move_guid.addr) {
Some(coin_type) => coin_type.clone(),
None => {
tracing::warn!(
"Could not find coin type from either event or address mapping, version: {}, event guid: {:?}",
txn_version,
event_move_guid
);
return Ok(None);
},
}
},
}
};
Expand Down
Loading

0 comments on commit 0764e6f

Please sign in to comment.