Finality votes cache (#116)

* removeInMemoryStorage + extract Kovan stuff to runtime

* removed comment from the future

* remove redundant conversions

* remove redundant `u8 as usize`

* remove redundant `u8 as usize`

* Update modules/ethereum/src/mock.rs

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>

* use hex-literal in kovan config

* cargo fmt --all

* extracted insert_header

* cargo fmt --all

* finality cache

* cargo fmt --all

* cargo fmt --all

* impl Default for FinalityVotes

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
Co-authored-by: Hernando Castano <castano.ha@gmail.com>
This commit is contained in:
Svyatoslav Nikolsky
2020-06-10 10:56:47 +03:00
committed by Bastian Köcher
parent ca8b370de2
commit 643075f7fa
8 changed files with 818 additions and 276 deletions
+20 -3
View File
@@ -49,6 +49,15 @@ pub type RawTransaction = Vec<u8>;
/// An ethereum address.
pub type Address = H160;
/// Complete header id.
#[derive(Encode, Decode, Default, RuntimeDebug, PartialEq, Clone, Copy)]
pub struct HeaderId {
/// Header number.
pub number: u64,
/// Header hash.
pub hash: H256,
}
/// An Aura header.
#[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Default, Serialize, Deserialize))]
@@ -156,8 +165,16 @@ pub struct SealedEmptyStep {
}
impl Header {
/// Get the hash of this header (keccak of the RLP with seal).
pub fn hash(&self) -> H256 {
/// Compute id of this header.
pub fn compute_id(&self) -> HeaderId {
HeaderId {
number: self.number,
hash: self.compute_hash(),
}
}
/// Compute hash of this header (keccak of the RLP with seal).
pub fn compute_hash(&self) -> H256 {
keccak_256(&self.rlp(true)).into()
}
@@ -175,7 +192,7 @@ impl Header {
pub fn seal_hash(&self, include_empty_steps: bool) -> Option<H256> {
Some(match include_empty_steps {
true => {
let mut message = self.hash().as_bytes().to_vec();
let mut message = self.compute_hash().as_bytes().to_vec();
message.extend_from_slice(self.seal.get(2)?);
keccak_256(&message).into()
}