Skip to content

Commit cc9ab4a

Browse files
fix conflicts and merge
2 parents 5c0213b + a321015 commit cc9ab4a

File tree

145 files changed

+11413
-1261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+11413
-1261
lines changed

beacon-chain/blockchain/process_attestation_helpers.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,19 @@ import (
2222
// The caller of this function must have a lock on forkchoice.
2323
func (s *Service) getRecentPreState(ctx context.Context, c *ethpb.Checkpoint) state.ReadOnlyBeaconState {
2424
headEpoch := slots.ToEpoch(s.HeadSlot())
25-
if c.Epoch < headEpoch {
26-
return nil
27-
}
28-
if !s.cfg.ForkChoiceStore.IsCanonical([32]byte(c.Root)) {
25+
if c.Epoch < headEpoch || c.Epoch == 0 {
2926
return nil
3027
}
3128
// Only use head state if the head state is compatible with the target checkpoint.
3229
headRoot, err := s.HeadRoot(ctx)
3330
if err != nil {
3431
return nil
3532
}
36-
headDependent, err := s.cfg.ForkChoiceStore.DependentRootForEpoch([32]byte(headRoot), c.Epoch)
33+
headDependent, err := s.cfg.ForkChoiceStore.DependentRootForEpoch([32]byte(headRoot), c.Epoch-1)
3734
if err != nil {
3835
return nil
3936
}
40-
targetDependent, err := s.cfg.ForkChoiceStore.DependentRootForEpoch([32]byte(c.Root), c.Epoch)
37+
targetDependent, err := s.cfg.ForkChoiceStore.DependentRootForEpoch([32]byte(c.Root), c.Epoch-1)
4138
if err != nil {
4239
return nil
4340
}
@@ -53,7 +50,11 @@ func (s *Service) getRecentPreState(ctx context.Context, c *ethpb.Checkpoint) st
5350
}
5451
return st
5552
}
56-
// Otherwise we need to advance the head state to the start of the target epoch.
53+
// At this point we can only have c.Epoch > headEpoch.
54+
if !s.cfg.ForkChoiceStore.IsCanonical([32]byte(c.Root)) {
55+
return nil
56+
}
57+
// Advance the head state to the start of the target epoch.
5758
// This point can only be reached if c.Root == headRoot and c.Epoch > headEpoch.
5859
slot, err := slots.EpochStart(c.Epoch)
5960
if err != nil {

beacon-chain/blockchain/process_attestation_test.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,123 @@ func TestService_GetRecentPreState(t *testing.T) {
181181
require.NotNil(t, service.getRecentPreState(ctx, &ethpb.Checkpoint{Epoch: 1, Root: ckRoot}))
182182
}
183183

184+
func TestService_GetRecentPreState_Epoch_0(t *testing.T) {
185+
service, _ := minimalTestService(t)
186+
ctx := t.Context()
187+
require.IsNil(t, service.getRecentPreState(ctx, &ethpb.Checkpoint{}))
188+
}
189+
190+
func TestService_GetRecentPreState_Old_Checkpoint(t *testing.T) {
191+
service, _ := minimalTestService(t)
192+
ctx := t.Context()
193+
s, err := util.NewBeaconState()
194+
require.NoError(t, err)
195+
ckRoot := bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)
196+
cp0 := &ethpb.Checkpoint{Epoch: 0, Root: ckRoot}
197+
err = s.SetFinalizedCheckpoint(cp0)
198+
require.NoError(t, err)
199+
200+
st, root, err := prepareForkchoiceState(ctx, 33, [32]byte(ckRoot), [32]byte{}, [32]byte{'R'}, cp0, cp0)
201+
require.NoError(t, err)
202+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, root))
203+
service.head = &head{
204+
root: [32]byte(ckRoot),
205+
state: s,
206+
slot: 33,
207+
}
208+
require.IsNil(t, service.getRecentPreState(ctx, &ethpb.Checkpoint{}))
209+
}
210+
211+
func TestService_GetRecentPreState_Same_DependentRoots(t *testing.T) {
212+
service, _ := minimalTestService(t)
213+
ctx := t.Context()
214+
s, err := util.NewBeaconState()
215+
require.NoError(t, err)
216+
ckRoot := bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)
217+
cp0 := &ethpb.Checkpoint{Epoch: 0, Root: ckRoot}
218+
219+
// Create a fork 31 <-- 32 <--- 64
220+
// \---------33
221+
// With the same dependent root at epoch 0 for a checkpoint at epoch 2
222+
st, blk, err := prepareForkchoiceState(ctx, 31, [32]byte(ckRoot), [32]byte{}, [32]byte{}, cp0, cp0)
223+
require.NoError(t, err)
224+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
225+
st, blk, err = prepareForkchoiceState(ctx, 32, [32]byte{'S'}, blk.Root(), [32]byte{}, cp0, cp0)
226+
require.NoError(t, err)
227+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
228+
st, blk, err = prepareForkchoiceState(ctx, 64, [32]byte{'T'}, blk.Root(), [32]byte{}, cp0, cp0)
229+
require.NoError(t, err)
230+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
231+
st, blk, err = prepareForkchoiceState(ctx, 33, [32]byte{'U'}, [32]byte(ckRoot), [32]byte{}, cp0, cp0)
232+
require.NoError(t, err)
233+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
234+
cpRoot := blk.Root()
235+
236+
service.head = &head{
237+
root: [32]byte{'T'},
238+
state: s,
239+
slot: 64,
240+
}
241+
require.NotNil(t, service.getRecentPreState(ctx, &ethpb.Checkpoint{Epoch: 2, Root: cpRoot[:]}))
242+
}
243+
244+
func TestService_GetRecentPreState_Different_DependentRoots(t *testing.T) {
245+
service, _ := minimalTestService(t)
246+
ctx := t.Context()
247+
s, err := util.NewBeaconState()
248+
require.NoError(t, err)
249+
ckRoot := bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)
250+
cp0 := &ethpb.Checkpoint{Epoch: 0, Root: ckRoot}
251+
252+
// Create a fork 30 <-- 31 <-- 32 <--- 64
253+
// \---------33
254+
// With the same dependent root at epoch 0 for a checkpoint at epoch 2
255+
st, blk, err := prepareForkchoiceState(ctx, 30, [32]byte(ckRoot), [32]byte{}, [32]byte{}, cp0, cp0)
256+
require.NoError(t, err)
257+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
258+
st, blk, err = prepareForkchoiceState(ctx, 31, [32]byte{'S'}, blk.Root(), [32]byte{}, cp0, cp0)
259+
require.NoError(t, err)
260+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
261+
st, blk, err = prepareForkchoiceState(ctx, 32, [32]byte{'T'}, blk.Root(), [32]byte{}, cp0, cp0)
262+
require.NoError(t, err)
263+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
264+
st, blk, err = prepareForkchoiceState(ctx, 64, [32]byte{'U'}, blk.Root(), [32]byte{}, cp0, cp0)
265+
require.NoError(t, err)
266+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
267+
st, blk, err = prepareForkchoiceState(ctx, 33, [32]byte{'V'}, [32]byte(ckRoot), [32]byte{}, cp0, cp0)
268+
require.NoError(t, err)
269+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blk))
270+
cpRoot := blk.Root()
271+
272+
service.head = &head{
273+
root: [32]byte{'T'},
274+
state: s,
275+
slot: 64,
276+
}
277+
require.IsNil(t, service.getRecentPreState(ctx, &ethpb.Checkpoint{Epoch: 2, Root: cpRoot[:]}))
278+
}
279+
280+
func TestService_GetRecentPreState_Different(t *testing.T) {
281+
service, _ := minimalTestService(t)
282+
ctx := t.Context()
283+
s, err := util.NewBeaconState()
284+
require.NoError(t, err)
285+
ckRoot := bytesutil.PadTo([]byte{'A'}, fieldparams.RootLength)
286+
cp0 := &ethpb.Checkpoint{Epoch: 0, Root: ckRoot}
287+
err = s.SetFinalizedCheckpoint(cp0)
288+
require.NoError(t, err)
289+
290+
st, root, err := prepareForkchoiceState(ctx, 33, [32]byte(ckRoot), [32]byte{}, [32]byte{'R'}, cp0, cp0)
291+
require.NoError(t, err)
292+
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, root))
293+
service.head = &head{
294+
root: [32]byte(ckRoot),
295+
state: s,
296+
slot: 33,
297+
}
298+
require.IsNil(t, service.getRecentPreState(ctx, &ethpb.Checkpoint{}))
299+
}
300+
184301
func TestService_GetAttPreState_Concurrency(t *testing.T) {
185302
service, _ := minimalTestService(t)
186303
ctx := t.Context()

beacon-chain/blockchain/process_block.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func getStateVersionAndPayload(st state.BeaconState) (int, interfaces.ExecutionD
134134
return preStateVersion, preStateHeader, nil
135135
}
136136

137-
func (s *Service) onBlockBatch(ctx context.Context, blks []consensusblocks.ROBlock, avs das.AvailabilityStore) error {
137+
func (s *Service) onBlockBatch(ctx context.Context, blks []consensusblocks.ROBlock, avs das.AvailabilityChecker) error {
138138
ctx, span := trace.StartSpan(ctx, "blockChain.onBlockBatch")
139139
defer span.End()
140140

@@ -306,7 +306,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []consensusblocks.ROBlo
306306
return s.saveHeadNoDB(ctx, lastB, lastBR, preState, !isValidPayload)
307307
}
308308

309-
func (s *Service) areSidecarsAvailable(ctx context.Context, avs das.AvailabilityStore, roBlock consensusblocks.ROBlock) error {
309+
func (s *Service) areSidecarsAvailable(ctx context.Context, avs das.AvailabilityChecker, roBlock consensusblocks.ROBlock) error {
310310
blockVersion := roBlock.Version()
311311
block := roBlock.Block()
312312
slot := block.Slot()
@@ -634,9 +634,7 @@ func missingDataColumnIndices(store *filesystem.DataColumnStorage, root [fieldpa
634634
return nil, nil
635635
}
636636

637-
numberOfColumns := params.BeaconConfig().NumberOfColumns
638-
639-
if uint64(len(expected)) > numberOfColumns {
637+
if len(expected) > fieldparams.NumberOfColumns {
640638
return nil, errMaxDataColumnsExceeded
641639
}
642640

@@ -818,10 +816,9 @@ func (s *Service) areDataColumnsAvailable(
818816

819817
case <-ctx.Done():
820818
var missingIndices any = "all"
821-
numberOfColumns := params.BeaconConfig().NumberOfColumns
822-
missingIndicesCount := uint64(len(missing))
819+
missingIndicesCount := len(missing)
823820

824-
if missingIndicesCount < numberOfColumns {
821+
if missingIndicesCount < fieldparams.NumberOfColumns {
825822
missingIndices = helpers.SortedPrettySliceFromMap(missing)
826823
}
827824

beacon-chain/blockchain/process_block_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,8 @@ func TestMissingBlobIndices(t *testing.T) {
24952495
}
24962496

24972497
func TestMissingDataColumnIndices(t *testing.T) {
2498-
countPlusOne := params.BeaconConfig().NumberOfColumns + 1
2498+
const countPlusOne = fieldparams.NumberOfColumns + 1
2499+
24992500
tooManyColumns := make(map[uint64]bool, countPlusOne)
25002501
for i := range countPlusOne {
25012502
tooManyColumns[uint64(i)] = true

beacon-chain/blockchain/receive_block.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ var epochsSinceFinalityExpandCache = primitives.Epoch(4)
3939

4040
// BlockReceiver interface defines the methods of chain service for receiving and processing new blocks.
4141
type BlockReceiver interface {
42-
ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte, avs das.AvailabilityStore) error
43-
ReceiveBlockBatch(ctx context.Context, blocks []blocks.ROBlock, avs das.AvailabilityStore) error
42+
ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte, avs das.AvailabilityChecker) error
43+
ReceiveBlockBatch(ctx context.Context, blocks []blocks.ROBlock, avs das.AvailabilityChecker) error
4444
HasBlock(ctx context.Context, root [32]byte) bool
4545
RecentBlockSlot(root [32]byte) (primitives.Slot, error)
4646
BlockBeingSynced([32]byte) bool
@@ -69,7 +69,7 @@ type SlashingReceiver interface {
6969
// 1. Validate block, apply state transition and update checkpoints
7070
// 2. Apply fork choice to the processed block
7171
// 3. Save latest head info
72-
func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte, avs das.AvailabilityStore) error {
72+
func (s *Service) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, blockRoot [32]byte, avs das.AvailabilityChecker) error {
7373
ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlock")
7474
defer span.End()
7575
// Return early if the block is blacklisted
@@ -242,7 +242,7 @@ func (s *Service) validateExecutionAndConsensus(
242242
return postState, isValidPayload, nil
243243
}
244244

245-
func (s *Service) handleDA(ctx context.Context, avs das.AvailabilityStore, block blocks.ROBlock) (time.Duration, error) {
245+
func (s *Service) handleDA(ctx context.Context, avs das.AvailabilityChecker, block blocks.ROBlock) (time.Duration, error) {
246246
var err error
247247
start := time.Now()
248248
if avs != nil {
@@ -332,7 +332,7 @@ func (s *Service) executePostFinalizationTasks(ctx context.Context, finalizedSta
332332
// ReceiveBlockBatch processes the whole block batch at once, assuming the block batch is linear ,transitioning
333333
// the state, performing batch verification of all collected signatures and then performing the appropriate
334334
// actions for a block post-transition.
335-
func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []blocks.ROBlock, avs das.AvailabilityStore) error {
335+
func (s *Service) ReceiveBlockBatch(ctx context.Context, blocks []blocks.ROBlock, avs das.AvailabilityChecker) error {
336336
ctx, span := trace.StartSpan(ctx, "blockChain.ReceiveBlockBatch")
337337
defer span.End()
338338

beacon-chain/blockchain/service_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,13 @@ func TestUpdateCustodyInfoInDB(t *testing.T) {
603603
custodyRequirement = uint64(4)
604604
earliestStoredSlot = primitives.Slot(12)
605605
numberOfCustodyGroups = uint64(64)
606-
numberOfColumns = uint64(128)
607606
)
608607

609608
params.SetupTestConfigCleanup(t)
610609
cfg := params.BeaconConfig()
611610
cfg.FuluForkEpoch = fuluForkEpoch
612611
cfg.CustodyRequirement = custodyRequirement
613612
cfg.NumberOfCustodyGroups = numberOfCustodyGroups
614-
cfg.NumberOfColumns = numberOfColumns
615613
params.OverrideBeaconConfig(cfg)
616614

617615
ctx := t.Context()

beacon-chain/blockchain/testing/mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interf
274274
}
275275

276276
// ReceiveBlockBatch processes blocks in batches from initial-sync.
277-
func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []blocks.ROBlock, _ das.AvailabilityStore) error {
277+
func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []blocks.ROBlock, _ das.AvailabilityChecker) error {
278278
if s.State == nil {
279279
return ErrNilState
280280
}
@@ -304,7 +304,7 @@ func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []blocks.ROBl
304304
}
305305

306306
// ReceiveBlock mocks ReceiveBlock method in chain service.
307-
func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, _ [32]byte, _ das.AvailabilityStore) error {
307+
func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.ReadOnlySignedBeaconBlock, _ [32]byte, _ das.AvailabilityChecker) error {
308308
if s.ReceiveBlockMockErr != nil {
309309
return s.ReceiveBlockMockErr
310310
}

beacon-chain/core/blocks/eth1_data.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func Eth1DataHasEnoughSupport(beaconState state.ReadOnlyBeaconState, data *ethpb
6060
voteCount := uint64(0)
6161

6262
for _, vote := range beaconState.Eth1DataVotes() {
63-
if AreEth1DataEqual(vote, data.Copy()) {
63+
if AreEth1DataEqual(vote, data) {
6464
voteCount++
6565
}
6666
}

beacon-chain/core/peerdas/das_core.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math"
66
"slices"
77

8+
fieldparams "github.com/OffchainLabs/prysm/v7/config/fieldparams"
89
"github.com/OffchainLabs/prysm/v7/config/params"
910
"github.com/OffchainLabs/prysm/v7/crypto/hash"
1011
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
@@ -96,8 +97,7 @@ func ComputeColumnsForCustodyGroup(custodyGroup uint64) ([]uint64, error) {
9697
return nil, ErrCustodyGroupTooLarge
9798
}
9899

99-
numberOfColumns := cfg.NumberOfColumns
100-
100+
numberOfColumns := uint64(fieldparams.NumberOfColumns)
101101
columnsPerGroup := numberOfColumns / numberOfCustodyGroups
102102

103103
columns := make([]uint64, 0, columnsPerGroup)
@@ -112,8 +112,9 @@ func ComputeColumnsForCustodyGroup(custodyGroup uint64) ([]uint64, error) {
112112
// ComputeCustodyGroupForColumn computes the custody group for a given column.
113113
// It is the reciprocal function of ComputeColumnsForCustodyGroup.
114114
func ComputeCustodyGroupForColumn(columnIndex uint64) (uint64, error) {
115+
const numberOfColumns = fieldparams.NumberOfColumns
116+
115117
cfg := params.BeaconConfig()
116-
numberOfColumns := cfg.NumberOfColumns
117118
numberOfCustodyGroups := cfg.NumberOfCustodyGroups
118119

119120
if columnIndex >= numberOfColumns {

beacon-chain/core/peerdas/das_core_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func TestComputeColumnsForCustodyGroup(t *testing.T) {
3030
func TestComputeCustodyGroupForColumn(t *testing.T) {
3131
params.SetupTestConfigCleanup(t)
3232
config := params.BeaconConfig()
33-
config.NumberOfColumns = 128
3433
config.NumberOfCustodyGroups = 64
3534
params.OverrideBeaconConfig(config)
3635

0 commit comments

Comments
 (0)