Skip to content

Cancel the context of worker function when miner is stopped #3180

Merged
lukasz-zimnoch merged 5 commits intomainfrom
pre-params-7
Aug 18, 2022
Merged

Cancel the context of worker function when miner is stopped #3180
lukasz-zimnoch merged 5 commits intomainfrom
pre-params-7

Conversation

@pdyraga
Copy link
Copy Markdown
Member

@pdyraga pdyraga commented Aug 18, 2022

Refs #3161
Depends on #3177

This change allows stopping the worker function immediately when the miner receives the stop signal. This is important for long-running worker functions when a single iteration can take a couple of minutes. Thanks to the change from tss-lib (bnb-chain/tss-lib#191) we can now stop the pre-param generation immediately with this mechanism.

I have also added a mutex to mockPersistence in pool_test.go. There is a single goroutine writing to the map, but it's a separate goroutine from the test one reading from a map so having a mutex feels safer, especially since there might be some changes in miner or some other tests can be added to pool_test.go.

Base automatically changed from pre-params-6 to main August 18, 2022 10:45
This change allows stopping the worker function immediately when the miner
receives the stop signal. This is important for long-running worker functions
when a single iteration can take a couple of minutes. Thanks to the change from
tss-lib (bnb-chain/tss-lib#191) we can now stop the
pre-param generation immediately with this mechanism.

I have also added a mutex to `mockPersistence` in `pool_test.go`. There is
a single goroutine writing to the map, but it's a separate goroutine from the
test one reading from a map so having a mutex feels safer, especially since
there might be some changes in miner or some other tests can be added to
`pool_test.go`.
Improved the handling of errors to not log on the ERROR level in case the
parent context was cancelled by the miner.

tss-lib returns generic errors saying "timeout or error while ...".
There are three possibilities:
1. Pool canceled the parent `ctx`. This is normal and we should not log anything
   in this case.
2. `timingOutCtx` timed out. It means the machine is not fast enough or that it
   was just unlucky. We should log a warning.
3. There is some error from tss-lib generator. We log it as a warning because
   we'll re-attempt to generate parameters again.
@pdyraga pdyraga marked this pull request as ready for review August 18, 2022 10:51
@pdyraga pdyraga requested a review from lukasz-zimnoch August 18, 2022 10:51
@pdyraga pdyraga self-assigned this Aug 18, 2022
@pdyraga pdyraga added this to the v2.0.0-m3 milestone Aug 18, 2022
Comment thread pkg/miner/miner.go Outdated
Comment thread pkg/miner/miner.go Outdated
This way is much cleaner - the miner is creating and maintaining this
array and we can use a concrete type there.
The select is much more elegant and ensures the goroutine does not leak
after the context is done.
lukasz-zimnoch
lukasz-zimnoch previously approved these changes Aug 18, 2022
The test failed on CI but keeps passing locally. There was a potential
problem when the pool generated enough parameters to reach the capacity
and although all of them were persisted, the last one was not written to
the buffered channel given it's blocking operation. In this case
pool.CurrentSize() is off-by-one to persistence.parameterCount().
@lukasz-zimnoch lukasz-zimnoch merged commit a3853bd into main Aug 18, 2022
@lukasz-zimnoch lukasz-zimnoch deleted the pre-params-7 branch August 18, 2022 12:35
@pdyraga pdyraga removed their assignment Sep 30, 2022
@pdyraga pdyraga modified the milestones: v2.0.0-m3, v2.0.0-m4 Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants