diff --git a/srml/eth-relay/src/lib.rs b/srml/eth-relay/src/lib.rs index fb0c0300e..a1a13943b 100644 --- a/srml/eth-relay/src/lib.rs +++ b/srml/eth-relay/src/lib.rs @@ -87,7 +87,7 @@ decl_storage! { if let Some(h) = &config.header { let header: EthHeader = rlp::decode(&h).expect("can't deserialize the header"); - >::genesis_header(&header,config.genesis_difficulty); + >::init_genesis_header(&header,config.genesis_difficulty); // TODO: initilize other parameters. } @@ -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); >::deposit_event(RawEvent::NewHeader(header)); } @@ -157,7 +157,7 @@ decl_event! { impl Module { // 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(); @@ -214,10 +214,12 @@ impl Module { 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(); diff --git a/srml/eth-relay/src/tests.rs b/srml/eth-relay/src/tests.rs index e86b9c573..88a8c91a6 100644 --- a/srml/eth-relay/src/tests.rs +++ b/srml/eth-relay/src/tests.rs @@ -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)); }); @@ -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.");