Skip to content

Commit

Permalink
Revert "use storage ledgerinfo for txn APIs"
Browse files Browse the repository at this point in the history
This reverts commit efe0365.
  • Loading branch information
areshand committed Sep 21, 2024
1 parent 1abb125 commit ee84fb4
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 20 deletions.
3 changes: 1 addition & 2 deletions api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,10 +863,9 @@ impl Context {
pub fn get_transaction_by_hash(
&self,
hash: HashValue,
ledger_version: u64,
) -> Result<Option<TransactionOnChainData>> {
self.db
.get_transaction_by_hash(hash, ledger_version, true)?
.get_transaction_by_hash(hash, true)?
.map(|t| self.convert_into_transaction_on_chain_data(t))
.transpose()
}
Expand Down
18 changes: 7 additions & 11 deletions api/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,11 +793,10 @@ impl TransactionsApi {
let context = self.context.clone();
let accept_type = accept_type.clone();

let ledger_info =
api_spawn_blocking(move || context.get_latest_storage_ledger_info()).await?;
let ledger_info = api_spawn_blocking(move || context.get_latest_ledger_info()).await?;

let txn_data = self
.get_by_hash(hash.into(), &ledger_info)
.get_by_hash(hash.into())
.await
.context(format!("Failed to get transaction by hash {}", hash))
.map_err(|err| {
Expand Down Expand Up @@ -837,7 +836,7 @@ impl TransactionsApi {
api_spawn_blocking(move || context.get_latest_storage_ledger_info()).await?;

let txn_data = self
.get_by_hash(hash.into(), &ledger_info)
.get_by_hash(hash.into())
.await
.context(format!("Failed to get transaction by hash {}", hash))
.map_err(|err| {
Expand Down Expand Up @@ -961,15 +960,12 @@ impl TransactionsApi {
async fn get_by_hash(
&self,
hash: aptos_crypto::HashValue,
ledger_info: &LedgerInfo,
) -> anyhow::Result<Option<TransactionData>> {
let context = self.context.clone();
let version = ledger_info.version();
let from_db =
tokio::task::spawn_blocking(move || context.get_transaction_by_hash(hash, version))
.await
.context("Failed to join task to read transaction by hash")?
.context("Failed to read transaction by hash from DB")?;
let from_db = tokio::task::spawn_blocking(move || context.get_transaction_by_hash(hash))
.await
.context("Failed to join task to read transaction by hash")?
.context("Failed to read transaction by hash from DB")?;
Ok(match from_db {
None => self
.context
Expand Down
1 change: 0 additions & 1 deletion peer-monitoring-service/server/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ mod database_mock {
fn get_transaction_by_hash(
&self,
hash: HashValue,
ledger_version: Version,
fetch_events: bool,
) -> Result<Option<TransactionWithProof>>;

Expand Down
1 change: 0 additions & 1 deletion state-sync/state-sync-driver/src/tests/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ mock! {
fn get_transaction_by_hash(
&self,
hash: HashValue,
ledger_version: Version,
fetch_events: bool,
) -> Result<Option<TransactionWithProof>>;

Expand Down
1 change: 0 additions & 1 deletion state-sync/storage-service/server/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ mock! {
fn get_transaction_by_hash(
&self,
hash: HashValue,
ledger_version: Version,
fetch_events: bool,
) -> aptos_storage_interface::Result<Option<TransactionWithProof>>;

Expand Down
3 changes: 1 addition & 2 deletions storage/aptosdb/src/db/include/aptosdb_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,13 @@ impl DbReader for AptosDB {
fn get_transaction_by_hash(
&self,
hash: HashValue,
ledger_version: Version,
fetch_events: bool,
) -> Result<Option<TransactionWithProof>> {
gauged_api("get_transaction_by_hash", || {
self.ledger_db
.transaction_db()
.get_transaction_version_by_hash(&hash)?
.map(|v| self.get_transaction_with_proof(v, ledger_version, fetch_events))
.map(|v| self.get_transaction_with_proof(v, v, fetch_events))
.transpose()
})
}
Expand Down
2 changes: 1 addition & 1 deletion storage/aptosdb/src/db/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ pub fn verify_committed_transactions(
.try_as_signed_user_txn()
.unwrap();
let txn_with_proof = db
.get_transaction_by_hash(txn_to_commit.transaction().hash(), ledger_version, true)
.get_transaction_by_hash(txn_to_commit.transaction().hash(), true)
.unwrap()
.unwrap();
assert_eq!(
Expand Down
3 changes: 3 additions & 0 deletions storage/aptosdb/src/ledger_db/transaction_db_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ proptest! {
let hash = txn.hash();
prop_assert_eq!(transaction_db.get_transaction(version as Version).unwrap(), txn);
prop_assert_eq!(transaction_db.get_transaction_version_by_hash(&hash).unwrap(), Some(version as Version));
if version > 0 {
prop_assert_eq!(transaction_db.get_transaction_version_by_hash(&hash).unwrap(), None);
}
}

prop_assert!(transaction_db.get_transaction(num_txns as Version).is_err());
Expand Down
1 change: 0 additions & 1 deletion storage/storage-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ pub trait DbReader: Send + Sync {
fn get_transaction_by_hash(
&self,
hash: HashValue,
ledger_version: Version,
fetch_events: bool,
) -> Result<Option<TransactionWithProof>>;

Expand Down

0 comments on commit ee84fb4

Please sign in to comment.