Remove #[derive(Clone)]
from Synchronizer
#4161
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
I submit this PR for 2 reason:
Synchronizer
instance in CKB process. Andstruct BlockFetchCMD
should depend onSyncState
instead ofSynchronizer
ChainService
verify a failed block, ChainService should transfer theVerifyFailedBlockInfo
toSynchronizer
, thenSynchronizer
must ban the malicious peer.So I want to add a new field:
tokio::sync::mpsc::UnboundedReceiver<VerifyFailedBlockInfo>
field to theSynchronizer
struct:https://github.com/nervosnetwork/ckb/pull/3958/files#diff-66d6800da6ed28c35f087178b6e0f1b31d6fea529dd97a86f6b5ce5dda26bbfcR884-R903
But
UnboundedReceiver
cannot be cloned, andUnboundedReceiver
'sfn recv(&mut self)
method need mutable self. Then I have to useArc<Mutex< ... >>
to wrapUnboundedReceiver
, this is not good:By removing
#[derive(Clone)]
attribute fromSynchronizer
, this code can be improved to this:What is changed and how it works?
What's Changed:
Related changes
#[derive(Clone)]
fromSynchronizer
BlockFetchCMD
depend onSyncState
instead ofSynchronizer
. This means that the initialization ofBlockFetchCMD
will no longer require cloning theSynchronizer
.Check List
Tests
Side effects
Release note