WithDataColumnRetentionEpochs: Use dataColumnRetentionEpoch instead of blobColumnRetentionEpoch. (#15872)

This commit is contained in:
Manu NALEPA
2025-10-15 16:44:49 +02:00
committed by GitHub
parent c811fadf33
commit 9742333f68
5 changed files with 69 additions and 3 deletions

View File

@@ -1032,5 +1032,5 @@ func extractFileMetadata(path string) (*fileMetadata, error) {
// period computes the period of a given epoch.
func period(epoch primitives.Epoch) uint64 {
return uint64(epoch / params.BeaconConfig().MinEpochsForBlobsSidecarsRequest)
return uint64(epoch / params.BeaconConfig().MinEpochsForDataColumnSidecarsRequest)
}

View File

@@ -126,7 +126,7 @@ func NewWarmedEphemeralDataColumnStorageUsingFs(t testing.TB, fs afero.Fs, opts
func NewEphemeralDataColumnStorageUsingFs(t testing.TB, fs afero.Fs, opts ...DataColumnStorageOption) *DataColumnStorage {
opts = append(opts,
WithDataColumnRetentionEpochs(params.BeaconConfig().MinEpochsForBlobsSidecarsRequest),
WithDataColumnRetentionEpochs(params.BeaconConfig().MinEpochsForDataColumnSidecarsRequest),
WithDataColumnFs(fs),
)

View File

@@ -0,0 +1,2 @@
### Fixed
- `WithDataColumnRetentionEpochs`: Use `dataColumnRetentionEpoch` instead of `blobColumnRetentionEpoch`.

View File

@@ -68,8 +68,13 @@ func BeaconNodeOptions(c *cli.Context) ([]node.Option, error) {
filesystem.WithLayout(c.String(BlobStorageLayout.Name)), // This is validated in the Action func for BlobStorageLayout.
)
dataColumnRetentionEpoch, err := dataColumnRetentionEpoch(c)
if err != nil {
return nil, errors.Wrap(err, "data column retention epoch")
}
dataColumnStorageOption := node.WithDataColumnStorageOptions(
filesystem.WithDataColumnRetentionEpochs(blobRetentionEpoch),
filesystem.WithDataColumnRetentionEpochs(dataColumnRetentionEpoch),
filesystem.WithDataColumnBasePath(dataColumnStoragePath(c)),
)
@@ -116,6 +121,26 @@ func blobRetentionEpoch(cliCtx *cli.Context) (primitives.Epoch, error) {
return re, nil
}
// dataColumnRetentionEpoch returns the spec default MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUEST
// or a user-specified flag overriding this value. If a user-specified override is
// smaller than the spec default, an error will be returned.
func dataColumnRetentionEpoch(cliCtx *cli.Context) (primitives.Epoch, error) {
defaultValue := params.BeaconConfig().MinEpochsForDataColumnSidecarsRequest
if !cliCtx.IsSet(BlobRetentionEpochFlag.Name) {
return defaultValue, nil
}
// We use on purpose the same retention flag for both blobs and data columns.
customValue := primitives.Epoch(cliCtx.Uint64(BlobRetentionEpochFlag.Name))
// Validate the epoch value against the spec default.
if customValue < defaultValue {
return defaultValue, errors.Wrapf(errInvalidBlobRetentionEpochs, "%s=%d, spec=%d", BlobRetentionEpochFlag.Name, customValue, defaultValue)
}
return customValue, nil
}
func init() {
BlobStorageLayout.Action = validateLayoutFlag
}

View File

@@ -61,6 +61,45 @@ func TestConfigureBlobRetentionEpoch(t *testing.T) {
_, err = blobRetentionEpoch(cliCtx)
require.ErrorIs(t, err, errInvalidBlobRetentionEpochs)
}
func TestConfigureDataColumnRetentionEpoch(t *testing.T) {
specValue := params.BeaconConfig().MinEpochsForDataColumnSidecarsRequest
app := cli.App{}
set := flag.NewFlagSet("test", 0)
cliCtx := cli.NewContext(&app, set, nil)
// Test case: Specification value
expected := specValue
actual, err := dataColumnRetentionEpoch(cliCtx)
require.NoError(t, err)
require.Equal(t, expected, actual)
// Manually define the flag in the set, so the following code can use set.Set
set.Uint64(BlobRetentionEpochFlag.Name, 0, "")
// Test case: Input epoch is greater than or equal to specification value.
expected = specValue + 1
err = set.Set(BlobRetentionEpochFlag.Name, fmt.Sprintf("%d", expected))
require.NoError(t, err)
actual, err = dataColumnRetentionEpoch(cliCtx)
require.NoError(t, err)
require.Equal(t, primitives.Epoch(expected), actual)
// Test case: Input epoch is less than specification value.
expected = specValue - 1
err = set.Set(BlobRetentionEpochFlag.Name, fmt.Sprintf("%d", expected))
require.NoError(t, err)
actual, err = dataColumnRetentionEpoch(cliCtx)
require.ErrorIs(t, err, errInvalidBlobRetentionEpochs)
require.Equal(t, specValue, actual)
}
func TestDataColumnStoragePath_FlagSpecified(t *testing.T) {
app := cli.App{}
set := flag.NewFlagSet("test", 0)