Weber Beacon Chain
Notice: This document is a work-in-progress for researchers and implementers of the Weber protocol.
Table of contents
Introduction
The Weber Beacon Chain is the core consensus layer of the Weber protocol. It coordinates validators, processes attestations, and provides finality guarantees for the blockchain. While inspired by other PoS consensus mechanisms, Weber introduces several unique enhancements to improve throughput, finality time, and security.
Key features of the Weber Beacon Chain include:
- A weighted voting mechanism based on validator reputation
- Enhanced validator rotation for improved decentralization
- Optimistic block acceptance for faster finality
- A multi-tiered validator accountability system
This document specifies the beacon chain's operation, including state transitions, block processing rules, and epoch processing logic.
Custom types
Name |
SSZ equivalent |
Description |
Slot |
uint64 |
A slot number |
Epoch |
uint64 |
An epoch number |
CommitteeIndex |
uint64 |
A committee index at a slot |
ValidatorIndex |
uint64 |
A validator registry index |
Gwei |
uint64 |
An amount in Gwei |
Root |
Bytes32 |
A Merkle root |
Hash32 |
Bytes32 |
A 32-byte hash |
Version |
Bytes4 |
A fork version |
DomainType |
Bytes4 |
A domain type |
ForkDigest |
Bytes4 |
A digest of the current fork data |
Domain |
Bytes32 |
A domain parameter for BLS signatures |
BLSPubkey |
Bytes48 |
A BLS12-381 public key |
BLSSignature |
Bytes96 |
A BLS12-381 signature |
ValidatorScore |
uint16 |
Weber-specific validator performance score |
QuickFinalityBit |
boolean |
Weber-specific optimistic finality flag |
Constants
Misc
Name |
Value |
Unit |
Duration |
GENESIS_SLOT |
0 |
slots |
0 |
GENESIS_EPOCH |
0 |
epochs |
0 |
FAR_FUTURE_EPOCH |
2^64 - 1 |
epochs |
∞ |
BASE_REWARDS_PER_EPOCH |
5 |
rewards |
5 |
DEPOSIT_CONTRACT_TREE_DEPTH |
2^5 (= 32) |
- |
- |
JUSTIFICATION_BITS_LENGTH |
4 |
bits |
- |
ENDIANNESS |
'little' |
- |
- |
MAX_COMMITTEES_PER_SLOT |
2^6 (= 64) |
committees |
- |
TARGET_COMMITTEE_SIZE |
2^7 (= 128) |
validators |
- |
MAX_VALIDATORS_PER_COMMITTEE |
2^11 (= 2,048) |
validators |
- |
SHUFFLE_ROUND_COUNT |
90 |
rounds |
- |
HYSTERESIS_QUOTIENT |
4 |
- |
- |
HYSTERESIS_DOWNWARD_MULTIPLIER |
1 |
- |
- |
HYSTERESIS_UPWARD_MULTIPLIER |
5 |
- |
- |
VALIDATOR_ROTATION_PERIOD |
2^10 (= 1,024) |
epochs |
~28 days |
Time parameters
Name |
Value |
Unit |
Duration |
SECONDS_PER_SLOT |
8 |
seconds |
8 seconds |
SECONDS_PER_EPOCH |
8 * 32 (= 256) |
seconds |
4.27 minutes |
MIN_ATTESTATION_INCLUSION_DELAY |
1 |
slots |
8 seconds |
SLOTS_PER_EPOCH |
32 |
slots |
4.27 minutes |
MIN_SEED_LOOKAHEAD |
1 |
epochs |
4.27 minutes |
MAX_SEED_LOOKAHEAD |
4 |
epochs |
17.07 minutes |
MIN_EPOCHS_TO_INACTIVITY_PENALTY |
4 |
epochs |
17.07 minutes |
EPOCHS_PER_ETH1_VOTING_PERIOD |
2^6 (= 64) |
epochs |
4.57 hours |
SLOTS_PER_HISTORICAL_ROOT |
2^13 (= 8,192) |
slots |
~18.2 hours |
MIN_VALIDATOR_WITHDRAWABILITY_DELAY |
2^8 (= 256) |
epochs |
~18.2 hours |
OPTIMAL_ATTESTATION_PROPAGATION_DELAY |
6 |
slots |
48 seconds |
EPOCHS_PER_SLASHINGS_VECTOR |
2^13 (= 8,192) |
epochs |
~24.3 days |
MIN_EPOCHS_FOR_BLOCK_REQUESTS |
2^11 (= 2,048) |
epochs |
~6.1 days |
EPOCHS_PER_SYNC_COMMITTEE_PERIOD |
2^9 (= 512) |
epochs |
~36.6 hours |
QUICK_FINALITY_THRESHOLD |
3 |
slots |
24 seconds |
State list lengths
Name |
Value |
EPOCHS_PER_HISTORICAL_VECTOR |
2^16 (= 65,536) |
EPOCHS_PER_SLASHINGS_VECTOR |
2^13 (= 8,192) |
HISTORICAL_ROOTS_LIMIT |
2^24 (= 16,777,216) |
VALIDATOR_REGISTRY_LIMIT |
2^40 (= 1,099,511,627,776) |
Rewards and penalties
Name |
Value |
BASE_REWARD_FACTOR |
2^6 (= 64) |
WHISTLEBLOWER_REWARD_QUOTIENT |
2^9 (= 512) |
PROPOSER_REWARD_QUOTIENT |
2^3 (= 8) |
INACTIVITY_PENALTY_QUOTIENT |
2^26 (= 67,108,864) |
MIN_SLASHING_PENALTY_QUOTIENT |
2^7 (= 128) |
PROPORTIONAL_SLASHING_MULTIPLIER |
1 |
REPUTATION_REWARD_MULTIPLIER |
2^4 (= 16) |
Max operations per block
Name |
Value |
MAX_PROPOSER_SLASHINGS |
2^4 (= 16) |
MAX_ATTESTER_SLASHINGS |
2^1 (= 2) |
MAX_ATTESTATIONS |
2^7 (= 128) |
MAX_DEPOSITS |
2^4 (= 16) |
MAX_VOLUNTARY_EXITS |
2^4 (= 16) |
MAX_VALIDATOR_ROTATIONS |
2^3 (= 8) |
Containers
Weber domain types
| class WeberDomainType(IntEnum):
BEACON_PROPOSER = 0
BEACON_ATTESTER = 1
RANDAO = 2
DEPOSIT = 3
VOLUNTARY_EXIT = 4
SELECTION_PROOF = 5
AGGREGATE_AND_PROOF = 6
VALIDATOR_ROTATION = 7
WEBER_SYNC_COMMITTEE = 8
QUICK_FINALITY_VOTE = 9
|
Validator
| class Validator(Container):
pubkey: BLSPubkey
withdrawal_credentials: Bytes32
effective_balance: Gwei
slashed: boolean
activation_eligibility_epoch: Epoch
activation_epoch: Epoch
exit_epoch: Epoch
withdrawable_epoch: Epoch
performance_score: ValidatorScore # Weber-specific validator reputation metric
rotation_epoch: Epoch # Weber-specific validator rotation tracking
|
AttestationData
| class AttestationData(Container):
slot: Slot
index: CommitteeIndex
beacon_block_root: Root
source: Checkpoint
target: Checkpoint
quick_finality: QuickFinalityBit # Weber-specific optimistic finality flag
|
IndexedAttestation
| class IndexedAttestation(Container):
attesting_indices: List[ValidatorIndex, MAX_VALIDATORS_PER_COMMITTEE]
data: AttestationData
signature: BLSSignature
|
PendingAttestation
| class PendingAttestation(Container):
aggregation_bits: Bitlist[MAX_VALIDATORS_PER_COMMITTEE]
data: AttestationData
inclusion_delay: Slot
proposer_index: ValidatorIndex
weighted_votes: Gwei # Weber-specific weighted voting power
|
Checkpoint
| class Checkpoint(Container):
epoch: Epoch
root: Root
|
BeaconBlock
| class BeaconBlockHeader(Container):
slot: Slot
proposer_index: ValidatorIndex
parent_root: Root
state_root: Root
body_root: Root
|
| class BeaconBlockBody(Container):
randao_reveal: BLSSignature
eth1_data: Eth1Data
graffiti: Bytes32
proposer_slashings: List[ProposerSlashing, MAX_PROPOSER_SLASHINGS]
attester_slashings: List[AttesterSlashing, MAX_ATTESTER_SLASHINGS]
attestations: List[Attestation, MAX_ATTESTATIONS]
deposits: List[Deposit, MAX_DEPOSITS]
voluntary_exits: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS]
validator_rotations: List[SignedValidatorRotation, MAX_VALIDATOR_ROTATIONS] # Weber-specific
sync_aggregate: SyncAggregate
quick_finality_votes: List[QuickFinalityVote, MAX_COMMITTEES_PER_SLOT] # Weber-specific
|
| class BeaconBlock(Container):
slot: Slot
proposer_index: ValidatorIndex
parent_root: Root
state_root: Root
body: BeaconBlockBody
|
| class SignedBeaconBlock(Container):
message: BeaconBlock
signature: BLSSignature
|
BeaconState
| class BeaconState(Container):
# Versioning
genesis_time: uint64
genesis_validators_root: Root
slot: Slot
fork: Fork
# History
latest_block_header: BeaconBlockHeader
block_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT]
state_roots: Vector[Root, SLOTS_PER_HISTORICAL_ROOT]
historical_roots: List[Root, HISTORICAL_ROOTS_LIMIT]
# Eth1
eth1_data: Eth1Data
eth1_data_votes: List[Eth1Data, EPOCHS_PER_ETH1_VOTING_PERIOD * SLOTS_PER_EPOCH]
eth1_deposit_index: uint64
# Registry
validators: List[Validator, VALIDATOR_REGISTRY_LIMIT]
balances: List[Gwei, VALIDATOR_REGISTRY_LIMIT]
# Randomness
randao_mixes: Vector[Bytes32, EPOCHS_PER_HISTORICAL_VECTOR]
# Slashings
slashings: Vector[Gwei, EPOCHS_PER_SLASHINGS_VECTOR]
# Attestations
previous_epoch_attestations: List[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH]
current_epoch_attestations: List[PendingAttestation, MAX_ATTESTATIONS * SLOTS_PER_EPOCH]
# Finality
justification_bits: Bitvector[JUSTIFICATION_BITS_LENGTH]
previous_justified_checkpoint: Checkpoint
current_justified_checkpoint: Checkpoint
finalized_checkpoint: Checkpoint
# Weber specific additions
quick_finality_checkpoints: List[Checkpoint, QUICK_FINALITY_THRESHOLD] # Weber optimistic finality
validator_reputation_scores: List[ValidatorScore, VALIDATOR_REGISTRY_LIMIT] # Reputation tracking
next_rotation_validators: List[ValidatorIndex, MAX_VALIDATORS_PER_EPOCH] # Scheduled rotations
sync_committee: SyncCommittee # Current sync committee
next_sync_committee: SyncCommittee # Next sync committee
|
Epoch processing
Justification and finalization
Weber uses a modified version of Casper FFG for finality, with the following enhancements:
| def process_justification_and_finalization(state: BeaconState) -> None:
# Standard justification and finalization logic
# [...]
# Weber additions: Quick finality system
if should_apply_quick_finality(state):
quick_finality_checkpoint = create_quick_finality_checkpoint(state)
state.quick_finality_checkpoints.append(quick_finality_checkpoint)
if len(state.quick_finality_checkpoints) > QUICK_FINALITY_THRESHOLD:
state.quick_finality_checkpoints.pop(0)
# If we have enough consistent checkpoints, finalize immediately
if all_checkpoints_consistent(state.quick_finality_checkpoints) and
len(state.quick_finality_checkpoints) >= QUICK_FINALITY_THRESHOLD:
state.finalized_checkpoint = state.current_justified_checkpoint
|
Rewards and penalties
Weber extends the standard PoS rewards and penalties with a reputation-based system:
| def process_rewards_and_penalties(state: BeaconState) -> None:
# Standard rewards and penalties logic
# [...]
# Weber additions: Apply reputation-based adjustments
for index, validator in enumerate(state.validators):
# Update reputation score based on attestation performance
update_validator_reputation(state, index)
# Apply reputation multiplier to rewards
if validator.performance_score > BASELINE_PERFORMANCE_SCORE:
multiplier = 1 + (validator.performance_score - BASELINE_PERFORMANCE_SCORE) / MAX_PERFORMANCE_SCORE
multiplier = min(multiplier, MAX_REPUTATION_MULTIPLIER)
state.balances[index] += int(state.balances[index] * multiplier * REPUTATION_REWARD_RATE)
|
Registry updates
Weber implements scheduled validator rotation to enhance network security and decentralization:
| def process_registry_updates(state: BeaconState) -> None:
# Standard registry update logic
# [...]
# Weber additions: Validator rotation
current_epoch = get_current_epoch(state)
if current_epoch % VALIDATOR_ROTATION_PERIOD == 0:
for validator_index in state.next_rotation_validators:
validator = state.validators[validator_index]
if validator.rotation_epoch <= current_epoch:
initiate_validator_rotation(state, validator_index)
# Prepare next rotation batch
prepare_next_validator_rotation(state, current_epoch + VALIDATOR_ROTATION_PERIOD)
|
Slashings
Weber enhances the slashing mechanism with graduated penalties based on validator reputation:
| def process_slashings(state: BeaconState) -> None:
# Standard slashing logic
# [...]
# Weber additions: Reputation-based slashing adjustments
epoch = get_current_epoch(state)
total_balance = get_total_active_balance(state)
adjusted_total_slashing = Gwei(0)
for index, validator in enumerate(state.validators):
if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch:
# Apply reputation-based slashing multiplier
reputation_multiplier = 1 + (MAX_PERFORMANCE_SCORE - validator.performance_score) * 0.5
penalty_numerator = validator.effective_balance * adjusted_total_slashing * 3
penalty = penalty_numerator // total_balance
penalty = min(validator.effective_balance, penalty)
# Apply reputation-adjusted penalty
state.balances[index] -= int(penalty * reputation_multiplier)
|
Final updates
| def process_final_updates(state: BeaconState) -> None:
# Standard final updates logic
# [...]
# Weber additions: Reputation score decay
current_epoch = get_current_epoch(state)
if current_epoch % REPUTATION_RESET_PERIOD == 0:
for i in range(len(state.validators)):
state.validators[i].performance_score = apply_score_decay(
state.validators[i].performance_score,
REPUTATION_DECAY_RATE
)
|
State transition function
Block processing
Weber's block processing includes traditional PoS operations with additional Weber-specific features:
| def process_block(state: BeaconState, block: BeaconBlock) -> None:
process_block_header(state, block)
process_randao(state, block.body)
process_eth1_data(state, block.body)
process_operations(state, block.body)
process_weber_operations(state, block.body) # Weber-specific operations
|
| def process_weber_operations(state: BeaconState, body: BeaconBlockBody) -> None:
# Process validator rotations
for rotation in body.validator_rotations:
process_validator_rotation(state, rotation)
# Process quick finality votes
for vote in body.quick_finality_votes:
process_quick_finality_vote(state, vote)
# Process sync committee messages
process_sync_aggregate(state, body.sync_aggregate)
|
Epoch state transition
| def process_epoch(state: BeaconState) -> None:
process_justification_and_finalization(state)
process_rewards_and_penalties(state)
process_registry_updates(state)
process_slashings(state)
process_eth1_data_reset(state)
process_effective_balance_updates(state)
process_slashings_reset(state)
process_randao_mixes_reset(state)
process_historical_roots_update(state)
process_participation_record_updates(state)
process_sync_committee_updates(state)
process_final_updates(state)
process_weber_epoch_updates(state) # Weber-specific epoch updates
|
Genesis state initialization
Weber's genesis state initializes the beacon chain with customized parameters:
| def initialize_beacon_state_from_eth1(
eth1_block_hash: Bytes32,
eth1_timestamp: uint64,
deposits: Sequence[Deposit],
execution_payload_header: ExecutionPayloadHeader=None,
) -> BeaconState:
state = BeaconState(
genesis_time=eth1_timestamp + GENESIS_DELAY,
eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))),
latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())),
)
# Initialize validators
for deposit in deposits:
process_deposit(state, deposit)
# Process initial activations
for validator_index, validator in enumerate(state.validators):
balance = state.balances[validator_index]
validator.effective_balance = min(
balance - balance % EFFECTIVE_BALANCE_INCREMENT,
MAX_EFFECTIVE_BALANCE
)
if validator.effective_balance == MAX_EFFECTIVE_BALANCE:
validator.activation_eligibility_epoch = GENESIS_EPOCH
validator.activation_epoch = GENESIS_EPOCH
# Initialize Weber-specific fields
state.quick_finality_checkpoints = []
state.validator_reputation_scores = [ValidatorScore(INITIAL_REPUTATION_SCORE) for _ in range(len(state.validators))]
state.next_rotation_validators = []
# Set execution payload header
if execution_payload_header is not None:
state.latest_execution_payload_header = execution_payload_header
# Initialize sync committees
active_validator_indices = get_active_validator_indices(state, GENESIS_EPOCH)
sync_committee = get_next_sync_committee(state, active_validator_indices)
state.current_sync_committee = sync_committee
state.next_sync_committee = get_next_sync_committee(state, active_validator_indices)
return state
|
Weber-specific consensus improvements
Weber introduces several innovations to the PoS consensus mechanism that enhance security, efficiency, and decentralization. This section details these improvements.
Enhanced validator rotation
To prevent validator stagnation and encourage decentralization, Weber implements a mandatory validator rotation system:
| class ValidatorRotation(Container):
"""
A scheduled rotation for a validator.
"""
validator_index: ValidatorIndex
activation_epoch: Epoch
exit_epoch: Epoch
new_pubkey: BLSPubkey
rotation_credentials: Bytes32
|
| class SignedValidatorRotation(Container):
"""
A signed validator rotation message.
"""
message: ValidatorRotation
signature: BLSSignature
|
| def initiate_validator_rotation(state: BeaconState, validator_index: ValidatorIndex) -> None:
"""
Begin the process of rotating a validator.
This function is called during epoch processing when rotation is scheduled.
"""
validator = state.validators[validator_index]
# Check if already scheduled or recently rotated
current_epoch = get_current_epoch(state)
if validator.exit_epoch <= current_epoch + VALIDATOR_ROTATION_PERIOD:
return # Already scheduled for exit or recently rotated
# Set validator to exit after rotation delay
validator.exit_epoch = compute_activation_exit_epoch(current_epoch)
# Log rotation in next_rotation_validators for tracking
state.next_rotation_validators.append(validator_index)
# Emit rotation event for off-chain monitoring
emit_validator_rotation_scheduled(state, validator_index, validator.exit_epoch)
|
| def process_validator_rotation(state: BeaconState, signed_rotation: SignedValidatorRotation) -> None:
"""
Process a validator rotation message included in a block.
This registers a new validator key that will take over after the current validator exits.
"""
rotation = signed_rotation.message
validator = state.validators[rotation.validator_index]
# Verify the rotation is scheduled
if rotation.validator_index not in state.next_rotation_validators:
raise ValueError("Validator not scheduled for rotation")
# Verify the signature
domain = get_domain(state, WeberDomainType.VALIDATOR_ROTATION)
signing_root = compute_signing_root(rotation, domain)
if not bls.Verify(validator.pubkey, signing_root, signed_rotation.signature):
raise ValueError("Invalid rotation signature")
# Process the rotation by creating a new validator entry
pubkey = rotation.new_pubkey
withdrawal_credentials = rotation.rotation_credentials
# Reuse deposit processing logic with modifications
effective_balance = validator.effective_balance
validator_index = process_rotation_validator(
state, pubkey, withdrawal_credentials, effective_balance, rotation.validator_index
)
# Update rotation tracking
state.next_rotation_validators.remove(rotation.validator_index)
return validator_index
|
Weighted voting mechanism
Weber improves traditional PoS voting by weighting attestations based on validator reputation:
| def get_attestation_weight(state: BeaconState, validator_index: ValidatorIndex) -> Gwei:
"""
Calculate the effective weight of a validator's attestation based on reputation.
This is used in fork choice and finality calculations.
"""
validator = state.validators[validator_index]
reputation_score = state.validator_reputation_scores[validator_index]
# Base weight is the effective balance
base_weight = validator.effective_balance
# Apply reputation modifier (ranges from 0.5 to 1.5 based on score)
reputation_multiplier = 0.5 + (reputation_score / MAX_REPUTATION_SCORE)
weighted_balance = base_weight * reputation_multiplier
return Gwei(weighted_balance)
|
| def update_validator_reputation(state: BeaconState, validator_index: ValidatorIndex) -> None:
"""
Update a validator's reputation score based on recent performance.
"""
# Get validator's recent activity
inclusion_delay = get_inclusion_delay(state, validator_index)
participated_current = has_participated_in_current_epoch(state, validator_index)
participated_previous = has_participated_in_previous_epoch(state, validator_index)
was_proposer = was_recent_proposer(state, validator_index)
# Calculate performance score adjustments
delay_score = max(0, MAX_INCLUSION_DELAY - inclusion_delay) if inclusion_delay > 0 else 0
participation_score = PARTICIPATION_SCORE_CURRENT if participated_current else 0
participation_score += PARTICIPATION_SCORE_PREVIOUS if participated_previous else 0
proposer_score = PROPOSER_SCORE if was_proposer else 0
# Calculate penalties
missed_attestation_penalty = 0
if not participated_current and not participated_previous:
missed_attestation_penalty = MISSED_ATTESTATION_PENALTY
# Update reputation score
current_score = state.validator_reputation_scores[validator_index]
new_score = current_score + delay_score + participation_score + proposer_score - missed_attestation_penalty
# Clamp to valid range
new_score = max(0, min(new_score, MAX_REPUTATION_SCORE))
state.validator_reputation_scores[validator_index] = ValidatorScore(new_score)
|
Block acceptance optimization
Weber introduces optimistic block acceptance to speed up transaction throughput:
| class QuickFinalityVote(Container):
"""
A vote for optimistic finality of a block.
"""
block_root: Root
validator_index: ValidatorIndex
slot: Slot
quick_finality: QuickFinalityBit
|
| def process_quick_finality_vote(state: BeaconState, vote: QuickFinalityVote) -> None:
"""
Process a quick finality vote from a validator.
"""
validator_index = vote.validator_index
validator = state.validators[validator_index]
# Verify validator is active and eligible for quick finality voting
if not is_active_validator(validator, get_current_epoch(state)):
raise ValueError("Validator not active")
# Verify validator has high enough reputation to vote for quick finality
if state.validator_reputation_scores[validator_index] < QUICK_FINALITY_MIN_SCORE:
raise ValueError("Validator reputation score too low for quick finality voting")
# Register vote in state
block_root = vote.block_root
# Find or create checkpoint for this block
for checkpoint in state.quick_finality_checkpoints:
if checkpoint.root == block_root:
# Update existing checkpoint
checkpoint.quick_finality = True
return
# Create new checkpoint
current_epoch = compute_epoch_at_slot(vote.slot)
new_checkpoint = Checkpoint(epoch=current_epoch, root=block_root)
state.quick_finality_checkpoints.append(new_checkpoint)
# Emit event for quick finality vote
emit_quick_finality_vote(state, validator_index, block_root)
|
| def should_apply_quick_finality(state: BeaconState) -> bool:
"""
Determine if the state is eligible for quick finality.
"""
# We need minimum number of active validators
active_validators = get_active_validator_count(state)
if active_validators < MIN_VALIDATORS_FOR_QUICK_FINALITY:
return False
# We need minimum percentage of validators with high reputation
high_rep_validators = count_high_reputation_validators(state)
if high_rep_validators / active_validators < MIN_HIGH_REP_RATIO_FOR_QUICK_FINALITY:
return False
# Network must be healthy (no recent slashings above threshold)
if has_excessive_slashings(state):
return False
return True
|
Validator accountability system
Weber implements a more robust accountability system to incentivize validator performance:
| def process_weber_epoch_updates(state: BeaconState) -> None:
"""
Process Weber-specific updates at the end of each epoch.
"""
current_epoch = get_current_epoch(state)
# Update validator accountability metrics
update_validator_metrics(state)
# Apply rewards and penalties based on accountability
apply_accountability_rewards(state)
# Check for automatic validator jailing conditions
check_and_jail_validators(state)
# Process rotation schedules
if current_epoch % VALIDATOR_ROTATION_CHECK_PERIOD == 0:
process_rotation_schedule(state)
# Update network health indicators
update_network_health_metrics(state)
|
| def update_validator_metrics(state: BeaconState) -> None:
"""
Update validator performance metrics for accountability tracking.
"""
epoch = get_current_epoch(state)
for validator_index, validator in enumerate(state.validators):
if is_active_validator(validator, epoch):
# Calculate various performance metrics
attestation_performance = calculate_attestation_performance(state, validator_index)
proposal_performance = calculate_proposal_performance(state, validator_index)
inclusion_rate = calculate_inclusion_rate(state, validator_index)
# Update the validator's accountability record
update_validator_accountability(
state,
validator_index,
attestation_performance,
proposal_performance,
inclusion_rate
)
|
| def apply_accountability_rewards(state: BeaconState) -> None:
"""
Apply additional rewards and penalties based on validator accountability.
"""
for validator_index, validator in enumerate(state.validators):
if not is_active_validator(validator, get_current_epoch(state)):
continue
reputation_score = state.validator_reputation_scores[validator_index]
# Calculate accountability multiplier
accountability_multiplier = calculate_accountability_multiplier(
state, validator_index, reputation_score
)
# Apply multiplier to base rewards
if accountability_multiplier > 1.0:
# Apply bonus reward
bonus = int((accountability_multiplier - 1.0) * BASE_REWARD * reputation_score / MAX_REPUTATION_SCORE)
state.balances[validator_index] += Gwei(bonus)
elif accountability_multiplier < 1.0:
# Apply penalty
penalty = int((1.0 - accountability_multiplier) * BASE_PENALTY * (MAX_REPUTATION_SCORE - reputation_score) / MAX_REPUTATION_SCORE)
state.balances[validator_index] = max(0, state.balances[validator_index] - Gwei(penalty))
|
These Weber-specific improvements collectively enable a more efficient, secure, and decentralized consensus protocol that builds upon the proven foundation of PoS while addressing many of its limitations.