Skip to content

Commit 2d46d6f

Browse files
authored
Various small optimizations (#15153)
* Reconstruct data columns from gossip source: Call `setSeenDataColumnIndex`. * `reconstructAndBroadcastDataColumnSidecars`: Minor optimisation. Avoid to range over all columns. * Reconstructed data columns sidecars from EL: Avoid broadcasting already received data columns.
1 parent 57107e5 commit 2d46d6f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

beacon-chain/sync/data_columns_reconstruct.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func (s *Service) reconstructDataColumns(ctx context.Context, verifiedRODataColu
109109
}
110110

111111
// Save the data columns sidecars in the database.
112+
// Note: We do not call `receiveDataColumn`, because it will ignore
113+
// incoming data columns via gossip while we did not broadcast (yet) the reconstructed data columns.
112114
if err := s.cfg.dataColumnStorage.Save(verifiedRODataColumns); err != nil {
113115
return errors.Wrap(err, "save data column sidecars")
114116
}
@@ -214,6 +216,9 @@ func (s *Service) scheduleReconstructedDataColumnsBroadcast(
214216
if err := s.cfg.p2p.BroadcastDataColumn(ctx, root, subnet, verifiedRODataColumn.DataColumnSidecar); err != nil {
215217
log.WithError(err).Error("Broadcast data column")
216218
}
219+
220+
// Now, we can set the data column as seen.
221+
s.setSeenDataColumnIndex(slot, proposerIndex, verifiedRODataColumn.Index)
217222
}
218223

219224
// Sort the missing data columns.

beacon-chain/sync/subscriber_beacon_blocks.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,23 @@ func (s *Service) reconstructAndBroadcastDataColumnSidecars(ctx context.Context,
118118
return
119119
}
120120

121-
// Broadcast data column and then save to db (if needs to be in custody)
122-
for _, sidecar := range sidecars {
123-
if !info.CustodyColumns[sidecar.Index] {
121+
blockSlot := block.Slot()
122+
proposerIndex := block.ProposerIndex()
123+
124+
// Broadcast and save data columns sidecars to custody but not yet received.
125+
sidecarCount := uint64(len(sidecars))
126+
for columnIndex := range info.CustodyColumns {
127+
if columnIndex >= sidecarCount {
128+
log.WithField("index", columnIndex).Error("Sidecar index out of range - should never happen")
124129
continue
125130
}
126131

132+
if s.hasSeenDataColumnIndex(blockSlot, proposerIndex, columnIndex) {
133+
continue
134+
}
135+
136+
sidecar := sidecars[columnIndex]
137+
127138
if err := s.cfg.p2p.BroadcastDataColumn(ctx, blockRoot, sidecar.Index, sidecar.DataColumnSidecar); err != nil {
128139
log.WithFields(dataColumnFields(sidecar.RODataColumn)).WithError(err).Error("Failed to broadcast data column")
129140
}

0 commit comments

Comments
 (0)