Skip to content

Commit 61bd6a5

Browse files
committed
added more logging, changed some strategy
1 parent fd3c63f commit 61bd6a5

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

beacon_chain/nimbus_beacon_node.nim

+2-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ proc initFullNode(
565565
dag.cfg.MAX_BLOBS_PER_BLOCK_ELECTRA,
566566
ColumnSyncerDirection.Forward, getLocalHeadSlot,
567567
getLocalWallSlot, getFirstSlotAtFinalizedEpoch, getBackfillSlot,
568-
getFrontfillSlot, dag.tail.slot, peerdasBlockVerifier,
568+
getFrontfillSlot, isWithinWeakSubjectivityPeriod,
569+
dag.tail.slot, peerdasBlockVerifier,
569570
shutdownEvent = node.shutdownEvent,
570571
flags = columnSyncerFlags,
571572
modes = columnManagerModes)

beacon_chain/sync/column_syncer.nim

+29-33
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import
2121
export phase0, altair, merge, chronos, chronicles, results,
2222
helpers, peer_scores, sync_queue, forks, sync_protocol
2323

24-
logScope:
25-
topics = "columnsync"
26-
2724
const
2825
ColumnSyncWorkerCount* = 15
2926
## Number of workers to spawn for column syncing
@@ -63,6 +60,7 @@ type
6360
MAX_BLOBS_PER_BLOCK_ELECTRA: uint64
6461
responseTimeout: chronos.Duration
6562
maxHeadAge: uint64
63+
isWithinWeakSubjectivityPeriod: GetBoolCallback
6664
assist*: ColumnSyncerAssist[A]
6765
getLocalHeadSlot: GetSlotCallback
6866
getLocalWallSlot: GetSlotCallback
@@ -146,6 +144,7 @@ proc newColumnManager*[A, B](
146144
getFinalizedSlotCb: GetSlotCallback,
147145
getBackfillSlotCb: GetSlotCallback,
148146
getFrontfillSlotCb: GetSlotCallback,
147+
weakSubjectivityPeriodCb: GetBoolCallback,
149148
progressPivot: Slot,
150149
peerdasBlockVerifier: PeerdasBlockVerifier,
151150
shutdownEvent: AsyncEvent,
@@ -173,6 +172,7 @@ proc newColumnManager*[A, B](
173172
MAX_BLOBS_PER_BLOCK_ELECTRA: maxBlobsPerBlockElectra,
174173
getLocalHeadSlot: getLocalHeadSlotCb,
175174
getLocalWallSlot: getLocalWallSlotCb,
175+
isWithinWeakSubjectivityPeriod: weakSubjectivityPeriodCb,
176176
getSafeSlot: getSafeSlot,
177177
getFirstSlot: getFirstSlot,
178178
getLastSlot: getLastSlot,
@@ -194,22 +194,21 @@ proc fetchBlocksForColumnNavigation[A, B](man: ColumnManager[A, B], peer: A,
194194
{.async: (raises: [CancelledError], raw: true).} =
195195
mixin getScore, `==`
196196

197-
logScope:
198-
peer_score = peer.getScore()
199-
peer_speed = peer.netKbps()
200-
direction = man.direction
201-
topics = "columnsync"
197+
debugEcho "fetching block for column navigation"
202198

203199
doAssert(not(req.isEmpty()), "Request must not be empty!")
204200
debug "Requesting blocks from peer",
205201
peer_score = req.item.getScore(),
206-
peer_speed = req.item.netKbps()
202+
peer_speed = req.item.netKbps(),
203+
topics = "columnsync"
207204

208205
beaconBlocksByRange_v2(peer, req.slot, req.count, 1'u64)
209206

210207
proc shouldGetDataColumns[A, B](
211208
man: ColumnManager[A, B],
212209
s: Slot): bool =
210+
211+
debugEcho "checking if we should get data columns in the current fork"
213212
let
214213
wallEpoch = man.getLocalWallSlot().epoch
215214
epoch = s.epoch()
@@ -224,6 +223,7 @@ proc shouldGetDataColumns[A, B](
224223

225224
proc checkDataColumns(data_columns: seq[DataColumnSidecars]):
226225
Result[void, string] =
226+
debugEcho "verifying data columns from column syncer"
227227
for data_column_sidecars in data_columns:
228228
for data_column_sidecar in data_column_sidecars:
229229
? data_column_sidecar[].verify_data_column_sidecar_inclusion_proof()
@@ -235,6 +235,7 @@ proc checkDataColumns(data_columns: seq[DataColumnSidecars]):
235235
proc intersectionColumns[A, B](
236236
man: ColumnManager[A, B],
237237
peer: A): List[ColumnIndex, NUMBER_OF_COLUMNS] =
238+
debugEcho "computing interesecting columns for the current peer"
238239
let
239240
remoteNodeId =
240241
fetchNodeIdFromPeerId(peer)
@@ -291,13 +292,8 @@ proc getDataColumnSidecarsByRange[A, B](man: ColumnManager[A, B],
291292
{.async: (raises: [CancelledError], raw: true).} =
292293
mixin getScore, `==`
293294

294-
logScope:
295-
peer_score = peer.getScore()
296-
peer_speed = peer.netKbps()
297-
topics = "columnsync"
298-
299295
doAssert(not(r.isEmpty()), "Request must not be empty")
300-
debug "Requesting data column sidecars from peer",
296+
debug "Requesting data column sidecars by range from peer",
301297
topics = "columnsync"
302298
dataColumnSidecarsByRange(peer, r.slot, r.count, req_cols)
303299

@@ -324,6 +320,9 @@ proc filterRelevantPeers[A, B](man: ColumnManager[A, B],
324320
## and returns a refreshed peer list based on
325321
## whichever's peer status is recent and relevant
326322
##
323+
324+
325+
327326
var
328327
refreshed_peer_set: seq[A]
329328
for peer in peers:
@@ -530,20 +529,13 @@ proc serializeColumnTable*[A, B](
530529
proc columnSyncStrategyImpartial[A, B](
531530
man: ColumnManager[A, B], index: int, peer: A
532531
) {.async: (raises: [CancelledError]).} =
533-
logScope:
534-
peer_score = peer.getScore()
535-
peer_speed = peer.netKbps()
536-
index = index
537532

538533
var
539534
headSlot = man.getLocalHeadSlot()
540535
wallSlot = man.getLocalWallSlot()
541536
peerSlot = peer.getHeadSlot()
542537

543538
block:
544-
logScope:
545-
peer = peer
546-
547539
debug "Peer's syncing status", wall_clock_slot = wallSlot,
548540
remote_head_slot = peerSlot, local_head_slot = headSlot,
549541
direction = man.direction, topics = "columnsync"
@@ -592,10 +584,7 @@ proc columnSyncStrategyImpartial[A, B](
592584
wallSlot = man.getLocalWallSlot()
593585

594586
if man.remainingSlots() <= man.maxHeadAge:
595-
logScope:
596-
peer = peer
597-
598-
info "We are in sync with the network", wall_clock_slot = wallSlot,
587+
info "Column syncing is completed", wall_clock_slot = wallSlot,
599588
remote_head_slot = peerSlot, local_head_slot = headSlot,
600589
direction = man.direction, topics = "columnsync"
601590

@@ -629,7 +618,8 @@ proc columnSyncStrategyImpartial[A, B](
629618
return
630619

631620
debug "Creating new request for peer", wall_clock_slot = wallSlot,
632-
remote_head_slot = peerSlot, local_head_slot = headSlot
621+
remote_head_slot = peerSlot, local_head_slot = headSlot,
622+
topics = "columnsync"
633623

634624
man.workers[index].status = ColumnSyncerStatus.Downloading
635625

@@ -650,7 +640,7 @@ proc columnSyncStrategyImpartial[A, B](
650640
man.assist.push(req)
651641
warn "Incorrect blocks sequence received",
652642
blocks_count = len(blockData),
653-
reason = error, topics = columnsync
643+
reason = error, topics = "columnsync"
654644
return
655645

656646
let shouldGetDataColumns =
@@ -1030,7 +1020,8 @@ proc startColumnSyncWorkers[A, B](man: ColumnManager[A, B]) =
10301020
man.workers[i].future =
10311021
columnSyncWorkerImparital[A, B](man, i)
10321022

1033-
proc stopColumnSyncWorkers[A, B](man: ColumnManager[A, B]) =
1023+
proc stopColumnSyncWorkers[A, B](man: ColumnManager[A, B])
1024+
{.async: (raises: []).} =
10341025
# Cancelling all the column sync workers
10351026
let pending = man.workers.mapIt(it.future.cancelAndWait())
10361027
await noCancel allFutures(pending)
@@ -1077,13 +1068,10 @@ proc columnSyncLoop[A, B](
10771068
man: ColumnManager[A, B]
10781069
) {.async: (raises: [CancelledError]).} =
10791070

1080-
logScope:
1081-
direction = man.direction
1082-
topics = "columnsync"
1083-
10841071
mixin getKey, getScore
10851072
var pauseTime = 0
10861073

1074+
man.initColumnSyncerAssist()
10871075
man.startColumnSyncWorkers()
10881076

10891077
debug "Column sync loop has started",
@@ -1201,6 +1189,14 @@ proc columnSyncLoop[A, B](
12011189
man.avgSyncSpeed.formatBiggestFloat(ffDecimal, 4) &
12021190
"slots/s (" & map & ":" & currentSlot & ")"
12031191

1192+
if (man.assist.direction == ColumnSyncerDirection.Forward) and
1193+
(ColumnSyncerMode.NoGenesisSync in man.modes):
1194+
if not(man.isWithinWeakSubjectivityPeriod()):
1195+
fatal WeakSubjectivityLogMessage, current_slot = wallSlot
1196+
await man.stopColumnSyncWorkers()
1197+
man.shutdownEvent.fire()
1198+
return
1199+
12041200
if man.remainingSlots() <= man.maxHeadAge:
12051201
man.notInSyncEvent.clear()
12061202
# We are marking SyncManager as not working only when we are in sync and

beacon_chain/sync/column_syncer_assist.nim

+12-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type
6565
debtsCount: uint64
6666
readyQueue: HeapQueue[ColumnSyncResult[T]]
6767
rewind: Option[RewindPoint]
68+
db: BeaconChainDB
6869
peerdasBlockVerifier: PeerdasBlockVerifier
6970

7071
proc init[T](t1: typedesc[ColumnSyncRequest], direction: ColumnSyncerDirection, start: Slot,
@@ -587,8 +588,16 @@ proc push*[T](cas: ColumnSyncerAssist[T], sr: ColumnSyncRequest[T],
587588
missingParentSlot = some(blk[].slot)
588589
break
589590
of VerifierError.Duplicate:
590-
# Keep going, happens naturally
591-
discard
591+
debug "Attempting to persist downloaded columns into store",
592+
topics = "columnsync"
593+
# it means the block syncer has enqueued
594+
# the block first, and we can now call the
595+
# block reliable, hence we can directly
596+
# attempt to persist the data column sidecar
597+
# into the columns store
598+
for cl in col.get:
599+
cas.db.putDataColumnSidecar(cl[])
600+
592601
of VerifierError.UnviableFork:
593602
# Keep going as to register other unviable blocks with the
594603
# quarantine
@@ -601,7 +610,7 @@ proc push*[T](cas: ColumnSyncerAssist[T], sr: ColumnSyncRequest[T],
601610

602611
let req = item.request
603612
notice "Received invalid sequence of blocks",
604-
blocks_count = len(item.data)
613+
blocks_count = len(item.data), topics = "columnsync"
605614
req.item.updateScore(PeerScoreBadValues)
606615
break
607616

0 commit comments

Comments
 (0)