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

Backport #309 #312

Merged
merged 3 commits into from
May 30, 2023
Merged
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
12 changes: 0 additions & 12 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ tokio = { version = "~1.14.1", features = ["full"] }
tokio-stream = "0.1.8"
tonic = { version = "0.5.2", features = ["tls"] }
trees = "0.4.2"
uuid = { version = "1.0.0", features = ["v4", "fast-rng"] }

[dev-dependencies]
matches = "0.1.9"
Expand Down
5 changes: 2 additions & 3 deletions core/src/bundle_account_locker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ mod tests {
system_transaction::transfer, transaction::VersionedTransaction,
},
std::{collections::HashSet, sync::Arc},
uuid::Uuid,
};

#[test]
Expand Down Expand Up @@ -266,11 +265,11 @@ mod tests {

let packet_bundle0 = PacketBundle {
batch: PacketBatch::new(vec![Packet::from_data(None, &tx0).unwrap()]),
uuid: Uuid::new_v4(),
bundle_id: tx0.signatures[0].to_string(),
};
let packet_bundle1 = PacketBundle {
batch: PacketBatch::new(vec![Packet::from_data(None, &tx1).unwrap()]),
uuid: Uuid::new_v4(),
bundle_id: tx1.signatures[0].to_string(),
};

let mut transaction_errors = TransactionErrorMetrics::default();
Expand Down
107 changes: 55 additions & 52 deletions core/src/bundle_sanitizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn get_sanitized_bundle(

Ok(SanitizedBundle {
transactions,
uuid: packet_bundle.uuid,
bundle_id: packet_bundle.bundle_id.clone(),
})
}

Expand Down Expand Up @@ -167,16 +167,16 @@ mod tests {
transaction_error_metrics::TransactionErrorMetrics,
},
solana_sdk::{
bundle::sanitized::derive_bundle_id,
hash::Hash,
instruction::Instruction,
packet::Packet,
pubkey::Pubkey,
signature::{Keypair, Signer},
system_transaction::transfer,
transaction::{SanitizedTransaction, Transaction, VersionedTransaction},
transaction::{Transaction, VersionedTransaction},
},
std::{collections::HashSet, sync::Arc},
uuid::Uuid,
};

#[test]
Expand All @@ -198,10 +198,12 @@ mod tests {
genesis_config.hash(),
));
let packet = Packet::from_data(None, &tx).unwrap();
let tx_signature = tx.signatures[0];
let bundle_id = derive_bundle_id(&[tx]);

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet]),
uuid: Uuid::new_v4(),
bundle_id,
};

let mut transaction_errors = TransactionErrorMetrics::default();
Expand All @@ -214,10 +216,7 @@ mod tests {
)
.unwrap();
assert_eq!(sanitized_bundle.transactions.len(), 1);
assert_eq!(
sanitized_bundle.transactions[0].signature(),
&tx.signatures[0]
);
assert_eq!(sanitized_bundle.transactions[0].signature(), &tx_signature);
}

#[test]
Expand All @@ -239,10 +238,11 @@ mod tests {
genesis_config.hash(),
));
let packet = Packet::from_data(None, &tx).unwrap();
let bundle_id = derive_bundle_id(&[tx]);

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet]),
uuid: Uuid::new_v4(),
bundle_id,
};

let consensus_accounts_cache = HashSet::from([kp.pubkey()]);
Expand Down Expand Up @@ -276,11 +276,12 @@ mod tests {
genesis_config.hash(),
));
let packet = Packet::from_data(None, &tx).unwrap();
let bundle_id = derive_bundle_id(&[tx]);

// bundle with a duplicate transaction
let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet.clone(), packet]),
uuid: Uuid::new_v4(),
bundle_id,
};

// fails to pop because bundle it locks the same transaction twice
Expand Down Expand Up @@ -310,10 +311,11 @@ mod tests {
let tx =
VersionedTransaction::from(transfer(&mint_keypair, &kp.pubkey(), 1, Hash::default()));
let packet = Packet::from_data(None, &tx).unwrap();
let bundle_id = derive_bundle_id(&[tx]);

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet.clone(), packet]),
uuid: Uuid::new_v4(),
bundle_id,
};

// fails to pop because bundle has bad blockhash
Expand Down Expand Up @@ -347,10 +349,11 @@ mod tests {
genesis_config.hash(),
));
let packet = Packet::from_data(None, &tx).unwrap();
let bundle_id = derive_bundle_id(&[tx]);

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet.clone()]),
uuid: Uuid::new_v4(),
bundle_id: bundle_id.clone(),
};

