-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Integrate the new pre-confirmation signing task adapters #2784
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
Changes from 58 commits
ca5f695
c76d4b6
b91726e
eb315e1
e5817e8
e34311a
efff269
fa4f651
a934075
aa6310f
9f6ba77
61e479f
842b3e6
03ec51f
d940d01
4a02950
b2fbe7f
ccb97e1
c7e9662
01e81e2
6723485
5bfea01
729972f
287283e
78dec7c
0440743
9c156c5
f9d8a46
7ccd113
6638691
c7cc9a1
703da90
d235932
fb7058c
393e0d7
502eb74
cad5445
12f853f
d0505cb
cb4e69a
648cb0e
7b145dd
91a5ac0
a8a37e3
f5f5c1e
a381b9a
6f196ad
cfed22f
22eaa46
d57971d
29487a9
4f04933
b393ee9
6fa24d6
cb39a1c
324979b
ca53bf5
cef8b12
e84a385
291d458
eab31c4
5bd14eb
5ad9c1a
18590a9
5a4fc12
5eaaef8
da350d8
40a927d
4969d67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Integrate the pre conf signature task into the main consensus task |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,26 +4,67 @@ use fuel_core_poa::pre_confirmation_signature_service::{ | |
| Error as PoaError, | ||
| Result as PoAResult, | ||
| }, | ||
| tx_receiver::TxReceiver, | ||
| tx_receiver::{ | ||
| TxReceiver, | ||
| TxSender, | ||
| }, | ||
| }; | ||
| use fuel_core_types::{ | ||
| fuel_tx::TxId, | ||
| services::p2p::PreconfirmationStatus, | ||
| }; | ||
|
|
||
| pub struct MPSCTxReceiver<T> { | ||
| sender: tokio::sync::mpsc::Sender<T>, | ||
| receiver: tokio::sync::mpsc::Receiver<T>, | ||
| } | ||
|
|
||
| impl Default for MPSCTxReceiver<Vec<(TxId, PreconfirmationStatus)>> { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| impl<T> MPSCTxReceiver<T> { | ||
| pub fn new() -> Self { | ||
| let (sender, receiver) = tokio::sync::mpsc::channel(1); | ||
|
||
| MPSCTxReceiver { sender, receiver } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct MPSCTxSender<T> { | ||
xgreenx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sender: tokio::sync::mpsc::Sender<T>, | ||
| } | ||
|
|
||
| impl TxReceiver for MPSCTxReceiver<Vec<(TxId, PreconfirmationStatus)>> { | ||
| type Txs = Preconfirmations; | ||
| type Sender = MPSCTxSender<Vec<(TxId, PreconfirmationStatus)>>; | ||
|
|
||
| async fn receive(&mut self) -> PoAResult<Self::Txs> { | ||
| self.receiver.recv().await.ok_or(PoaError::TxReceiver( | ||
| "Failed to receive transaction, channel closed".to_string(), | ||
| )) | ||
| } | ||
|
|
||
| fn get_sender(&self) -> Self::Sender { | ||
| MPSCTxSender { | ||
| sender: self.sender.clone(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TxSender for MPSCTxSender<Vec<(TxId, PreconfirmationStatus)>> { | ||
| type Txs = Preconfirmations; | ||
|
|
||
| async fn send(&mut self, txs: Self::Txs) -> PoAResult<()> { | ||
| self.sender | ||
| .send(txs) | ||
| .await | ||
| .map_err(|e| PoaError::TxReceiver(format!("{}", e))) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| #![allow(non_snake_case)] | ||
|
|
@@ -33,7 +74,6 @@ mod tests { | |
| #[tokio::test] | ||
| async fn receive__gets_what_is_sent_through_channel() { | ||
| // given | ||
| let (sender, receiver) = tokio::sync::mpsc::channel(1); | ||
| let txs = vec![ | ||
| ( | ||
| TxId::default(), | ||
|
|
@@ -49,7 +89,8 @@ mod tests { | |
| ), | ||
| ]; | ||
|
|
||
| let mut receiver = MPSCTxReceiver { receiver }; | ||
| let mut receiver = MPSCTxReceiver::new(); | ||
| let mut sender = receiver.get_sender(); | ||
|
|
||
| // when | ||
| sender.send(txs.clone()).await.unwrap(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.