-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Implement TxSink abstraction (#1204)
## What ❔ Implements a new abstraction: `TxSink` to be used in `TxSender`. Right now we have to use either `TxProxy` or master pool (e.g. only one component), but the code allows invalid configurations. Moreover, mixing two approaches on the `TxSender` level is unreasonably clunky and complex. Having a single abstraction seems to be a better approach. Additionally, it's a prerequisite for implementing an API layer for the framework.⚠️ There are quite a few possibilities for improvements here, but I suggest not going down the rabbit hole. As long as it's perceived as an incremental improvement, let's not focus on the adjacent code. We can always revisit this place next time it becomes problematic.
- Loading branch information
Showing
10 changed files
with
278 additions
and
143 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -902,4 +902,6 @@ reimplementation | |
composability | ||
md5 | ||
shivini | ||
balancer | ||
balancer | ||
lookups | ||
stateful |
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
37 changes: 37 additions & 0 deletions
37
core/lib/zksync_core/src/api_server/tx_sender/master_pool_sink.rs
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,37 @@ | ||
use zksync_dal::{transactions_dal::L2TxSubmissionResult, ConnectionPool}; | ||
use zksync_types::{fee::TransactionExecutionMetrics, l2::L2Tx}; | ||
|
||
use super::{tx_sink::TxSink, SubmitTxError}; | ||
use crate::metrics::{TxStage, APP_METRICS}; | ||
|
||
/// Wrapper for the master DB pool that allows to submit transactions to the mempool. | ||
#[derive(Debug)] | ||
pub struct MasterPoolSink { | ||
master_pool: ConnectionPool, | ||
} | ||
|
||
impl MasterPoolSink { | ||
pub fn new(master_pool: ConnectionPool) -> Self { | ||
Self { master_pool } | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl TxSink for MasterPoolSink { | ||
async fn submit_tx( | ||
&self, | ||
tx: L2Tx, | ||
execution_metrics: TransactionExecutionMetrics, | ||
) -> Result<L2TxSubmissionResult, SubmitTxError> { | ||
let submission_res_handle = self | ||
.master_pool | ||
.access_storage_tagged("api") | ||
.await? | ||
.transactions_dal() | ||
.insert_transaction_l2(tx, execution_metrics) | ||
.await; | ||
|
||
APP_METRICS.processed_txs[&TxStage::Mempool(submission_res_handle)].inc(); | ||
Ok(submission_res_handle) | ||
} | ||
} |
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
Oops, something went wrong.