Scale up weights; use existing constants and new PROPOSER_WEIGHT

This commit is contained in:
Barnabé Monnot 2021-03-26 18:36:49 +08:00
parent 59134fb0ae
commit 71d03a411c
2 changed files with 12 additions and 9 deletions

View File

@ -84,12 +84,12 @@ Altair is the first beacon chain hard fork. Its main features are:
| Name | Value | | Name | Value |
| - | - | | - | - |
| `TIMELY_HEAD_WEIGHT` | `3` | | `TIMELY_HEAD_WEIGHT` | `12` |
| `TIMELY_SOURCE_WEIGHT` | `3` | | `TIMELY_SOURCE_WEIGHT` | `12` |
| `TIMELY_TARGET_WEIGHT` | `6` | | `TIMELY_TARGET_WEIGHT` | `24` |
| `SYNC_REWARD_WEIGHT` | `2` | | `SYNC_REWARD_WEIGHT` | `8` |
| `NON_PROPOSER_TOTAL` | `14` | | `PROPOSER_WEIGHT` | `8` |
| `WEIGHT_DENOMINATOR` | `16` | | `WEIGHT_DENOMINATOR` | `64` |
*Note*: The sum of the weight fractions (7/8) plus the proposer inclusion fraction (1/8) equals 1. *Note*: The sum of the weight fractions (7/8) plus the proposer inclusion fraction (1/8) equals 1.
@ -478,7 +478,8 @@ def process_attestation(state: BeaconState, attestation: Attestation) -> None:
proposer_reward_numerator += get_base_reward(state, index) * weight proposer_reward_numerator += get_base_reward(state, index) * weight
# Reward proposer # Reward proposer
proposer_reward = Gwei(proposer_reward_numerator // (NON_PROPOSER_TOTAL * PROPOSER_REWARD_QUOTIENT)) reward_denominator = (WEIGHT_DENOMINATOR - PROPOSER_WEIGHT) * PROPOSER_REWARD_QUOTIENT
proposer_reward = Gwei(proposer_reward_numerator // reward_denominator)
increase_balance(state, get_beacon_proposer_index(state), proposer_reward) increase_balance(state, get_beacon_proposer_index(state), proposer_reward)
``` ```
@ -551,7 +552,8 @@ def process_sync_committee(state: BeaconState, aggregate: SyncAggregate) -> None
for included_index in included_indices: for included_index in included_indices:
effective_balance = state.validators[included_index].effective_balance effective_balance = state.validators[included_index].effective_balance
inclusion_reward = Gwei(max_slot_rewards * effective_balance // committee_effective_balance) inclusion_reward = Gwei(max_slot_rewards * effective_balance // committee_effective_balance)
proposer_reward = Gwei((inclusion_reward * WEIGHT_DENOMINATOR) // (NON_PROPOSER_TOTAL * PROPOSER_REWARD_QUOTIENT)) proposer_denominator = (WEIGHT_DENOMINATOR - PROPOSER_WEIGHT) * PROPOSER_REWARD_QUOTIENT
proposer_reward = Gwei((inclusion_reward * WEIGHT_DENOMINATOR) // proposer_denominator)
increase_balance(state, get_beacon_proposer_index(state), proposer_reward) increase_balance(state, get_beacon_proposer_index(state), proposer_reward)
increase_balance(state, included_index, inclusion_reward) increase_balance(state, included_index, inclusion_reward)
``` ```

View File

@ -137,7 +137,8 @@ def compute_sync_committee_proposer_reward(spec, state, committee, committee_bit
inclusion_reward = compute_sync_committee_inclusion_reward( inclusion_reward = compute_sync_committee_inclusion_reward(
spec, state, index, committee, committee_bits, spec, state, index, committee, committee_bits,
) )
proposer_reward += spec.Gwei((inclusion_reward * spec.WEIGHT_DENOMINATOR) // (spec.NON_PROPOSER_TOTAL * spec.PROPOSER_REWARD_QUOTIENT)) proposer_denominator = (spec.WEIGHT_DENOMINATOR - spec.PROPOSER_WEIGHT) * spec.PROPOSER_REWARD_QUOTIENT
proposer_reward += spec.Gwei((inclusion_reward * spec.WEIGHT_DENOMINATOR) // proposer_denominator)
return proposer_reward return proposer_reward