-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement consensus spec v1.5.0-alpha.10 #14733
Changes from 11 commits
ee39207
491498e
45c4612
910f1ce
83cbd88
bc47d24
16473b9
511adcc
f553245
6448406
aee1467
ed695aa
96dadbd
fa39ce4
acc70e7
30a0a37
c9b8eef
f37f0c2
35da875
070eaa0
012b224
1a49d61
cea2442
73d78c9
1145786
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ Notable features: | |
- Save light client updates and bootstraps in DB. | ||
- Added more comprehensive tests for `BlockToLightClientHeader`. [PR](https://github.com/prysmaticlabs/prysm/pull/14699) | ||
- Added light client feature flag check to RPC handlers. [PR](https://github.com/prysmaticlabs/prysm/pull/14736) | ||
- Add field param placeholder for Electra blob target and max to pass spec tests. | ||
|
||
### Changed | ||
|
||
|
@@ -126,6 +127,9 @@ Notable features: | |
- Check kzg commitments align with blobs and proofs for beacon api end point. | ||
- Revert "Proposer checks gas limit before accepting builder's bid". | ||
- Updated quic-go to v0.48.2 . | ||
- Enforce Compound prefix (0x02) for target when processing pending consolidation request. | ||
- Limit consolidating by validator's effective balance. | ||
- Use 16-bit random value for proposer and sync committee selection filter. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add this to the unreleased section |
||
|
||
### Deprecated | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package altair | |
|
||
import ( | ||
"context" | ||
"encoding/binary" | ||
goErrors "errors" | ||
"fmt" | ||
"time" | ||
|
@@ -22,8 +23,6 @@ import ( | |
"github.com/prysmaticlabs/prysm/v5/time/slots" | ||
) | ||
|
||
const maxRandomByte = uint64(1<<8 - 1) | ||
|
||
var ( | ||
ErrTooLate = errors.New("sync message is too late") | ||
) | ||
|
@@ -91,19 +90,22 @@ func NextSyncCommittee(ctx context.Context, s state.BeaconState) (*ethpb.SyncCom | |
// """ | ||
// epoch = Epoch(get_current_epoch(state) + 1) | ||
// | ||
// MAX_RANDOM_BYTE = 2**8 - 1 | ||
// MAX_RANDOM_VALUE = 2**16 - 1 # [Modified in Electra] | ||
// active_validator_indices = get_active_validator_indices(state, epoch) | ||
// active_validator_count = uint64(len(active_validator_indices)) | ||
// seed = get_seed(state, epoch, DOMAIN_SYNC_COMMITTEE) | ||
// i = 0 | ||
// i = uint64(0) | ||
// sync_committee_indices: List[ValidatorIndex] = [] | ||
// while len(sync_committee_indices) < SYNC_COMMITTEE_SIZE: | ||
// shuffled_index = compute_shuffled_index(uint64(i % active_validator_count), active_validator_count, seed) | ||
// candidate_index = active_validator_indices[shuffled_index] | ||
// random_byte = hash(seed + uint_to_bytes(uint64(i // 32)))[i % 32] | ||
// # [Modified in Electra] | ||
// random_bytes = hash(seed + uint_to_bytes(i // 16)) | ||
// offset = i % 16 * 2 | ||
// random_value = bytes_to_uint64(random_bytes[offset:offset + 2]) | ||
// effective_balance = state.validators[candidate_index].effective_balance | ||
// # [Modified in Electra:EIP7251] | ||
// if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE_ELECTRA * random_byte: | ||
// if effective_balance * MAX_RANDOM_VALUE >= MAX_EFFECTIVE_BALANCE_ELECTRA * random_value: | ||
// sync_committee_indices.append(candidate_index) | ||
// i += 1 | ||
// return sync_committee_indices | ||
|
@@ -123,12 +125,11 @@ func NextSyncCommitteeIndices(ctx context.Context, s state.BeaconState) ([]primi | |
cIndices := make([]primitives.ValidatorIndex, 0, syncCommitteeSize) | ||
hashFunc := hash.CustomSHA256Hasher() | ||
|
||
maxEB := cfg.MaxEffectiveBalanceElectra | ||
if s.Version() < version.Electra { | ||
maxEB = cfg.MaxEffectiveBalance | ||
} | ||
// Preallocate buffers to avoid repeated allocations | ||
seedBuffer := make([]byte, len(seed)+8) | ||
copy(seedBuffer, seed[:]) | ||
|
||
for i := primitives.ValidatorIndex(0); uint64(len(cIndices)) < params.BeaconConfig().SyncCommitteeSize; i++ { | ||
for i := primitives.ValidatorIndex(0); uint64(len(cIndices)) < syncCommitteeSize; i++ { | ||
if ctx.Err() != nil { | ||
return nil, ctx.Err() | ||
} | ||
|
@@ -137,18 +138,30 @@ func NextSyncCommitteeIndices(ctx context.Context, s state.BeaconState) ([]primi | |
if err != nil { | ||
return nil, err | ||
} | ||
|
||
b := append(seed[:], bytesutil.Bytes8(uint64(i.Div(32)))...) | ||
randomByte := hashFunc(b)[i%32] | ||
cIndex := indices[sIndex] | ||
v, err := s.ValidatorAtIndexReadOnly(cIndex) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
effectiveBal := v.EffectiveBalance() | ||
if effectiveBal*maxRandomByte >= maxEB*uint64(randomByte) { | ||
cIndices = append(cIndices, cIndex) | ||
|
||
if s.Version() >= version.Electra { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is related to: ethereum/consensus-specs#4039 |
||
// Use the preallocated seed buffer | ||
binary.LittleEndian.PutUint64(seedBuffer[len(seed):], uint64(i/16)) | ||
randomByte := hashFunc(seedBuffer) | ||
offset := (i % 16) * 2 | ||
randomValue := uint64(randomByte[offset]) | uint64(randomByte[offset+1])<<8 | ||
|
||
if effectiveBal*fieldparams.MaxRandomValueElectra >= cfg.MaxEffectiveBalanceElectra*randomValue { | ||
cIndices = append(cIndices, cIndex) | ||
} | ||
} else { | ||
// Use the preallocated seed buffer | ||
binary.LittleEndian.PutUint64(seedBuffer[len(seed):], uint64(i/32)) | ||
randomByte := hashFunc(seedBuffer)[i%32] | ||
if effectiveBal*fieldparams.MaxRandomByte >= cfg.MaxEffectiveBalance*uint64(randomByte) { | ||
cIndices = append(cIndices, cIndex) | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ func createValidatorsWithTotalActiveBalance(totalBal primitives.Gwei) []*eth.Val | |
vals := make([]*eth.Validator, num) | ||
for i := range vals { | ||
wd := make([]byte, 32) | ||
wd[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unexpected. Why is it changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to: ethereum/consensus-specs#4020 |
||
wd[0] = params.BeaconConfig().CompoundingWithdrawalPrefixByte | ||
wd[31] = byte(i) | ||
|
||
vals[i] = ð.Validator{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,7 @@ import ( | |
// break | ||
// | ||
// # Calculate the consolidated balance | ||
// max_effective_balance = get_max_effective_balance(source_validator) | ||
// source_effective_balance = min(state.balances[pending_consolidation.source_index], max_effective_balance) | ||
// source_effective_balance = min(state.balances[pending_consolidation.source_index], source_validator.effective_balance) | ||
// | ||
// # Move active balance to target. Excess balance is withdrawable. | ||
// decrease_balance(state, pending_consolidation.source_index, source_effective_balance) | ||
|
@@ -78,7 +77,7 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err | |
if err != nil { | ||
return err | ||
} | ||
b := min(validatorBalance, helpers.ValidatorMaxEffectiveBalance(sourceValidator)) | ||
b := min(validatorBalance, sourceValidator.EffectiveBalance()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related to: ethereum/consensus-specs#4040 |
||
|
||
if err := helpers.DecreaseBalance(st, pc.SourceIndex, b); err != nil { | ||
return err | ||
|
@@ -141,8 +140,8 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err | |
// if not (has_correct_credential and is_correct_source_address): | ||
// return | ||
// | ||
// # Verify that target has execution withdrawal credentials | ||
// if not has_execution_withdrawal_credential(target_validator): | ||
// # Verify that target has compounding withdrawal credentials | ||
// if not has_compounding_withdrawal_credential(target_validator): | ||
// return | ||
// | ||
// # Verify the source and the target are active | ||
|
@@ -175,10 +174,6 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err | |
// source_index=source_index, | ||
// target_index=target_index | ||
// )) | ||
// | ||
// # Churn any target excess active balance of target and raise its max | ||
// if has_eth1_withdrawal_credential(target_validator): | ||
// switch_to_compounding_validator(state, target_index) | ||
func ProcessConsolidationRequests(ctx context.Context, st state.BeaconState, reqs []*enginev1.ConsolidationRequest) error { | ||
if len(reqs) == 0 || st == nil { | ||
return nil | ||
|
@@ -253,7 +248,7 @@ func ProcessConsolidationRequests(ctx context.Context, st state.BeaconState, req | |
} | ||
|
||
// Target validator must have their withdrawal credentials set appropriately. | ||
if !helpers.HasExecutionWithdrawalCredentials(tgtV) { | ||
if !helpers.HasCompoundingWithdrawalCredential(tgtV) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related to ethereum/consensus-specs#4020 |
||
continue | ||
} | ||
|
||
|
@@ -298,13 +293,6 @@ func ProcessConsolidationRequests(ctx context.Context, st state.BeaconState, req | |
if err := st.AppendPendingConsolidation(ð.PendingConsolidation{SourceIndex: srcIdx, TargetIndex: tgtIdx}); err != nil { | ||
return fmt.Errorf("failed to append pending consolidation: %w", err) // This should never happen. | ||
} | ||
|
||
if helpers.HasETH1WithdrawalCredential(tgtV) { | ||
if err := SwitchToCompoundingValidator(st, tgtIdx); err != nil { | ||
log.WithError(err).Error("failed to switch to compounding validator") | ||
continue | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,6 +217,7 @@ func TestSlashValidator_OK(t *testing.T) { | |
} | ||
|
||
func TestSlashValidator_Electra(t *testing.T) { | ||
helpers.ClearCache() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running |
||
validatorCount := 100 | ||
registry := make([]*ethpb.Validator, 0, validatorCount) | ||
balances := make([]uint64, 0, validatorCount) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this to the unreleased section