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 Nov 22, 2024
1 parent 303f81e commit c8af1e3
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 c8af1e3

Please sign in to comment.