mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-02 04:03:35 +00:00
Fix bug in eth1 voting
This commit is contained in:
@@ -301,12 +301,14 @@ fn eth1_block_hash_at_start_of_voting_period<T: EthSpec, S: Store>(
|
|||||||
) -> Result<Hash256, Error> {
|
) -> Result<Hash256, Error> {
|
||||||
let period = T::SlotsPerEth1VotingPeriod::to_u64();
|
let period = T::SlotsPerEth1VotingPeriod::to_u64();
|
||||||
|
|
||||||
// Find `state.eth1_data.block_hash` for the state at the start of the voting period.
|
if (state.eth1_data_votes.len() as u64) < period / 2 {
|
||||||
if state.slot % period < period / 2 {
|
// If there are less than 50% of the votes in the current state, it's impossible that the
|
||||||
// When the state is less than half way through the period we can safely assume that
|
// `eth1_data.block_hash` has changed from the value at `state.eth1_data.block_hash`.
|
||||||
// the eth1_data has not changed since the start of the period.
|
|
||||||
Ok(state.eth1_data.block_hash)
|
Ok(state.eth1_data.block_hash)
|
||||||
} else {
|
} else {
|
||||||
|
// If there have been more than 50% of votes in this period it's possible (but not
|
||||||
|
// necessary) that the `state.eth1_data.block_hash` has been changed since the start of the
|
||||||
|
// voting period.
|
||||||
let slot = (state.slot / period) * period;
|
let slot = (state.slot / period) * period;
|
||||||
let prev_state_root = state
|
let prev_state_root = state
|
||||||
.get_state_root(slot)
|
.get_state_root(slot)
|
||||||
|
|||||||
Reference in New Issue
Block a user