Skip to content

Commit

Permalink
streamDataColumnBatch: Sort columns by index. (#14542)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nalepae committed Oct 23, 2024
1 parent 3908a0b commit f2fe91e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions beacon-chain/sync/rpc_data_column_sidecars_by_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sync

import (
"context"
"slices"
"time"

libp2pcore "github.com/libp2p/go-libp2p/core"
Expand All @@ -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()

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2fe91e

Please sign in to comment.