Skip to content

Conversation

@AeonSw4n
Copy link
Contributor

No description provided.

@AeonSw4n
Copy link
Contributor Author

AeonSw4n commented Jul 14, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from 1da7cda to 70a26f8 Compare July 14, 2023 10:10
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from eff69b1 to b9df35d Compare July 14, 2023 10:10
@tholonious tholonious force-pushed the p/pos-mempool-persister branch from 70a26f8 to eb8b2ad Compare July 14, 2023 13:18
@tholonious tholonious force-pushed the p/pos-mempool-struct branch from b9df35d to 2fb5c44 Compare July 14, 2023 13:18
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from eb8b2ad to 68106a5 Compare July 17, 2023 02:31
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 2fb5c44 to b6cd870 Compare July 17, 2023 02:31
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from 68106a5 to 0a7c3f9 Compare July 17, 2023 02:33
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from b6cd870 to ff0b36b Compare July 17, 2023 02:34
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from 0a7c3f9 to a2c1809 Compare July 17, 2023 02:42
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from ff0b36b to a17e42f Compare July 17, 2023 02:42
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from a2c1809 to 6603cd8 Compare July 17, 2023 03:36
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from a17e42f to f5b9b44 Compare July 17, 2023 03:36
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from 6603cd8 to a92cb78 Compare July 17, 2023 06:45
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 2608a9b to 18fda34 Compare July 17, 2023 06:45
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from a92cb78 to 1b552a4 Compare July 18, 2023 23:59
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 18fda34 to 6a001f7 Compare July 18, 2023 23:59
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from 1b552a4 to eb2dc76 Compare July 19, 2023 00:22
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 6a001f7 to 5b67ada Compare July 19, 2023 00:22
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from eb2dc76 to 1ed361a Compare July 20, 2023 03:24
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 5b67ada to 7b148e9 Compare July 20, 2023 03:24
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from 1ed361a to 1f3a5b9 Compare July 21, 2023 03:33
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 7b148e9 to 58422b6 Compare July 21, 2023 03:33
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from 1f3a5b9 to cf4b33c Compare July 21, 2023 04:06
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 126aa11 to 10eef8e Compare August 7, 2023 20:48
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-persister branch from e7d55db to 12b41f6 Compare August 7, 2023 23:44
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from 10eef8e to c588ceb Compare August 7, 2023 23:44
Base automatically changed from p/pos-mempool-persister to feature/pos-mempool August 8, 2023 06:16
@AeonSw4n AeonSw4n force-pushed the p/pos-mempool-struct branch from c588ceb to a362392 Compare August 8, 2023 06:17
@deso-protocol deso-protocol deleted a comment from lazynina Aug 8, 2023
@tholonious tholonious force-pushed the p/pos-mempool-struct branch from a362392 to 9479b92 Compare August 9, 2023 18:31
if err != nil {
return errors.Wrapf(err, "CheckBalanceIncrease: Problem getting spendable balance")
}
if err := dmp.ledger.CanIncreaseBalance(*userPk, txnFee, spendableBalanceNanos); err != nil {
Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor

@tholonious tholonious Aug 14, 2023

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().

Copy link
Contributor Author

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?

Copy link
Contributor

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

Comment on lines 87 to 90
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)
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Contributor

@tholonious tholonious Aug 14, 2023

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().

@AeonSw4n AeonSw4n merged commit a9f7827 into feature/pos-mempool Aug 22, 2023
@AeonSw4n AeonSw4n deleted the p/pos-mempool-struct branch August 22, 2023 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants