Skip to content

Commit

Permalink
Review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Murzin <[email protected]>
  • Loading branch information
dima74 authored and mversic committed Jul 12, 2024
1 parent 6a07dc4 commit 5e735c6
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,20 @@ impl Sumeragi {
"Block sync update received"
);

if categorize_block_sync(&block, &state.view()).is_ok() {
let block_sync_type = categorize_block_sync(&block, &state.view());
if block_sync_type.is_ok() {
// Release block writer before creating new one
let _ = voting_block.take();
}

match handle_block_sync(&self.chain_id, block, state, genesis_account, &|e| {
self.send_event(e)
}) {
match handle_categorized_block_sync(
&self.chain_id,
block,
state,
genesis_account,
&|e| self.send_event(e),
block_sync_type,
) {
Ok(BlockSyncOk::CommitBlock(block, state_block, topology)) => {
self.topology = topology;
self.commit_block(block, state_block);
Expand Down Expand Up @@ -1231,14 +1237,34 @@ enum BlockSyncError {
},
}

#[cfg(test)]
fn handle_block_sync<'state, F: Fn(PipelineEventBox)>(
chain_id: &ChainId,
block: SignedBlock,
state: &'state State,
genesis_account: &AccountId,
handle_events: &F,
) -> Result<BlockSyncOk<'state>, (SignedBlock, BlockSyncError)> {
let (mut state_block, soft_fork) = match categorize_block_sync(&block, &state.view()) {
let block_sync_type = categorize_block_sync(&block, &state.view());
handle_categorized_block_sync(
chain_id,
block,
state,
genesis_account,
handle_events,
block_sync_type,
)
}

fn handle_categorized_block_sync<'state, F: Fn(PipelineEventBox)>(
chain_id: &ChainId,
block: SignedBlock,
state: &'state State,
genesis_account: &AccountId,
handle_events: &F,
block_sync_type: Result<BlockSyncType, BlockSyncError>,
) -> Result<BlockSyncOk<'state>, (SignedBlock, BlockSyncError)> {
let (mut state_block, soft_fork) = match block_sync_type {
Ok(BlockSyncType::CommitBlock) => (state.block(), false),
Ok(BlockSyncType::ReplaceTopBlock) => (state.block_and_revert(), true),
Err(e) => return Err((block, e)),
Expand Down

0 comments on commit 5e735c6

Please sign in to comment.