From bd1cc34f012a8719fa1f5d37aeea522cd36bc8cb Mon Sep 17 00:00:00 2001 From: "zhoujun.ma" Date: Sun, 25 Feb 2024 12:47:22 -0800 Subject: [PATCH] make api, indexer, fake aptos db aware of block metadata ext txns --- api/src/context.rs | 4 +++- crates/indexer/src/indexer/fetcher.rs | 8 +++++++- .../indexer-grpc-fullnode/src/stream_coordinator.rs | 8 +++++++- storage/aptosdb/src/fake_aptosdb.rs | 5 ++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/api/src/context.rs b/api/src/context.rs index ffcd13c320f4e1..030652028e9dba 100644 --- a/api/src/context.rs +++ b/api/src/context.rs @@ -648,7 +648,9 @@ impl Context { .into_iter() .map(|t| { // Update the timestamp if the next block occurs - if let Some(txn) = t.transaction.try_as_block_metadata() { + if let Some(txn) = t.transaction.try_as_block_metadata_ext() { + timestamp = txn.timestamp_usecs(); + } else if let Some(txn) = t.transaction.try_as_block_metadata() { timestamp = txn.timestamp_usecs(); } let txn = converter.try_into_onchain_transaction(timestamp, t)?; diff --git a/crates/indexer/src/indexer/fetcher.rs b/crates/indexer/src/indexer/fetcher.rs index c565ddf516eabc..780ec643353d62 100644 --- a/crates/indexer/src/indexer/fetcher.rs +++ b/crates/indexer/src/indexer/fetcher.rs @@ -252,7 +252,13 @@ async fn fetch_nexts( // Do not update block_height if first block is block metadata if ind > 0 { // Update the timestamp if the next block occurs - if let Some(txn) = raw_txn.transaction.try_as_block_metadata() { + if let Some(txn) = raw_txn.transaction.try_as_block_metadata_ext() { + timestamp = txn.timestamp_usecs(); + epoch = txn.epoch(); + epoch_bcs = aptos_api_types::U64::from(epoch); + block_height += 1; + block_height_bcs = aptos_api_types::U64::from(block_height); + } else if let Some(txn) = raw_txn.transaction.try_as_block_metadata() { timestamp = txn.timestamp_usecs(); epoch = txn.epoch(); epoch_bcs = aptos_api_types::U64::from(epoch); diff --git a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs index dc710b437b2323..d5a95af6e196b3 100644 --- a/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs +++ b/ecosystem/indexer-grpc/indexer-grpc-fullnode/src/stream_coordinator.rs @@ -363,7 +363,13 @@ impl IndexerStreamCoordinator { // Do not update block_height if first block is block metadata if ind > 0 { // Update the timestamp if the next block occurs - if let Some(txn) = raw_txn.transaction.try_as_block_metadata() { + if let Some(txn) = raw_txn.transaction.try_as_block_metadata_ext() { + timestamp = txn.timestamp_usecs(); + epoch = txn.epoch(); + epoch_bcs = aptos_api_types::U64::from(epoch); + block_height += 1; + block_height_bcs = aptos_api_types::U64::from(block_height); + } else if let Some(txn) = raw_txn.transaction.try_as_block_metadata() { timestamp = txn.timestamp_usecs(); epoch = txn.epoch(); epoch_bcs = aptos_api_types::U64::from(epoch); diff --git a/storage/aptosdb/src/fake_aptosdb.rs b/storage/aptosdb/src/fake_aptosdb.rs index fdc0609424d8f6..3cd3ad65ad9951 100644 --- a/storage/aptosdb/src/fake_aptosdb.rs +++ b/storage/aptosdb/src/fake_aptosdb.rs @@ -338,7 +338,10 @@ impl FakeAptosDB { .or_insert(user_txn.sequence_number()); } - if let Some(txn) = txn_to_commit.transaction().try_as_block_metadata() { + if let Some(txn) = txn_to_commit.transaction().try_as_block_metadata_ext() { + self.latest_block_timestamp + .fetch_max(txn.timestamp_usecs(), Ordering::Relaxed); + } else if let Some(txn) = txn_to_commit.transaction().try_as_block_metadata() { self.latest_block_timestamp .fetch_max(txn.timestamp_usecs(), Ordering::Relaxed); }