-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Execution] Add TransactionDeduper trait and implementation using (ha…
…sh, signature) (#8367) (#8458) Cherry-pick #8367. Expected to be a noop until onchain config is changed. ### Description Adding TransactionDeduper trait and an implementation. The dedup is done within a block, just before transaction shuffle. It's guarded by an onchain config. The purpose is to not send duplicate transactions to execution. While execution correctness is not affected by duplicates (and other work removed false error logs that fired due to them), it's possible that duplicate transactions could hurt throughput of parallel execution. By deduping ahead of time, we don't have to worry about that. The implementation finds duplicates by matching (raw txn bcs hash, signature). Because calculating hash can be relatively expensive, it is only done when a shallow match is found of (account, seq_no), and it's done in parallel. Overhead (as seen on forge): * When there are no duplicates, the dedup is negligible -- it takes ~2ms per second. * When there are ~100 duplicates per block, the dedup takes ~10ms per second. ### Test Plan Added unit tests.
- Loading branch information
Showing
15 changed files
with
502 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright © Aptos Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use crate::txn_hash_and_authenticator_deduper::TxnHashAndAuthenticatorDeduper; | ||
use aptos_logger::info; | ||
use aptos_types::{on_chain_config::TransactionDeduperType, transaction::SignedTransaction}; | ||
use std::sync::Arc; | ||
|
||
/// Interface to dedup transactions. The dedup filters duplicate transactions within a block. | ||
pub trait TransactionDeduper: Send + Sync { | ||
fn dedup(&self, txns: Vec<SignedTransaction>) -> Vec<SignedTransaction>; | ||
} | ||
|
||
/// No Op Deduper to maintain backward compatibility | ||
struct NoOpDeduper {} | ||
|
||
impl TransactionDeduper for NoOpDeduper { | ||
fn dedup(&self, txns: Vec<SignedTransaction>) -> Vec<SignedTransaction> { | ||
txns | ||
} | ||
} | ||
|
||
pub fn create_transaction_deduper( | ||
deduper_type: TransactionDeduperType, | ||
) -> Arc<dyn TransactionDeduper> { | ||
match deduper_type { | ||
TransactionDeduperType::NoDedup => Arc::new(NoOpDeduper {}), | ||
TransactionDeduperType::TxnHashAndAuthenticatorV1 => { | ||
info!("Using simple hash set transaction deduper"); | ||
Arc::new(TxnHashAndAuthenticatorDeduper::new()) | ||
}, | ||
} | ||
} |
Oops, something went wrong.