-
Notifications
You must be signed in to change notification settings - Fork 298
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
fix: mempool locking mechanism in v1 and cat #1582
Conversation
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 with two comments:
- Consider removing the
panic
- Consider a unit test for
deleteOrderedTx
@@ -58,6 +63,9 @@ func (s *store) remove(txKey types.TxKey) bool { | |||
return false | |||
} | |||
s.bytes -= tx.size() | |||
if err := s.deleteOrderedTx(tx); err != nil { | |||
panic(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'm concerned about the panic here. Should we consider:
- logging this error and
return false
instead? - modifying the
remove
function signature to propagate the error?
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.
The panic is in place because this would imply a developer error i.e. this shouldn't error so long as the developer has correctly implemented this method (the tx should always be in the ordered list if it exists in the map)
if idx >= len(s.orderedTxs) || s.orderedTxs[idx] != tx { | ||
return fmt.Errorf("transaction %X not found in ordered list", tx.key) | ||
} | ||
s.orderedTxs = append(s.orderedTxs[:idx], s.orderedTxs[idx+1:]...) |
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 the idx is the last transaction in the ordered list, I expect s.orderedTxs[idx+1:]
to fail.
Perhaps this needs a unit test where deleteOrderedTx
is invoked on the last tx in the ordered list to verify there is no bug here.
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.
TestStoreSimple
actually tests this by adding a tx and removing it. Since it's the only transaction, it is defacto the last tx in the ordered list
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 the idx is the last transaction, s.orderedTxs[idx+1:]
will be empty.
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 with a few questions:
- should we be upstreaming this?
- did you bump
celestia-core
incelestia-app
to verify that the failed test passes? - should we move the tests catching concurrency bugs to core?
require.Empty(t, store.txs) | ||
} | ||
|
||
func TestStoreOrdering(t *testing.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.
should we be testing this with higher transaction count?
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's the advantage
if idx >= len(s.orderedTxs) || s.orderedTxs[idx] != tx { | ||
return fmt.Errorf("transaction %X not found in ordered list", tx.key) | ||
} | ||
s.orderedTxs = append(s.orderedTxs[:idx], s.orderedTxs[idx+1:]...) |
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 the idx is the last transaction, s.orderedTxs[idx+1:]
will be empty.
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'll approve once I understand exactly how sorting works in the store since go slices can be deceitful lol more unit tests would be useful to make it fool proof
Yes I did (locally)
Upstream doesn't have a version of cat or the v1 priority mempool. This locking mechanism isn't an issue in v0
No I don't think so. The test can catch a wider net of bugs in celestia-app |
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.
Added another test case for deleteOrderedTx
Removed the auto-merge by accident |
Upgrade to https://github.com/celestiaorg/celestia-core/releases/tag/v1.44.2-tm-v0.34.35 to pick up the fix in celestiaorg/celestia-core#1582 (cherry picked from commit 885c317) # Conflicts: # test/interchain/go.mod # test/interchain/go.sum
This is residual of #1553
The problem is now even more subtle. Because the mempool mutexes weren't over both CheckTx and the actual adding of the transaction to the mempool we occasionally hit a situation as follows:
This PR fixes this pattern, however this won't be watertight for the CAT pool until we can order both on gas fee (priority) and nonce.