-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add new pre confirmed intermediate state in TxUpdateSender
#2845
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 2 commits
b4d3d5b
271b43f
f988fdb
15417af
1327b39
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 @@ | ||
| New status to manage the pre confirmation status send in `TxUpdateSender`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,20 +64,46 @@ pub(crate) fn validate_tx_update_stream_state( | |
| use State::*; | ||
| use StateTransitions::*; | ||
| match (state, transition) { | ||
| (Empty, AddMsg(TxStatusMessage::Status(s))) => { | ||
| if s.is_submitted() { | ||
| Initial(s) | ||
| } else { | ||
| // If not Submitted, it's an early success. | ||
| EarlySuccess(s) | ||
| (Empty, AddMsg(TxStatusMessage::Status(s))) => match s { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is pretty convoluted piece of code now :-/ I tried to create a flowchart based on the state transitions and it looks ✔️ for me. I'm attaching it here for future reviewers (I can't guarantee it's perfectly correct): stateDiagram-v2
[*] --> Empty
Empty --> Submitted: AddMsg(Submitted)
Empty --> Preconfirmed: AddMsg(PreConfAny)
Empty --> EarlySuccess: AddMsg(Other)
Empty --> Failed: AddMsg(Failed/Failure)
Empty --> Empty: Next
Submitted --> Submitted: AddMsg(Submitted)
Submitted --> Preconfirmed: AddMsg(PreConfAny)
Submitted --> Success: AddMsg(Other)
Submitted --> LateFailed: AddMsg(Failed/Failure)
Submitted --> Empty: Next
Preconfirmed --> Success: AddMsg(Any)
Preconfirmed --> LateFailed: AddMsg(Failed/Failure)
Preconfirmed --> Empty: Next
EarlySuccess --> Closed: Next
EarlySuccess --> EarlySuccess: Any
Success --> SenderClosed: Next
Success --> Success: Any
Failed --> Closed: Next
Failed --> Failed: Any
LateFailed --> Failed: Next
LateFailed --> LateFailed: Any
SenderClosed --> SenderClosed: Any
Closed --> Closed: Any
Empty --> Closed: CloseRecv
Submitted --> Closed: CloseRecv
Preconfirmed --> Closed: CloseRecv
EarlySuccess --> Closed: CloseRecv
Success --> Closed: CloseRecv
Failed --> Closed: CloseRecv
LateFailed --> Closed: CloseRecv
SenderClosed --> Closed: CloseRecv
|
||
| TransactionStatus::Submitted(s) => Submitted(TransactionStatus::Submitted(s)), | ||
| TransactionStatus::PreConfirmationSuccess(s) => { | ||
| Preconfirmed(TransactionStatus::PreConfirmationSuccess(s)) | ||
| } | ||
| } | ||
| TransactionStatus::PreConfirmationFailure(s) => { | ||
| Preconfirmed(TransactionStatus::PreConfirmationFailure(s)) | ||
| } | ||
| TransactionStatus::PreConfirmationSqueezedOut(s) => { | ||
| Preconfirmed(TransactionStatus::PreConfirmationSqueezedOut(s)) | ||
| } | ||
AurelienFT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| s => EarlySuccess(s), | ||
| }, | ||
| (Empty, AddMsg(TxStatusMessage::FailedStatus)) => Failed, | ||
| (Empty, AddFailure) => Failed, | ||
| (Empty | Initial(_), Next) => Empty, | ||
| (Initial(s1), AddMsg(TxStatusMessage::Status(s2))) => Success(s1, s2), | ||
| (Initial(s1), AddMsg(TxStatusMessage::FailedStatus)) => LateFailed(s1), | ||
| (Initial(s), AddFailure) => LateFailed(s), | ||
| (Empty | Submitted(_) | Preconfirmed(_), Next) => Empty, | ||
| ( | ||
| Submitted(_), | ||
| AddMsg(TxStatusMessage::Status(TransactionStatus::Submitted(s))), | ||
| ) => Submitted(TransactionStatus::Submitted(s)), | ||
AurelienFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ( | ||
| Submitted(_), | ||
| AddMsg(TxStatusMessage::Status(TransactionStatus::PreConfirmationSuccess(s))), | ||
| ) => Preconfirmed(TransactionStatus::PreConfirmationSuccess(s)), | ||
| ( | ||
| Submitted(_), | ||
| AddMsg(TxStatusMessage::Status(TransactionStatus::PreConfirmationFailure(s))), | ||
| ) => Preconfirmed(TransactionStatus::PreConfirmationFailure(s)), | ||
| ( | ||
| Submitted(_), | ||
| AddMsg(TxStatusMessage::Status( | ||
| TransactionStatus::PreConfirmationSqueezedOut(s), | ||
| )), | ||
| ) => Preconfirmed(TransactionStatus::PreConfirmationSqueezedOut(s)), | ||
AurelienFT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (Submitted(s1), AddMsg(TxStatusMessage::Status(s2))) => Success(s1, s2), | ||
| (Submitted(s1), AddMsg(TxStatusMessage::FailedStatus)) => LateFailed(s1), | ||
| (Submitted(s), AddFailure) => LateFailed(s), | ||
| (Preconfirmed(s1), AddMsg(TxStatusMessage::Status(s2))) => Success(s1, s2), | ||
| (Preconfirmed(s1), AddMsg(TxStatusMessage::FailedStatus)) => LateFailed(s1), | ||
| (Preconfirmed(s), AddFailure) => LateFailed(s), | ||
| (_, CloseRecv) => Closed, | ||
| (EarlySuccess(_) | Failed | SenderClosed(_), Next) => Closed, | ||
| (LateFailed(_), Next) => Failed, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,8 @@ impl From<TransactionStatus> for TxStatusMessage { | |
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub(super) enum State { | ||
AurelienFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Empty, | ||
| Initial(TransactionStatus), | ||
| Submitted(TransactionStatus), | ||
| Preconfirmed(TransactionStatus), | ||
| EarlySuccess(TransactionStatus), | ||
| Success(TransactionStatus, TransactionStatus), | ||
| Failed, | ||
|
|
@@ -86,12 +87,47 @@ impl TxUpdateStream { | |
| self.state = match state { | ||
| State::Empty => match msg { | ||
| TxStatusMessage::Status(TransactionStatus::Submitted(s)) => { | ||
| State::Initial(TransactionStatus::Submitted(s)) | ||
| State::Submitted(TransactionStatus::Submitted(s)) | ||
AurelienFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| TxStatusMessage::Status(TransactionStatus::PreConfirmationSuccess(s)) => { | ||
| State::Preconfirmed(TransactionStatus::PreConfirmationSuccess(s)) | ||
| } | ||
| TxStatusMessage::Status(TransactionStatus::PreConfirmationFailure(s)) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like another state machine, so again, here's the diagram which looks ✔️ stateDiagram-v2
[*] --> Empty
Empty --> Submitted : Msg-Status(Submitted(s))
Empty --> Preconfirmed : Msg-Status(PreConfirmationSuccess(s))
Empty --> Preconfirmed : Msg-Status(PreConfirmationFailure(s))
Empty --> Preconfirmed : Msg-Status(PreConfirmationSqueezedOut(s))
Empty --> EarlySuccess : Msg-Status(other s)
Empty --> Failed : Msg-FailedStatus
Submitted --> Submitted : Msg-Status(Submitted(s2))
Submitted --> Preconfirmed : Msg-Status(PreConfirmationSuccess(s2))
Submitted --> Preconfirmed : Msg-Status(PreConfirmationFailure(s2))
Submitted --> Preconfirmed : Msg-Status(PreConfirmationSqueezedOut(s2))
Submitted --> Success : Msg-Status(other s2)
Submitted --> LateFailed : Msg-FailedStatus
Preconfirmed --> Success : Msg-Status(s2)
Preconfirmed --> LateFailed : Msg-FailedStatus
EarlySuccess --> EarlySuccess : any message
Success --> Success : any message
Failed --> Failed : any message
LateFailed --> LateFailed : any message
|
||
| State::Preconfirmed(TransactionStatus::PreConfirmationFailure(s)) | ||
| } | ||
| TxStatusMessage::Status( | ||
| TransactionStatus::PreConfirmationSqueezedOut(s), | ||
| ) => { | ||
| State::Preconfirmed(TransactionStatus::PreConfirmationSqueezedOut(s)) | ||
| } | ||
AurelienFT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| TxStatusMessage::Status(s) => State::EarlySuccess(s), | ||
|
|
||
| TxStatusMessage::FailedStatus => State::Failed, | ||
| }, | ||
| State::Initial(s1) => { | ||
| State::Submitted(s1) => match msg { | ||
| TxStatusMessage::Status(TransactionStatus::Submitted(s2)) => { | ||
| State::Submitted(TransactionStatus::Submitted(s2)) | ||
| } | ||
|
|
||
| TxStatusMessage::Status(TransactionStatus::PreConfirmationSuccess( | ||
| s2, | ||
| )) => State::Preconfirmed(TransactionStatus::PreConfirmationSuccess(s2)), | ||
| TxStatusMessage::Status(TransactionStatus::PreConfirmationFailure( | ||
| s2, | ||
| )) => State::Preconfirmed(TransactionStatus::PreConfirmationFailure(s2)), | ||
| TxStatusMessage::Status( | ||
| TransactionStatus::PreConfirmationSqueezedOut(s2), | ||
| ) => { | ||
| State::Preconfirmed(TransactionStatus::PreConfirmationSqueezedOut(s2)) | ||
| } | ||
AurelienFT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| TxStatusMessage::Status(s2) => State::Success(s1, s2), | ||
|
|
||
| TxStatusMessage::FailedStatus => State::LateFailed(s1), | ||
| }, | ||
| State::Preconfirmed(s1) => { | ||
AurelienFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if let TxStatusMessage::Status(s2) = msg { | ||
| State::Success(s1, s2) | ||
| } else { | ||
|
|
@@ -105,7 +141,7 @@ impl TxUpdateStream { | |
| pub fn add_failure(&mut self) { | ||
| let state = std::mem::replace(&mut self.state, State::Empty); | ||
| self.state = match state { | ||
| State::Initial(s) => State::LateFailed(s), | ||
| State::Submitted(s) | State::Preconfirmed(s) => State::LateFailed(s), | ||
| State::Empty => State::Failed, | ||
| s => s, | ||
| }; | ||
|
|
@@ -118,7 +154,8 @@ impl TxUpdateStream { | |
| pub fn try_next(&mut self) -> Option<TxStatusMessage> { | ||
| let state = std::mem::replace(&mut self.state, State::Empty); | ||
| match state { | ||
| State::Initial(s) => Some(TxStatusMessage::Status(s)), | ||
| State::Submitted(s) => Some(TxStatusMessage::Status(s)), | ||
| State::Preconfirmed(s) => Some(TxStatusMessage::Status(s)), | ||
| State::Empty => None, | ||
| State::EarlySuccess(s) | State::SenderClosed(s) => { | ||
| self.state = State::Closed; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.