Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
a511601f
Verified
Commit
a511601f
authored
2 months ago
by
Michal Kucharczyk
Browse files
Options
Downloads
Patches
Plain Diff
mvl: finality_timeout call added + renaming
parent
1a3a1284
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/client/transaction-pool/src/fork_aware_txpool/multi_view_listener.rs
+85
-43
85 additions, 43 deletions
...saction-pool/src/fork_aware_txpool/multi_view_listener.rs
with
85 additions
and
43 deletions
substrate/client/transaction-pool/src/fork_aware_txpool/multi_view_listener.rs
+
85
−
43
View file @
a511601f
...
...
@@ -84,22 +84,27 @@ enum TransactionStatusUpdate<ChainApi: graph::ChainApi> {
/// Marks a transaction as invalidated.
///
/// If all pre-conditions are met, an external invalid event will be sent out.
Transaction
Invalidated
(
ExtrinsicHash
<
ChainApi
>
),
Invalidated
(
ExtrinsicHash
<
ChainApi
>
),
/// Notifies that a transaction was finalized in a specific block hash and transaction index.
///
/// Send out an external finalized event.
Transaction
Finalized
(
ExtrinsicHash
<
ChainApi
>
,
BlockHash
<
ChainApi
>
,
TxIndex
),
Finalized
(
ExtrinsicHash
<
ChainApi
>
,
BlockHash
<
ChainApi
>
,
TxIndex
),
/// Notifies that a transaction was broadcasted with a list of peer addresses.
///
/// Sends out an external broadcasted event.
Transaction
Broadcasted
(
ExtrinsicHash
<
ChainApi
>
,
Vec
<
String
>
),
Broadcasted
(
ExtrinsicHash
<
ChainApi
>
,
Vec
<
String
>
),
/// Notifies that a transaction was dropped from the pool.
///
/// If all preconditions are met, an external dropped event will be sent out.
TransactionDropped
(
ExtrinsicHash
<
ChainApi
>
,
DroppedReason
<
ExtrinsicHash
<
ChainApi
>>
),
Dropped
(
ExtrinsicHash
<
ChainApi
>
,
DroppedReason
<
ExtrinsicHash
<
ChainApi
>>
),
/// Notifies that a finality watcher timed out.
///
/// An external finality timed out event will be sent out.
FinalityTimeout
(
ExtrinsicHash
<
ChainApi
>
,
BlockHash
<
ChainApi
>
),
}
impl
<
ChainApi
>
TransactionStatusUpdate
<
ChainApi
>
...
...
@@ -108,10 +113,11 @@ where
{
fn
hash
(
&
self
)
->
ExtrinsicHash
<
ChainApi
>
{
match
self
{
Self
::
TransactionInvalidated
(
hash
)
|
Self
::
TransactionFinalized
(
hash
,
_
,
_
)
|
Self
::
TransactionBroadcasted
(
hash
,
_
)
|
Self
::
TransactionDropped
(
hash
,
_
)
=>
*
hash
,
Self
::
Invalidated
(
hash
)
|
Self
::
Finalized
(
hash
,
_
,
_
)
|
Self
::
Broadcasted
(
hash
,
_
)
|
Self
::
Dropped
(
hash
,
_
)
=>
*
hash
,
Self
::
FinalityTimeout
(
hash
,
_
)
=>
*
hash
,
}
}
}
...
...
@@ -123,17 +129,19 @@ where
{
fn
into
(
self
)
->
TransactionStatus
<
ExtrinsicHash
<
ChainApi
>
,
BlockHash
<
ChainApi
>>
{
match
self
{
TransactionStatusUpdate
::
Transaction
Invalidated
(
_
)
=>
TransactionStatus
::
Invalid
,
TransactionStatusUpdate
::
Transaction
Finalized
(
_
,
hash
,
index
)
=>
TransactionStatusUpdate
::
Invalidated
(
_
)
=>
TransactionStatus
::
Invalid
,
TransactionStatusUpdate
::
Finalized
(
_
,
hash
,
index
)
=>
TransactionStatus
::
Finalized
((
*
hash
,
*
index
)),
TransactionStatusUpdate
::
Transaction
Broadcasted
(
_
,
peers
)
=>
TransactionStatusUpdate
::
Broadcasted
(
_
,
peers
)
=>
TransactionStatus
::
Broadcast
(
peers
.clone
()),
TransactionStatusUpdate
::
Transaction
Dropped
(
_
,
DroppedReason
::
Usurped
(
by
))
=>
TransactionStatusUpdate
::
Dropped
(
_
,
DroppedReason
::
Usurped
(
by
))
=>
TransactionStatus
::
Usurped
(
*
by
),
TransactionStatusUpdate
::
Transaction
Dropped
(
_
,
DroppedReason
::
LimitsEnforced
)
=>
TransactionStatusUpdate
::
Dropped
(
_
,
DroppedReason
::
LimitsEnforced
)
=>
TransactionStatus
::
Dropped
,
TransactionStatusUpdate
::
Transaction
Dropped
(
_
,
DroppedReason
::
Invalid
)
=>
TransactionStatusUpdate
::
Dropped
(
_
,
DroppedReason
::
Invalid
)
=>
TransactionStatus
::
Invalid
,
TransactionStatusUpdate
::
FinalityTimeout
(
_
,
block_hash
)
=>
TransactionStatus
::
FinalityTimeout
(
*
block_hash
),
}
}
}
...
...
@@ -144,17 +152,20 @@ where
{
fn
fmt
(
&
self
,
f
:
&
mut
std
::
fmt
::
Formatter
<
'_
>
)
->
std
::
fmt
::
Result
{
match
self
{
Self
::
TransactionInvalidated
(
h
)
=>
{
write!
(
f
,
"TransactionInvalidated({h})"
)
Self
::
Invalidated
(
h
)
=>
{
write!
(
f
,
"Invalidated({h})"
)
},
Self
::
Finalized
(
h
,
b
,
i
)
=>
{
write!
(
f
,
"Finalized({h},{b},{i})"
)
},
Self
::
TransactionFinaliz
ed
(
h
,
b
,
i
)
=>
{
write!
(
f
,
"
FinalizeTransaction({h},{b},{i
})"
)
Self
::
Broadcast
ed
(
h
,
_
)
=>
{
write!
(
f
,
"
Broadcasted({h
})"
)
},
Self
::
TransactionBroadcast
ed
(
h
,
_
)
=>
{
write!
(
f
,
"
TransactionBroadcasted({h
})"
)
Self
::
Dropp
ed
(
h
,
r
)
=>
{
write!
(
f
,
"
Dropped({h},{r:?
})"
)
},
Self
::
TransactionDropped
(
h
,
r
)
=>
{
write!
(
f
,
"
TransactionDropped
({h},{
r
:?})"
)
Self
::
FinalityTimeout
(
h
,
b
)
=>
{
write!
(
f
,
"
FinalityTimeout
({h},{
b
:?})"
)
},
}
}
...
...
@@ -174,45 +185,54 @@ where
}
}
}
impl
<
ChainApi
>
ControllerCommand
<
ChainApi
>
where
ChainApi
:
graph
::
ChainApi
,
{
/// Creates new instance of a command requesting [`TransactionStatus::Invalid`] transaction
/// status.
fn
new_transaction_invalidated
(
tx_hash
:
ExtrinsicHash
<
ChainApi
>
)
->
Self
{
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
TransactionInvalidated
(
tx_hash
),
)
fn
new_invalidated
(
tx_hash
:
ExtrinsicHash
<
ChainApi
>
)
->
Self
{
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
Invalidated
(
tx_hash
))
}
/// Creates new instance of a command requesting [`TransactionStatus::Broadcast`] transaction
/// status.
fn
new_
transaction_
broadcasted
(
tx_hash
:
ExtrinsicHash
<
ChainApi
>
,
peers
:
Vec
<
String
>
)
->
Self
{
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
TransactionBroadcasted
(
tx_hash
,
peers
)
,
)
fn
new_broadcasted
(
tx_hash
:
ExtrinsicHash
<
ChainApi
>
,
peers
:
Vec
<
String
>
)
->
Self
{
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
Broadcasted
(
tx_hash
,
peers
,
)
)
}
/// Creates new instance of a command requesting [`TransactionStatus::Finalized`] transaction
/// status.
fn
new_
transaction_
finalized
(
fn
new_finalized
(
tx_hash
:
ExtrinsicHash
<
ChainApi
>
,
block_hash
:
BlockHash
<
ChainApi
>
,
index
:
TxIndex
,
)
->
Self
{
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
Transaction
Finalized
(
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
Finalized
(
tx_hash
,
block_hash
,
index
,
))
}
/// Creates new instance of a command requesting [`TransactionStatus::Dropped`] transaction
/// status.
fn
new_
transaction_
dropped
(
fn
new_dropped
(
tx_hash
:
ExtrinsicHash
<
ChainApi
>
,
reason
:
DroppedReason
<
ExtrinsicHash
<
ChainApi
>>
,
)
->
Self
{
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
Transaction
Dropped
(
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
Dropped
(
tx_hash
,
reason
,
))
}
/// Creates new instance of a command requesting [`TransactionStatus::FinalityTimeout`]
/// transaction status.
fn
new_finality_timeout
(
tx_hash
:
ExtrinsicHash
<
ChainApi
>
,
block_hash
:
BlockHash
<
ChainApi
>
,
)
->
Self
{
ControllerCommand
::
TransactionStatusRequest
(
TransactionStatusUpdate
::
FinalityTimeout
(
tx_hash
,
block_hash
,
))
}
}
/// This struct allows to create and control listener for multiple transactions.
...
...
@@ -366,11 +386,11 @@ where
Some
(
status
)
}
},
TransactionStatus
::
FinalityTimeout
(
_
)
=>
Some
(
status
),
TransactionStatus
::
Finalized
(
_
)
=>
{
self
.terminate
=
true
;
Some
(
status
)
},
TransactionStatus
::
FinalityTimeout
(
_
)
|
TransactionStatus
::
Retracted
(
_
)
|
TransactionStatus
::
Broadcast
(
_
)
|
TransactionStatus
::
Usurped
(
_
)
|
...
...
@@ -667,9 +687,8 @@ where
pub
(
crate
)
fn
transactions_invalidated
(
&
self
,
invalid_hashes
:
&
[
ExtrinsicHash
<
ChainApi
>
])
{
log_xt_trace!
(
target
:
LOG_TARGET
,
invalid_hashes
,
"transactions_invalidated"
);
for
tx_hash
in
invalid_hashes
{
if
let
Err
(
error
)
=
self
.controller
.unbounded_send
(
ControllerCommand
::
new_transaction_invalidated
(
*
tx_hash
))
if
let
Err
(
error
)
=
self
.controller
.unbounded_send
(
ControllerCommand
::
new_invalidated
(
*
tx_hash
))
{
trace!
(
target
:
LOG_TARGET
,
...
...
@@ -692,7 +711,7 @@ where
for
(
tx_hash
,
peers
)
in
propagated
{
if
let
Err
(
error
)
=
self
.controller
.unbounded_send
(
ControllerCommand
::
new_
transaction_
broadcasted
(
tx_hash
,
peers
))
.unbounded_send
(
ControllerCommand
::
new_broadcasted
(
tx_hash
,
peers
))
{
trace!
(
target
:
LOG_TARGET
,
...
...
@@ -711,9 +730,8 @@ where
pub
(
crate
)
fn
transaction_dropped
(
&
self
,
dropped
:
DroppedTransaction
<
ExtrinsicHash
<
ChainApi
>>
)
{
let
DroppedTransaction
{
tx_hash
,
reason
}
=
dropped
;
trace!
(
target
:
LOG_TARGET
,
?
tx_hash
,
?
reason
,
"transaction_dropped"
);
if
let
Err
(
error
)
=
self
.controller
.unbounded_send
(
ControllerCommand
::
new_transaction_dropped
(
tx_hash
,
reason
))
if
let
Err
(
error
)
=
self
.controller
.unbounded_send
(
ControllerCommand
::
new_dropped
(
tx_hash
,
reason
))
{
trace!
(
target
:
LOG_TARGET
,
...
...
@@ -736,7 +754,7 @@ where
trace!
(
target
:
LOG_TARGET
,
?
tx_hash
,
"transaction_finalized"
);
if
let
Err
(
error
)
=
self
.controller
.unbounded_send
(
ControllerCommand
::
new_
transaction_
finalized
(
tx_hash
,
block
,
idx
))
.unbounded_send
(
ControllerCommand
::
new_finalized
(
tx_hash
,
block
,
idx
))
{
trace!
(
target
:
LOG_TARGET
,
...
...
@@ -747,6 +765,30 @@ where
};
}
/// Send `FinalityTimeout` event for given transactions at given block.
///
/// This will trigger `FinalityTimeout` event to the external watcher.
pub
(
crate
)
fn
transactions_finality_timeout
(
&
self
,
tx_hashes
:
&
[
ExtrinsicHash
<
ChainApi
>
],
block
:
BlockHash
<
ChainApi
>
,
)
{
for
tx_hash
in
tx_hashes
{
trace!
(
target
:
LOG_TARGET
,
?
tx_hash
,
"transaction_finality_timeout"
);
if
let
Err
(
error
)
=
self
.controller
.unbounded_send
(
ControllerCommand
::
new_finality_timeout
(
*
tx_hash
,
block
))
{
trace!
(
target
:
LOG_TARGET
,
?
tx_hash
,
%
error
,
"transaction_finality_timeout: send message failed"
);
};
}
}
/// Removes stale controllers.
pub
(
crate
)
fn
remove_stale_controllers
(
&
self
)
{
self
.external_controllers
.write
()
.retain
(|
_
,
c
|
!
c
.is_closed
());
...
...
This diff is collapsed.
Click to expand it.
Michal Kucharczyk
@michalkucharczyk
mentioned in commit
24a4b55e
·
1 month ago
mentioned in commit
24a4b55e
mentioned in commit 24a4b55efc067c7d382aeda03f58e20e0b106523
Toggle commit list
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment