mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
* Fulu: Implement params. * KZG tests: Re-implement `getRandBlob` to avoid tests cyclical dependencies. Not ideal, but any better idea welcome. * Fulu testing util: Implement `GenerateCellsAndProofs`. * Create `RODataColumn`. * Implement `MerkleProofKZGCommitments`. * Export `leavesFromCommitments`. * Implement peerDAS core. * Add changelog. * Update beacon-chain/core/peerdas/das_core.go Co-authored-by: terence <terence@prysmaticlabs.com> * Fix Terence's comment: Use `IsNil`. * Fix Terence's comment: Avoid useless `filteredIndices`. * Fix Terence's comment: Simplify odd/even cases. * Fix Terence's comment: Use `IsNil`. * Spectests: Add Fulu networking * Fix Terence's comment: `CustodyGroups`: Stick to the spec by returning a (sorted) slice. * Fix Terence's comment: `CustodyGroups`: Handle correctly the `maxUint256` case. * Update beacon-chain/core/peerdas/das_core.go Co-authored-by: terence <terence@prysmaticlabs.com> * Fix Terence's comment: `ComputeColumnsForCustodyGroup`: Add test if `custodyGroup == numberOfCustodyGroup` * `CustodyGroups`: Test if `custodyGroupCount > numberOfCustodyGroup`. * `CustodyGroups`: Add a shortcut if all custody groups are needed. * `ComputeCystodyGroupForColumn`: Move from `p2p_interface.go` to `das_core.go`. * Fix Terence's comment: Fix `ComputeCustodyGroupForColumn`. * Fix Terence's comment: Remove `constructCellsAndProofs` function. * Fix Terence's comment: `ValidatorsCustodyRequirement`: Use effective balance instead of balance. * `MerkleProofKZGCommitments`: Add tests * Remove peer sampling. * `DataColumnSidecars`: Add missing tests. * Fix Jame's comment. * Fix James' comment. * Fix James' comment. * Fix James' coment. * Fix James' comment. --------- Co-authored-by: terence <terence@prysmaticlabs.com>
164 lines
4.4 KiB
Go
164 lines
4.4 KiB
Go
package params_test
|
|
|
|
import (
|
|
"bytes"
|
|
"math"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/OffchainLabs/prysm/v6/beacon-chain/state/genesis"
|
|
"github.com/OffchainLabs/prysm/v6/config/params"
|
|
"github.com/OffchainLabs/prysm/v6/consensus-types/primitives"
|
|
"github.com/OffchainLabs/prysm/v6/runtime/version"
|
|
"github.com/OffchainLabs/prysm/v6/testing/require"
|
|
)
|
|
|
|
// Test cases can be executed in an arbitrary order. TestOverrideBeaconConfigTestTeardown checks
|
|
// that there's no state mutation leak from the previous test, therefore we need a sentinel flag,
|
|
// to make sure that previous test case has already been completed and check can be run.
|
|
var testOverrideBeaconConfigExecuted bool
|
|
|
|
func TestConfig_OverrideBeaconConfig(t *testing.T) {
|
|
// Ensure that param modifications are safe.
|
|
params.SetupTestConfigCleanup(t)
|
|
cfg := params.BeaconConfig()
|
|
cfg.SlotsPerEpoch = 5
|
|
params.OverrideBeaconConfig(cfg)
|
|
if c := params.BeaconConfig(); c.SlotsPerEpoch != 5 {
|
|
t.Errorf("Shardcount in BeaconConfig incorrect. Wanted %d, got %d", 5, c.SlotsPerEpoch)
|
|
}
|
|
testOverrideBeaconConfigExecuted = true
|
|
}
|
|
|
|
func TestConfig_OverrideBeaconConfigTestTeardown(t *testing.T) {
|
|
if !testOverrideBeaconConfigExecuted {
|
|
t.Skip("State leak can occur only if state mutating test has already completed")
|
|
}
|
|
cfg := params.BeaconConfig()
|
|
if cfg.SlotsPerEpoch == 5 {
|
|
t.Fatal("Parameter update has been leaked out of previous test")
|
|
}
|
|
}
|
|
|
|
func TestConfig_DataRace(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
wg := new(sync.WaitGroup)
|
|
for i := 0; i < 10; i++ {
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
cfg := params.BeaconConfig()
|
|
params.OverrideBeaconConfig(cfg)
|
|
}()
|
|
go func() uint64 {
|
|
defer wg.Done()
|
|
return params.BeaconConfig().MaxDeposits
|
|
}()
|
|
}
|
|
wg.Wait()
|
|
}
|
|
|
|
func TestConfig_WithinDAPeriod(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
block primitives.Epoch
|
|
current primitives.Epoch
|
|
within bool
|
|
}{
|
|
{
|
|
name: "before",
|
|
block: 0,
|
|
current: params.BeaconConfig().MinEpochsForBlobsSidecarsRequest + 1,
|
|
within: false,
|
|
},
|
|
{
|
|
name: "same",
|
|
block: 0,
|
|
current: 0,
|
|
within: true,
|
|
},
|
|
{
|
|
name: "boundary",
|
|
block: 0,
|
|
current: params.BeaconConfig().MinEpochsForBlobsSidecarsRequest,
|
|
within: true,
|
|
},
|
|
{
|
|
name: "one less",
|
|
block: params.BeaconConfig().MinEpochsForBlobsSidecarsRequest - 1,
|
|
current: params.BeaconConfig().MinEpochsForBlobsSidecarsRequest,
|
|
within: true,
|
|
},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
require.Equal(t, c.within, params.WithinDAPeriod(c.block, c.current))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestConfigGenesisValidatorRoot(t *testing.T) {
|
|
g, err := genesis.State(params.MainnetName)
|
|
require.NoError(t, err)
|
|
|
|
gvr := g.GenesisValidatorsRoot()
|
|
|
|
if !bytes.Equal(gvr, params.BeaconConfig().GenesisValidatorsRoot[:]) {
|
|
t.Fatal("mainnet params genesis validator root does not match the mainnet genesis state value")
|
|
}
|
|
}
|
|
|
|
func Test_MaxBlobCount(t *testing.T) {
|
|
cfg := params.MainnetConfig()
|
|
cfg.ElectraForkEpoch = 10
|
|
require.Equal(t, cfg.MaxBlobsPerBlock(primitives.Slot(cfg.ElectraForkEpoch)*cfg.SlotsPerEpoch-1), 6)
|
|
require.Equal(t, cfg.MaxBlobsPerBlock(primitives.Slot(cfg.ElectraForkEpoch)*cfg.SlotsPerEpoch), 9)
|
|
cfg.ElectraForkEpoch = math.MaxUint64
|
|
}
|
|
|
|
func Test_TargetBlobCount(t *testing.T) {
|
|
cfg := params.MainnetConfig()
|
|
cfg.ElectraForkEpoch = 10
|
|
require.Equal(t, cfg.TargetBlobsPerBlock(primitives.Slot(cfg.ElectraForkEpoch)*cfg.SlotsPerEpoch-1), 3)
|
|
require.Equal(t, cfg.TargetBlobsPerBlock(primitives.Slot(cfg.ElectraForkEpoch)*cfg.SlotsPerEpoch), 6)
|
|
cfg.ElectraForkEpoch = math.MaxUint64
|
|
}
|
|
|
|
func TestMaxBlobsPerBlockByVersion(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
v int
|
|
want int
|
|
}{
|
|
{
|
|
name: "Version below Electra",
|
|
v: version.Electra - 1,
|
|
want: params.BeaconConfig().DeprecatedMaxBlobsPerBlock,
|
|
},
|
|
{
|
|
name: "Version equal to Electra",
|
|
v: version.Electra,
|
|
want: params.BeaconConfig().DeprecatedMaxBlobsPerBlockElectra,
|
|
},
|
|
{
|
|
name: "Version equal to Fulu",
|
|
v: version.Fulu,
|
|
want: params.BeaconConfig().DeprecatedMaxBlobsPerBlockFulu,
|
|
},
|
|
{
|
|
name: "Version above Fulu",
|
|
v: version.Fulu + 1,
|
|
want: params.BeaconConfig().DeprecatedMaxBlobsPerBlockFulu,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := params.BeaconConfig().MaxBlobsPerBlockByVersion(tt.v)
|
|
if got != tt.want {
|
|
t.Errorf("MaxBlobsPerBlockByVersion(%d) = %d, want %d", tt.v, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|