Skip to content

Commit

Permalink
Potuz's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Dec 20, 2024
1 parent 012b224 commit 1a49d61
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
5 changes: 2 additions & 3 deletions beacon-chain/core/altair/sync_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ func NextSyncCommitteeIndices(ctx context.Context, s state.BeaconState) ([]primi
binary.LittleEndian.PutUint64(seedBuffer[len(seed):], uint64(i/16))
randomByte := hashFunc(seedBuffer)
offset := (i % 16) * 2
randomByteSlice := bytesutil.PadTo(randomByte[offset:offset+2], 8)
randomValue := binary.LittleEndian.Uint64(randomByteSlice)
randomValue := uint64(randomByte[offset]) | uint64(randomByte[offset+1])<<8

if effectiveBal*fieldparams.MaxRandomValueElectra >= cfg.MaxEffectiveBalanceElectra*randomValue {
cIndices = append(cIndices, cIndex)
Expand All @@ -160,7 +159,7 @@ func NextSyncCommitteeIndices(ctx context.Context, s state.BeaconState) ([]primi
// Use the preallocated seed buffer
binary.LittleEndian.PutUint64(seedBuffer[len(seed):], uint64(i/32))
randomByte := hashFunc(seedBuffer)[i%32]
if effectiveBal*fieldparams.MaxRandomValue >= cfg.MaxEffectiveBalance*uint64(randomByte) {
if effectiveBal*fieldparams.MaxRandomByte >= cfg.MaxEffectiveBalance*uint64(randomByte) {
cIndices = append(cIndices, cIndex)
}
}
Expand Down
6 changes: 2 additions & 4 deletions beacon-chain/core/helpers/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ func ComputeProposerIndex(bState state.ReadOnlyBeaconState, activeIndices []prim
binary.LittleEndian.PutUint64(seedBuffer[len(seed):], i/16)
randomByte := hashFunc(seedBuffer)
offset := (i % 16) * 2

randomByteSlice := bytesutil.PadTo(randomByte[offset:offset+2], 8)
randomValue := binary.LittleEndian.Uint64(randomByteSlice)
randomValue := uint64(randomByte[offset]) | uint64(randomByte[offset+1])<<8

if effectiveBal*fieldparams.MaxRandomValueElectra >= beaconConfig.MaxEffectiveBalanceElectra*randomValue {
return candidateIndex, nil
Expand All @@ -407,7 +405,7 @@ func ComputeProposerIndex(bState state.ReadOnlyBeaconState, activeIndices []prim
binary.LittleEndian.PutUint64(seedBuffer[len(seed):], i/32)
randomByte := hashFunc(seedBuffer)[i%32]

if effectiveBal*fieldparams.MaxRandomValue >= beaconConfig.MaxEffectiveBalance*uint64(randomByte) {
if effectiveBal*fieldparams.MaxRandomByte >= beaconConfig.MaxEffectiveBalance*uint64(randomByte) {
return candidateIndex, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/helpers/validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ func computeProposerIndexWithValidators(validators []*ethpb.Validator, activeInd
if v != nil {
effectiveBal = v.EffectiveBalance
}
if effectiveBal*fieldparams.MaxRandomValue >= params.BeaconConfig().MaxEffectiveBalance*uint64(randomByte) {
if effectiveBal*fieldparams.MaxRandomByte >= params.BeaconConfig().MaxEffectiveBalance*uint64(randomByte) {
return candidateIndex, nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions config/fieldparams/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ const (
MaxDeposits = 16 // Maximum number of deposits in a block.
MaxVoluntaryExits = 16 // Maximum number of voluntary exits in a block.
MaxBlsToExecutionChanges = 16 // Maximum number of bls to execution changes in a block.
MaxRandomValue = uint64(1<<8 - 1) // Maximum value for a random value using for proposer and sync committee sampling.
MaxRandomValueElectra = uint64(1<<16 - 1) // Maximum value for a random value using for proposer and sync committee sampling.
MaxRandomByte = uint64(1<<8 - 1) // MaxRandomByte defines max for a random byte using for proposer and sync committee sampling.
MaxRandomValueElectra = uint64(1<<16 - 1) // MaxRandomValueElectra defines max for a random value using for proposer and sync committee sampling.
)
8 changes: 3 additions & 5 deletions config/fieldparams/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ const (
SyncCommitteeAggregationBytesLength = 1 // SyncCommitteeAggregationBytesLength defines the sync committee aggregate bytes.
SyncAggregateSyncCommitteeBytesLength = 4 // SyncAggregateSyncCommitteeBytesLength defines the length of sync committee bytes in a sync aggregate.
MaxWithdrawalsPerPayload = 4 // MaxWithdrawalsPerPayloadLength defines the maximum number of withdrawals that can be included in a payload.
MaxBlobCommitmentsPerBlock = 16 // MaxBlobCommitmentsPerBlock defines the theoretical limit of blobs can be included in a block.
MaxBlobCommitmentsPerBlockElectra = 32 // MaxBlobCommitmentsPerBlockElectra defines the theoretical limit of blobs can be included in a block. (This only applies to minimal config post Electra)
LogMaxBlobCommitments = 4 // Log_2 of MaxBlobCommitmentsPerBlock
LogMaxBlobCommitmentsElectra = 5 // Log_2 of MaxBlobCommitmentsPerBlockElectra. (This only applies to minimal config post Electra)
MaxBlobCommitmentsPerBlock = 32 // MaxBlobCommitmentsPerBlock defines the theoretical limit of blobs can be included in a block.
LogMaxBlobCommitments = 5 // Log_2 of MaxBlobCommitmentsPerBlock
BlobLength = 131072 // BlobLength defines the byte length of a blob.
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
BlobSidecarSize = 131928 // defined to match blob sidecar size in bazel ssz codegen
Expand All @@ -53,6 +51,6 @@ const (
MaxDeposits = 16 // Maximum number of deposits in a block.
MaxVoluntaryExits = 16 // Maximum number of voluntary exits in a block.
MaxBlsToExecutionChanges = 16 // Maximum number of bls to execution changes in a block.
MaxRandomValue = uint64(1<<8 - 1) // Maximum value for a random value using for proposer and sync committee sampling.
MaxRandomByte = uint64(1<<8 - 1) // Maximum value for a random value using for proposer and sync committee sampling.
MaxRandomValueElectra = uint64(1<<16 - 1) // Maximum value for a random value using for proposer and sync committee sampling.
)
1 change: 0 additions & 1 deletion config/params/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var placeholderFields = []string{
"FULU_FORK_VERSION",
"KZG_COMMITMENT_INCLUSION_PROOF_DEPTH", // Compile time constant on BlobSidecar.commitment_inclusion_proof.
"MAX_BLOBS_PER_BLOCK_EIP7594",
"MAX_BLOBS_PER_BLOCK_ELECTRA",
"MAX_BLOBS_PER_BLOCK_FULU",
"MAX_BLOB_COMMITMENTS_PER_BLOCK", // Compile time constant on BeaconBlockBodyDeneb.blob_kzg_commitments.
"MAX_BYTES_PER_TRANSACTION", // Used for ssz of EL transactions. Unused in Prysm.
Expand Down
1 change: 1 addition & 0 deletions testing/spectest/shared/electra/sanity/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ go_library(
"//beacon-chain/core/transition:go_default_library",
"//beacon-chain/state:go_default_library",
"//beacon-chain/state/state-native:go_default_library",
"//config/params:go_default_library",
"//consensus-types/blocks:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//testing/require:go_default_library",
Expand Down
6 changes: 6 additions & 0 deletions testing/spectest/shared/electra/sanity/block_processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state"
state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/consensus-types/blocks"
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
Expand All @@ -35,6 +36,11 @@ func RunBlockProcessingTest(t *testing.T, config, folderPath string) {
testFolders, testsFolderPath := utils.TestFolders(t, config, "electra", folderPath)
for _, folder := range testFolders {
t.Run(folder.Name(), func(t *testing.T) {
params.SetupTestConfigCleanup(t)
cfg := params.BeaconConfig().Copy()
cfg.ElectraForkEpoch = 0
params.OverrideBeaconConfig(cfg)

helpers.ClearCache()
preBeaconStateFile, err := util.BazelFileBytes(testsFolderPath, folder.Name(), "pre.ssz_snappy")
require.NoError(t, err)
Expand Down

0 comments on commit 1a49d61

Please sign in to comment.