Skip to content

Commit ee300f3

Browse files
committed
streamDataColumnBatch: Sort columns by index. (#14542)
https://github.com/ethereum/consensus-specs/blob/dev/specs/_features/eip7594/p2p-interface.md#datacolumnsidecarsbyrange-v1 The following data column sidecars, where they exist, MUST be sent in (slot, column_index) order.
1 parent ba0b318 commit ee300f3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

beacon-chain/sync/rpc_data_column_sidecars_by_range.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sync
22

33
import (
44
"context"
5+
"slices"
56
"time"
67

78
libp2pcore "github.com/libp2p/go-libp2p/core"
@@ -19,7 +20,7 @@ import (
1920
"github.com/sirupsen/logrus"
2021
)
2122

22-
func (s *Service) streamDataColumnBatch(ctx context.Context, batch blockBatch, wQuota uint64, wantedDataColumnIndices map[uint64]bool, stream libp2pcore.Stream) (uint64, error) {
23+
func (s *Service) streamDataColumnBatch(ctx context.Context, batch blockBatch, wQuota uint64, wantedDataColumnIndices []uint64, stream libp2pcore.Stream) (uint64, error) {
2324
_, span := trace.StartSpan(ctx, "sync.streamDataColumnBatch")
2425
defer span.End()
2526

@@ -40,7 +41,7 @@ func (s *Service) streamDataColumnBatch(ctx context.Context, batch blockBatch, w
4041
return wQuota, errors.Wrapf(err, "could not retrieve data columns indice for block root %#x", blockRoot)
4142
}
4243

43-
for dataColumnIndex := range wantedDataColumnIndices {
44+
for _, dataColumnIndex := range wantedDataColumnIndices {
4445
isDataColumnStored := storedDataColumnsIndices[dataColumnIndex]
4546

4647
// Skip if the data column is not stored.
@@ -157,10 +158,11 @@ func (s *Service) dataColumnSidecarsByRangeRPCHandler(ctx context.Context, msg i
157158
}
158159

159160
// Derive the wanted columns for the request.
160-
wantedColumns := make(map[uint64]bool, len(r.Columns))
161-
for _, c := range r.Columns {
162-
wantedColumns[c] = true
163-
}
161+
wantedColumns := make([]uint64, len(r.Columns))
162+
copy(wantedColumns, r.Columns)
163+
164+
// Sort the wanted columns.
165+
slices.Sort[[]uint64](wantedColumns)
164166

165167
var batch blockBatch
166168
wQuota := params.BeaconConfig().MaxRequestDataColumnSidecars

0 commit comments

Comments
 (0)