Proto/Alpha: use record for mining slot.

This commit is contained in:
Grégoire Henry 2017-04-02 16:07:19 +02:00
parent ef3180c561
commit 5449cbbfe6
8 changed files with 35 additions and 20 deletions

View File

@ -50,7 +50,7 @@ let block_forged ?prev ops =
| Ok nonce -> nonce in
Block_repr.forge_header (block ops)
Block_repr.{
mining_slot = Raw_level_repr.of_int32_exn 1l, 0l ;
mining_slot = {level = Raw_level_repr.of_int32_exn 1l ; priority = 0l } ;
seed_nonce_hash = Proto.Nonce_storage.hash (generate_seed_nonce ());
proof_of_work_nonce = generate_proof_of_work_nonce () ;
}

View File

@ -51,7 +51,8 @@ let inject_block cctxt block
let shell =
{ Store.Block_header.net_id = bi.net ; predecessor = bi.hash ;
timestamp ; fitness ; operations } in
let slot = level.level, Int32.of_int priority in
let slot =
{ Block.level = level.level ; priority = Int32.of_int priority } in
compute_stamp cctxt block
src_sk shell slot seed_nonce_hash >>=? fun proof_of_work_nonce ->
Client_proto_rpcs.Helpers.Forge.block cctxt

View File

@ -260,7 +260,7 @@ let apply_main ctxt accept_failing_script block pred_timestamp operations =
Mining.pay_mining_bond ctxt block delegate_pkh >>=? fun ctxt ->
(* do effectful stuff *)
Fitness.increase ctxt >>=? fun ctxt ->
let priority = snd block.proto.mining_slot in
let priority = block.proto.mining_slot.priority in
fold_left_s (fun ctxt operation ->
apply_operation
ctxt accept_failing_script
@ -269,9 +269,7 @@ let apply_main ctxt accept_failing_script block pred_timestamp operations =
>>=? fun (ctxt, _contracts) -> return ctxt)
ctxt operations >>=? fun ctxt ->
(* end of level (from this point nothing should fail) *)
let reward =
Mining.base_mining_reward ctxt
~priority:(snd block.proto.mining_slot) in
let reward = Mining.base_mining_reward ctxt ~priority in
Nonce.record_hash ctxt
delegate_pkh reward block.proto.seed_nonce_hash >>=? fun ctxt ->
Reward.pay_due_rewards ctxt >>=? fun ctxt ->

View File

@ -21,25 +21,35 @@ type header = {
and proto_header = {
mining_slot: mining_slot ;
seed_nonce_hash: Nonce_hash.t ;
proof_of_work_nonce: MBytes.t ;}
proof_of_work_nonce: MBytes.t ;
}
and mining_slot = Raw_level_repr.t * Int32.t
and mining_slot = {
level: Raw_level_repr.t ;
priority: Int32.t ;
}
let mining_slot_encoding =
let open Data_encoding in
tup2 Raw_level_repr.encoding int32
conv
(fun { level ; priority } -> level, priority)
(fun (level, priority) -> { level ; priority })
(obj2
(req "level" Raw_level_repr.encoding)
(req "proprity" int32))
let proto_header_encoding =
let open Data_encoding in
conv
(fun { mining_slot ; seed_nonce_hash ; proof_of_work_nonce } ->
(mining_slot, seed_nonce_hash, proof_of_work_nonce))
(fun (mining_slot, seed_nonce_hash, proof_of_work_nonce) ->
(mining_slot, (seed_nonce_hash, proof_of_work_nonce)))
(fun (mining_slot, (seed_nonce_hash, proof_of_work_nonce)) ->
{ mining_slot ; seed_nonce_hash ; proof_of_work_nonce })
(obj3
(req "slot" mining_slot_encoding)
(req "seed_nonce_hash" Nonce_hash.encoding)
(req "proof_of_work_nonce" (Fixed.bytes Constants_repr.proof_of_work_nonce_size)))
(merge_objs
mining_slot_encoding
(obj2
(req "seed_nonce_hash" Nonce_hash.encoding)
(req "proof_of_work_nonce" (Fixed.bytes Constants_repr.proof_of_work_nonce_size))))
let signed_proto_header_encoding =
let open Data_encoding in

View File

@ -22,7 +22,10 @@ and proto_header = {
proof_of_work_nonce: MBytes.t ;
}
and mining_slot = Raw_level_repr.t * Int32.t
and mining_slot = {
level: Raw_level_repr.t ;
priority: Int32.t ;
}
val mining_slot_encoding: mining_slot Data_encoding.encoding

View File

@ -133,7 +133,7 @@ let check_timestamp c priority pred_timestamp =
(Timestamp_too_early (minimal_time, timestamp))
let check_mining_rights c
{ Block.proto = { mining_slot = (raw_level, priority) } }
{ Block.proto = { mining_slot = { level = raw_level ; priority } } }
pred_timestamp =
Level.current c >>=? fun current_level ->
fail_unless
@ -145,7 +145,7 @@ let check_mining_rights c
return delegate
let pay_mining_bond c
{ Block.proto = { mining_slot = (_raw_level, priority) } }
{ Block.proto = { mining_slot = { priority} } }
id =
if Compare.Int32.(priority >= Constants.first_free_mining_slot c)
then return c

View File

@ -436,7 +436,7 @@ let forge_block _ctxt
(net_id, predecessor, timestamp, fitness, operations,
raw_level, priority, seed_nonce_hash, proof_of_work_nonce) : MBytes.t tzresult Lwt.t =
let priority = Int32.of_int priority in
let mining_slot = (raw_level, priority) in
let mining_slot = { Block.level = raw_level ; priority } in
return (Block.forge_header
{ net_id ; predecessor ; timestamp ; fitness ; operations }
{ mining_slot ; seed_nonce_hash ; proof_of_work_nonce })

View File

@ -530,7 +530,10 @@ module Block : sig
proof_of_work_nonce: MBytes.t ;
}
and mining_slot = Raw_level.t * Int32.t
and mining_slot = {
level: Raw_level.t ;
priority: Int32.t ;
}
val mining_slot_encoding: mining_slot Data_encoding.encoding