Store versioned transactions in the ledger, disabled by default (#19139)
* Add support for versioned transactions, but disable by default * merge conflicts * trent's feedback * bump Cargo.lock * Fix transaction error encoding * Rename legacy_transaction method * cargo clippy * Clean up casts, int arithmetic, and unused methods * Check for duplicates in sanitized message conversion * fix clippy * fix new test * Fix bpf conditional compilation for message module
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
use crate::bank::Bank;
|
||||
use solana_sdk::{
|
||||
sanitized_transaction::SanitizedTransaction,
|
||||
transaction::{Result, Transaction},
|
||||
use {
|
||||
crate::bank::Bank,
|
||||
solana_sdk::transaction::{Result, SanitizedTransaction},
|
||||
std::borrow::Cow,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Deref;
|
||||
|
||||
// Represents the results of trying to lock a set of accounts
|
||||
pub struct TransactionBatch<'a, 'b> {
|
||||
lock_results: Vec<Result<()>>,
|
||||
bank: &'a Bank,
|
||||
sanitized_txs: Cow<'b, [SanitizedTransaction<'b>]>,
|
||||
sanitized_txs: Cow<'b, [SanitizedTransaction]>,
|
||||
pub(crate) needs_unlock: bool,
|
||||
}
|
||||
|
||||
@@ -18,7 +16,7 @@ impl<'a, 'b> TransactionBatch<'a, 'b> {
|
||||
pub fn new(
|
||||
lock_results: Vec<Result<()>>,
|
||||
bank: &'a Bank,
|
||||
sanitized_txs: Cow<'b, [SanitizedTransaction<'b>]>,
|
||||
sanitized_txs: Cow<'b, [SanitizedTransaction]>,
|
||||
) -> Self {
|
||||
assert_eq!(lock_results.len(), sanitized_txs.len());
|
||||
Self {
|
||||
@@ -37,10 +35,6 @@ impl<'a, 'b> TransactionBatch<'a, 'b> {
|
||||
&self.sanitized_txs
|
||||
}
|
||||
|
||||
pub fn transactions_iter(&self) -> impl Iterator<Item = &Transaction> {
|
||||
self.sanitized_txs.iter().map(Deref::deref)
|
||||
}
|
||||
|
||||
pub fn bank(&self) -> &Bank {
|
||||
self.bank
|
||||
}
|
||||
@@ -58,38 +52,33 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::genesis_utils::{create_genesis_config_with_leader, GenesisConfigInfo};
|
||||
use solana_sdk::{signature::Keypair, system_transaction};
|
||||
use std::convert::TryFrom;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[test]
|
||||
fn test_transaction_batch() {
|
||||
let (bank, txs) = setup();
|
||||
|
||||
// Test getting locked accounts
|
||||
let batch = bank.prepare_batch(txs.iter()).unwrap();
|
||||
let batch = bank.prepare_sanitized_batch(&txs);
|
||||
|
||||
// Grab locks
|
||||
assert!(batch.lock_results().iter().all(|x| x.is_ok()));
|
||||
|
||||
// Trying to grab locks again should fail
|
||||
let batch2 = bank.prepare_batch(txs.iter()).unwrap();
|
||||
let batch2 = bank.prepare_sanitized_batch(&txs);
|
||||
assert!(batch2.lock_results().iter().all(|x| x.is_err()));
|
||||
|
||||
// Drop the first set of locks
|
||||
drop(batch);
|
||||
|
||||
// Now grabbing locks should work again
|
||||
let batch2 = bank.prepare_batch(txs.iter()).unwrap();
|
||||
let batch2 = bank.prepare_sanitized_batch(&txs);
|
||||
assert!(batch2.lock_results().iter().all(|x| x.is_ok()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_simulation_batch() {
|
||||
let (bank, txs) = setup();
|
||||
let txs = txs
|
||||
.into_iter()
|
||||
.map(SanitizedTransaction::try_from)
|
||||
.collect::<Result<Vec<_>>>()
|
||||
.unwrap();
|
||||
|
||||
// Prepare batch without locks
|
||||
let batch = bank.prepare_simulation_batch(txs[0].clone());
|
||||
@@ -104,7 +93,7 @@ mod tests {
|
||||
assert!(batch3.lock_results().iter().all(|x| x.is_ok()));
|
||||
}
|
||||
|
||||
fn setup() -> (Bank, Vec<Transaction>) {
|
||||
fn setup() -> (Bank, Vec<SanitizedTransaction>) {
|
||||
let dummy_leader_pubkey = solana_sdk::pubkey::new_rand();
|
||||
let GenesisConfigInfo {
|
||||
genesis_config,
|
||||
@@ -118,8 +107,12 @@ mod tests {
|
||||
let pubkey2 = solana_sdk::pubkey::new_rand();
|
||||
|
||||
let txs = vec![
|
||||
system_transaction::transfer(&mint_keypair, &pubkey, 1, genesis_config.hash()),
|
||||
system_transaction::transfer(&keypair2, &pubkey2, 1, genesis_config.hash()),
|
||||
system_transaction::transfer(&mint_keypair, &pubkey, 1, genesis_config.hash())
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
system_transaction::transfer(&keypair2, &pubkey2, 1, genesis_config.hash())
|
||||
.try_into()
|
||||
.unwrap(),
|
||||
];
|
||||
|
||||
(bank, txs)
|
||||
|
Reference in New Issue
Block a user