Simplify replay vote tracking by using packet metadata (#21112)
This commit is contained in:
@ -22,6 +22,7 @@ use {
|
||||
pub struct SanitizedTransaction {
|
||||
message: SanitizedMessage,
|
||||
message_hash: Hash,
|
||||
is_simple_vote_tx: bool,
|
||||
signatures: Vec<Signature>,
|
||||
}
|
||||
|
||||
@ -41,6 +42,7 @@ impl SanitizedTransaction {
|
||||
pub fn try_create(
|
||||
tx: VersionedTransaction,
|
||||
message_hash: Hash,
|
||||
is_simple_vote_tx: Option<bool>,
|
||||
address_mapper: impl Fn(&v0::Message) -> Result<MappedAddresses>,
|
||||
) -> Result<Self> {
|
||||
tx.sanitize()?;
|
||||
@ -58,9 +60,15 @@ impl SanitizedTransaction {
|
||||
return Err(TransactionError::AccountLoadedTwice);
|
||||
}
|
||||
|
||||
let is_simple_vote_tx = is_simple_vote_tx.unwrap_or_else(|| {
|
||||
let mut ix_iter = message.program_instructions_iter();
|
||||
ix_iter.next().map(|(program_id, _ix)| program_id) == Some(&crate::vote::program::id())
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
message,
|
||||
message_hash,
|
||||
is_simple_vote_tx,
|
||||
signatures,
|
||||
})
|
||||
}
|
||||
@ -76,6 +84,7 @@ impl SanitizedTransaction {
|
||||
Self {
|
||||
message_hash: tx.message.hash(),
|
||||
message: SanitizedMessage::Legacy(tx.message),
|
||||
is_simple_vote_tx: false,
|
||||
signatures: tx.signatures,
|
||||
}
|
||||
}
|
||||
@ -106,6 +115,11 @@ impl SanitizedTransaction {
|
||||
&self.message_hash
|
||||
}
|
||||
|
||||
/// Returns true if this transaction is a simple vote
|
||||
pub fn is_simple_vote_transaction(&self) -> bool {
|
||||
self.is_simple_vote_tx
|
||||
}
|
||||
|
||||
/// Convert this sanitized transaction into a versioned transaction for
|
||||
/// recording in the ledger.
|
||||
pub fn to_versioned_transaction(&self) -> VersionedTransaction {
|
||||
|
Reference in New Issue
Block a user