From 7b3f317abfe3439e20f3148596fec58d42c33016 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 30 Mar 2019 17:12:43 +1100 Subject: [PATCH 1/3] Fix bug with attestation production It was being produced with the wrong source root. I will raise an issue on the spec as it's a tricky one. --- beacon_node/beacon_chain/src/beacon_chain.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 614cc46d81..45a28b7822 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -475,11 +475,7 @@ where /// Produce an `AttestationData` that is valid for the present `slot` and given `shard`. pub fn produce_attestation_data(&self, shard: u64) -> Result { trace!("BeaconChain::produce_attestation: shard: {}", shard); - let source_epoch = self.state.read().current_justified_epoch; - let source_root = *self.state.read().get_block_root( - source_epoch.start_slot(self.spec.slots_per_epoch), - &self.spec, - )?; + let state = self.state.read(); let target_root = *self.state.read().get_block_root( self.state @@ -500,8 +496,8 @@ where epoch: self.state.read().slot.epoch(self.spec.slots_per_epoch), crosslink_data_root: Hash256::zero(), }, - source_epoch, - source_root, + source_epoch: state.current_justified_epoch, + source_root: state.current_justified_root, }) } From dbcc88ad67aff419a9af00037809d599dc3dc1e9 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 30 Mar 2019 17:13:23 +1100 Subject: [PATCH 2/3] Ensure BitVec is initialized using a multiple of 8 I found it was panic-ing when supplied a non-power-of-zero len. --- beacon_node/beacon_chain/src/beacon_chain.rs | 5 ++++- eth2/utils/boolean-bitfield/src/lib.rs | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 45a28b7822..7c2336a28b 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -692,7 +692,10 @@ where }, }; - trace!("BeaconChain::produce_block: updating state for new block.",); + debug!( + "Produced block with {} attestations, updating state.", + block.body.attestations.len() + ); per_block_processing_without_verifying_block_signature(&mut state, &block, &self.spec)?; diff --git a/eth2/utils/boolean-bitfield/src/lib.rs b/eth2/utils/boolean-bitfield/src/lib.rs index cdd0bc3d77..d90b28dc5b 100644 --- a/eth2/utils/boolean-bitfield/src/lib.rs +++ b/eth2/utils/boolean-bitfield/src/lib.rs @@ -33,9 +33,11 @@ impl BooleanBitfield { } /// Create a new bitfield with the given length `initial_len` and all values set to `bit`. - pub fn from_elem(inital_len: usize, bit: bool) -> Self { + pub fn from_elem(initial_len: usize, bit: bool) -> Self { + // BitVec can panic if we don't set the len to be a multiple of 8. + let len = ((initial_len + 7) / 8) * 8; Self { - 0: BitVec::from_elem(inital_len, bit), + 0: BitVec::from_elem(len, bit), } } From ed6d0b46d03b088f5074b3b17c723723c19d9437 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sat, 30 Mar 2019 17:16:04 +1100 Subject: [PATCH 3/3] Add committee len to AttesterDuties --- eth2/types/src/attestation_duty.rs | 1 + eth2/types/src/beacon_state/epoch_cache.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/eth2/types/src/attestation_duty.rs b/eth2/types/src/attestation_duty.rs index 80d912a83f..299fdd44cf 100644 --- a/eth2/types/src/attestation_duty.rs +++ b/eth2/types/src/attestation_duty.rs @@ -6,4 +6,5 @@ pub struct AttestationDuty { pub slot: Slot, pub shard: Shard, pub committee_index: usize, + pub committee_len: usize, } diff --git a/eth2/types/src/beacon_state/epoch_cache.rs b/eth2/types/src/beacon_state/epoch_cache.rs index 32d9a643e9..62df902714 100644 --- a/eth2/types/src/beacon_state/epoch_cache.rs +++ b/eth2/types/src/beacon_state/epoch_cache.rs @@ -92,6 +92,7 @@ impl EpochCache { slot, shard, committee_index: k, + committee_len: crosslink_committee.committee.len(), }; attestation_duties[*validator_index] = Some(attestation_duty) }