File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -126,8 +126,7 @@ impl ConsensusEngine<CodeChainMachine> for Cuckoo {
126126 if !self . verifier . verify ( & message, & seal. proof ) {
127127 return Err ( From :: from ( BlockError :: InvalidProofOfWork ) )
128128 }
129- let max_hash = ( U256 :: max_value ( ) - * header. score ( ) ) / * header. score ( ) ;
130- if U256 :: from ( header. hash ( ) ) > max_hash {
129+ if U256 :: from ( header. hash ( ) ) > self . score_to_target ( header. score ( ) ) {
131130 return Err ( From :: from ( BlockError :: InvalidScore ( OutOfBounds {
132131 min : Some ( * header. score ( ) ) ,
133132 max : Some ( * header. score ( ) ) ,
@@ -167,4 +166,8 @@ impl ConsensusEngine<CodeChainMachine> for Cuckoo {
167166 let author = * block. header ( ) . author ( ) ;
168167 self . machine . add_balance ( block, & author, & self . params . block_reward )
169168 }
169+
170+ fn score_to_target ( & self , score : & U256 ) -> U256 {
171+ ( U256 :: max_value ( ) - * score) / * score
172+ }
170173}
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ use std::sync::{Arc, Weak};
3737
3838use ckey:: ECDSASignature ;
3939use cnetwork:: NetworkExtension ;
40- use ctypes:: { Address , Bytes , H256 } ;
40+ use ctypes:: { Address , Bytes , H256 , U256 } ;
4141use unexpected:: { Mismatch , OutOfBounds } ;
4242
4343use self :: epoch:: { EpochVerifier , NoOp , PendingTransition } ;
@@ -212,6 +212,10 @@ pub trait ConsensusEngine<M: Machine>: Sync + Send {
212212 fn network_extension ( & self ) -> Option < Arc < NetworkExtension > > {
213213 None
214214 }
215+
216+ fn score_to_target ( & self , _score : & U256 ) -> U256 {
217+ U256 :: zero ( )
218+ }
215219}
216220
217221/// Results of a query of whether an epoch change occurred at the given block.
You can’t perform that action at this time.
0 commit comments