-
Notifications
You must be signed in to change notification settings - Fork 492
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
CoinsRegistry
: Refactor DescendantOf
#11697
CoinsRegistry
: Refactor DescendantOf
#11697
Conversation
fa0c139
to
4feada5
Compare
@@ -239,7 +240,7 @@ public void SwitchToUnconfirmFromBlock(Height blockHeight) | |||
{ | |||
foreach (var coin in AsCoinsViewNoLock().AtBlockHeight(blockHeight)) | |||
{ | |||
var descendantCoins = DescendantOfAndSelf(coin); |
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.
NoLock
variant should be used here.
@@ -11,16 +11,10 @@ public interface ICoinsView : IEnumerable<SmartCoin> | |||
|
|||
ICoinsView Available(); | |||
|
|||
ICoinsView ChildrenOf(SmartCoin coin); |
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.
Only needed for computing of descendants.
? EmptyCoinsView | ||
: new CoinsView(Coins.Where(x => x.TransactionId == coin.SpenderTransaction.GetHash())); | ||
|
||
public ICoinsView DescendantOf(SmartCoin coin) |
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.
Moved to CoinsRegistry
7c9741b
to
f0c9669
Compare
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.
What do you think of having DescendantOf
instead of DescendantOfAndSelf
? Or a boolean parameter. I know we currently don't use it, but I believe the API would be cleaner.
Otherwise the PR is great
private ImmutableArray<SmartCoin> DescendantOfAndSelfNoLock(SmartCoin coin) | ||
{ | ||
HashSet<SmartCoin> allCoins = new(Coins); | ||
allCoins.UnionWith(SpentCoins); |
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.
AsAllCoinsViewNoLock()
should be used here, I believe.
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'm hesitant here. You are right in the sense that we do that everywhere but to me it makes little sense really.
I think it would be better to have a set of all coins so that we can just iterate over it and that's it. It does not add anything to the memory because we would just store pointers.
Otherwise, it seems like we create the set of all coins again and again.
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 agree that it makes little sense; we can introduce it here and change it in other places? I believe that in classes like this one, consistency is really important so it's easier to understand.
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 agree that it makes little sense; we can introduce it here and change it in other places? I believe that in classes like this one, consistency is really important so it's easier to understand.
It would be great to fix it consistently everywhere or as much as possible. Yes.
IEnumerable<SmartCoin> Generator(SmartCoin parentCoin, bool addSelf) | ||
{ | ||
IEnumerable<SmartCoin> childrenOf = parentCoin.SpenderTransaction is not null | ||
? allCoins.Where(x => x.TransactionId == parentCoin.SpenderTransaction.GetHash()) // Inefficient. |
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.
This would be much cleaner and more efficient with #11516 's factoring. Anyway.
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.
Could we just add the dictionary you had in that PR? As a small atomic 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.
Could we just add the dictionary you had in that PR? As a small atomic PR?
I will look into it, the smallest PR possible with the dictionary. This structure makes a lot of sense because the values are by tx anyway.
I think it's a good idea, I'll try to address that. |
3ac3519
to
9433aaf
Compare
CoinsRegistry
: Refactor DescendantOfAndSelfNoLock
CoinsRegistry
: Refactor DescendantOf
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.
tACK, code LGTM
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.
Nice PR; utACK
Just one note: We are changing the interface, maybe some third party code is using it? I don't believe so but I was surprised in the past so...
It's imho a similar case to #11696 (review). I'm working on testing that for that 3rd party project. And other than that, we need to try. |
No description provided.