mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
* wip * fixing tests * adding script to update workspace for eth clients * updating test sepc to 1.6.0 and fixing broadcaster test * fix specrefs * more ethspecify fixes * still trying to fix ethspecify * fixing attestation tests * fixing sha for consensus specs * removing script for now until i have something more standard * fixing more p2p tests * fixing discovery tests * attempting to fix discovery test flakeyness * attempting to fix port binding issue * more attempts to fix flakey tests * Revert "more attempts to fix flakey tests" This reverts commit25e8183703. * Revert "attempting to fix port binding issue" This reverts commit583df8000d. * Revert "attempting to fix discovery test flakeyness" This reverts commit3c76525870. * Revert "fixing discovery tests" This reverts commit8c701bf3b9. * Revert "fixing more p2p tests" This reverts commit140d5db203. * Revert "fixing attestation tests" This reverts commit26ded244cb. * fixing attestation tests * fixing more p2p tests * fixing discovery tests * attempting to fix discovery test flakeyness * attempting to fix port binding issue * more attempts to fix flakey tests * changelog * fixing import * adding some missing dependencies, but TestService_BroadcastAttestationWithDiscoveryAttempts is still failing * attempting to fix test * reverting test as it migrated to other pr * reverting test * fixing test from merge * Fix `TestService_BroadcastAttestationWithDiscoveryAttempts`. * Fix again `TestService_Start_OnlyStartsOnce`. * fixing TestListenForNewNodes * removing manual set of fulu epoch * missed a few * fixing subnet test * Update beacon-chain/rpc/eth/config/handlers_test.go Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com> * removing a few more missed spots of reverting fulu epoch setting * updating test name based on feedback * fixing rest apis, they actually need the setting of the epoch due to the guard --------- Co-authored-by: Manu NALEPA <enalepa@offchainlabs.com> Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
213 lines
7.0 KiB
Go
213 lines
7.0 KiB
Go
package das
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/OffchainLabs/prysm/v6/beacon-chain/db/filesystem"
|
|
"github.com/OffchainLabs/prysm/v6/beacon-chain/verification"
|
|
"github.com/OffchainLabs/prysm/v6/config/params"
|
|
"github.com/OffchainLabs/prysm/v6/consensus-types/blocks"
|
|
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
|
|
"github.com/OffchainLabs/prysm/v6/encoding/bytesutil"
|
|
"github.com/OffchainLabs/prysm/v6/testing/require"
|
|
"github.com/OffchainLabs/prysm/v6/testing/util"
|
|
"github.com/OffchainLabs/prysm/v6/time/slots"
|
|
errors "github.com/pkg/errors"
|
|
)
|
|
|
|
func Test_commitmentsToCheck(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
params.BeaconConfig().FuluForkEpoch = params.BeaconConfig().ElectraForkEpoch + 4096*2
|
|
fulu := primitives.Slot(params.BeaconConfig().FuluForkEpoch) * params.BeaconConfig().SlotsPerEpoch
|
|
windowSlots, err := slots.EpochEnd(params.BeaconConfig().MinEpochsForBlobsSidecarsRequest)
|
|
require.NoError(t, err)
|
|
windowSlots = windowSlots + primitives.Slot(params.BeaconConfig().FuluForkEpoch)
|
|
maxBlobs := params.LastNetworkScheduleEntry().MaxBlobsPerBlock
|
|
commits := make([][]byte, maxBlobs+1)
|
|
for i := 0; i < len(commits); i++ {
|
|
commits[i] = bytesutil.PadTo([]byte{byte(i)}, 48)
|
|
}
|
|
cases := []struct {
|
|
name string
|
|
commits [][]byte
|
|
block func(*testing.T) blocks.ROBlock
|
|
slot primitives.Slot
|
|
err error
|
|
}{
|
|
{
|
|
name: "pre deneb",
|
|
block: func(t *testing.T) blocks.ROBlock {
|
|
bb := util.NewBeaconBlockBellatrix()
|
|
sb, err := blocks.NewSignedBeaconBlock(bb)
|
|
require.NoError(t, err)
|
|
rb, err := blocks.NewROBlock(sb)
|
|
require.NoError(t, err)
|
|
return rb
|
|
},
|
|
},
|
|
{
|
|
name: "commitments within da",
|
|
block: func(t *testing.T) blocks.ROBlock {
|
|
d := util.NewBeaconBlockFulu()
|
|
d.Block.Slot = fulu + 100
|
|
mb := params.GetNetworkScheduleEntry(slots.ToEpoch(d.Block.Slot)).MaxBlobsPerBlock
|
|
d.Block.Body.BlobKzgCommitments = commits[:mb]
|
|
sb, err := blocks.NewSignedBeaconBlock(d)
|
|
require.NoError(t, err)
|
|
rb, err := blocks.NewROBlock(sb)
|
|
require.NoError(t, err)
|
|
return rb
|
|
},
|
|
commits: func() [][]byte {
|
|
mb := params.GetNetworkScheduleEntry(slots.ToEpoch(fulu + 100)).MaxBlobsPerBlock
|
|
return commits[:mb]
|
|
}(),
|
|
slot: fulu + 100,
|
|
},
|
|
{
|
|
name: "commitments outside da",
|
|
block: func(t *testing.T) blocks.ROBlock {
|
|
d := util.NewBeaconBlockFulu()
|
|
d.Block.Slot = fulu
|
|
// block is from slot 0, "current slot" is window size +1 (so outside the window)
|
|
d.Block.Body.BlobKzgCommitments = commits[:maxBlobs]
|
|
sb, err := blocks.NewSignedBeaconBlock(d)
|
|
require.NoError(t, err)
|
|
rb, err := blocks.NewROBlock(sb)
|
|
require.NoError(t, err)
|
|
return rb
|
|
},
|
|
slot: fulu + windowSlots + 1,
|
|
},
|
|
{
|
|
name: "excessive commitments",
|
|
block: func(t *testing.T) blocks.ROBlock {
|
|
d := util.NewBeaconBlockFulu()
|
|
d.Block.Slot = fulu + 100
|
|
// block is from slot 0, "current slot" is window size +1 (so outside the window)
|
|
d.Block.Body.BlobKzgCommitments = commits
|
|
sb, err := blocks.NewSignedBeaconBlock(d)
|
|
require.NoError(t, err)
|
|
rb, err := blocks.NewROBlock(sb)
|
|
require.NoError(t, err)
|
|
c, err := rb.Block().Body().BlobKzgCommitments()
|
|
require.NoError(t, err)
|
|
require.Equal(t, true, len(c) > params.BeaconConfig().MaxBlobsPerBlock(sb.Block().Slot()))
|
|
return rb
|
|
},
|
|
slot: windowSlots + 1,
|
|
err: errIndexOutOfBounds,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
b := c.block(t)
|
|
co, err := commitmentsToCheck(b, c.slot)
|
|
if c.err != nil {
|
|
require.ErrorIs(t, err, c.err)
|
|
} else {
|
|
require.NoError(t, err)
|
|
}
|
|
require.Equal(t, len(c.commits), len(co))
|
|
for i := 0; i < len(c.commits); i++ {
|
|
require.Equal(t, true, bytes.Equal(c.commits[i], co[i]))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLazilyPersistent_Missing(t *testing.T) {
|
|
ctx := t.Context()
|
|
store := filesystem.NewEphemeralBlobStorage(t)
|
|
ds := util.SlotAtEpoch(t, params.BeaconConfig().DenebForkEpoch)
|
|
|
|
blk, blobSidecars := util.GenerateTestDenebBlockWithSidecar(t, [32]byte{}, ds, 3)
|
|
|
|
mbv := &mockBlobBatchVerifier{t: t, scs: blobSidecars}
|
|
as := NewLazilyPersistentStore(store, mbv)
|
|
|
|
// Only one commitment persisted, should return error with other indices
|
|
require.NoError(t, as.Persist(ds, blobSidecars[2]))
|
|
err := as.IsDataAvailable(ctx, ds, blk)
|
|
require.ErrorIs(t, err, errMissingSidecar)
|
|
|
|
// All but one persisted, return missing idx
|
|
require.NoError(t, as.Persist(ds, blobSidecars[0]))
|
|
err = as.IsDataAvailable(ctx, ds, blk)
|
|
require.ErrorIs(t, err, errMissingSidecar)
|
|
|
|
// All persisted, return nil
|
|
require.NoError(t, as.Persist(ds, blobSidecars...))
|
|
|
|
require.NoError(t, as.IsDataAvailable(ctx, ds, blk))
|
|
}
|
|
|
|
func TestLazilyPersistent_Mismatch(t *testing.T) {
|
|
ctx := t.Context()
|
|
store := filesystem.NewEphemeralBlobStorage(t)
|
|
ds := util.SlotAtEpoch(t, params.BeaconConfig().DenebForkEpoch)
|
|
|
|
blk, blobSidecars := util.GenerateTestDenebBlockWithSidecar(t, [32]byte{}, ds, 3)
|
|
|
|
mbv := &mockBlobBatchVerifier{t: t, err: errors.New("kzg check should not run")}
|
|
blobSidecars[0].KzgCommitment = bytesutil.PadTo([]byte("nope"), 48)
|
|
as := NewLazilyPersistentStore(store, mbv)
|
|
|
|
// Only one commitment persisted, should return error with other indices
|
|
require.NoError(t, as.Persist(ds, blobSidecars[0]))
|
|
err := as.IsDataAvailable(ctx, ds, blk)
|
|
require.NotNil(t, err)
|
|
require.ErrorIs(t, err, errCommitmentMismatch)
|
|
}
|
|
|
|
func TestLazyPersistOnceCommitted(t *testing.T) {
|
|
ds := util.SlotAtEpoch(t, params.BeaconConfig().DenebForkEpoch)
|
|
_, blobSidecars := util.GenerateTestDenebBlockWithSidecar(t, [32]byte{}, ds, 6)
|
|
|
|
as := NewLazilyPersistentStore(filesystem.NewEphemeralBlobStorage(t), &mockBlobBatchVerifier{})
|
|
// stashes as expected
|
|
require.NoError(t, as.Persist(ds, blobSidecars...))
|
|
// ignores duplicates
|
|
require.ErrorIs(t, as.Persist(ds, blobSidecars...), ErrDuplicateSidecar)
|
|
|
|
// ignores index out of bound
|
|
blobSidecars[0].Index = 6
|
|
require.ErrorIs(t, as.Persist(ds, blobSidecars[0]), errIndexOutOfBounds)
|
|
_, moreBlobSidecars := util.GenerateTestDenebBlockWithSidecar(t, [32]byte{}, ds, 4)
|
|
|
|
// ignores sidecars before the retention period
|
|
slotOOB := util.SlotAtEpoch(t, params.BeaconConfig().MinEpochsForBlobsSidecarsRequest)
|
|
slotOOB += ds + 32
|
|
require.NoError(t, as.Persist(slotOOB, moreBlobSidecars[0]))
|
|
|
|
// doesn't ignore new sidecars with a different block root
|
|
require.NoError(t, as.Persist(ds, moreBlobSidecars...))
|
|
}
|
|
|
|
type mockBlobBatchVerifier struct {
|
|
t *testing.T
|
|
scs []blocks.ROBlob
|
|
err error
|
|
verified map[[32]byte]primitives.Slot
|
|
}
|
|
|
|
var _ BlobBatchVerifier = &mockBlobBatchVerifier{}
|
|
|
|
func (m *mockBlobBatchVerifier) VerifiedROBlobs(_ context.Context, _ blocks.ROBlock, scs []blocks.ROBlob) ([]blocks.VerifiedROBlob, error) {
|
|
require.Equal(m.t, len(scs), len(m.scs))
|
|
for i := range m.scs {
|
|
require.Equal(m.t, m.scs[i], scs[i])
|
|
}
|
|
vscs := verification.FakeVerifySliceForTest(m.t, scs)
|
|
return vscs, m.err
|
|
}
|
|
|
|
func (m *mockBlobBatchVerifier) MarkVerified(root [32]byte, slot primitives.Slot) {
|
|
if m.verified == nil {
|
|
m.verified = make(map[[32]byte]primitives.Slot)
|
|
}
|
|
m.verified[root] = slot
|
|
}
|