ethereum / beacon_chain

MIT License
209 stars 65 forks source link

Fix ActiveState.chain maintenance and FFG rewards #122

Closed hwwhww closed 5 years ago

hwwhww commented 5 years ago
  1. Filled the missing active_state.chain maintenance during processing block
  2. voter_indices = block_vote_cache[block_hash]['total_voter_deposits'] -> voter_indices = block_vote_cache[block_hash]['voter_indices']
  3. Keep the balance nonnegative now until we have clear rule of forced exit.
  4. Fix FFG reward slot iteration: range(last_state_recalc - config['cycle_length'], last_state_recalc) -> range(max(last_state_recalc - config['cycle_length'], 0), last_state_recalc)
  5. Fix formula: quadratic_penalty_quotient = int(sqrt(config['sqrt_e_drop_time'] / config['slot_duration'])) -> quadratic_penalty_quotient = (config['sqrt_e_drop_time'] / config['slot_duration']) ** 2
hwwhww commented 5 years ago

The balance B is 3.2E+19, reward_quotient is 1146880.

  1. When slot = config['cycle_length'] * 3, then time_since_finality <= 3 * config['cycle_length']:
Slot rewards_and_penalties cumulative rewards_and_penalties B + cumulative rewards_and_penalties
0 -2.7901785714E+13 -2.7901785714E+13 3.1999972098E+19
1 -5.5803571429E+13 -8.3705357143E+13 3.1999916295E+19
2 -8.3705357143E+13 -1.6741071429E+14 3.1999832589E+19
3 -1.1160714286E+14 -2.7901785714E+14 3.1999720982E+19
4 -1.3950892857E+14 -4.1852678571E+14 3.1999581473E+19
  1. When slot = config['cycle_length'] * 4 then time_since_finality > 3 * config['cycle_length']:
    • time_since_finality: 256
    • quadratic_penalty_quotient: 17179869184
    • The difference validators[index].balance * time_since_finality // quadratic_penalty_quotient: 4.76837E+11
Slot rewards_and_penalties cumulative rewards_and_penalties B + cumulative rewards_and_penalties
0 -2.8378622872E+13 -2.8378622872E+13 3.1999971621E+19
1 -5.6757245745E+13 -8.5135868617E+13 3.1999914864E+19
2 -8.5135868617E+13 -1.7027173723E+14 3.1999829728E+19
3 -1.1351449149E+14 -2.8378622872E+14 3.1999716214E+19
4 -1.4189311436E+14 -4.2567934309E+14 3.1999574321E+19
hwwhww commented 5 years ago

@djrtwo this one is also ready to review! 🙂

djrtwo commented 5 years ago

lgtm

djrtwo commented 5 years ago

mergginnnggggggg