From e74b307cf50f28da9642b3869ff2b1ddfa259434 Mon Sep 17 00:00:00 2001 From: Guoteng Rao <3603304+grao1991@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:21:08 -0700 Subject: [PATCH] [Fix] Fix indexer FN and localnet. (#14727) * [Fix] Only use version from internal indexer when it is enabled. * fix the localnet support. --------- Co-authored-by: Larry Liu --- api/src/context.rs | 14 ++++++-------- crates/aptos/src/node/local_testnet/node.rs | 8 +++++--- storage/indexer/src/indexer_reader.rs | 4 ++++ types/src/indexer/indexer_db_reader.rs | 2 ++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/api/src/context.rs b/api/src/context.rs index 939276891d81c..4cea588b9906a 100644 --- a/api/src/context.rs +++ b/api/src/context.rs @@ -259,12 +259,12 @@ impl Context { } pub fn get_latest_ledger_info(&self) -> Result { - if self.indexer_reader.is_some() { - let ledger_info = self.get_latest_internal_indexer_ledger_version_and_ledger_info()?; - Ok(ledger_info) - } else { - self.get_latest_storage_ledger_info() + if let Some(indexer_reader) = self.indexer_reader.as_ref() { + if indexer_reader.is_internal_indexer_enabled() { + return self.get_latest_internal_indexer_ledger_info(); + } } + self.get_latest_storage_ledger_info() } pub fn get_latest_ledger_info_and_verify_lookup_version( @@ -292,9 +292,7 @@ impl Context { Ok((latest_ledger_info, requested_ledger_version)) } - pub fn get_latest_internal_indexer_ledger_version_and_ledger_info< - E: ServiceUnavailableError, - >( + pub fn get_latest_internal_indexer_ledger_info( &self, ) -> Result { if let Some(indexer_reader) = self.indexer_reader.as_ref() { diff --git a/crates/aptos/src/node/local_testnet/node.rs b/crates/aptos/src/node/local_testnet/node.rs index e40974a6ba78e..e51a63a73fe1f 100644 --- a/crates/aptos/src/node/local_testnet/node.rs +++ b/crates/aptos/src/node/local_testnet/node.rs @@ -153,9 +153,11 @@ impl NodeManager { node_config.indexer_grpc.use_data_service_interface = run_txn_stream; node_config.indexer_grpc.address.set_port(txn_stream_port); - // So long as the indexer relies on storage indexing tables, this must be set - // for the indexer GRPC stream on the node to work. - node_config.storage.enable_indexer = run_txn_stream; + node_config.indexer_table_info.table_info_service_mode = match run_txn_stream { + // Localnet should be responsible for backup or restore of table info tables. + true => aptos_config::config::TableInfoServiceMode::IndexingOnly, + false => aptos_config::config::TableInfoServiceMode::Disabled, + }; // Bind to the requested address. node_config.api.address.set_ip(IpAddr::V4(bind_to)); diff --git a/storage/indexer/src/indexer_reader.rs b/storage/indexer/src/indexer_reader.rs index 0368d80c612a5..535d043d50119 100644 --- a/storage/indexer/src/indexer_reader.rs +++ b/storage/indexer/src/indexer_reader.rs @@ -40,6 +40,10 @@ impl IndexerReaders { } impl IndexerReader for IndexerReaders { + fn is_internal_indexer_enabled(&self) -> bool { + self.db_indexer_reader.is_some() + } + fn get_table_info(&self, handle: TableHandle) -> anyhow::Result> { if let Some(table_info_reader) = &self.table_info_reader { return Ok(table_info_reader.get_table_info_with_retry(handle)?); diff --git a/types/src/indexer/indexer_db_reader.rs b/types/src/indexer/indexer_db_reader.rs index 016524dc5bb67..164b927de37dc 100644 --- a/types/src/indexer/indexer_db_reader.rs +++ b/types/src/indexer/indexer_db_reader.rs @@ -21,6 +21,8 @@ pub enum Order { } pub trait IndexerReader: Send + Sync { + fn is_internal_indexer_enabled(&self) -> bool; + fn get_table_info(&self, handle: TableHandle) -> Result>; fn get_events(