Skip to content

Commit

Permalink
Try fix #145
Browse files Browse the repository at this point in the history
  • Loading branch information
hackfisher committed Dec 6, 2019
1 parent 914f3f5 commit 7eff857
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions srml/eth-relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ decl_storage! {
if let Some(h) = &config.header {
let header: EthHeader = rlp::decode(&h).expect("can't deserialize the header");

<Module<T>>::genesis_header(&header,config.genesis_difficulty);
<Module<T>>::init_genesis_header(&header,config.genesis_difficulty);

// TODO: initilize other parameters.
}
Expand All @@ -107,7 +107,7 @@ decl_module! {
// TODO: Check authority

// TODO: Just for easy testing.
Self::genesis_header(&header, genesis_difficulty);
Self::init_genesis_header(&header, genesis_difficulty);

<Module<T>>::deposit_event(RawEvent::NewHeader(header));
}
Expand Down Expand Up @@ -157,7 +157,7 @@ decl_event! {

impl<T: Trait> Module<T> {
// TOOD: what is the total difficulty for genesis/begin header
pub fn genesis_header(header: &EthHeader, genesis_difficulty: u64) {
pub fn init_genesis_header(header: &EthHeader, genesis_difficulty: u64) {
let header_hash = header.hash();
let block_number = header.number();

Expand Down Expand Up @@ -214,10 +214,12 @@ impl<T: Trait> Module<T> {
let parent_hash = header.parent_hash();

let number = header.number();
ensure!(
number >= Self::begin_header().unwrap().number(),
"block nubmer is too small."
);

if let Some(begin_header) = Self::begin_header() {
ensure!(number >= begin_header.number(), "block nubmer is too small.");
} else {
return Err("Begin header does not exits.");
}

let prev_header = Self::header_of(parent_hash).unwrap();

Expand Down
4 changes: 2 additions & 2 deletions srml/eth-relay/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn verify_receipt_proof() {
hash: Some(H256::from(hex!("f1a5bc27877e219b859b0bb1f2f440134553019f9bb5a2eca7a4703263e736c9"))),
};

EthRelay::genesis_header(&header, 0x624c22d93f8e59_u64);
EthRelay::init_genesis_header(&header, 0x624c22d93f8e59_u64);

assert_eq!(EthRelay::verify_receipt(&proof_record), Some(receipt));
});
Expand Down Expand Up @@ -131,7 +131,7 @@ fn relay_header() {
};


EthRelay::genesis_header(&header1, 0x624c22d93f8e59_u64);
EthRelay::init_genesis_header(&header1, 0x624c22d93f8e59_u64);

EthRelay::verify_header(&header2).expect("Verify Failed.");

Expand Down

0 comments on commit 7eff857

Please sign in to comment.