mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 01:05:47 +00:00
BaconState serialization fixed and reorganiztion around induction and deposits
This commit is contained in:
@@ -62,6 +62,7 @@ impl Encodable for BeaconState {
|
||||
s.append(&self.genesis_time);
|
||||
s.append(&self.fork_data);
|
||||
s.append(&self.validator_registry);
|
||||
s.append(&self.validator_balances);
|
||||
s.append(&self.validator_registry_latest_change_slot);
|
||||
s.append(&self.validator_registry_exit_count);
|
||||
s.append(&self.validator_registry_delta_chain_tip);
|
||||
@@ -89,6 +90,7 @@ impl Decodable for BeaconState {
|
||||
let (genesis_time, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (fork_data, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (validator_registry, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (validator_balances, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (validator_registry_latest_change_slot, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (validator_registry_exit_count, i) = <_>::ssz_decode(bytes, i)?;
|
||||
let (validator_registry_delta_chain_tip, i) = <_>::ssz_decode(bytes, i)?;
|
||||
@@ -114,6 +116,7 @@ impl Decodable for BeaconState {
|
||||
genesis_time,
|
||||
fork_data,
|
||||
validator_registry,
|
||||
validator_balances,
|
||||
validator_registry_latest_change_slot,
|
||||
validator_registry_exit_count,
|
||||
validator_registry_delta_chain_tip,
|
||||
@@ -145,6 +148,7 @@ impl<T: RngCore> TestRandom<T> for BeaconState {
|
||||
genesis_time: <_>::random_for_test(rng),
|
||||
fork_data: <_>::random_for_test(rng),
|
||||
validator_registry: <_>::random_for_test(rng),
|
||||
validator_balances: <_>::random_for_test(rng),
|
||||
validator_registry_latest_change_slot: <_>::random_for_test(rng),
|
||||
validator_registry_exit_count: <_>::random_for_test(rng),
|
||||
validator_registry_delta_chain_tip: <_>::random_for_test(rng),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use super::ssz::{Decodable, DecodeError, Encodable, SszStream};
|
||||
use super::{DepositData, Hash256};
|
||||
use super::{DepositData, DepositInput, Hash256};
|
||||
use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
use bls::{Keypair, create_proof_of_possession};
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct Deposit {
|
||||
@@ -10,6 +11,29 @@ pub struct Deposit {
|
||||
pub deposit_data: DepositData,
|
||||
}
|
||||
|
||||
impl Deposit {
|
||||
pub fn zero_with_rand_keypair() -> Self{
|
||||
let kp = Keypair::random();
|
||||
let deposit_input = DepositInput {
|
||||
pubkey: kp.pk.clone(),
|
||||
withdrawal_credentials: Hash256::zero(),
|
||||
randao_commitment: Hash256::zero(),
|
||||
poc_commitment: Hash256::zero(),
|
||||
proof_of_possession: create_proof_of_possession(&kp)
|
||||
};
|
||||
let deposit_data = DepositData {
|
||||
deposit_input: deposit_input,
|
||||
value: 0,
|
||||
timestamp: 0
|
||||
};
|
||||
Self {
|
||||
merkle_branch: Vec::new(),
|
||||
merkle_tree_index: 0,
|
||||
deposit_data: deposit_data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for Deposit {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append_vec(&self.merkle_branch);
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::ssz::{Decodable, DecodeError, Encodable, SszStream};
|
||||
use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct ForkData {
|
||||
pub pre_fork_version: u64,
|
||||
pub post_fork_version: u64,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::bls::PublicKey;
|
||||
use super::bls::{Keypair, PublicKey};
|
||||
use super::{Hash256};
|
||||
use crate::test_utils::TestRandom;
|
||||
use rand::RngCore;
|
||||
@@ -43,6 +43,23 @@ pub struct ValidatorRecord {
|
||||
pub second_last_poc_slot: u64
|
||||
}
|
||||
|
||||
impl ValidatorRecord {
|
||||
pub fn zero_with_rand_keypair() -> Self {
|
||||
Self {
|
||||
pubkey: Keypair::random().pk,
|
||||
withdrawal_credentials: Hash256::zero(),
|
||||
randao_commitment: Hash256::zero(),
|
||||
randao_layers: 0,
|
||||
status: ValidatorStatus::from(0),
|
||||
latest_status_change_slot: 0,
|
||||
exit_count: 0,
|
||||
poc_commitment: Hash256::zero(),
|
||||
last_poc_change_slot: 0,
|
||||
second_last_poc_slot: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ValidatorRecord {
|
||||
pub fn status_is(&self, status: ValidatorStatus) -> bool {
|
||||
self.status == status
|
||||
|
||||
Reference in New Issue
Block a user