Refactor: Sanitized transaction creation (#23558)
* Refactor: SanitizedTransaction::try_create optionally computes hash * Refactor: Add SimpleAddressLoader
This commit is contained in:
@ -70,7 +70,8 @@ use {
|
||||
system_instruction,
|
||||
sysvar::stake_history,
|
||||
transaction::{
|
||||
self, AddressLoader, SanitizedTransaction, TransactionError, VersionedTransaction,
|
||||
self, AddressLoader, MessageHash, SanitizedTransaction, TransactionError,
|
||||
VersionedTransaction,
|
||||
},
|
||||
},
|
||||
solana_send_transaction_service::{
|
||||
@ -4277,10 +4278,9 @@ where
|
||||
|
||||
fn sanitize_transaction(
|
||||
transaction: VersionedTransaction,
|
||||
address_loader: &impl AddressLoader,
|
||||
address_loader: impl AddressLoader,
|
||||
) -> Result<SanitizedTransaction> {
|
||||
let message_hash = transaction.message.hash();
|
||||
SanitizedTransaction::try_create(transaction, message_hash, None, address_loader)
|
||||
SanitizedTransaction::try_create(transaction, MessageHash::Compute, None, address_loader)
|
||||
.map_err(|err| Error::invalid_params(format!("invalid transaction: {}", err)))
|
||||
}
|
||||
|
||||
@ -4420,7 +4420,7 @@ pub mod tests {
|
||||
system_program, system_transaction,
|
||||
timing::slot_duration_from_slots_per_year,
|
||||
transaction::{
|
||||
self, DisabledAddressLoader, Transaction, TransactionError, TransactionVersion,
|
||||
self, SimpleAddressLoader, Transaction, TransactionError, TransactionVersion,
|
||||
},
|
||||
},
|
||||
solana_transaction_status::{
|
||||
@ -7823,7 +7823,8 @@ pub mod tests {
|
||||
.to_string(),
|
||||
);
|
||||
assert_eq!(
|
||||
sanitize_transaction(unsanitary_versioned_tx, &DisabledAddressLoader).unwrap_err(),
|
||||
sanitize_transaction(unsanitary_versioned_tx, SimpleAddressLoader::Disabled)
|
||||
.unwrap_err(),
|
||||
expect58
|
||||
);
|
||||
}
|
||||
@ -7843,9 +7844,9 @@ pub mod tests {
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
sanitize_transaction(versioned_tx, &DisabledAddressLoader).unwrap_err(),
|
||||
sanitize_transaction(versioned_tx, SimpleAddressLoader::Disabled).unwrap_err(),
|
||||
Error::invalid_params(
|
||||
"invalid transaction: Transaction version is unsupported".to_string(),
|
||||
"invalid transaction: Transaction loads an address table account that doesn't exist".to_string(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -225,7 +225,8 @@ pub(crate) mod tests {
|
||||
signature::{Keypair, Signature, Signer},
|
||||
system_transaction,
|
||||
transaction::{
|
||||
DisabledAddressLoader, SanitizedTransaction, Transaction, VersionedTransaction,
|
||||
MessageHash, SanitizedTransaction, SimpleAddressLoader, Transaction,
|
||||
VersionedTransaction,
|
||||
},
|
||||
},
|
||||
solana_transaction_status::{
|
||||
@ -304,14 +305,13 @@ pub(crate) mod tests {
|
||||
Blockstore::open(&ledger_path).expect("Expected to be able to open database ledger");
|
||||
let blockstore = Arc::new(blockstore);
|
||||
|
||||
let message_hash = Hash::new_unique();
|
||||
let transaction = build_test_transaction_legacy();
|
||||
let transaction = VersionedTransaction::from(transaction);
|
||||
let transaction = SanitizedTransaction::try_create(
|
||||
transaction,
|
||||
message_hash,
|
||||
Some(true),
|
||||
&DisabledAddressLoader,
|
||||
MessageHash::Compute,
|
||||
None,
|
||||
SimpleAddressLoader::Disabled,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
Reference in New Issue
Block a user