Enhance mainchain reorg handling with mining pause and robust recovery
This commit is contained in:
+19
-9
@@ -3426,16 +3426,26 @@ bool P2PServer::P2PClient::on_checkpoint_response(const uint8_t* buf, uint32_t c
|
||||
}
|
||||
|
||||
if (mismatch_count > 0) {
|
||||
LOGWARN(2, "Checkpoint validation: " << mismatch_count << "/" << count
|
||||
<< " mismatches with peer " << static_cast<char*>(m_addrString));
|
||||
// Check if we're in a reorg grace period - if so, don't take drastic action
|
||||
const bool in_grace_period = side_chain.is_in_reorg_grace_period();
|
||||
|
||||
// If more than half the checkpoints mismatch, we may be on wrong chain
|
||||
if (mismatch_count > count / 2) {
|
||||
LOGERR(1, "DIVERGENCE DETECTED: More than 50% checkpoint mismatch with peer "
|
||||
<< static_cast<char*>(m_addrString) << " (" << mismatch_count << "/" << count << ")");
|
||||
// Trigger recovery if we have significantly different checkpoints
|
||||
if (!peer_checkpoints.empty()) {
|
||||
side_chain.trigger_recovery(peer_checkpoints[0].height);
|
||||
if (in_grace_period) {
|
||||
LOGINFO(2, "Checkpoint mismatch (" << mismatch_count << "/" << count
|
||||
<< ") with peer " << static_cast<char*>(m_addrString)
|
||||
<< " - IGNORED (mainchain reorg grace period active)");
|
||||
}
|
||||
else {
|
||||
LOGWARN(2, "Checkpoint validation: " << mismatch_count << "/" << count
|
||||
<< " mismatches with peer " << static_cast<char*>(m_addrString));
|
||||
|
||||
// If more than half the checkpoints mismatch, we may be on wrong chain
|
||||
if (mismatch_count > count / 2) {
|
||||
LOGERR(1, "DIVERGENCE DETECTED: More than 50% checkpoint mismatch with peer "
|
||||
<< static_cast<char*>(m_addrString) << " (" << mismatch_count << "/" << count << ")");
|
||||
// Trigger recovery if we have significantly different checkpoints
|
||||
if (!peer_checkpoints.empty()) {
|
||||
side_chain.trigger_recovery(peer_checkpoints[0].height);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (count > 0) {
|
||||
|
||||
Reference in New Issue
Block a user