Skip to content

Commit

Permalink
[cp][aptos-release-v1.20] [Fix] Fix indexer FN and localnet. (#14730)
Browse files Browse the repository at this point in the history
* [Fix] Only use version from internal indexer when it is enabled.

* fix the localnet support.

---------

Co-authored-by: Larry Liu <[email protected]>
(cherry picked from commit e74b307)

Co-authored-by: Guoteng Rao <[email protected]>
  • Loading branch information
github-actions[bot] and grao1991 authored Sep 24, 2024
1 parent ea2e5e2 commit b6187e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
14 changes: 6 additions & 8 deletions api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ impl Context {
}

pub fn get_latest_ledger_info<E: ServiceUnavailableError>(&self) -> Result<LedgerInfo, E> {
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<E: StdApiError>(
Expand Down Expand Up @@ -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<E: ServiceUnavailableError>(
&self,
) -> Result<LedgerInfo, E> {
if let Some(indexer_reader) = self.indexer_reader.as_ref() {
Expand Down
8 changes: 5 additions & 3 deletions crates/aptos/src/node/local_testnet/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions storage/indexer/src/indexer_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<TableInfo>> {
if let Some(table_info_reader) = &self.table_info_reader {
return Ok(table_info_reader.get_table_info_with_retry(handle)?);
Expand Down
2 changes: 2 additions & 0 deletions types/src/indexer/indexer_db_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<TableInfo>>;

fn get_events(
Expand Down

0 comments on commit b6187e1

Please sign in to comment.