Skip to content

Commit 899104b

Browse files
committed
Fix validator stuck after falling behind due to N-04 block payload rejection
HandleBlockAnnounce sent a BlockRequestMessage to fetch missing blocks, but the BlockPayloadMessage response was always rejected by the N-04 anti-injection guard (which requires _isSyncing flag). This caused validators that fell behind to get permanently stuck. Replace the BlockRequest approach with TrySyncFromPeers, which uses the proper SyncRequest/SyncResponse path, correctly sets the sync guard, and restarts consensus after catching up.
1 parent 3f66fea commit 899104b

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/node/Basalt.Node/NodeCoordinator.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -935,20 +935,15 @@ private void HandleBlockRequest(PeerId sender, BlockRequestMessage request)
935935

936936
private void HandleBlockAnnounce(PeerId sender, BlockAnnounceMessage announce)
937937
{
938-
// If we don't have this block, request it
939-
if (_chainManager.GetBlockByHash(announce.BlockHash) == null)
938+
_peerManager!.UpdatePeerBestBlock(sender, announce.BlockNumber, announce.BlockHash);
939+
940+
// If we're behind, trigger a full sync. Previously this sent a BlockRequestMessage,
941+
// but the BlockPayloadMessage response was rejected by the N-04 anti-injection guard
942+
// when not in sync mode, causing validators to get permanently stuck after falling behind.
943+
if (announce.BlockNumber > _chainManager.LatestBlockNumber)
940944
{
941-
var request = new BlockRequestMessage
942-
{
943-
SenderId = _localPeerId,
944-
Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
945-
StartNumber = announce.BlockNumber,
946-
Count = 1,
947-
};
948-
_gossip!.SendToPeer(sender, request);
945+
_ = Task.Run(() => TrySyncFromPeers(_cts?.Token ?? CancellationToken.None));
949946
}
950-
951-
_peerManager!.UpdatePeerBestBlock(sender, announce.BlockNumber, announce.BlockHash);
952947
}
953948

954949
private void HandleBlockPayload(PeerId sender, BlockPayloadMessage payload)

0 commit comments

Comments
 (0)