From f2fe91e98e6977acf8edf969a4ff8221e180cf21 Mon Sep 17 00:00:00 2001 From: Manu NALEPA Date: Wed, 16 Oct 2024 17:35:10 +0200 Subject: [PATCH] `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. --- .../sync/rpc_data_column_sidecars_by_range.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/beacon-chain/sync/rpc_data_column_sidecars_by_range.go b/beacon-chain/sync/rpc_data_column_sidecars_by_range.go index d40fb8653e5a..0385b09b5369 100644 --- a/beacon-chain/sync/rpc_data_column_sidecars_by_range.go +++ b/beacon-chain/sync/rpc_data_column_sidecars_by_range.go @@ -2,6 +2,7 @@ package sync import ( "context" + "slices" "time" libp2pcore "github.com/libp2p/go-libp2p/core" @@ -19,7 +20,7 @@ import ( "github.com/sirupsen/logrus" ) -func (s *Service) streamDataColumnBatch(ctx context.Context, batch blockBatch, wQuota uint64, wantedDataColumnIndices map[uint64]bool, stream libp2pcore.Stream) (uint64, error) { +func (s *Service) streamDataColumnBatch(ctx context.Context, batch blockBatch, wQuota uint64, wantedDataColumnIndices []uint64, stream libp2pcore.Stream) (uint64, error) { _, span := trace.StartSpan(ctx, "sync.streamDataColumnBatch") defer span.End() @@ -40,7 +41,7 @@ func (s *Service) streamDataColumnBatch(ctx context.Context, batch blockBatch, w return wQuota, errors.Wrapf(err, "could not retrieve data columns indice for block root %#x", blockRoot) } - for dataColumnIndex := range wantedDataColumnIndices { + for _, dataColumnIndex := range wantedDataColumnIndices { isDataColumnStored := storedDataColumnsIndices[dataColumnIndex] // Skip if the data column is not stored. @@ -157,10 +158,11 @@ func (s *Service) dataColumnSidecarsByRangeRPCHandler(ctx context.Context, msg i } // Derive the wanted columns for the request. - wantedColumns := make(map[uint64]bool, len(r.Columns)) - for _, c := range r.Columns { - wantedColumns[c] = true - } + wantedColumns := make([]uint64, len(r.Columns)) + copy(wantedColumns, r.Columns) + + // Sort the wanted columns. + slices.Sort[[]uint64](wantedColumns) var batch blockBatch wQuota := params.BeaconConfig().MaxRequestDataColumnSidecars