Sequencer calls cmd/transaction-filterer#4294
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #4294 +/- ##
==========================================
- Coverage 34.84% 33.05% -1.79%
==========================================
Files 488 489 +1
Lines 57870 57944 +74
==========================================
- Hits 20163 19156 -1007
- Misses 34134 35423 +1289
+ Partials 3573 3365 -208 |
❌ 6 Tests Failed:
View the top 3 failed tests by shortest run time
📣 Thoughts on this report? Let Codecov know! | Powered by Codecov |
0eb6f47 to
04ecb8a
Compare
eb20adc to
eb88a51
Compare
MishkaRogachev
left a comment
There was a problem hiding this comment.
A few minor questions
tsahee
left a comment
There was a problem hiding this comment.
small comments in the meantime. I think this PR will need to change after some things currently in the merge queue.
Generally good
| func (s *ExecutionEngine) StopAndWait() { | ||
| s.StopWaiter.StopAndWait() | ||
|
|
||
| if s.transactionFiltererRPCClient != nil { |
There was a problem hiding this comment.
Do this before the parent stopandwait.
Parent stopAndWait will kill parent context, and you'll end up with a non-ordered shutdown.
There was a problem hiding this comment.
Fixed ExecutionEngine StopWaiter start/stop
There was a problem hiding this comment.
@tsahee I am noop here regarding this pattern, but have question, why the order should be stopChild then stopParent?
I think parent might be in mid of thread sending request thru child but child already stoped, this will cause error during shutdown?
There was a problem hiding this comment.
StopAndWait cancels the context, then waits for all threads to be done.
Child uses a context that's a child of parent context so once you call parent stopandwait, both parent and child context will be closed and all threads will end without particular order.
If parent creates threads that should be closed while child is still active - these threads should be done by a different child.
tsahee
left a comment
There was a problem hiding this comment.
approving with comments, will open separate issues for those
| if n.ExecEngine.Started() { | ||
| n.ExecEngine.StopAndWait() | ||
| } | ||
| if n.consensusRPCClient != nil { |
There was a problem hiding this comment.
if there's a reason this moved - document it in a comment because we won't remember that.
There was a problem hiding this comment.
This was not moved, it was created in this PR.
consensusRPCClient didn't have a StopAndWait func before this PR.
Given that, adding a code comment for that is still useful?
There was a problem hiding this comment.
ah, was confused with the addressfilterservice
| const namespace = "transactionfilterer" | ||
|
|
||
| type TransactionFiltererAPI struct { | ||
| apiMutex sync.Mutex // avoids concurrent transactions with the same nonce |
There was a problem hiding this comment.
use a channel with a single sink to ensure transactions are treated one by one. We should eventually have a service with some more internal state that could e.g. make sure it's filter requests pass through, retries if needed etc.. no need to catch a lock while handling a request.
There was a problem hiding this comment.
If following a strategy like this, then adding a message queue layer between the sequencer and cmd/transaction-filterer is a way to move forward.
But it seems over engineering right now TBH.
| // Only used for testing. | ||
| // Sequencer and TransactionFiltererAPI depend on each other, as a workaround for the egg/chicken problem, | ||
| // we set the sequencer client after both are created. | ||
| func (t *TransactionFiltererAPI) SetSequencerClient(_ *testing.T, sequencerClient *ethclient.Client) error { |
There was a problem hiding this comment.
Using go testing package in production code is a bit anti-pattern I think. I can see the need for it here from the comment. But the impact of this is that go now will compile testing related package/runtime into production code. increase the binary size. and might cause some issues or affect the speed (I think)
There was a problem hiding this comment.
using testing.T input in code that's only used for testing helps make sure it's not used anywhere outside of tests by mistakes. Binary size is irrelevant, having a function that can be called from tests and only from tests is useful.
There was a problem hiding this comment.
also, since no member function of testing.T is called I don't believe even binary size will increase
There was a problem hiding this comment.
My worries is not only the binary size, but the test-related runtime or execution.
| if n.ExecEngine.Started() { | ||
| n.ExecEngine.StopAndWait() | ||
| } | ||
| if n.consensusRPCClient != nil { |
There was a problem hiding this comment.
ah, was confused with the addressfilterservice
| // Only used for testing. | ||
| // Sequencer and TransactionFiltererAPI depend on each other, as a workaround for the egg/chicken problem, | ||
| // we set the sequencer client after both are created. | ||
| func (t *TransactionFiltererAPI) SetSequencerClient(_ *testing.T, sequencerClient *ethclient.Client) error { |
There was a problem hiding this comment.
using testing.T input in code that's only used for testing helps make sure it's not used anywhere outside of tests by mistakes. Binary size is irrelevant, having a function that can be called from tests and only from tests is useful.
| const namespace = "transactionfilterer" | ||
|
|
||
| type TransactionFiltererAPI struct { | ||
| apiMutex sync.Mutex // avoids concurrent transactions with the same nonce |
| // Only used for testing. | ||
| // Sequencer and TransactionFiltererAPI depend on each other, as a workaround for the egg/chicken problem, | ||
| // we set the sequencer client after both are created. | ||
| func (t *TransactionFiltererAPI) SetSequencerClient(_ *testing.T, sequencerClient *ethclient.Client) error { |
There was a problem hiding this comment.
also, since no member function of testing.T is called I don't believe even binary size will increase
| func (s *ExecutionEngine) StopAndWait() { | ||
| s.StopWaiter.StopAndWait() | ||
|
|
||
| if s.transactionFiltererRPCClient != nil { |
There was a problem hiding this comment.
StopAndWait cancels the context, then waits for all threads to be done.
Child uses a context that's a child of parent context so once you call parent stopandwait, both parent and child context will be closed and all threads will end without particular order.
If parent creates threads that should be closed while child is still active - these threads should be done by a different child.
Resolves NIT-4252
Sequencer calls cmd/transaction-filterer to filter delayed transaction.
Attention to the base branch.