Shell/Peer_metadata: change counters to aribtrary precision integers
This commit is contained in:
parent
9d34bd6f16
commit
0392284716
@ -23,8 +23,12 @@
|
|||||||
(* *)
|
(* *)
|
||||||
(*****************************************************************************)
|
(*****************************************************************************)
|
||||||
|
|
||||||
type counter = int
|
type counter = Z.t
|
||||||
let counter = Data_encoding.int31
|
let counter = Data_encoding.z
|
||||||
|
let ((+) : counter -> counter -> counter) = Z.add
|
||||||
|
|
||||||
|
let zero : counter = Z.zero
|
||||||
|
let one : counter = Z.one
|
||||||
|
|
||||||
(* Distributed DB peer metadata *)
|
(* Distributed DB peer metadata *)
|
||||||
type messages =
|
type messages =
|
||||||
@ -319,18 +323,18 @@ type t = {
|
|||||||
|
|
||||||
let empty () =
|
let empty () =
|
||||||
let empty_request () =
|
let empty_request () =
|
||||||
{ branch = 0 ; head = 0 ; block_header = 0 ;
|
{ branch = zero ; head = zero ; block_header = zero ;
|
||||||
operations = 0 ; protocols = 0 ;
|
operations = zero ; protocols = zero ;
|
||||||
operation_hashes_for_block = 0 ;
|
operation_hashes_for_block = zero ;
|
||||||
operations_for_block = 0 ;
|
operations_for_block = zero ;
|
||||||
other = 0 ;
|
other = zero ;
|
||||||
} in
|
} in
|
||||||
{
|
{
|
||||||
responses = { sent = empty_request () ;
|
responses = { sent = empty_request () ;
|
||||||
failed = empty_request () ;
|
failed = empty_request () ;
|
||||||
received = empty_request () ;
|
received = empty_request () ;
|
||||||
unexpected = 0 ;
|
unexpected = zero ;
|
||||||
outdated = 0 ;
|
outdated = zero ;
|
||||||
} ;
|
} ;
|
||||||
requests =
|
requests =
|
||||||
{ sent = empty_request () ;
|
{ sent = empty_request () ;
|
||||||
@ -338,20 +342,20 @@ let empty () =
|
|||||||
scheduled = empty_request () ;
|
scheduled = empty_request () ;
|
||||||
received = empty_request () ;
|
received = empty_request () ;
|
||||||
} ;
|
} ;
|
||||||
valid_blocks = 0 ;
|
valid_blocks = zero ;
|
||||||
old_heads = 0 ;
|
old_heads = zero ;
|
||||||
prevalidator_results =
|
prevalidator_results =
|
||||||
{ cannot_download = 0 ; cannot_parse = 0 ;
|
{ cannot_download = zero ; cannot_parse = zero ;
|
||||||
refused_by_prefilter = 0 ; refused_by_postfilter = 0 ;
|
refused_by_prefilter = zero ; refused_by_postfilter = zero ;
|
||||||
applied = 0 ; branch_delayed = 0 ; branch_refused = 0 ;
|
applied = zero ; branch_delayed = zero ; branch_refused = zero ;
|
||||||
refused = 0 ; duplicate = 0 ; outdated = 0
|
refused = zero ; duplicate = zero ; outdated = zero
|
||||||
} ;
|
} ;
|
||||||
unactivated_chains = 0 ;
|
unactivated_chains = zero ;
|
||||||
inactive_chains = 0 ;
|
inactive_chains = zero ;
|
||||||
future_blocks_advertised = 0 ;
|
future_blocks_advertised = zero ;
|
||||||
unadvertised = {block = 0 ; operations = 0 ; protocol = 0 } ;
|
unadvertised = {block = zero ; operations = zero ; protocol = zero } ;
|
||||||
advertisements = { sent = { head = 0 ; branch = 0 ; } ;
|
advertisements = { sent = { head = zero ; branch = zero ; } ;
|
||||||
received = { head = 0 ; branch = 0 ; } }
|
received = { head = zero ; branch = zero ; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -413,24 +417,24 @@ let encoding =
|
|||||||
|
|
||||||
let incr_requests (msgs : messages) (req : requests_kind) =
|
let incr_requests (msgs : messages) (req : requests_kind) =
|
||||||
match req with
|
match req with
|
||||||
| Branch -> msgs.branch <- msgs.branch + 1
|
| Branch -> msgs.branch <- msgs.branch + one
|
||||||
| Head -> msgs.head <- msgs.head + 1
|
| Head -> msgs.head <- msgs.head + one
|
||||||
| Block_header -> msgs.block_header <- msgs.block_header + 1
|
| Block_header -> msgs.block_header <- msgs.block_header + one
|
||||||
| Operations -> msgs.operations <- msgs.operations + 1
|
| Operations -> msgs.operations <- msgs.operations + one
|
||||||
| Protocols -> msgs.protocols <- msgs.protocols + 1
|
| Protocols -> msgs.protocols <- msgs.protocols + one
|
||||||
| Operation_hashes_for_block ->
|
| Operation_hashes_for_block ->
|
||||||
msgs.operation_hashes_for_block <- msgs.operation_hashes_for_block + 1
|
msgs.operation_hashes_for_block <- msgs.operation_hashes_for_block + one
|
||||||
| Operations_for_block ->
|
| Operations_for_block ->
|
||||||
msgs.operations_for_block <- msgs.operations_for_block + 1
|
msgs.operations_for_block <- msgs.operations_for_block + one
|
||||||
| Other ->
|
| Other ->
|
||||||
msgs.other <- msgs.other + 1
|
msgs.other <- msgs.other + one
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let incr_unadvertised { unadvertised = u ; _ } = function
|
let incr_unadvertised { unadvertised = u ; _ } = function
|
||||||
| Block -> u.block <- u.block + 1
|
| Block -> u.block <- u.block + one
|
||||||
| Operations -> u.operations <- u.operations + 1
|
| Operations -> u.operations <- u.operations + one
|
||||||
| Protocol -> u.protocol <- u.protocol + 1
|
| Protocol -> u.protocol <- u.protocol + one
|
||||||
|
|
||||||
|
|
||||||
let incr ({responses = rsps ; requests = rqst ; _ } as m) metadata =
|
let incr ({responses = rsps ; requests = rqst ; _ } as m) metadata =
|
||||||
@ -450,77 +454,77 @@ let incr ({responses = rsps ; requests = rqst ; _ } as m) metadata =
|
|||||||
| Sent_response req ->
|
| Sent_response req ->
|
||||||
incr_requests rsps.sent req
|
incr_requests rsps.sent req
|
||||||
| Unexpected_response ->
|
| Unexpected_response ->
|
||||||
rsps.unexpected <- rsps.unexpected + 1
|
rsps.unexpected <- rsps.unexpected + one
|
||||||
| Outdated_response ->
|
| Outdated_response ->
|
||||||
rsps.outdated <- rsps.outdated + 1
|
rsps.outdated <- rsps.outdated + one
|
||||||
(* Advertisements *)
|
(* Advertisements *)
|
||||||
| Sent_advertisement ad ->
|
| Sent_advertisement ad ->
|
||||||
begin match ad with
|
begin match ad with
|
||||||
| Head ->
|
| Head ->
|
||||||
m.advertisements.sent.head <- m.advertisements.sent.head + 1
|
m.advertisements.sent.head <- m.advertisements.sent.head + one
|
||||||
| Branch ->
|
| Branch ->
|
||||||
m.advertisements.sent.branch <- m.advertisements.sent.branch + 1
|
m.advertisements.sent.branch <- m.advertisements.sent.branch + one
|
||||||
end
|
end
|
||||||
| Received_advertisement ad ->
|
| Received_advertisement ad ->
|
||||||
begin match ad with
|
begin match ad with
|
||||||
| Head ->
|
| Head ->
|
||||||
m.advertisements.received.head <- m.advertisements.received.head + 1
|
m.advertisements.received.head <- m.advertisements.received.head + one
|
||||||
| Branch ->
|
| Branch ->
|
||||||
m.advertisements.received.branch <- m.advertisements.received.branch + 1
|
m.advertisements.received.branch <- m.advertisements.received.branch + one
|
||||||
end
|
end
|
||||||
(* Unexpected erroneous msg *)
|
(* Unexpected erroneous msg *)
|
||||||
| Unactivated_chain ->
|
| Unactivated_chain ->
|
||||||
m.unactivated_chains <- m.unactivated_chains + 1
|
m.unactivated_chains <- m.unactivated_chains + one
|
||||||
| Inactive_chain ->
|
| Inactive_chain ->
|
||||||
m.inactive_chains <- m.inactive_chains + 1
|
m.inactive_chains <- m.inactive_chains + one
|
||||||
| Future_block ->
|
| Future_block ->
|
||||||
m.future_blocks_advertised <- m.future_blocks_advertised + 1
|
m.future_blocks_advertised <- m.future_blocks_advertised + one
|
||||||
| Unadvertised u -> incr_unadvertised m u
|
| Unadvertised u -> incr_unadvertised m u
|
||||||
(* Peer validator *)
|
(* Peer validator *)
|
||||||
| Valid_blocks ->
|
| Valid_blocks ->
|
||||||
m.valid_blocks <- m.valid_blocks + 1
|
m.valid_blocks <- m.valid_blocks + one
|
||||||
| Old_heads ->
|
| Old_heads ->
|
||||||
m.old_heads <- m.old_heads + 1
|
m.old_heads <- m.old_heads + one
|
||||||
(* prevalidation *)
|
(* prevalidation *)
|
||||||
| Cannot_download ->
|
| Cannot_download ->
|
||||||
m.prevalidator_results <-
|
m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
cannot_download = m.prevalidator_results.cannot_download + 1 }
|
cannot_download = m.prevalidator_results.cannot_download + one }
|
||||||
| Cannot_parse -> m.prevalidator_results <-
|
| Cannot_parse -> m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
cannot_parse = m.prevalidator_results.cannot_parse + 1 }
|
cannot_parse = m.prevalidator_results.cannot_parse + one }
|
||||||
| Refused_by_prefilter -> m.prevalidator_results <-
|
| Refused_by_prefilter -> m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
refused_by_prefilter =
|
refused_by_prefilter =
|
||||||
m.prevalidator_results.refused_by_prefilter + 1 }
|
m.prevalidator_results.refused_by_prefilter + one }
|
||||||
| Refused_by_postfilter -> m.prevalidator_results <-
|
| Refused_by_postfilter -> m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
refused_by_postfilter =
|
refused_by_postfilter =
|
||||||
m.prevalidator_results.refused_by_postfilter + 1 }
|
m.prevalidator_results.refused_by_postfilter + one }
|
||||||
| Applied ->
|
| Applied ->
|
||||||
m.prevalidator_results <-
|
m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
applied = m.prevalidator_results.applied + 1 }
|
applied = m.prevalidator_results.applied + one }
|
||||||
| Branch_delayed ->
|
| Branch_delayed ->
|
||||||
m.prevalidator_results <-
|
m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
branch_delayed = m.prevalidator_results.branch_delayed + 1 }
|
branch_delayed = m.prevalidator_results.branch_delayed + one }
|
||||||
| Branch_refused ->
|
| Branch_refused ->
|
||||||
m.prevalidator_results <-
|
m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
branch_refused = m.prevalidator_results.branch_refused + 1 }
|
branch_refused = m.prevalidator_results.branch_refused + one }
|
||||||
| Refused ->
|
| Refused ->
|
||||||
m.prevalidator_results <-
|
m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
refused = m.prevalidator_results.refused + 1 }
|
refused = m.prevalidator_results.refused + one }
|
||||||
| Duplicate ->
|
| Duplicate ->
|
||||||
m.prevalidator_results <-
|
m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
duplicate = m.prevalidator_results.duplicate + 1 }
|
duplicate = m.prevalidator_results.duplicate + one }
|
||||||
| Outdated ->
|
| Outdated ->
|
||||||
m.prevalidator_results <-
|
m.prevalidator_results <-
|
||||||
{ m.prevalidator_results with
|
{ m.prevalidator_results with
|
||||||
outdated = m.prevalidator_results.outdated + 1 }
|
outdated = m.prevalidator_results.outdated + one }
|
||||||
|
|
||||||
|
|
||||||
(* shortcuts to update sent/failed requests/responses *)
|
(* shortcuts to update sent/failed requests/responses *)
|
||||||
|
Loading…
Reference in New Issue
Block a user