mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Update ethereum-types to 0.5
This commit is contained in:
@@ -210,7 +210,7 @@ where
|
||||
|
||||
trace!("Child vote length: {}", votes.len());
|
||||
for (candidate, votes) in votes.iter() {
|
||||
let candidate_bit: BitVec = BitVec::from_bytes(&candidate);
|
||||
let candidate_bit: BitVec = BitVec::from_bytes(candidate.as_bytes());
|
||||
|
||||
// if the bitmasks don't match, exclude candidate
|
||||
if !bitmask.iter().eq(candidate_bit.iter().take(bit)) {
|
||||
|
||||
@@ -134,9 +134,10 @@ fn per_block_processing_signature_optional(
|
||||
let new_mix = {
|
||||
let mut mix = state.latest_randao_mixes
|
||||
[state.slot.as_usize() % spec.latest_randao_mixes_length]
|
||||
.as_bytes()
|
||||
.to_vec();
|
||||
mix.append(&mut ssz_encode(&block.randao_reveal));
|
||||
Hash256::from(&hash(&mix)[..])
|
||||
Hash256::from_slice(&hash(&mix)[..])
|
||||
};
|
||||
|
||||
state.latest_randao_mixes[state.slot.as_usize() % spec.latest_randao_mixes_length] = new_mix;
|
||||
|
||||
@@ -626,7 +626,7 @@ impl EpochProcessable for BeaconState {
|
||||
}
|
||||
|
||||
fn hash_tree_root<T: TreeHash>(input: Vec<T>) -> Hash256 {
|
||||
Hash256::from(&input.hash_tree_root()[..])
|
||||
Hash256::from_slice(&input.hash_tree_root()[..])
|
||||
}
|
||||
|
||||
fn winning_root(
|
||||
|
||||
@@ -7,7 +7,7 @@ edition = "2018"
|
||||
[dependencies]
|
||||
bls = { path = "../utils/bls" }
|
||||
boolean-bitfield = { path = "../utils/boolean-bitfield" }
|
||||
ethereum-types = "0.4.0"
|
||||
ethereum-types = "0.5"
|
||||
hashing = { path = "../utils/hashing" }
|
||||
honey-badger-split = { path = "../utils/honey-badger-split" }
|
||||
log = "0.4"
|
||||
@@ -21,6 +21,7 @@ ssz = { path = "../utils/ssz" }
|
||||
ssz_derive = { path = "../utils/ssz_derive" }
|
||||
swap_or_not_shuffle = { path = "../utils/swap_or_not_shuffle" }
|
||||
test_random_derive = { path = "../utils/test_random_derive" }
|
||||
int_to_bytes = { path = "../utils/int_to_bytes" }
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.6.0"
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct Attestation {
|
||||
|
||||
impl Attestation {
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from(&self.hash_tree_root()[..])
|
||||
Hash256::from_slice(&self.hash_tree_root()[..])
|
||||
}
|
||||
|
||||
pub fn signable_message(&self, custody_bit: bool) -> Vec<u8> {
|
||||
|
||||
@@ -35,7 +35,7 @@ impl Eq for AttestationData {}
|
||||
|
||||
impl AttestationData {
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from(&self.hash_tree_root()[..])
|
||||
Hash256::from_slice(&self.hash_tree_root()[..])
|
||||
}
|
||||
|
||||
pub fn signable_message(&self, custody_bit: bool) -> Vec<u8> {
|
||||
|
||||
@@ -27,8 +27,8 @@ impl AttesterSlashingBuilder {
|
||||
let shard = 0;
|
||||
let justified_epoch = Epoch::new(0);
|
||||
let epoch = Epoch::new(0);
|
||||
let hash_1 = Hash256::from(&[1][..]);
|
||||
let hash_2 = Hash256::from(&[2][..]);
|
||||
let hash_1 = Hash256::from_low_u64_le(1);
|
||||
let hash_2 = Hash256::from_low_u64_le(2);
|
||||
|
||||
let mut slashable_attestation_1 = SlashableAttestation {
|
||||
validator_indices: validator_indices.to_vec(),
|
||||
|
||||
@@ -42,7 +42,7 @@ impl BeaconBlock {
|
||||
}
|
||||
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from(&self.hash_tree_root()[..])
|
||||
Hash256::from_slice(&self.hash_tree_root()[..])
|
||||
}
|
||||
|
||||
pub fn proposal_root(&self, spec: &ChainSpec) -> Hash256 {
|
||||
@@ -57,7 +57,7 @@ impl BeaconBlock {
|
||||
shard: spec.beacon_chain_shard_number,
|
||||
block_root: block_without_signature_root,
|
||||
};
|
||||
Hash256::from(&proposal.hash_tree_root()[..])
|
||||
Hash256::from_slice(&proposal.hash_tree_root()[..])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::test_utils::TestRandom;
|
||||
use crate::{validator::StatusFlags, validator_registry::get_active_validator_indices, *};
|
||||
use bls::verify_proof_of_possession;
|
||||
use honey_badger_split::SplitExt;
|
||||
use int_to_bytes::int_to_bytes32;
|
||||
use log::{debug, error, trace};
|
||||
use rand::RngCore;
|
||||
use rayon::prelude::*;
|
||||
@@ -326,7 +327,7 @@ impl BeaconState {
|
||||
///
|
||||
/// Spec v0.2.0
|
||||
pub fn canonical_root(&self) -> Hash256 {
|
||||
Hash256::from(&self.hash_tree_root()[..])
|
||||
Hash256::from_slice(&self.hash_tree_root()[..])
|
||||
}
|
||||
|
||||
/// The epoch corresponding to `self.slot`.
|
||||
@@ -487,19 +488,20 @@ impl BeaconState {
|
||||
let mut input = self
|
||||
.get_randao_mix(epoch, spec)
|
||||
.ok_or_else(|| Error::InsufficientRandaoMixes)?
|
||||
.as_bytes()
|
||||
.to_vec();
|
||||
|
||||
input.append(
|
||||
&mut self
|
||||
.get_active_index_root(epoch, spec)
|
||||
.ok_or_else(|| Error::InsufficientIndexRoots)?
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
);
|
||||
|
||||
// TODO: ensure `Hash256::from(u64)` == `int_to_bytes32`.
|
||||
input.append(&mut Hash256::from(epoch.as_u64()).to_vec());
|
||||
input.append(&mut int_to_bytes32(epoch.as_u64()));
|
||||
|
||||
Ok(Hash256::from(&hash(&input[..])[..]))
|
||||
Ok(Hash256::from_slice(&hash(&input[..])[..]))
|
||||
}
|
||||
|
||||
/// Returns the crosslink committees for some slot.
|
||||
@@ -1311,7 +1313,7 @@ impl BeaconState {
|
||||
}
|
||||
|
||||
fn hash_tree_root<T: TreeHash>(input: Vec<T>) -> Hash256 {
|
||||
Hash256::from(&input.hash_tree_root()[..])
|
||||
Hash256::from_slice(&input.hash_tree_root()[..])
|
||||
}
|
||||
|
||||
impl From<Error> for InclusionError {
|
||||
|
||||
@@ -145,8 +145,8 @@ impl BeaconStateBuilder {
|
||||
state.previous_calculation_epoch = epoch - 1;
|
||||
state.current_calculation_epoch = epoch;
|
||||
|
||||
state.previous_epoch_seed = Hash256::from(&b"previous_seed"[..]);
|
||||
state.current_epoch_seed = Hash256::from(&b"current_seed"[..]);
|
||||
state.previous_epoch_seed = Hash256::from([0x01; 32]);
|
||||
state.current_epoch_seed = Hash256::from([0x02; 32]);
|
||||
|
||||
state.previous_justified_epoch = epoch - 2;
|
||||
state.justified_epoch = epoch - 1;
|
||||
|
||||
@@ -25,13 +25,13 @@ impl ProposerSlashingBuilder {
|
||||
let proposal_data_1 = ProposalSignedData {
|
||||
slot,
|
||||
shard,
|
||||
block_root: Hash256::from(&[1][..]),
|
||||
block_root: Hash256::from_low_u64_le(1),
|
||||
};
|
||||
|
||||
let proposal_data_2 = ProposalSignedData {
|
||||
slot,
|
||||
shard,
|
||||
block_root: Hash256::from(&[2][..]),
|
||||
block_root: Hash256::from_low_u64_le(2),
|
||||
};
|
||||
|
||||
let proposal_signature_1 = {
|
||||
|
||||
@@ -6,6 +6,6 @@ impl<T: RngCore> TestRandom<T> for Address {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
let mut key_bytes = vec![0; 20];
|
||||
rng.fill_bytes(&mut key_bytes);
|
||||
Address::from(&key_bytes[..])
|
||||
Address::from_slice(&key_bytes[..])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,6 @@ impl<T: RngCore> TestRandom<T> for Hash256 {
|
||||
fn random_for_test(rng: &mut T) -> Self {
|
||||
let mut key_bytes = vec![0; 32];
|
||||
rng.fill_bytes(&mut key_bytes);
|
||||
Hash256::from(&key_bytes[..])
|
||||
Hash256::from_slice(&key_bytes[..])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,5 @@ edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bytes = "0.4.9"
|
||||
ethereum-types = "0.4.0"
|
||||
ethereum-types = "0.5"
|
||||
hashing = { path = "../hashing" }
|
||||
|
||||
@@ -59,7 +59,7 @@ impl Decodable for H256 {
|
||||
if bytes.len() < 32 || bytes.len() - 32 < index {
|
||||
Err(DecodeError::TooShort)
|
||||
} else {
|
||||
Ok((H256::from(&bytes[index..(index + 32)]), index + 32))
|
||||
Ok((H256::from_slice(&bytes[index..(index + 32)]), index + 32))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ impl Decodable for Address {
|
||||
if bytes.len() < 20 || bytes.len() - 20 < index {
|
||||
Err(DecodeError::TooShort)
|
||||
} else {
|
||||
Ok((Address::from(&bytes[index..(index + 20)]), index + 20))
|
||||
Ok((Address::from_slice(&bytes[index..(index + 20)]), index + 20))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ mod tests {
|
||||
*/
|
||||
let input = vec![42_u8; 32];
|
||||
let (decoded, i) = H256::ssz_decode(&input, 0).unwrap();
|
||||
assert_eq!(decoded.to_vec(), input);
|
||||
assert_eq!(decoded.as_bytes(), &input[..]);
|
||||
assert_eq!(i, 32);
|
||||
|
||||
/*
|
||||
@@ -104,7 +104,7 @@ mod tests {
|
||||
let mut input = vec![42_u8; 32];
|
||||
input.push(12);
|
||||
let (decoded, i) = H256::ssz_decode(&input, 0).unwrap();
|
||||
assert_eq!(decoded.to_vec()[..], input[0..32]);
|
||||
assert_eq!(decoded.as_bytes(), &input[0..32]);
|
||||
assert_eq!(i, 32);
|
||||
|
||||
/*
|
||||
|
||||
@@ -55,13 +55,13 @@ impl Encodable for bool {
|
||||
|
||||
impl Encodable for H256 {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append_encoded_raw(&self.to_vec());
|
||||
s.append_encoded_raw(self.as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for Address {
|
||||
fn ssz_append(&self, s: &mut SszStream) {
|
||||
s.append_encoded_raw(&self.to_vec());
|
||||
s.append_encoded_raw(self.as_bytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user