Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Not for review] Add new TransactionPayload variant for orderless txns #15115

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions Cargo.lock

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

95 changes: 89 additions & 6 deletions api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use crate::{
};
use anyhow::{anyhow, bail, ensure, format_err, Context as AnyhowContext, Result};
use aptos_api_types::{
AptosErrorCode, AsConverter, BcsBlock, GasEstimation, LedgerInfo, ResourceGroup,
TransactionOnChainData,
transaction::ReplayProtector, AptosErrorCode, AsConverter, BcsBlock, GasEstimation, LedgerInfo, ResourceGroup, TransactionOnChainData, TransactionSummary
};
use aptos_config::config::{GasEstimationConfig, NodeConfig, RoleType};
use aptos_crypto::HashValue;
Expand All @@ -34,7 +33,7 @@ use aptos_types::{
chain_id::ChainId,
contract_event::{ContractEvent, ContractEventV1, EventWithVersion},
event::EventKey,
indexer::indexer_db_reader::IndexerReader,
indexer::indexer_db_reader::{IndexedTransactionSummary, IndexerReader},
ledger_info::LedgerInfoWithSignatures,
on_chain_config::{GasSchedule, GasScheduleV2, OnChainConfig, OnChainExecutionConfig},
state_store::{
Expand Down Expand Up @@ -786,6 +785,41 @@ impl Context {
Ok(txns)
}

pub fn render_transaction_summaries<E: InternalError>(
&self,
ledger_info: &LedgerInfo,
data: Vec<IndexedTransactionSummary>,
) -> Result<Vec<aptos_api_types::TransactionSummary>, E> {
if data.is_empty() {
return Ok(vec![]);
}

// Question: Is it worth adding timestamp based on the version here? Or should we rather just store the timestamp in IndexedTransactionSummary.
let txn_summaries: Vec<aptos_api_types::TransactionSummary> = data
.into_iter()
.map(|t| {
// let timestamp = self.db.get_block_timestamp(t.version)?;
Ok(
TransactionSummary {
sender: t.sender.into(),
version: t.version.into(),
transaction_hash: t.transaction_hash.into(),
replay_protector: match t.replay_protector {
aptos_types::transaction::ReplayProtector::Nonce(nonce) => ReplayProtector::Nonce(nonce.into()),
aptos_types::transaction::ReplayProtector::SequenceNumber(seq_num) => ReplayProtector::SequenceNumber(seq_num.into())
},
// timestamp: timestamp.into(),
}
)
})
.collect::<Result<_, anyhow::Error>>()
.context("Failed to convert transaction summary data from storage")
.map_err(|err| {
E::internal_with_code(err, AptosErrorCode::InternalError, ledger_info)
})?;
Ok(txn_summaries)
}

pub fn get_transactions(
&self,
start_version: u64,
Expand Down Expand Up @@ -833,7 +867,7 @@ impl Context {
.collect()
}

pub fn get_account_transactions<E: NotFoundError + InternalError>(
pub fn get_ordered_account_transactions<E: NotFoundError + InternalError>(
&self,
address: AccountAddress,
start_seq_number: Option<u64>,
Expand All @@ -854,7 +888,7 @@ impl Context {
};

let txns_res = if !db_sharding_enabled(&self.node_config) {
self.db.get_account_transactions(
self.db.get_ordered_account_transactions(
address,
start_seq_number,
limit as u64,
Expand All @@ -868,7 +902,7 @@ impl Context {
.map_err(|err| {
E::internal_with_code(err, AptosErrorCode::InternalError, ledger_info)
})?
.get_account_transactions(
.get_ordered_account_transactions(
address,
start_seq_number,
limit as u64,
Expand All @@ -893,6 +927,55 @@ impl Context {
.map_err(|err| E::internal_with_code(err, AptosErrorCode::InternalError, ledger_info))
}

pub fn get_account_all_transaction_summaries<E: NotFoundError + InternalError>(
&self,
address: AccountAddress,
start_version: Option<u64>,
end_version: Option<u64>,
limit: u16,
ledger_version: u64,
ledger_info: &LedgerInfo,
) -> Result<Vec<IndexedTransactionSummary>, E> {
let txns_res = if !db_sharding_enabled(&self.node_config) {
self.db.get_account_all_transaction_summaries(
address,
start_version,
end_version,
limit as u64,
ledger_version,
)
} else {
self.indexer_reader
.as_ref()
.ok_or_else(|| anyhow!("Indexer reader is None"))
.map_err(|err| {
E::internal_with_code(err, AptosErrorCode::InternalError, ledger_info)
})?
.get_account_all_transaction_summaries(
address,
start_version,
end_version,
limit as u64,
ledger_version,
)
.map_err(|e| AptosDbError::Other(e.to_string()))
};
txns_res
.context("Failed to retrieve account transaction summaries")
.map_err(|err| {
E::internal_with_code(err, AptosErrorCode::InternalError, ledger_info)
})
// .map(|txns| txns.iter().map(|t| TransactionSummary {
// sender: t.sender.into(),
// version: t.version.into(),
// transaction_hash: t.transaction_hash.into(),
// replay_protector: match t.replay_protector {
// aptos_types::transaction::ReplayProtector::Nonce(nonce) => ReplayProtector::Nonce(nonce.into()),
// aptos_types::transaction::ReplayProtector::SequenceNumber(seq_num) => ReplayProtector::SequenceNumber(seq_num.into())
// },
// }).collect())
}

pub fn get_transaction_by_hash(
&self,
hash: HashValue,
Expand Down
4 changes: 2 additions & 2 deletions api/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn new_test_context_with_config(test_name: String, node_config: NodeConfig) -> T
fn new_test_context_with_db_sharding_and_internal_indexer(test_name: String) -> TestContext {
let mut node_config = NodeConfig::default();
node_config.storage.rocksdb_configs.enable_storage_sharding = true;
node_config.indexer_db_config = InternalIndexerDBConfig::new(true, true, true, 0, true, 10);
node_config.indexer_db_config = InternalIndexerDBConfig::new(true, true, true, true, 0, true, 10);
let test_context = super_new_test_context(test_name, node_config, false, None);
let _ = test_context
.get_indexer_reader()
Expand All @@ -52,6 +52,6 @@ fn new_test_context_with_sharding_and_delayed_internal_indexer(
) -> TestContext {
let mut node_config = NodeConfig::default();
node_config.storage.rocksdb_configs.enable_storage_sharding = true;
node_config.indexer_db_config = InternalIndexerDBConfig::new(true, true, true, 0, true, 1);
node_config.indexer_db_config = InternalIndexerDBConfig::new(true, true, true, true, 0, true, 1);
super_new_test_context(test_name, node_config, false, end_version)
}
Loading
Loading