Skip to content

Commit 0edd4b7

Browse files
committed
refactor reconcile_height
1 parent 9734a39 commit 0edd4b7

File tree

1 file changed

+24
-36
lines changed
  • crates/fuel-core/src/service/adapters/consensus_module

1 file changed

+24
-36
lines changed

crates/fuel-core/src/service/adapters/consensus_module/poa.rs

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -852,37 +852,7 @@ impl RedisLeaderLeaseAdapter {
852852
return Ok(Some(block));
853853
}
854854

855-
tracing::info!(
856-
"Repairing sub-quorum block at height {current_height} \
857-
(found on {count}/{} nodes)",
858-
blocks_by_node.len()
859-
);
860-
match self.repair_sub_quorum_block(&block, count) {
861-
Ok(true) => {
862-
tracing::info!(
863-
"Repair succeeded — block at height {current_height} \
864-
now has quorum"
865-
);
866-
Ok(Some(block))
867-
}
868-
Ok(false) => {
869-
tracing::warn!(
870-
"Repair failed to reach quorum at height \
871-
{current_height} — will retry next round"
872-
);
873-
Err(anyhow!(
874-
"Backlog unresolved at height {current_height}: \
875-
repair failed to reach quorum"
876-
))
877-
}
878-
Err(e) => {
879-
tracing::warn!("Repair error at height {current_height}: {e}");
880-
Err(anyhow!(
881-
"Backlog unresolved at height {current_height}: \
882-
repair error: {e}"
883-
))
884-
}
885-
}
855+
self.repair_sub_quorum_block(current_height, block, count, blocks_by_node.len())
886856
}
887857

888858
fn select_height_winner(
@@ -1022,9 +992,15 @@ impl RedisLeaderLeaseAdapter {
1022992
/// - The total (pre_existing + newly written) must reach quorum
1023993
fn repair_sub_quorum_block(
1024994
&self,
1025-
block: &SealedBlock,
995+
current_height: u32,
996+
block: SealedBlock,
1026997
pre_existing_count: usize,
1027-
) -> anyhow::Result<bool> {
998+
node_count: usize,
999+
) -> anyhow::Result<Option<SealedBlock>> {
1000+
tracing::info!(
1001+
"Repairing sub-quorum block at height {current_height} \
1002+
(found on {pre_existing_count}/{node_count} nodes)"
1003+
);
10281004
let epoch = match *self
10291005
.current_epoch_token
10301006
.lock()
@@ -1037,15 +1013,15 @@ impl RedisLeaderLeaseAdapter {
10371013
));
10381014
}
10391015
};
1040-
let block_data = postcard::to_allocvec(block)?;
1016+
let block_data = postcard::to_allocvec(&block)?;
10411017
// Start from the pre-existing count (nodes already confirmed to
10421018
// have this specific block during reconciliation). Only count
10431019
// newly Written nodes — HeightExists means the node has *some*
10441020
// block at this height, but it might be a different block from
10451021
// a competing leader's partial write.
10461022
let mut total_with_block = pre_existing_count;
10471023
for redis_node in &self.redis_nodes {
1048-
match self.publish_block_on_node(redis_node, epoch, block, &block_data) {
1024+
match self.publish_block_on_node(redis_node, epoch, &block, &block_data) {
10491025
Ok(WriteBlockResult::Written) => {
10501026
total_with_block = total_with_block.saturating_add(1);
10511027
}
@@ -1068,10 +1044,22 @@ impl RedisLeaderLeaseAdapter {
10681044
let reached_quorum = self.quorum_reached(total_with_block);
10691045
if reached_quorum {
10701046
poa_metrics().repair_success_total.inc();
1047+
tracing::info!(
1048+
"Repair succeeded — block at height {current_height} \
1049+
now has quorum"
1050+
);
1051+
Ok(Some(block))
10711052
} else {
10721053
poa_metrics().repair_failure_total.inc();
1054+
tracing::warn!(
1055+
"Repair failed to reach quorum at height \
1056+
{current_height} — will retry next round"
1057+
);
1058+
Err(anyhow!(
1059+
"Backlog unresolved at height {current_height}: \
1060+
repair failed to reach quorum"
1061+
))
10731062
}
1074-
Ok(reached_quorum)
10751063
}
10761064
}
10771065

0 commit comments

Comments
 (0)