Skip to content

Commit

Permalink
added code to check the validation status of a block header before st…
Browse files Browse the repository at this point in the history
…aking on it;

resetting bestnode if it has been waiting for validation more than 15 seconds
  • Loading branch information
Bill White committed Aug 7, 2016
1 parent 42d57e9 commit 7b4b24a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/blocktree.mli
Expand Up @@ -30,9 +30,11 @@ val node_targetinfo : blocktree -> targetinfo
val node_timestamp : blocktree -> int64
val node_cumulstk : blocktree -> big_int
val node_blockheight : blocktree -> int64
val node_validationstatus : blocktree -> validationstatus
val node_children_ref : blocktree -> (hashval * blocktree) list ref
val eq_node : blocktree -> blocktree -> bool
val find_best_validated_block_from : blocktree -> big_int -> big_int
val find_best_validated_block : unit -> unit
val is_recent_staker : hashval -> blocktree -> int -> bool
val record_recent_staker : hashval -> blocktree -> int -> unit
val add_to_headers_file : string -> unit
Expand Down
18 changes: 13 additions & 5 deletions src/qeditas.ml
Expand Up @@ -233,6 +233,13 @@ let stakingthread () =
let sleeplen = !sleepuntil -. (Unix.time()) in
if sleeplen > 1.0 then Unix.sleep (int_of_float sleeplen);
let best = !bestnode in
begin
match node_validationstatus best with
| InvalidBlock -> find_best_validated_block()
| Waiting(tm) ->
if tm +. 15.0 < Unix.time() then find_best_validated_block()
| _ -> ()
end;
try
let pbhh = node_prevblockhash best in
let blkh = node_blockheight best in
Expand Down Expand Up @@ -477,11 +484,12 @@ let stakingthread () =
children_ref := (bhdnewh,newnode)::!children_ref;
(*** missing: code to broadcast to peers ***)
in
if pbhh = node_prevblockhash !bestnode then (*** if the bestnode has changed, don't publish it unless the cumulative stake is higher ***)
publish_new_block()
else if csnew > node_cumulstk !bestnode then
(Printf.fprintf !log "best != bestnode, but this block better cs\n"; flush stdout;
publish_new_block())
if node_validationstatus !bestnode = ValidBlock then (*** Don't publish a successor unless the previous block has been fully validated ***)
if pbhh = node_prevblockhash !bestnode then (*** if the bestnode has changed, don't publish it unless the cumulative stake is higher ***)
publish_new_block()
else if csnew > node_cumulstk !bestnode then
(Printf.fprintf !log "best != bestnode, but this block better cs\n"; flush stdout;
publish_new_block())
end
| NoStakeUpTo(tm) ->
let ftm = Int64.add (Int64.of_float (Unix.time())) 36000L in (* reduce to 3600 *)
Expand Down

0 comments on commit 7b4b24a

Please sign in to comment.