-
Notifications
You must be signed in to change notification settings - Fork 108
PoS Mempool Struct #603
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
PoS Mempool Struct #603
Conversation
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
1da7cda to
70a26f8
Compare
eff69b1 to
b9df35d
Compare
70a26f8 to
eb8b2ad
Compare
b9df35d to
2fb5c44
Compare
eb8b2ad to
68106a5
Compare
2fb5c44 to
b6cd870
Compare
68106a5 to
0a7c3f9
Compare
b6cd870 to
ff0b36b
Compare
0a7c3f9 to
a2c1809
Compare
ff0b36b to
a17e42f
Compare
a2c1809 to
6603cd8
Compare
a17e42f to
f5b9b44
Compare
6603cd8 to
a92cb78
Compare
2608a9b to
18fda34
Compare
a92cb78 to
1b552a4
Compare
18fda34 to
6a001f7
Compare
1b552a4 to
eb2dc76
Compare
6a001f7 to
5b67ada
Compare
eb2dc76 to
1ed361a
Compare
5b67ada to
7b148e9
Compare
1ed361a to
1f3a5b9
Compare
7b148e9 to
58422b6
Compare
1f3a5b9 to
cf4b33c
Compare
126aa11 to
10eef8e
Compare
e7d55db to
12b41f6
Compare
10eef8e to
c588ceb
Compare
c588ceb to
a362392
Compare
This reverts commit 1da7cda.
a362392 to
9479b92
Compare
lib/pos_mempool.go
Outdated
| if err != nil { | ||
| return errors.Wrapf(err, "CheckBalanceIncrease: Problem getting spendable balance") | ||
| } | ||
| if err := dmp.ledger.CanIncreaseBalance(*userPk, txnFee, spendableBalanceNanos); err != nil { |
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 think the name is a little confusing is all. @tholonious - how do you feel about the naming convention here? If it's clear to you, then I'm happy to keep it as is so we don't have a long and unwieldy name. I know what it's doing now, but the name didn't make it clear to me at first glance.
| } | ||
| for _, prunedTxn := range prunedTxns { | ||
| if err := dmp.removeTransactionNoLock(prunedTxn, true); err != nil { | ||
| glog.Errorf("PosMempool.pruneNoLock: Problem removing transaction from mempool: %v", err) |
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.
Should we return the error here instead of glogging it?
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 guess the assumption here is that this loop will never error because the txn no longer exists in the transaction register, in which case the dmp.removeTransactionNoLock() call will never error.
@AeonSw4n, IMO it's fine to replace the dmp.removeTransactionNoLock() call here with a helper function that just does the following:
// Decrease the appropriate ledger's balance by the transaction fee.
dmp.ledger.DecreaseBalance(*userPk, txn.Fee)
// Emit an event for the removed transaction.
if persistToDb {
event := &MempoolEvent{
Txn: txn,
Type: MempoolEventRemove,
}
dmp.persister.EnqueueEvent(event)
}
This would guarantee there's no error returned, and clarify for us in the future how pruneNoLock() differs from removeTransactionNoLock().
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.
Yes, this glog should never happen, except maybe if prunedTxn or prunedTxn.Hash were nil. Either way, it's mostly a dummy error handler.
@tholonious re the code split, I prefer making the call to removeTransactionNoLock. It's nice that both "removeTransaction" and "removeTransactioNoLock" erase transactions. This property will not hold for the new "sub-remove" function.
Imo it's also intuitive to call an internal remove function for each pruned txn. Perhaps making assumptions that dmp.removeTransactionNoLock() doesn't panic on non-existing transactions isn't that bad?
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.
@AeonSw4n, that seems fine. The implementation of dmp.removeTransactionNoLock() is encapsulated within the same struct anyway so that's a reasonable assumption.
Definitely add a comment in the code here that this function call will never error so it's clearer to readers
lib/pos_mempool_test.go
Outdated
| dir, err := os.MkdirTemp("", "badgerdb-mempool") | ||
| require.NoError(err) | ||
| t.Logf("BadgerDB directory: %s\nIt should be automatically removed at the end of the test", dir) | ||
| defer os.RemoveAll(dir) |
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.
Should we move this to a helper function and use t.Cleanup? This way we can reduce code duplication across tests. Maybe even a NewTestPoSMempool function that takes in the appropriate attributes and then cleans itself up properly upon test completion.
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! It's cool how t.Cleanup is like a better defer.
| } | ||
| for _, prunedTxn := range prunedTxns { | ||
| if err := dmp.removeTransactionNoLock(prunedTxn, true); err != nil { | ||
| glog.Errorf("PosMempool.pruneNoLock: Problem removing transaction from mempool: %v", err) |
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 guess the assumption here is that this loop will never error because the txn no longer exists in the transaction register, in which case the dmp.removeTransactionNoLock() call will never error.
@AeonSw4n, IMO it's fine to replace the dmp.removeTransactionNoLock() call here with a helper function that just does the following:
// Decrease the appropriate ledger's balance by the transaction fee.
dmp.ledger.DecreaseBalance(*userPk, txn.Fee)
// Emit an event for the removed transaction.
if persistToDb {
event := &MempoolEvent{
Txn: txn,
Type: MempoolEventRemove,
}
dmp.persister.EnqueueEvent(event)
}
This would guarantee there's no error returned, and clarify for us in the future how pruneNoLock() differs from removeTransactionNoLock().
No description provided.