state: merge SledState::{queue, process_queue}.
We never want to call one without the other, so just do them together.
This commit is contained in:
parent
93586867bc
commit
de2400031c
|
|
@ -56,7 +56,6 @@ impl Service<Request> for StateService {
|
||||||
let (rsp_tx, rsp_rx) = oneshot::channel();
|
let (rsp_tx, rsp_rx) = oneshot::channel();
|
||||||
|
|
||||||
self.sled.queue(QueuedBlock { block, rsp_tx });
|
self.sled.queue(QueuedBlock { block, rsp_tx });
|
||||||
self.sled.process_queue();
|
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
rsp_rx
|
rsp_rx
|
||||||
|
|
|
||||||
|
|
@ -60,19 +60,12 @@ impl SledState {
|
||||||
|
|
||||||
/// Queue a finalized block to be committed to the state.
|
/// Queue a finalized block to be committed to the state.
|
||||||
///
|
///
|
||||||
/// After queueing a finalized block, call [`process_queue`] to check whether
|
/// After queueing a finalized block, this method checks whether the newly
|
||||||
/// the newly queued block (and any of its descendants) can be committed to
|
/// queued block (and any of its descendants) can be committed to the state.
|
||||||
/// the state.
|
|
||||||
pub fn queue(&mut self, queued_block: QueuedBlock) {
|
pub fn queue(&mut self, queued_block: QueuedBlock) {
|
||||||
let prev_hash = queued_block.block.header.previous_block_hash;
|
let prev_hash = queued_block.block.header.previous_block_hash;
|
||||||
self.queued_by_prev_hash.insert(prev_hash, queued_block);
|
self.queued_by_prev_hash.insert(prev_hash, queued_block);
|
||||||
}
|
|
||||||
|
|
||||||
/// Process the queue of finalized blocks, committing any that can be committed in-order.
|
|
||||||
///
|
|
||||||
/// This should be called after [`queue`], to check whether the newly queued block
|
|
||||||
/// (and any of its descendants) can be committed to the state.
|
|
||||||
pub fn process_queue(&mut self) {
|
|
||||||
// Cloning means the closure doesn't hold a borrow of &self,
|
// Cloning means the closure doesn't hold a borrow of &self,
|
||||||
// conflicting with mutable access in the loop below.
|
// conflicting with mutable access in the loop below.
|
||||||
let hash_by_height = self.hash_by_height.clone();
|
let hash_by_height = self.hash_by_height.clone();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue