Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Support sending VersionedTransaction in tests #22862

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

31 changes: 30 additions & 1 deletion banks-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use {
commitment_config::CommitmentLevel,
message::Message,
signature::Signature,
transaction::{self, Transaction},
transaction::{self, Transaction, VersionedTransaction},
},
tarpc::{
client::{self, NewClient, RequestDispatch},
Expand Down Expand Up @@ -136,6 +136,17 @@ impl BanksClient {
.map_err(Into::into)
}

pub fn process_versioned_transaction_with_commitment_and_context(
&mut self,
ctx: Context,
transaction: VersionedTransaction,
commitment: CommitmentLevel,
) -> impl Future<Output = Result<Option<transaction::Result<()>>, BanksClientError>> + '_ {
self.inner
.process_versioned_transaction_with_commitment_and_context(ctx, transaction, commitment)
.map_err(Into::into)
}

pub fn get_account_with_commitment_and_context(
&mut self,
ctx: Context,
Expand Down Expand Up @@ -217,6 +228,24 @@ impl BanksClient {
})
}

/// Send a transaction and return after the transaction has been rejected or
/// reached the given level of commitment.
pub fn process_versioned_transaction_with_commitment(
&mut self,
transaction: VersionedTransaction,
commitment: CommitmentLevel,
) -> impl Future<Output = Result<(), BanksClientError>> + '_ {
let mut ctx = context::current();
ctx.deadline += Duration::from_secs(50);
self.process_versioned_transaction_with_commitment_and_context(ctx, transaction, commitment)
.map(|result| match result? {
None => Err(BanksClientError::ClientError(
"invalid blockhash or fee-payer",
)),
Some(transaction_result) => Ok(transaction_result?),
})
}

/// Send a transaction and return any preflight (sanitization or simulation) errors, or return
/// after the transaction has been rejected or reached the given level of commitment.
pub fn process_transaction_with_preflight_and_commitment(
Expand Down
6 changes: 5 additions & 1 deletion banks-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use {
message::Message,
pubkey::Pubkey,
signature::Signature,
transaction::{self, Transaction, TransactionError},
transaction::{self, Transaction, TransactionError, VersionedTransaction},
},
};

Expand Down Expand Up @@ -65,6 +65,10 @@ pub trait Banks {
transaction: Transaction,
commitment: CommitmentLevel,
) -> Option<transaction::Result<()>>;
async fn process_versioned_transaction_with_commitment_and_context(
transaction: VersionedTransaction,
commitment: CommitmentLevel,
) -> Option<transaction::Result<()>>;
async fn get_account_with_commitment_and_context(
address: Pubkey,
commitment: CommitmentLevel,
Expand Down
1 change: 1 addition & 0 deletions banks-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2021"
bincode = "1.3.3"
crossbeam-channel = "0.5"
futures = "0.3"
log = "0.4.11"
solana-banks-interface = { path = "../banks-interface", version = "=1.10.0" }
solana-runtime = { path = "../runtime", version = "=1.10.0" }
solana-sdk = { path = "../sdk", version = "=1.10.0" }
Expand Down
54 changes: 51 additions & 3 deletions banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
bincode::{deserialize, serialize},
crossbeam_channel::{unbounded, Receiver, Sender},
futures::{future, prelude::stream::StreamExt},
log::warn,
solana_banks_interface::{
Banks, BanksRequest, BanksResponse, BanksTransactionResultWithSimulation,
TransactionConfirmationStatus, TransactionSimulationDetails, TransactionStatus,
Expand All @@ -21,7 +22,7 @@ use {
message::{Message, SanitizedMessage},
pubkey::Pubkey,
signature::Signature,
transaction::{self, SanitizedTransaction, Transaction},
transaction::{self, SanitizedTransaction, Transaction, VersionedTransaction},
},
solana_send_transaction_service::{
send_transaction_service::{SendTransactionService, TransactionInfo},
Expand Down Expand Up @@ -79,12 +80,15 @@ impl BanksServer {
while let Ok(info) = transaction_receiver.try_recv() {
transaction_infos.push(info);
}
let transactions: Vec<_> = transaction_infos
let transactions: Vec<VersionedTransaction> = transaction_infos
.into_iter()
.map(|info| deserialize(&info.wire_transaction).unwrap())
.collect();
let bank = bank_forks.read().unwrap().working_bank();
let _ = bank.try_process_transactions(transactions.iter());
let res = bank.try_process_entry_transactions(transactions);
if let Err(err) = res {
warn!("failed to process transactions: {:?}", err);
}
}
}

Expand Down Expand Up @@ -161,6 +165,20 @@ fn verify_transaction(
}
}

fn verify_versioned_transaction(
transaction: &VersionedTransaction,
_feature_set: &Arc<FeatureSet>,
) -> transaction::Result<()> {
if let Err(err) = transaction.verify_and_hash_message() {
Err(err)
// TODO: Can't verify precompiles without looking up address map accounts...
//} else if let Err(err) = transaction.verify_precompiles(feature_set) {
// Err(err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if verify_precompiles is possible because program accounts are guaranteed to be in the static list?

} else {
Ok(())
}
}

#[tarpc::server]
impl Banks for BanksServer {
async fn send_transaction_with_context(self, _: Context, transaction: Transaction) {
Expand Down Expand Up @@ -314,6 +332,36 @@ impl Banks for BanksServer {
.await
}

async fn process_versioned_transaction_with_commitment_and_context(
self,
_: Context,
transaction: VersionedTransaction,
commitment: CommitmentLevel,
) -> Option<transaction::Result<()>> {
if let Err(err) =
verify_versioned_transaction(&transaction, &self.bank(commitment).feature_set)
{
return Some(Err(err));
}

let blockhash = &transaction.message.recent_blockhash();
let last_valid_block_height = self
.bank(commitment)
.get_blockhash_last_valid_block_height(blockhash)
.unwrap();
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
let info = TransactionInfo::new(
signature,
serialize(&transaction).unwrap(),
last_valid_block_height,
None,
None,
);
self.transaction_sender.send(info).unwrap();
self.poll_signature_status(&signature, blockhash, last_valid_block_height, commitment)
.await
}

async fn get_account_with_commitment_and_context(
self,
_: Context,
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3351,8 +3351,8 @@ impl Bank {
.into_iter()
.map(|tx| {
let message_hash = tx.message.hash();
SanitizedTransaction::try_create(tx, message_hash, None, |_| {
Err(TransactionError::UnsupportedVersion)
SanitizedTransaction::try_create(tx, message_hash, None, |lookups| {
self.load_lookup_table_addresses(lookups)
})
})
.collect::<Result<Vec<_>>>()?;
Expand Down
Loading