let mut transaction_errors = TransactionErrorMetrics::default();
Expand All @@ -376,7 +379,7 @@ mod tests {
// try to process the same one again shall fail
let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet]),
uuid: Uuid::new_v4(),
bundle_id,
};

assert!(get_sanitized_bundle(
Expand Down Expand Up @@ -406,24 +409,23 @@ mod tests {
});

let kp = Keypair::new();
let tx =
SanitizedTransaction::try_from_legacy_transaction(Transaction::new_signed_with_payer(
&[Instruction::new_with_bytes(
tip_manager.tip_payment_program_id(),
&[0],
vec![],
)],
Some(&kp.pubkey()),
&[&kp],
genesis_config.hash(),
))
.unwrap();

let packet = Packet::from_data(None, &tx.to_versioned_transaction()).unwrap();
let tx = VersionedTransaction::from(Transaction::new_signed_with_payer(
&[Instruction::new_with_bytes(
tip_manager.tip_payment_program_id(),
&[0],
vec![],
)],
Some(&kp.pubkey()),
&[&kp],
genesis_config.hash(),
));
tx.sanitize(false).unwrap();
let packet = Packet::from_data(None, &tx).unwrap();
let bundle_id = derive_bundle_id(&[tx]);

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet]),
uuid: Uuid::new_v4(),
bundle_id,
};

// fails to pop because bundle mentions tip program
Expand All @@ -445,20 +447,19 @@ mod tests {
let bank = Arc::new(Bank::new_no_wallclock_throttle_for_tests(&genesis_config));

let kp = Keypair::new();
let tx =
SanitizedTransaction::try_from_legacy_transaction(Transaction::new_signed_with_payer(
&[create_lookup_table(kp.pubkey(), kp.pubkey(), bank.slot()).0],
Some(&kp.pubkey()),
&[&kp],
genesis_config.hash(),
))
.unwrap();

let packet = Packet::from_data(None, &tx.to_versioned_transaction()).unwrap();
let tx = VersionedTransaction::from(Transaction::new_signed_with_payer(
&[create_lookup_table(kp.pubkey(), kp.pubkey(), bank.slot()).0],
Some(&kp.pubkey()),
&[&kp],
genesis_config.hash(),
));
tx.sanitize(false).unwrap();
let packet = Packet::from_data(None, &tx).unwrap();
let bundle_id = derive_bundle_id(&[tx]);

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet]),
uuid: Uuid::new_v4(),
bundle_id,
};

let mut transaction_errors = TransactionErrorMetrics::default();
Expand All @@ -480,7 +481,7 @@ mod tests {

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![]),
uuid: Uuid::new_v4(),
bundle_id: String::default(),
};
// fails to pop because empty bundle
let mut transaction_errors = TransactionErrorMetrics::default();
Expand All @@ -506,18 +507,20 @@ mod tests {

let kp = Keypair::new();

let packets = (0..MAX_PACKETS_PER_BUNDLE + 1).map(|i| {
let tx = VersionedTransaction::from(transfer(
&mint_keypair,
&kp.pubkey(),
i as u64,
genesis_config.hash(),
));
Packet::from_data(None, &tx).unwrap()
});
let txs = (0..MAX_PACKETS_PER_BUNDLE + 1)
.map(|i| {
VersionedTransaction::from(transfer(
&mint_keypair,
&kp.pubkey(),
i as u64,
genesis_config.hash(),
))
})
.collect::<Vec<_>>();
let packets = txs.iter().map(|tx| Packet::from_data(None, tx).unwrap());
let packet_bundle = PacketBundle {
batch: PacketBatch::new(packets.collect()),
uuid: Uuid::new_v4(),
bundle_id: derive_bundle_id(&txs),
};
// fails to pop because too many packets in a bundle
let mut transaction_errors = TransactionErrorMetrics::default();
Expand Down Expand Up @@ -554,7 +557,7 @@ mod tests {

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet]),
uuid: Uuid::new_v4(),
bundle_id: derive_bundle_id(&[tx]),
};

// fails to pop because one of the packets is marked as discard
Expand Down Expand Up @@ -599,7 +602,7 @@ mod tests {

let packet_bundle = PacketBundle {
batch: PacketBatch::new(vec![packet]),
uuid: Uuid::new_v4(),
bundle_id: derive_bundle_id(&[tx]),
};
let mut transaction_errors = TransactionErrorMetrics::default();
assert!(get_sanitized_bundle(
Expand Down
Loading