Change get_latest_attesting_balances() to get_weight()
This commit is contained in:
parent
89f2eae318
commit
7637158a2f
|
@ -18,7 +18,7 @@
|
|||
- [`get_current_slot`](#get_current_slot)
|
||||
- [`compute_slots_since_epoch_start`](#compute_slots_since_epoch_start)
|
||||
- [`get_ancestor`](#get_ancestor)
|
||||
- [`get_latest_attesting_balance`](#get_latest_attesting_balance)
|
||||
- [`get_weight`](#get_weight)
|
||||
- [`filter_block_tree`](#filter_block_tree)
|
||||
- [`get_filtered_block_tree`](#get_filtered_block_tree)
|
||||
- [`get_head`](#get_head)
|
||||
|
@ -174,10 +174,10 @@ def get_ancestor(store: Store, root: Root, slot: Slot) -> Root:
|
|||
return root
|
||||
```
|
||||
|
||||
#### `get_latest_attesting_balance`
|
||||
#### `get_weight`
|
||||
|
||||
```python
|
||||
def get_latest_attesting_balance(store: Store, root: Root) -> Gwei:
|
||||
def get_weight(store: Store, root: Root) -> Gwei:
|
||||
state = store.checkpoint_states[store.justified_checkpoint]
|
||||
active_indices = get_active_validator_indices(state, get_current_epoch(state))
|
||||
attestation_score = Gwei(sum(
|
||||
|
@ -197,7 +197,6 @@ def get_latest_attesting_balance(store: Store, root: Root) -> Gwei:
|
|||
committee_weight = get_total_active_balance(state) // SLOTS_PER_EPOCH
|
||||
proposer_score = (committee_weight * PROPOSER_SCORE_BOOST) // 100
|
||||
return attestation_score + proposer_score
|
||||
|
||||
```
|
||||
|
||||
#### `filter_block_tree`
|
||||
|
@ -270,7 +269,7 @@ def get_head(store: Store) -> Root:
|
|||
return head
|
||||
# Sort by latest attesting balance with ties broken lexicographically
|
||||
# Ties broken by favoring block with lexicographically higher root
|
||||
head = max(children, key=lambda root: (get_latest_attesting_balance(store, root), root))
|
||||
head = max(children, key=lambda root: (get_weight(store, root), root))
|
||||
```
|
||||
|
||||
#### `should_update_justified_checkpoint`
|
||||
|
|
|
@ -177,7 +177,7 @@ def get_opt_head_block_root(spec, mega_store):
|
|||
return head
|
||||
# Sort by latest attesting balance with ties broken lexicographically
|
||||
# Ties broken by favoring block with lexicographically higher root
|
||||
head = max(children, key=lambda root: (spec.get_latest_attesting_balance(store, root), root))
|
||||
head = max(children, key=lambda root: (spec.get_weight(store, root), root))
|
||||
|
||||
|
||||
def is_invalidated(mega_store, block_root):
|
||||
|
|
|
@ -729,14 +729,14 @@ def test_proposer_boost(spec, state):
|
|||
on_tick_and_append_step(spec, store, time, test_steps)
|
||||
yield from add_block(spec, store, signed_block, test_steps)
|
||||
assert store.proposer_boost_root == spec.hash_tree_root(block)
|
||||
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) > 0
|
||||
assert spec.get_weight(store, spec.hash_tree_root(block)) > 0
|
||||
|
||||
# Ensure that boost is removed after slot is over
|
||||
time = (store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
|
||||
spec.config.SECONDS_PER_SLOT)
|
||||
on_tick_and_append_step(spec, store, time, test_steps)
|
||||
assert store.proposer_boost_root == spec.Root()
|
||||
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) == 0
|
||||
assert spec.get_weight(store, spec.hash_tree_root(block)) == 0
|
||||
|
||||
next_slots(spec, state, 3)
|
||||
block = build_empty_block_for_next_slot(spec, state)
|
||||
|
@ -747,14 +747,14 @@ def test_proposer_boost(spec, state):
|
|||
on_tick_and_append_step(spec, store, time, test_steps)
|
||||
yield from add_block(spec, store, signed_block, test_steps)
|
||||
assert store.proposer_boost_root == spec.hash_tree_root(block)
|
||||
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) > 0
|
||||
assert spec.get_weight(store, spec.hash_tree_root(block)) > 0
|
||||
|
||||
# Ensure that boost is removed after slot is over
|
||||
time = (store.genesis_time + block.slot * spec.config.SECONDS_PER_SLOT +
|
||||
spec.config.SECONDS_PER_SLOT)
|
||||
on_tick_and_append_step(spec, store, time, test_steps)
|
||||
assert store.proposer_boost_root == spec.Root()
|
||||
assert spec.get_latest_attesting_balance(store, spec.hash_tree_root(block)) == 0
|
||||
assert spec.get_weight(store, spec.hash_tree_root(block)) == 0
|
||||
|
||||
test_steps.append({
|
||||
'checks': {
|
||||
|
|
Loading…
Reference in New Issue