From a0148b5aaeffa2f22b4c937fd934e6fdc47040aa Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 13 May 2019 15:12:19 +1000 Subject: [PATCH] Rename SSZ traits (Encodable -> Encode) --- .../db/src/stores/beacon_block_store.rs | 2 +- .../db/src/stores/beacon_state_store.rs | 2 +- beacon_node/db/src/stores/validator_store.rs | 2 +- beacon_node/eth2-libp2p/src/behaviour.rs | 8 +++--- beacon_node/eth2-libp2p/src/rpc/protocol.rs | 10 +++---- beacon_node/rpc/src/attestation.rs | 2 +- beacon_node/rpc/src/beacon_block.rs | 2 +- beacon_node/rpc/src/validator.rs | 2 +- eth2/README.md | 2 +- eth2/types/src/slot_epoch.rs | 2 +- eth2/types/src/slot_epoch_macros.rs | 12 ++++----- eth2/types/src/slot_height.rs | 2 +- eth2/types/src/test_utils/macros.rs | 2 +- eth2/types/src/tree_hash_vector.rs | 10 +++---- eth2/utils/bls/src/aggregate_signature.rs | 4 +-- .../utils/bls/src/fake_aggregate_signature.rs | 2 +- eth2/utils/bls/src/fake_signature.rs | 2 +- eth2/utils/bls/src/macros.rs | 6 ++--- eth2/utils/bls/src/public_key.rs | 2 +- eth2/utils/bls/src/secret_key.rs | 2 +- eth2/utils/bls/src/signature.rs | 2 +- eth2/utils/boolean-bitfield/src/lib.rs | 6 ++--- eth2/utils/fixed_len_vec/src/impls.rs | 18 ++++++------- eth2/utils/ssz/README.md | 20 +++++++------- eth2/utils/ssz/benches/benches.rs | 2 +- eth2/utils/ssz/examples/large_list.rs | 2 +- .../ssz/examples/large_list_of_structs.rs | 2 +- eth2/utils/ssz/examples/struct_definition.rs | 16 ++++++------ eth2/utils/ssz/src/decode.rs | 8 +++--- eth2/utils/ssz/src/decode/impls.rs | 20 +++++++------- eth2/utils/ssz/src/encode.rs | 8 +++--- eth2/utils/ssz/src/encode/impls.rs | 10 +++---- eth2/utils/ssz/src/lib.rs | 11 ++++---- eth2/utils/ssz/src/macros.rs | 26 +++++++++---------- eth2/utils/ssz/tests/tests.rs | 4 +-- eth2/utils/ssz_derive/src/lib.rs | 22 ++++++++-------- eth2/utils/ssz_derive/tests/tests.rs | 2 +- .../src/attestation_producer/grpc.rs | 2 +- validator_client/src/block_producer/grpc.rs | 2 +- 39 files changed, 130 insertions(+), 131 deletions(-) diff --git a/beacon_node/db/src/stores/beacon_block_store.rs b/beacon_node/db/src/stores/beacon_block_store.rs index 1f75da524..868caafe2 100644 --- a/beacon_node/db/src/stores/beacon_block_store.rs +++ b/beacon_node/db/src/stores/beacon_block_store.rs @@ -1,6 +1,6 @@ use super::BLOCKS_DB_COLUMN as DB_COLUMN; use super::{ClientDB, DBError}; -use ssz::Decodable; +use ssz::Decode; use std::sync::Arc; use types::{BeaconBlock, Hash256, Slot}; diff --git a/beacon_node/db/src/stores/beacon_state_store.rs b/beacon_node/db/src/stores/beacon_state_store.rs index 7822f4929..b7c512d9d 100644 --- a/beacon_node/db/src/stores/beacon_state_store.rs +++ b/beacon_node/db/src/stores/beacon_state_store.rs @@ -1,6 +1,6 @@ use super::STATES_DB_COLUMN as DB_COLUMN; use super::{ClientDB, DBError}; -use ssz::Decodable; +use ssz::Decode; use std::sync::Arc; use types::{BeaconState, EthSpec, Hash256}; diff --git a/beacon_node/db/src/stores/validator_store.rs b/beacon_node/db/src/stores/validator_store.rs index ac0030981..f653c9f71 100644 --- a/beacon_node/db/src/stores/validator_store.rs +++ b/beacon_node/db/src/stores/validator_store.rs @@ -4,7 +4,7 @@ use self::bytes::{BufMut, BytesMut}; use super::VALIDATOR_DB_COLUMN as DB_COLUMN; use super::{ClientDB, DBError}; use bls::PublicKey; -use ssz::{Decodable, Encodable}; +use ssz::{Decode, Encode}; use std::sync::Arc; #[derive(Debug, PartialEq)] diff --git a/beacon_node/eth2-libp2p/src/behaviour.rs b/beacon_node/eth2-libp2p/src/behaviour.rs index ddef39bc5..8f3a000e1 100644 --- a/beacon_node/eth2-libp2p/src/behaviour.rs +++ b/beacon_node/eth2-libp2p/src/behaviour.rs @@ -13,7 +13,7 @@ use libp2p::{ NetworkBehaviour, PeerId, }; use slog::{debug, o, trace, warn}; -use ssz::{ssz_encode, Decodable, DecodeError, Encodable}; +use ssz::{ssz_encode, Decode, DecodeError, Encode}; use types::{Attestation, BeaconBlock}; use types::{Topic, TopicHash}; @@ -197,13 +197,13 @@ pub enum PubsubMessage { } //TODO: Correctly encode/decode enums. Prefixing with integer for now. -impl Encodable for PubsubMessage { +impl Encode for PubsubMessage { fn is_ssz_fixed_len() -> bool { false } fn ssz_append(&self, buf: &mut Vec) { - let offset = ::ssz_fixed_len() + as Encodable>::ssz_fixed_len(); + let offset = ::ssz_fixed_len() + as Encode>::ssz_fixed_len(); let mut encoder = ssz::SszEncoder::container(buf, offset); @@ -226,7 +226,7 @@ impl Encodable for PubsubMessage { } } -impl Decodable for PubsubMessage { +impl Decode for PubsubMessage { fn is_ssz_fixed_len() -> bool { false } diff --git a/beacon_node/eth2-libp2p/src/rpc/protocol.rs b/beacon_node/eth2-libp2p/src/rpc/protocol.rs index 5d33f4e37..82257cc32 100644 --- a/beacon_node/eth2-libp2p/src/rpc/protocol.rs +++ b/beacon_node/eth2-libp2p/src/rpc/protocol.rs @@ -1,6 +1,6 @@ use super::methods::*; use libp2p::core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo}; -use ssz::{impl_decode_via_from, impl_encode_via_from, ssz_encode, Decodable, Encodable}; +use ssz::{impl_decode_via_from, impl_encode_via_from, ssz_encode, Decode, Encode}; use std::hash::{Hash, Hasher}; use std::io; use std::iter; @@ -203,7 +203,7 @@ where } } -impl Encodable for RPCEvent { +impl Encode for RPCEvent { fn is_ssz_fixed_len() -> bool { false } @@ -213,9 +213,9 @@ impl Encodable for RPCEvent { // This code has not been tested, it is a placeholder until we can update to the new libp2p // spec. fn ssz_append(&self, buf: &mut Vec) { - let offset = ::ssz_fixed_len() - + ::ssz_fixed_len() - + as Encodable>::ssz_fixed_len(); + let offset = ::ssz_fixed_len() + + ::ssz_fixed_len() + + as Encode>::ssz_fixed_len(); let mut encoder = ssz::SszEncoder::container(buf, offset); diff --git a/beacon_node/rpc/src/attestation.rs b/beacon_node/rpc/src/attestation.rs index 0b79c2cee..0a2242d71 100644 --- a/beacon_node/rpc/src/attestation.rs +++ b/beacon_node/rpc/src/attestation.rs @@ -7,7 +7,7 @@ use protos::services::{ }; use protos::services_grpc::AttestationService; use slog::{error, info, trace, warn}; -use ssz::{ssz_encode, Decodable}; +use ssz::{ssz_encode, Decode}; use std::sync::Arc; use types::{Attestation, EthSpec}; diff --git a/beacon_node/rpc/src/beacon_block.rs b/beacon_node/rpc/src/beacon_block.rs index 12e08728b..788fa7ae4 100644 --- a/beacon_node/rpc/src/beacon_block.rs +++ b/beacon_node/rpc/src/beacon_block.rs @@ -11,7 +11,7 @@ use protos::services::{ use protos::services_grpc::BeaconBlockService; use slog::Logger; use slog::{error, info, trace, warn}; -use ssz::{ssz_encode, Decodable}; +use ssz::{ssz_encode, Decode}; use std::sync::Arc; use types::{BeaconBlock, EthSpec, Signature, Slot}; diff --git a/beacon_node/rpc/src/validator.rs b/beacon_node/rpc/src/validator.rs index 58de39dc7..0e53d3cc7 100644 --- a/beacon_node/rpc/src/validator.rs +++ b/beacon_node/rpc/src/validator.rs @@ -5,7 +5,7 @@ use grpcio::{RpcContext, RpcStatus, RpcStatusCode, UnarySink}; use protos::services::{ActiveValidator, GetDutiesRequest, GetDutiesResponse, ValidatorDuty}; use protos::services_grpc::ValidatorService; use slog::{trace, warn}; -use ssz::Decodable; +use ssz::Decode; use std::sync::Arc; use types::{Epoch, EthSpec, RelativeEpoch}; diff --git a/eth2/README.md b/eth2/README.md index cf041e987..2159e2fd3 100644 --- a/eth2/README.md +++ b/eth2/README.md @@ -30,7 +30,7 @@ Rust crates containing logic common across the Lighthouse project. - [`ssz`](utils/ssz/): an implementation of the SimpleSerialize serialization/deserialization protocol used by Eth 2.0. - [`ssz_derive`](utils/ssz_derive/): provides procedural macros for - deriving SSZ `Encodable`, `Decodable`, and `TreeHash` methods. + deriving SSZ `Encode`, `Decode`, and `TreeHash` methods. - [`swap_or_not_shuffle`](utils/swap_or_not_shuffle/): a list-shuffling method which is slow, but allows for a subset of indices to be shuffled. - [`test_random_derive`](utils/test_random_derive/): provides procedural diff --git a/eth2/types/src/slot_epoch.rs b/eth2/types/src/slot_epoch.rs index a75600771..b0f4bdcf9 100644 --- a/eth2/types/src/slot_epoch.rs +++ b/eth2/types/src/slot_epoch.rs @@ -15,7 +15,7 @@ use crate::test_utils::TestRandom; use rand::RngCore; use serde_derive::{Deserialize, Serialize}; use slog; -use ssz::{ssz_encode, Decodable, DecodeError, Encodable}; +use ssz::{ssz_encode, Decode, DecodeError, Encode}; use std::cmp::{Ord, Ordering}; use std::fmt; use std::hash::{Hash, Hasher}; diff --git a/eth2/types/src/slot_epoch_macros.rs b/eth2/types/src/slot_epoch_macros.rs index 9baaa15a3..1e24f8e99 100644 --- a/eth2/types/src/slot_epoch_macros.rs +++ b/eth2/types/src/slot_epoch_macros.rs @@ -192,13 +192,13 @@ macro_rules! impl_display { macro_rules! impl_ssz { ($type: ident) => { - impl Encodable for $type { + impl Encode for $type { fn is_ssz_fixed_len() -> bool { - ::is_ssz_fixed_len() + ::is_ssz_fixed_len() } fn ssz_fixed_len() -> usize { - ::ssz_fixed_len() + ::ssz_fixed_len() } fn ssz_append(&self, buf: &mut Vec) { @@ -206,13 +206,13 @@ macro_rules! impl_ssz { } } - impl Decodable for $type { + impl Decode for $type { fn is_ssz_fixed_len() -> bool { - ::is_ssz_fixed_len() + ::is_ssz_fixed_len() } fn ssz_fixed_len() -> usize { - ::ssz_fixed_len() + ::ssz_fixed_len() } fn from_ssz_bytes(bytes: &[u8]) -> Result { diff --git a/eth2/types/src/slot_height.rs b/eth2/types/src/slot_height.rs index c8f73b5ac..47db392a9 100644 --- a/eth2/types/src/slot_height.rs +++ b/eth2/types/src/slot_height.rs @@ -3,7 +3,7 @@ use crate::test_utils::TestRandom; use rand::RngCore; use serde_derive::Serialize; -use ssz::{ssz_encode, Decodable, DecodeError, Encodable}; +use ssz::{ssz_encode, Decode, DecodeError, Encode}; use std::cmp::{Ord, Ordering}; use std::fmt; use std::hash::{Hash, Hasher}; diff --git a/eth2/types/src/test_utils/macros.rs b/eth2/types/src/test_utils/macros.rs index 7214567e8..b060882f2 100644 --- a/eth2/types/src/test_utils/macros.rs +++ b/eth2/types/src/test_utils/macros.rs @@ -5,7 +5,7 @@ macro_rules! ssz_tests { #[test] pub fn test_ssz_round_trip() { use crate::test_utils::{SeedableRng, TestRandom, XorShiftRng}; - use ssz::{ssz_encode, Decodable}; + use ssz::{ssz_encode, Decode}; let mut rng = XorShiftRng::from_seed([42; 16]); let original = $type::random_for_test(&mut rng); diff --git a/eth2/types/src/tree_hash_vector.rs b/eth2/types/src/tree_hash_vector.rs index 198b63b93..f436e69e2 100644 --- a/eth2/types/src/tree_hash_vector.rs +++ b/eth2/types/src/tree_hash_vector.rs @@ -1,7 +1,7 @@ use crate::test_utils::{RngCore, TestRandom}; use cached_tree_hash::CachedTreeHash; use serde_derive::{Deserialize, Serialize}; -use ssz::{Decodable, DecodeError, Encodable}; +use ssz::{Decode, DecodeError, Encode}; use std::ops::{Deref, DerefMut}; use tree_hash::TreeHash; @@ -82,18 +82,18 @@ where } } -impl Encodable for TreeHashVector +impl Encode for TreeHashVector where - T: Encodable, + T: Encode, { fn ssz_append(&self, s: &mut SszStream) { s.append_vec(self) } } -impl Decodable for TreeHashVector +impl Decode for TreeHashVector where - T: Decodable, + T: Decode, { fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError> { ssz::decode_ssz_list(bytes, index).and_then(|(vec, i)| Ok((vec.into(), i))) diff --git a/eth2/utils/bls/src/aggregate_signature.rs b/eth2/utils/bls/src/aggregate_signature.rs index 00afe19d6..2e4615324 100644 --- a/eth2/utils/bls/src/aggregate_signature.rs +++ b/eth2/utils/bls/src/aggregate_signature.rs @@ -6,7 +6,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::{encode as hex_encode, HexVisitor}; -use ssz::{Decodable, DecodeError}; +use ssz::{Decode, DecodeError}; use tree_hash::tree_hash_ssz_encoding_as_vector; /// A BLS aggregate signature. @@ -168,7 +168,7 @@ cached_tree_hash_ssz_encoding_as_vector!(AggregateSignature, 96); mod tests { use super::super::{Keypair, Signature}; use super::*; - use ssz::Encodable; + use ssz::Encode; #[test] pub fn test_ssz_round_trip() { diff --git a/eth2/utils/bls/src/fake_aggregate_signature.rs b/eth2/utils/bls/src/fake_aggregate_signature.rs index ac6cc5b2b..12532d080 100644 --- a/eth2/utils/bls/src/fake_aggregate_signature.rs +++ b/eth2/utils/bls/src/fake_aggregate_signature.rs @@ -3,7 +3,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::{encode as hex_encode, PrefixedHexVisitor}; -use ssz::{ssz_encode, Decodable, DecodeError}; +use ssz::{ssz_encode, Decode, DecodeError}; use tree_hash::tree_hash_ssz_encoding_as_vector; /// A BLS aggregate signature. diff --git a/eth2/utils/bls/src/fake_signature.rs b/eth2/utils/bls/src/fake_signature.rs index 02aad673a..0bf3d0a25 100644 --- a/eth2/utils/bls/src/fake_signature.rs +++ b/eth2/utils/bls/src/fake_signature.rs @@ -4,7 +4,7 @@ use hex::encode as hex_encode; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::HexVisitor; -use ssz::{ssz_encode, Decodable, DecodeError}; +use ssz::{ssz_encode, Decode, DecodeError}; use tree_hash::tree_hash_ssz_encoding_as_vector; /// A single BLS signature. diff --git a/eth2/utils/bls/src/macros.rs b/eth2/utils/bls/src/macros.rs index b5c9f8e33..af2cde190 100644 --- a/eth2/utils/bls/src/macros.rs +++ b/eth2/utils/bls/src/macros.rs @@ -1,6 +1,6 @@ macro_rules! impl_ssz { ($type: ident, $byte_size: expr, $item_str: expr) => { - impl ssz::Encodable for $type { + impl ssz::Encode for $type { fn is_ssz_fixed_len() -> bool { true } @@ -14,7 +14,7 @@ macro_rules! impl_ssz { } } - impl ssz::Decodable for $type { + impl ssz::Decode for $type { fn is_ssz_fixed_len() -> bool { true } @@ -25,7 +25,7 @@ macro_rules! impl_ssz { fn from_ssz_bytes(bytes: &[u8]) -> Result { let len = bytes.len(); - let expected = ::ssz_fixed_len(); + let expected = ::ssz_fixed_len(); if len != expected { Err(ssz::DecodeError::InvalidByteLength { len, expected }) diff --git a/eth2/utils/bls/src/public_key.rs b/eth2/utils/bls/src/public_key.rs index 565755b37..f72bb7646 100644 --- a/eth2/utils/bls/src/public_key.rs +++ b/eth2/utils/bls/src/public_key.rs @@ -4,7 +4,7 @@ use cached_tree_hash::cached_tree_hash_ssz_encoding_as_vector; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::{encode as hex_encode, HexVisitor}; -use ssz::{ssz_encode, Decodable, DecodeError}; +use ssz::{ssz_encode, Decode, DecodeError}; use std::default; use std::fmt; use std::hash::{Hash, Hasher}; diff --git a/eth2/utils/bls/src/secret_key.rs b/eth2/utils/bls/src/secret_key.rs index 39b4422a1..620780261 100644 --- a/eth2/utils/bls/src/secret_key.rs +++ b/eth2/utils/bls/src/secret_key.rs @@ -4,7 +4,7 @@ use hex::encode as hex_encode; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::HexVisitor; -use ssz::{ssz_encode, Decodable, DecodeError}; +use ssz::{ssz_encode, Decode, DecodeError}; use tree_hash::tree_hash_ssz_encoding_as_vector; /// A single BLS signature. diff --git a/eth2/utils/bls/src/signature.rs b/eth2/utils/bls/src/signature.rs index e8dd80e7f..5ad159828 100644 --- a/eth2/utils/bls/src/signature.rs +++ b/eth2/utils/bls/src/signature.rs @@ -5,7 +5,7 @@ use hex::encode as hex_encode; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::HexVisitor; -use ssz::{ssz_encode, Decodable, DecodeError}; +use ssz::{ssz_encode, Decode, DecodeError}; use tree_hash::tree_hash_ssz_encoding_as_vector; /// A single BLS signature. diff --git a/eth2/utils/boolean-bitfield/src/lib.rs b/eth2/utils/boolean-bitfield/src/lib.rs index 98ba61550..08e56e7c3 100644 --- a/eth2/utils/boolean-bitfield/src/lib.rs +++ b/eth2/utils/boolean-bitfield/src/lib.rs @@ -7,7 +7,7 @@ use cached_tree_hash::cached_tree_hash_bytes_as_list; use serde::de::{Deserialize, Deserializer}; use serde::ser::{Serialize, Serializer}; use serde_hex::{encode, PrefixedHexVisitor}; -use ssz::{Decodable, Encodable}; +use ssz::{Decode, Encode}; use std::cmp; use std::default; @@ -194,7 +194,7 @@ impl std::ops::BitOr for BooleanBitfield { } } -impl Encodable for BooleanBitfield { +impl Encode for BooleanBitfield { fn is_ssz_fixed_len() -> bool { false } @@ -204,7 +204,7 @@ impl Encodable for BooleanBitfield { } } -impl Decodable for BooleanBitfield { +impl Decode for BooleanBitfield { fn is_ssz_fixed_len() -> bool { false } diff --git a/eth2/utils/fixed_len_vec/src/impls.rs b/eth2/utils/fixed_len_vec/src/impls.rs index b27faa42d..c9d01b9b2 100644 --- a/eth2/utils/fixed_len_vec/src/impls.rs +++ b/eth2/utils/fixed_len_vec/src/impls.rs @@ -1,6 +1,6 @@ use super::*; // use cached_tree_hash::CachedTreeHash; -// use ssz::{Decodable, Encodable}; +// use ssz::{Decode, Encode}; // use tree_hash::TreeHash; impl tree_hash::TreeHash for FixedLenVec @@ -51,16 +51,16 @@ where } } -impl ssz::Encodable for FixedLenVec +impl ssz::Encode for FixedLenVec where - T: ssz::Encodable, + T: ssz::Encode, { fn is_ssz_fixed_len() -> bool { true } fn ssz_fixed_len() -> usize { - if ::is_ssz_fixed_len() { + if ::is_ssz_fixed_len() { T::ssz_fixed_len() * N::to_usize() } else { ssz::BYTES_PER_LENGTH_OFFSET @@ -86,16 +86,16 @@ where } } -impl ssz::Decodable for FixedLenVec +impl ssz::Decode for FixedLenVec where - T: ssz::Decodable + Default, + T: ssz::Decode + Default, { fn is_ssz_fixed_len() -> bool { T::is_ssz_fixed_len() } fn ssz_fixed_len() -> usize { - if ::is_ssz_fixed_len() { + if ::is_ssz_fixed_len() { T::ssz_fixed_len() * N::to_usize() } else { ssz::BYTES_PER_LENGTH_OFFSET @@ -127,10 +127,10 @@ mod ssz_tests { fn encode() { let vec: FixedLenVec = vec![0; 2].into(); assert_eq!(vec.as_ssz_bytes(), vec![0, 0, 0, 0]); - assert_eq!( as Encodable>::ssz_fixed_len(), 4); + assert_eq!( as Encode>::ssz_fixed_len(), 4); } - fn round_trip(item: T) { + fn round_trip(item: T) { let encoded = &item.as_ssz_bytes(); assert_eq!(T::from_ssz_bytes(&encoded), Ok(item)); } diff --git a/eth2/utils/ssz/README.md b/eth2/utils/ssz/README.md index 30d8ded72..0a9bbff25 100644 --- a/eth2/utils/ssz/README.md +++ b/eth2/utils/ssz/README.md @@ -38,8 +38,8 @@ spec is decided.*\ + [bytes v0.4.9](#bytes-v049) + [ethereum-types](#ethereum-types) * [Interface](#interface) - + [Encodable](#encodable) - + [Decodable](#decodable) + + [Encode](#encodable) + + [Decode](#decodable) + [SszStream](#sszstream) - [new()](#new) - [append(&mut self, value: &E) -> &mut Self](#appendmut-self-value-e---mut-self) @@ -299,24 +299,24 @@ Github: [ https://github.com/paritytech/primitives ](https://github.com/parityte ## Interface -### Encodable +### Encode -A type is **Encodable** if it has a valid ``ssz_append`` function. This is +A type is **Encode** if it has a valid ``ssz_append`` function. This is used to ensure that the object/type can be serialized. ```rust -pub trait Encodable { +pub trait Encode { fn ssz_append(&self, s: &mut SszStream); } ``` -### Decodable +### Decode -A type is **Decodable** if it has a valid ``ssz_decode`` function. This is +A type is **Decode** if it has a valid ``ssz_decode`` function. This is used to ensure the object is deserializable. ```rust -pub trait Decodable: Sized { +pub trait Decode: Sized { fn ssz_decode(bytes: &[u8], index: usize) -> Result<(Self, usize), DecodeError>; } ``` @@ -342,7 +342,7 @@ Appends a value that can be encoded into the stream. | Parameter | Description | |:---------:|:-----------------------------------------| -| ``value`` | Encodable value to append to the stream. | +| ``value`` | Encode value to append to the stream. | **Example** @@ -371,7 +371,7 @@ Appends some vector (list) of encodable values to the stream. | Parameter | Description | |:---------:|:----------------------------------------------| -| ``vec`` | Vector of Encodable objects to be serialized. | +| ``vec`` | Vector of Encode objects to be serialized. | **Example** diff --git a/eth2/utils/ssz/benches/benches.rs b/eth2/utils/ssz/benches/benches.rs index f774f1ce5..4604b0cd8 100644 --- a/eth2/utils/ssz/benches/benches.rs +++ b/eth2/utils/ssz/benches/benches.rs @@ -3,7 +3,7 @@ extern crate criterion; use criterion::black_box; use criterion::{Benchmark, Criterion}; -use ssz::{Decodable, Encodable}; +use ssz::{Decode, Encode}; use ssz_derive::{Decode, Encode}; #[derive(Clone, Copy, Encode, Decode)] diff --git a/eth2/utils/ssz/examples/large_list.rs b/eth2/utils/ssz/examples/large_list.rs index d6cba8240..618603604 100644 --- a/eth2/utils/ssz/examples/large_list.rs +++ b/eth2/utils/ssz/examples/large_list.rs @@ -2,7 +2,7 @@ //! //! Useful for `cargo flamegraph`. -use ssz::{Decodable, Encodable}; +use ssz::{Decode, Encode}; fn main() { let vec: Vec = vec![4242; 8196]; diff --git a/eth2/utils/ssz/examples/large_list_of_structs.rs b/eth2/utils/ssz/examples/large_list_of_structs.rs index 52e4f0e55..2924541ea 100644 --- a/eth2/utils/ssz/examples/large_list_of_structs.rs +++ b/eth2/utils/ssz/examples/large_list_of_structs.rs @@ -2,7 +2,7 @@ //! //! Useful for `cargo flamegraph`. -use ssz::{Decodable, Encodable}; +use ssz::{Decode, Encode}; use ssz_derive::{Decode, Encode}; #[derive(Clone, Copy, Encode, Decode)] diff --git a/eth2/utils/ssz/examples/struct_definition.rs b/eth2/utils/ssz/examples/struct_definition.rs index 835a87e36..fa3ed2a64 100644 --- a/eth2/utils/ssz/examples/struct_definition.rs +++ b/eth2/utils/ssz/examples/struct_definition.rs @@ -1,4 +1,4 @@ -use ssz::{Decodable, DecodeError, Encodable, SszDecoderBuilder, SszEncoder}; +use ssz::{Decode, DecodeError, Encode, SszDecoderBuilder, SszEncoder}; #[derive(Debug, PartialEq)] pub struct Foo { @@ -7,15 +7,15 @@ pub struct Foo { c: u16, } -impl Encodable for Foo { +impl Encode for Foo { fn is_ssz_fixed_len() -> bool { - ::is_ssz_fixed_len() && as Encodable>::is_ssz_fixed_len() + ::is_ssz_fixed_len() && as Encode>::is_ssz_fixed_len() } fn ssz_append(&self, buf: &mut Vec) { - let offset = ::ssz_fixed_len() - + as Encodable>::ssz_fixed_len() - + ::ssz_fixed_len(); + let offset = ::ssz_fixed_len() + + as Encode>::ssz_fixed_len() + + ::ssz_fixed_len(); let mut encoder = SszEncoder::container(buf, offset); @@ -27,9 +27,9 @@ impl Encodable for Foo { } } -impl Decodable for Foo { +impl Decode for Foo { fn is_ssz_fixed_len() -> bool { - ::is_ssz_fixed_len() && as Decodable>::is_ssz_fixed_len() + ::is_ssz_fixed_len() && as Decode>::is_ssz_fixed_len() } fn from_ssz_bytes(bytes: &[u8]) -> Result { diff --git a/eth2/utils/ssz/src/decode.rs b/eth2/utils/ssz/src/decode.rs index f2f95936d..891104733 100644 --- a/eth2/utils/ssz/src/decode.rs +++ b/eth2/utils/ssz/src/decode.rs @@ -26,7 +26,7 @@ pub enum DecodeError { /// /// See `examples/` for manual implementations or the crate root for implementations using /// `#[derive(Decode)]`. -pub trait Decodable: Sized { +pub trait Decode: Sized { /// Returns `true` if this object has a fixed-length. /// /// I.e., there are no variable length items in this object or any of it's contained objects. @@ -80,7 +80,7 @@ impl<'a> SszDecoderBuilder<'a> { } /// Declares that some type `T` is the next item in `bytes`. - pub fn register_type(&mut self) -> Result<(), DecodeError> { + pub fn register_type(&mut self) -> Result<(), DecodeError> { if T::is_ssz_fixed_len() { let start = self.items_index; self.items_index += T::ssz_fixed_len(); @@ -173,7 +173,7 @@ impl<'a> SszDecoderBuilder<'a> { /// /// ```rust /// use ssz_derive::{Encode, Decode}; -/// use ssz::{Decodable, Encodable, SszDecoder, SszDecoderBuilder}; +/// use ssz::{Decode, Encode, SszDecoder, SszDecoderBuilder}; /// /// #[derive(PartialEq, Debug, Encode, Decode)] /// struct Foo { @@ -215,7 +215,7 @@ impl<'a> SszDecoder<'a> { /// # Panics /// /// Panics when attempting to decode more items than actually exist. - pub fn decode_next(&mut self) -> Result { + pub fn decode_next(&mut self) -> Result { T::from_ssz_bytes(self.items.remove(0)) } } diff --git a/eth2/utils/ssz/src/decode/impls.rs b/eth2/utils/ssz/src/decode/impls.rs index b41c26bbf..8a5a36780 100644 --- a/eth2/utils/ssz/src/decode/impls.rs +++ b/eth2/utils/ssz/src/decode/impls.rs @@ -3,7 +3,7 @@ use ethereum_types::H256; macro_rules! impl_decodable_for_uint { ($type: ident, $bit_size: expr) => { - impl Decodable for $type { + impl Decode for $type { fn is_ssz_fixed_len() -> bool { true } @@ -14,7 +14,7 @@ macro_rules! impl_decodable_for_uint { fn from_ssz_bytes(bytes: &[u8]) -> Result { let len = bytes.len(); - let expected = ::ssz_fixed_len(); + let expected = ::ssz_fixed_len(); if len != expected { Err(DecodeError::InvalidByteLength { len, expected }) @@ -35,7 +35,7 @@ impl_decodable_for_uint!(u32, 32); impl_decodable_for_uint!(u64, 64); impl_decodable_for_uint!(usize, 64); -impl Decodable for bool { +impl Decode for bool { fn is_ssz_fixed_len() -> bool { true } @@ -46,7 +46,7 @@ impl Decodable for bool { fn from_ssz_bytes(bytes: &[u8]) -> Result { let len = bytes.len(); - let expected = ::ssz_fixed_len(); + let expected = ::ssz_fixed_len(); if len != expected { Err(DecodeError::InvalidByteLength { len, expected }) @@ -64,7 +64,7 @@ impl Decodable for bool { } } -impl Decodable for H256 { +impl Decode for H256 { fn is_ssz_fixed_len() -> bool { true } @@ -75,7 +75,7 @@ impl Decodable for H256 { fn from_ssz_bytes(bytes: &[u8]) -> Result { let len = bytes.len(); - let expected = ::ssz_fixed_len(); + let expected = ::ssz_fixed_len(); if len != expected { Err(DecodeError::InvalidByteLength { len, expected }) @@ -87,7 +87,7 @@ impl Decodable for H256 { macro_rules! impl_decodable_for_u8_array { ($len: expr) => { - impl Decodable for [u8; $len] { + impl Decode for [u8; $len] { fn is_ssz_fixed_len() -> bool { true } @@ -98,7 +98,7 @@ macro_rules! impl_decodable_for_u8_array { fn from_ssz_bytes(bytes: &[u8]) -> Result { let len = bytes.len(); - let expected = ::ssz_fixed_len(); + let expected = ::ssz_fixed_len(); if len != expected { Err(DecodeError::InvalidByteLength { len, expected }) @@ -115,7 +115,7 @@ macro_rules! impl_decodable_for_u8_array { impl_decodable_for_u8_array!(4); -impl Decodable for Vec { +impl Decode for Vec { fn is_ssz_fixed_len() -> bool { false } @@ -139,7 +139,7 @@ impl Decodable for Vec { /// The `ssz::SszDecoder` can also perform this functionality, however it it significantly faster /// as it is optimized to read same-typed items whilst `ssz::SszDecoder` supports reading items of /// differing types. -pub fn decode_list_of_variable_length_items( +pub fn decode_list_of_variable_length_items( bytes: &[u8], ) -> Result, DecodeError> { let mut next_variable_byte = read_offset(bytes)?; diff --git a/eth2/utils/ssz/src/encode.rs b/eth2/utils/ssz/src/encode.rs index afcf209b9..257ece2a2 100644 --- a/eth2/utils/ssz/src/encode.rs +++ b/eth2/utils/ssz/src/encode.rs @@ -6,7 +6,7 @@ mod impls; /// /// See `examples/` for manual implementations or the crate root for implementations using /// `#[derive(Encode)]`. -pub trait Encodable { +pub trait Encode { /// Returns `true` if this object has a fixed-length. /// /// I.e., there are no variable length items in this object or any of it's contained objects. @@ -50,7 +50,7 @@ pub trait Encodable { /// /// ```rust /// use ssz_derive::{Encode, Decode}; -/// use ssz::{Decodable, Encodable, SszEncoder}; +/// use ssz::{Decode, Encode, SszEncoder}; /// /// #[derive(PartialEq, Debug, Encode, Decode)] /// struct Foo { @@ -65,7 +65,7 @@ pub trait Encodable { /// }; /// /// let mut buf: Vec = vec![]; -/// let offset = ::ssz_fixed_len() + as Encodable>::ssz_fixed_len(); +/// let offset = ::ssz_fixed_len() + as Encode>::ssz_fixed_len(); /// /// let mut encoder = SszEncoder::container(&mut buf, offset); /// @@ -104,7 +104,7 @@ impl<'a> SszEncoder<'a> { } /// Append some `item` to the SSZ bytes. - pub fn append(&mut self, item: &T) { + pub fn append(&mut self, item: &T) { if T::is_ssz_fixed_len() { item.ssz_append(&mut self.buf); } else { diff --git a/eth2/utils/ssz/src/encode/impls.rs b/eth2/utils/ssz/src/encode/impls.rs index f9cb9fdcf..07886d68f 100644 --- a/eth2/utils/ssz/src/encode/impls.rs +++ b/eth2/utils/ssz/src/encode/impls.rs @@ -3,7 +3,7 @@ use ethereum_types::H256; macro_rules! impl_encodable_for_uint { ($type: ident, $bit_size: expr) => { - impl Encodable for $type { + impl Encode for $type { fn is_ssz_fixed_len() -> bool { true } @@ -25,7 +25,7 @@ impl_encodable_for_uint!(u32, 32); impl_encodable_for_uint!(u64, 64); impl_encodable_for_uint!(usize, 64); -impl Encodable for Vec { +impl Encode for Vec { fn is_ssz_fixed_len() -> bool { false } @@ -49,7 +49,7 @@ impl Encodable for Vec { } } -impl Encodable for bool { +impl Encode for bool { fn is_ssz_fixed_len() -> bool { true } @@ -63,7 +63,7 @@ impl Encodable for bool { } } -impl Encodable for H256 { +impl Encode for H256 { fn is_ssz_fixed_len() -> bool { true } @@ -79,7 +79,7 @@ impl Encodable for H256 { macro_rules! impl_encodable_for_u8_array { ($len: expr) => { - impl Encodable for [u8; $len] { + impl Encode for [u8; $len] { fn is_ssz_fixed_len() -> bool { true } diff --git a/eth2/utils/ssz/src/lib.rs b/eth2/utils/ssz/src/lib.rs index b0c8f3b4d..fceebcc44 100644 --- a/eth2/utils/ssz/src/lib.rs +++ b/eth2/utils/ssz/src/lib.rs @@ -9,7 +9,7 @@ //! //! ```rust //! use ssz_derive::{Encode, Decode}; -//! use ssz::{Decodable, Encodable}; +//! use ssz::{Decode, Encode}; //! //! #[derive(PartialEq, Debug, Encode, Decode)] //! struct Foo { @@ -32,17 +32,16 @@ //! //! ``` //! -//! See `examples/` for manual implementations of the `Encodable` and `Decodable` traits. +//! See `examples/` for manual implementations of the `Encode` and `Decode` traits. mod decode; mod encode; mod macros; pub use decode::{ - impls::decode_list_of_variable_length_items, Decodable, DecodeError, SszDecoder, - SszDecoderBuilder, + impls::decode_list_of_variable_length_items, Decode, DecodeError, SszDecoder, SszDecoderBuilder, }; -pub use encode::{Encodable, SszEncoder}; +pub use encode::{Encode, SszEncoder}; /// The number of bytes used to represent an offset. pub const BYTES_PER_LENGTH_OFFSET: usize = 4; @@ -54,7 +53,7 @@ pub const MAX_LENGTH_VALUE: usize = (1 << (BYTES_PER_LENGTH_OFFSET * 8)) - 1; /// Equivalent to `val.as_ssz_bytes()`. pub fn ssz_encode(val: &T) -> Vec where - T: Encodable, + T: Encode, { val.as_ssz_bytes() } diff --git a/eth2/utils/ssz/src/macros.rs b/eth2/utils/ssz/src/macros.rs index 48077674c..ed50ffd04 100644 --- a/eth2/utils/ssz/src/macros.rs +++ b/eth2/utils/ssz/src/macros.rs @@ -1,18 +1,18 @@ -/// Implements `Encodable` for `$impl_type` using an implementation of `From<$impl_type> for +/// Implements `Encode` for `$impl_type` using an implementation of `From<$impl_type> for /// $from_type`. /// -/// In effect, this allows for easy implementation of `Encodable` for some type that implements a -/// `From` conversion into another type that already has `Encodable` implemented. +/// In effect, this allows for easy implementation of `Encode` for some type that implements a +/// `From` conversion into another type that already has `Encode` implemented. #[macro_export] macro_rules! impl_encode_via_from { ($impl_type: ty, $from_type: ty) => { - impl ssz::Encodable for $impl_type { + impl ssz::Encode for $impl_type { fn is_ssz_fixed_len() -> bool { - <$from_type as ssz::Encodable>::is_ssz_fixed_len() + <$from_type as ssz::Encode>::is_ssz_fixed_len() } fn ssz_fixed_len() -> usize { - <$from_type as ssz::Encodable>::ssz_fixed_len() + <$from_type as ssz::Encode>::ssz_fixed_len() } fn ssz_append(&self, buf: &mut Vec) { @@ -24,21 +24,21 @@ macro_rules! impl_encode_via_from { }; } -/// Implements `Decodable` for `$impl_type` using an implementation of `From<$impl_type> for +/// Implements `Decode` for `$impl_type` using an implementation of `From<$impl_type> for /// $from_type`. /// -/// In effect, this allows for easy implementation of `Decodable` for some type that implements a -/// `From` conversion into another type that already has `Decodable` implemented. +/// In effect, this allows for easy implementation of `Decode` for some type that implements a +/// `From` conversion into another type that already has `Decode` implemented. #[macro_export] macro_rules! impl_decode_via_from { ($impl_type: ty, $from_type: tt) => { - impl ssz::Decodable for $impl_type { + impl ssz::Decode for $impl_type { fn is_ssz_fixed_len() -> bool { - <$from_type as ssz::Decodable>::is_ssz_fixed_len() + <$from_type as ssz::Decode>::is_ssz_fixed_len() } fn ssz_fixed_len() -> usize { - <$from_type as ssz::Decodable>::ssz_fixed_len() + <$from_type as ssz::Decode>::ssz_fixed_len() } fn from_ssz_bytes(bytes: &[u8]) -> Result { @@ -51,7 +51,7 @@ macro_rules! impl_decode_via_from { #[cfg(test)] mod tests { use crate as ssz; - use ssz::{Decodable, Encodable}; + use ssz::{Decode, Encode}; #[derive(PartialEq, Debug, Clone, Copy)] struct Wrapper(u64); diff --git a/eth2/utils/ssz/tests/tests.rs b/eth2/utils/ssz/tests/tests.rs index 94632203b..ed318d924 100644 --- a/eth2/utils/ssz/tests/tests.rs +++ b/eth2/utils/ssz/tests/tests.rs @@ -1,11 +1,11 @@ use ethereum_types::H256; -use ssz::{Decodable, DecodeError, Encodable}; +use ssz::{Decode, DecodeError, Encode}; use ssz_derive::{Decode, Encode}; mod round_trip { use super::*; - fn round_trip(items: Vec) { + fn round_trip(items: Vec) { for item in items { let encoded = &item.as_ssz_bytes(); assert_eq!(T::from_ssz_bytes(&encoded), Ok(item)); diff --git a/eth2/utils/ssz_derive/src/lib.rs b/eth2/utils/ssz_derive/src/lib.rs index 0e3e2de80..25cce2c3c 100644 --- a/eth2/utils/ssz_derive/src/lib.rs +++ b/eth2/utils/ssz_derive/src/lib.rs @@ -64,7 +64,7 @@ fn should_skip_serializing(field: &syn::Field) -> bool { false } -/// Implements `ssz::Encodable` for some `struct`. +/// Implements `ssz::Encode` for some `struct`. /// /// Fields are encoded in the order they are defined. #[proc_macro_derive(Encode, attributes(ssz))] @@ -85,18 +85,18 @@ pub fn ssz_encode_derive(input: TokenStream) -> TokenStream { let field_types_c = field_types_a.clone(); let output = quote! { - impl #impl_generics ssz::Encodable for #name #ty_generics #where_clause { + impl #impl_generics ssz::Encode for #name #ty_generics #where_clause { fn is_ssz_fixed_len() -> bool { #( - <#field_types_a as ssz::Encodable>::is_ssz_fixed_len() && + <#field_types_a as ssz::Encode>::is_ssz_fixed_len() && )* true } fn ssz_fixed_len() -> usize { - if ::is_ssz_fixed_len() { + if ::is_ssz_fixed_len() { #( - <#field_types_b as ssz::Encodable>::ssz_fixed_len() + + <#field_types_b as ssz::Encode>::ssz_fixed_len() + )* 0 } else { @@ -106,7 +106,7 @@ pub fn ssz_encode_derive(input: TokenStream) -> TokenStream { fn ssz_append(&self, buf: &mut Vec) { let offset = #( - <#field_types_c as ssz::Encodable>::ssz_fixed_len() + + <#field_types_c as ssz::Encode>::ssz_fixed_len() + )* 0; @@ -135,7 +135,7 @@ fn should_skip_deserializing(field: &syn::Field) -> bool { false } -/// Implements `ssz::Decodable` for some `struct`. +/// Implements `ssz::Decode` for some `struct`. /// /// Fields are decoded in the order they are defined. #[proc_macro_derive(Decode)] @@ -177,11 +177,11 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { }); is_fixed_lens.push(quote! { - <#ty as ssz::Decodable>::is_ssz_fixed_len() + <#ty as ssz::Decode>::is_ssz_fixed_len() }); fixed_lens.push(quote! { - <#ty as ssz::Decodable>::ssz_fixed_len() + <#ty as ssz::Decode>::ssz_fixed_len() }); } } @@ -190,7 +190,7 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { } let output = quote! { - impl #impl_generics ssz::Decodable for #name #ty_generics #where_clause { + impl #impl_generics ssz::Decode for #name #ty_generics #where_clause { fn is_ssz_fixed_len() -> bool { #( #is_fixed_lens && @@ -199,7 +199,7 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { } fn ssz_fixed_len() -> usize { - if ::is_ssz_fixed_len() { + if ::is_ssz_fixed_len() { #( #fixed_lens + )* diff --git a/eth2/utils/ssz_derive/tests/tests.rs b/eth2/utils/ssz_derive/tests/tests.rs index 53cafcd4b..d58db3b62 100644 --- a/eth2/utils/ssz_derive/tests/tests.rs +++ b/eth2/utils/ssz_derive/tests/tests.rs @@ -1,4 +1,4 @@ -use ssz::Encodable; +use ssz::Encode; use ssz_derive::Encode; #[derive(Debug, PartialEq, Encode)] diff --git a/validator_client/src/attestation_producer/grpc.rs b/validator_client/src/attestation_producer/grpc.rs index 6249db3e1..9ac0a433f 100644 --- a/validator_client/src/attestation_producer/grpc.rs +++ b/validator_client/src/attestation_producer/grpc.rs @@ -1,7 +1,7 @@ use super::beacon_node_attestation::BeaconNodeAttestation; use crate::block_producer::{BeaconNodeError, PublishOutcome}; use protos::services_grpc::AttestationServiceClient; -use ssz::{Decodable, Encodable}; +use ssz::{Decode, Encode}; use protos::services::{ Attestation as GrpcAttestation, ProduceAttestationDataRequest, PublishAttestationRequest, diff --git a/validator_client/src/block_producer/grpc.rs b/validator_client/src/block_producer/grpc.rs index 6ce7ae09d..820fbdb66 100644 --- a/validator_client/src/block_producer/grpc.rs +++ b/validator_client/src/block_producer/grpc.rs @@ -3,7 +3,7 @@ use protos::services::{ BeaconBlock as GrpcBeaconBlock, ProduceBeaconBlockRequest, PublishBeaconBlockRequest, }; use protos::services_grpc::BeaconBlockServiceClient; -use ssz::{Decodable, Encodable}; +use ssz::{Decode, Encode}; use std::sync::Arc; use types::{BeaconBlock, Signature, Slot};