-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Snapshot sync #2047
Snapshot sync #2047
Conversation
@@ -122,11 +122,13 @@ impl SleepState { | |||
/// Call `import_block()` to import a block asynchronously; `flush_queue()` flushes the queue. | |||
pub struct Client { | |||
mode: Mode, | |||
chain: Arc<BlockChain>, | |||
tracedb: Arc<TraceDB<BlockChain>>, | |||
chain: RwLock<Arc<BlockChain>>, |
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.
RwLock<Arc<T>>
doesn't guarantee or provide anything as Arc
only has a Deref
implementation
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.
It is a lock for a shared pointer. It is required to synchronously replace the pointer with another once.
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.
But you can always just clone the Arc
instead of accessing the shared pointer. Maybe it's worthing wrapping Arc<BlockChain>
into a structure with Deref
but without Clone
to prevent such situations?
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 would favor giving Client
full ownership of BlockChain
, only loaning it out temporarily to the TraceDB
.
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.
@tomusdrw I need to replace the pointer so that it points to another object. This is not the same as cloning Arc
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.
@rphmeier I'll leave this to another PR. This one is too big already
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.
Yeah, I understand, but the point is that even if you replace the pointer someone might be using the old one anyway (because after getting a lock you can just clone the Arc
and release the lock).
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.
Ah, ok. I'm sure that's not happening cause this pointer is not exposed out of the client. It is only used in TraceDB and we should really just pass a reference there as @rphmeier suggested.
Still left to do: