-
Notifications
You must be signed in to change notification settings - Fork 152
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
Parametrize the transaction staging strategy & make it volatile by default #1131
Conversation
324ac02
to
9d87645
Compare
Codecov Report
@@ Coverage Diff @@
## main #1131 +/- ##
==========================================
+ Coverage 87.46% 87.55% +0.08%
==========================================
Files 341 345 +4
Lines 29694 29956 +262
==========================================
+ Hits 25972 26227 +255
- Misses 2092 2097 +5
- Partials 1630 1632 +2
|
@planetarium/libplanet PTAL. |
{ | ||
_rwlock.ExitWriteLock(); | ||
StagePolicy.Stage(this, transaction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is StagePolicy.Stage()
thread-safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be so (interface-wise), and I believe VolatileStagePolicy<T>
, the only implementation, is so. (It uses ConcurrentDictionary<K, V>
under the hood.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if .Unstage()
is too, it seems that we can strip _rwlock
in BlockChain<T>.UnstageTransaction()
.
.ToImmutableHashSet(); | ||
foreach (TxId txId in txIds) | ||
{ | ||
StagePolicy.Unstage(this, txId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is StagePolicy.Unstage()
also thread-safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made every operation on IStagePolicy<T>
(protocol-wise) & VolatileStagePolicy<T>
(implementation-wise) sure they are thread safe: 131ed7d.
{ | ||
Transaction<T> tx = BlockChain.GetTransaction(txid); | ||
|
||
if (tx is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can BlockChain<T>.GetTransaction()
return null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If txid
is invalid there's the possibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆗
@planetarium/libplanet PTAL. |
/// </summary> | ||
public VolatileStagePolicy() | ||
{ | ||
_set = new ConcurrentDictionary<TxId, Transaction<T>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems there is no code to delete _set
's element. Is there a default capacity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we need to implement lifetiming, but I'm going to do it on a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are comments about the style of the code left, but there seems to be no big problem with the behavior right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
[changelog skip]
97263d7
131ed7d
to
97263d7
Compare
@planetarium/libplanet I rebased on the current main. Please review this again! |
This patch parametrizes
BlockChain<T>
's strategy to stage transactions through the newIStagePolicy<T>
interface, and introducedVolatileStagePolicy<T>
, which is an only built-in & default implementation.See also the changelog.