More updates base upon the specs

This commit is contained in:
Kirk Baird 2019-01-23 18:06:25 +11:00
parent 560dbe4ae1
commit e047fbe914
No known key found for this signature in database
GPG Key ID: BF864B7ED0BEA33F
10 changed files with 65 additions and 72 deletions

View File

@ -31,7 +31,7 @@ where
None => reject!(Invalid::JustifiedBlockNotInChain),
Some(local_justified_block_hash) => {
verify_or!(
data.justified_block_hash == local_justified_block_hash,
data.justified_block_root == local_justified_block_hash,
reject!(Invalid::JustifiedBlockHashMismatch)
);
}

View File

@ -21,8 +21,8 @@ where
Some(crosslink) => {
let local_shard_block_hash = crosslink.shard_block_root;
let shard_block_hash_is_permissable = {
(local_shard_block_hash == data.latest_crosslink_hash)
|| (local_shard_block_hash == data.shard_block_hash)
(local_shard_block_hash == data.latest_crosslink_root)
|| (local_shard_block_hash == data.shard_block_root)
};
verify_or!(
shard_block_hash_is_permissable,

View File

@ -7,10 +7,10 @@ pub fn genesis_beacon_block(state_root: Hash256, spec: &ChainSpec) -> BeaconBloc
slot: spec.genesis_slot_number,
parent_root: spec.zero_hash,
state_root,
randao_reveal: spec.zero_hash,
randao_reveal: spec.empty_signature.clone(),
eth1_data: Eth1Data {
deposit_root: Hash256::zero(),
block_hash: Hash256::zero(),
deposit_root: spec.zero_hash,
block_hash: spec.zero_hash,
},
signature: spec.empty_signature.clone(),
body: BeaconBlockBody {
@ -50,7 +50,7 @@ mod tests {
assert!(genesis_block.slot == 0);
assert!(genesis_block.parent_root.is_zero());
assert!(genesis_block.randao_reveal.is_zero());
assert_eq!(genesis_block.randao_reveal, Signature::empty_signature());
assert!(genesis_block.eth1_data.deposit_root.is_zero());
assert!(genesis_block.eth1_data.block_hash.is_zero());
}

View File

@ -109,8 +109,7 @@ fn initial_validators_for_testing() -> Vec<ValidatorRecord> {
let validator_record = ValidatorRecord {
pubkey: keypair.pk.clone(),
withdrawal_credentials: Hash256::zero(),
randao_commitment: Hash256::zero(),
randao_layers: 0,
proposer_slots: 0,
activation_slot: u64::max_value(),
exit_slot: u64::max_value(),
withdrawal_slot: u64::max_value(),

View File

@ -7,32 +7,32 @@ use rand::RngCore;
#[derive(Debug, Clone, PartialEq)]
pub struct Attestation {
pub data: AttestationData,
pub participation_bitfield: Bitfield,
pub aggregation_bitfield: Bitfield,
pub custody_bitfield: Bitfield,
pub aggregate_sig: AggregateSignature,
pub aggregate_signature: AggregateSignature,
}
impl Encodable for Attestation {
fn ssz_append(&self, s: &mut SszStream) {
s.append(&self.data);
s.append(&self.participation_bitfield);
s.append(&self.aggregation_bitfield);
s.append(&self.custody_bitfield);
s.append(&self.aggregate_sig);
s.append(&self.aggregate_signature);
}
}
impl Decodable for Attestation {
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
let (data, i) = AttestationData::ssz_decode(bytes, i)?;
let (participation_bitfield, i) = Bitfield::ssz_decode(bytes, i)?;
let (aggregation_bitfield, i) = Bitfield::ssz_decode(bytes, i)?;
let (custody_bitfield, i) = Bitfield::ssz_decode(bytes, i)?;
let (aggregate_sig, i) = AggregateSignature::ssz_decode(bytes, i)?;
let (aggregate_signature, i) = AggregateSignature::ssz_decode(bytes, i)?;
let attestation_record = Self {
data,
participation_bitfield,
aggregation_bitfield,
custody_bitfield,
aggregate_sig,
aggregate_signature,
};
Ok((attestation_record, i))
}
@ -42,9 +42,9 @@ impl Attestation {
pub fn zero() -> Self {
Self {
data: AttestationData::zero(),
participation_bitfield: Bitfield::new(),
aggregation_bitfield: Bitfield::new(),
custody_bitfield: Bitfield::new(),
aggregate_sig: AggregateSignature::new(),
aggregate_signature: AggregateSignature::new(),
}
}
}
@ -53,9 +53,9 @@ impl<T: RngCore> TestRandom<T> for Attestation {
fn random_for_test(rng: &mut T) -> Self {
Self {
data: <_>::random_for_test(rng),
participation_bitfield: <_>::random_for_test(rng),
aggregation_bitfield: <_>::random_for_test(rng),
custody_bitfield: <_>::random_for_test(rng),
aggregate_sig: <_>::random_for_test(rng),
aggregate_signature: <_>::random_for_test(rng),
}
}
}

View File

@ -7,23 +7,23 @@ pub const SSZ_ATTESTION_DATA_LENGTH: usize = {
8 + // slot
8 + // shard
32 + // beacon_block_hash
32 + // epoch_boundary_hash
32 + // epoch_boundary_root
32 + // shard_block_hash
32 + // latest_crosslink_hash
8 + // justified_slot
32 // justified_block_hash
32 // justified_block_root
};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct AttestationData {
pub slot: u64,
pub shard: u64,
pub beacon_block_hash: Hash256,
pub epoch_boundary_hash: Hash256,
pub shard_block_hash: Hash256,
pub latest_crosslink_hash: Hash256,
pub beacon_block_root: Hash256,
pub epoch_boundary_root: Hash256,
pub shard_block_root: Hash256,
pub latest_crosslink_root: Hash256,
pub justified_slot: u64,
pub justified_block_hash: Hash256,
pub justified_block_root: Hash256,
}
impl AttestationData {
@ -31,12 +31,12 @@ impl AttestationData {
Self {
slot: 0,
shard: 0,
beacon_block_hash: Hash256::zero(),
epoch_boundary_hash: Hash256::zero(),
shard_block_hash: Hash256::zero(),
latest_crosslink_hash: Hash256::zero(),
beacon_block_root: Hash256::zero(),
epoch_boundary_root: Hash256::zero(),
shard_block_root: Hash256::zero(),
latest_crosslink_root: Hash256::zero(),
justified_slot: 0,
justified_block_hash: Hash256::zero(),
justified_block_root: Hash256::zero(),
}
}
@ -51,12 +51,12 @@ impl Encodable for AttestationData {
fn ssz_append(&self, s: &mut SszStream) {
s.append(&self.slot);
s.append(&self.shard);
s.append(&self.beacon_block_hash);
s.append(&self.epoch_boundary_hash);
s.append(&self.shard_block_hash);
s.append(&self.latest_crosslink_hash);
s.append(&self.beacon_block_root);
s.append(&self.epoch_boundary_root);
s.append(&self.shard_block_root);
s.append(&self.latest_crosslink_root);
s.append(&self.justified_slot);
s.append(&self.justified_block_hash);
s.append(&self.justified_block_root);
}
}
@ -64,22 +64,22 @@ impl Decodable for AttestationData {
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
let (slot, i) = u64::ssz_decode(bytes, i)?;
let (shard, i) = u64::ssz_decode(bytes, i)?;
let (beacon_block_hash, i) = Hash256::ssz_decode(bytes, i)?;
let (epoch_boundary_hash, i) = Hash256::ssz_decode(bytes, i)?;
let (shard_block_hash, i) = Hash256::ssz_decode(bytes, i)?;
let (latest_crosslink_hash, i) = Hash256::ssz_decode(bytes, i)?;
let (beacon_block_root, i) = Hash256::ssz_decode(bytes, i)?;
let (epoch_boundary_root, i) = Hash256::ssz_decode(bytes, i)?;
let (shard_block_root, i) = Hash256::ssz_decode(bytes, i)?;
let (latest_crosslink_root, i) = Hash256::ssz_decode(bytes, i)?;
let (justified_slot, i) = u64::ssz_decode(bytes, i)?;
let (justified_block_hash, i) = Hash256::ssz_decode(bytes, i)?;
let (justified_block_root, i) = Hash256::ssz_decode(bytes, i)?;
let attestation_data = AttestationData {
slot,
shard,
beacon_block_hash,
epoch_boundary_hash,
shard_block_hash,
latest_crosslink_hash,
beacon_block_root,
epoch_boundary_root,
shard_block_root,
latest_crosslink_root,
justified_slot,
justified_block_hash,
justified_block_root,
};
Ok((attestation_data, i))
}
@ -90,12 +90,12 @@ impl<T: RngCore> TestRandom<T> for AttestationData {
Self {
slot: <_>::random_for_test(rng),
shard: <_>::random_for_test(rng),
beacon_block_hash: <_>::random_for_test(rng),
epoch_boundary_hash: <_>::random_for_test(rng),
shard_block_hash: <_>::random_for_test(rng),
latest_crosslink_hash: <_>::random_for_test(rng),
beacon_block_root: <_>::random_for_test(rng),
epoch_boundary_root: <_>::random_for_test(rng),
shard_block_root: <_>::random_for_test(rng),
latest_crosslink_root: <_>::random_for_test(rng),
justified_slot: <_>::random_for_test(rng),
justified_block_hash: <_>::random_for_test(rng),
justified_block_root: <_>::random_for_test(rng),
}
}
}

View File

@ -10,7 +10,7 @@ pub struct BeaconBlock {
pub slot: u64,
pub parent_root: Hash256,
pub state_root: Hash256,
pub randao_reveal: Hash256,
pub randao_reveal: Signature,
pub eth1_data: Eth1Data,
pub signature: Signature,
pub body: BeaconBlockBody,

View File

@ -47,8 +47,7 @@ fn status_flag_from_byte(flag: u8) -> Result<Option<StatusFlags>, StatusFlagsDec
pub struct ValidatorRecord {
pub pubkey: PublicKey,
pub withdrawal_credentials: Hash256,
pub randao_commitment: Hash256,
pub randao_layers: u64,
pub proposer_slots: u64,
pub activation_slot: u64,
pub exit_slot: u64,
pub withdrawal_slot: u64,
@ -73,8 +72,7 @@ impl Default for ValidatorRecord {
Self {
pubkey: PublicKey::default(),
withdrawal_credentials: Hash256::default(),
randao_commitment: Hash256::default(),
randao_layers: 0,
proposer_slots: 0,
activation_slot: std::u64::MAX,
exit_slot: std::u64::MAX,
withdrawal_slot: std::u64::MAX,
@ -99,8 +97,7 @@ impl Encodable for ValidatorRecord {
fn ssz_append(&self, s: &mut SszStream) {
s.append(&self.pubkey);
s.append(&self.withdrawal_credentials);
s.append(&self.randao_commitment);
s.append(&self.randao_layers);
s.append(&self.proposer_slots);
s.append(&self.activation_slot);
s.append(&self.exit_slot);
s.append(&self.withdrawal_slot);
@ -117,8 +114,7 @@ impl Decodable for ValidatorRecord {
fn ssz_decode(bytes: &[u8], i: usize) -> Result<(Self, usize), DecodeError> {
let (pubkey, i) = <_>::ssz_decode(bytes, i)?;
let (withdrawal_credentials, i) = <_>::ssz_decode(bytes, i)?;
let (randao_commitment, i) = <_>::ssz_decode(bytes, i)?;
let (randao_layers, i) = <_>::ssz_decode(bytes, i)?;
let (proposer_slots, i) = <_>::ssz_decode(bytes, i)?;
let (activation_slot, i) = <_>::ssz_decode(bytes, i)?;
let (exit_slot, i) = <_>::ssz_decode(bytes, i)?;
let (withdrawal_slot, i) = <_>::ssz_decode(bytes, i)?;
@ -135,8 +131,7 @@ impl Decodable for ValidatorRecord {
Self {
pubkey,
withdrawal_credentials,
randao_commitment,
randao_layers,
proposer_slots,
activation_slot,
exit_slot,
withdrawal_slot,
@ -157,8 +152,7 @@ impl<T: RngCore> TestRandom<T> for ValidatorRecord {
Self {
pubkey: <_>::random_for_test(rng),
withdrawal_credentials: <_>::random_for_test(rng),
randao_commitment: <_>::random_for_test(rng),
randao_layers: <_>::random_for_test(rng),
proposer_slots: <_>::random_for_test(rng),
activation_slot: <_>::random_for_test(rng),
exit_slot: <_>::random_for_test(rng),
withdrawal_slot: <_>::random_for_test(rng),

View File

@ -42,8 +42,7 @@ pub fn process_deposit(
let validator = ValidatorRecord {
pubkey: deposit_input.pubkey.clone(),
withdrawal_credentials: deposit_input.withdrawal_credentials,
randao_commitment: deposit_input.randao_commitment,
randao_layers: 0,
proposer_slots: 0,
activation_slot: spec.far_future_slot,
exit_slot: spec.far_future_slot,
withdrawal_slot: spec.far_future_slot,
@ -91,7 +90,6 @@ mod tests {
fn deposit_equals_record(dep: &Deposit, val: &ValidatorRecord) -> bool {
(dep.deposit_data.deposit_input.pubkey == val.pubkey)
& (dep.deposit_data.deposit_input.withdrawal_credentials == val.withdrawal_credentials)
& (dep.deposit_data.deposit_input.randao_commitment == val.randao_commitment)
& (verify_proof_of_possession(
&dep.deposit_data.deposit_input.proof_of_possession,
&val.pubkey,
@ -147,7 +145,6 @@ mod tests {
validator.pubkey = deposit.deposit_data.deposit_input.pubkey.clone();
validator.withdrawal_credentials =
deposit.deposit_data.deposit_input.withdrawal_credentials;
validator.randao_commitment = deposit.deposit_data.deposit_input.randao_commitment;
state.validator_registry.push(validator);
state.validator_balances.push(DEPOSIT_GWEI);

View File

@ -25,12 +25,15 @@ impl BeaconNode for BeaconBlockServiceClient {
let (signature, _) = Signature::ssz_decode(block.get_signature(), 0)
.map_err(|_| BeaconNodeError::DecodeFailure)?;
let (randao_reveal, _) = Signature::ssz_decode(block.get_randao_reveal(), 0)
.map_err(|_| BeaconNodeError::DecodeFailure)?;
// TODO: this conversion is incomplete; fix it.
Ok(Some(BeaconBlock {
slot: block.get_slot(),
parent_root: Hash256::zero(),
state_root: Hash256::zero(),
randao_reveal: Hash256::from(block.get_randao_reveal()),
randao_reveal,
eth1_data: Eth1Data {
deposit_root: Hash256::zero(),
block_hash: Hash256::zero(),
@ -63,7 +66,7 @@ impl BeaconNode for BeaconBlockServiceClient {
let mut grpc_block = GrpcBeaconBlock::new();
grpc_block.set_slot(block.slot);
grpc_block.set_block_root(vec![0]);
grpc_block.set_randao_reveal(block.randao_reveal.to_vec());
grpc_block.set_randao_reveal(ssz_encode(&block.randao_reveal));
grpc_block.set_signature(ssz_encode(&block.signature));
req.set_block(grpc_block);