-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from AurevoirXavier/develop
Patch for #145
- Loading branch information
Showing
14 changed files
with
773 additions
and
199 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "ethash" | ||
description = "An Apache-licensed Ethash implementation." | ||
version = "0.4.0" | ||
authors = ["Wei Tang <[email protected]>"] | ||
license = "Apache-2.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
byteorder = { version = "1", default-features = false } | ||
rlp = { version = "0.4", default-features = false } | ||
sha3 = { version = "0.8", default-features = false } | ||
|
||
ethereum-types = { git = "https://github.com/darwinia-network/parity-common.git", default-features = false } | ||
primitive-types = { git = "https://github.com/darwinia-network/parity-common.git", default-features = false, features = ["rlp"] } | ||
|
||
[dev-dependencies] | ||
hex-literal = "0.2.1" | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"byteorder/std", | ||
"rlp/std", | ||
"sha3/std", | ||
|
||
"ethereum-types/std", | ||
"primitive-types/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use alloc::vec::Vec; | ||
use core::marker::PhantomData; | ||
use ethereum_types::{H256, H64, U256}; | ||
|
||
pub trait Patch { | ||
fn epoch_length() -> U256; | ||
} | ||
|
||
pub struct EthereumPatch; | ||
impl Patch for EthereumPatch { | ||
fn epoch_length() -> U256 { | ||
U256::from(30000) | ||
} | ||
} | ||
|
||
pub struct LightDAG<P: Patch> { | ||
epoch: usize, | ||
cache: Vec<u8>, | ||
#[allow(dead_code)] | ||
cache_size: usize, | ||
full_size: usize, | ||
_marker: PhantomData<P>, | ||
} | ||
|
||
impl<P: Patch> LightDAG<P> { | ||
pub fn new(number: U256) -> Self { | ||
let epoch = (number / P::epoch_length()).as_usize(); | ||
let cache_size = crate::get_cache_size(epoch); | ||
let full_size = crate::get_full_size(epoch); | ||
let seed = crate::get_seedhash(epoch); | ||
|
||
let mut cache: Vec<u8> = Vec::with_capacity(cache_size); | ||
cache.resize(cache_size, 0); | ||
crate::make_cache(&mut cache, seed); | ||
|
||
Self { | ||
cache, | ||
cache_size, | ||
full_size, | ||
epoch, | ||
_marker: PhantomData, | ||
} | ||
} | ||
|
||
pub fn hashimoto(&self, hash: H256, nonce: H64) -> (H256, H256) { | ||
crate::hashimoto_light(hash, nonce, self.full_size, &self.cache) | ||
} | ||
|
||
pub fn is_valid_for(&self, number: U256) -> bool { | ||
(number / P::epoch_length()).as_usize() == self.epoch | ||
} | ||
} |
Oops, something went wrong.