Skip to content

Commit

Permalink
Don't ban nodes for block created in early catchup
Browse files Browse the repository at this point in the history
Problem: when a node is in early catchup and creates a block, it might
be considered worse than root and the node to be banned for gossiping
it.

Solution: if parent of the transition is in root history, do not ban.

Additionally, if we've seen gossip with the parent of transition and
its ancestor was in root history, do not ban. This one is implemented
heuristically via an LRU cache.
  • Loading branch information
georgeee committed Jul 10, 2023
1 parent 7a6cab6 commit 57fdad7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/lib/transition_handler/dune
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
kimchi_backend.pasta
kimchi_backend.pasta.basic
internal_tracing
transition_frontier_extensions
)
(instrumentation (backend bisect_ppx))
(preprocess (pps ppx_mina ppx_version ppx_jane)))
39 changes: 33 additions & 6 deletions src/lib/transition_handler/validator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Pipe_lib.Strict_pipe
open Mina_base
open Mina_state
open Cache_lib
open Mina_block
open Network_peer

module type CONTEXT = sig
Expand Down Expand Up @@ -87,6 +86,7 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~time_controller
Writer.t ) ~unprocessed_transition_cache =
let open Context in
let module Lru = Core_extended_cache.Lru in
let outdated_root_cache = Lru.create ~destruct:None 1000 in
O1trace.background_thread "validate_blocks_against_frontier" (fun () ->
Reader.iter transition_reader
~f:(fun (`Block transition_env, `Valid_cb vc) ->
Expand Down Expand Up @@ -118,8 +118,9 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~time_controller
in
let transition_time =
Mina_block.header transition
|> Header.protocol_state |> Protocol_state.blockchain_state
|> Blockchain_state.timestamp |> Block_time.to_time_exn
|> Mina_block.Header.protocol_state
|> Protocol_state.blockchain_state |> Blockchain_state.timestamp
|> Block_time.to_time_exn
in
Perf_histograms.add_span
~name:"accepted_transition_remote_latency"
Expand All @@ -143,18 +144,44 @@ let run ~context:(module Context : CONTEXT) ~trust_system ~time_controller
[%log internal] "Failure"
~metadata:[ ("reason", `String "Disconnected") ] ;
Mina_metrics.(Counter.inc_one Rejected_blocks.worse_than_root) ;
let protocol_state =
Mina_block.Header.protocol_state (Mina_block.header transition)
in
[%log error]
~metadata:
[ ("state_hash", State_hash.to_yojson transition_hash)
; ("reason", `String "not selected over current root")
; ( "protocol_state"
, Header.protocol_state (Mina_block.header transition)
|> Protocol_state.value_to_yojson )
, Protocol_state.value_to_yojson protocol_state )
]
"Validation error: external transition with state hash \
$state_hash was rejected for reason $reason" ;
let is_in_root_history =
let open Transition_frontier.Extensions in
get_extension
(Transition_frontier.extensions frontier)
Root_history
|> Root_history.mem
in
let parent_hash =
Protocol_state.previous_state_hash protocol_state
in
let action =
if
is_in_root_history transition_hash
|| Option.is_some
(Lru.find outdated_root_cache transition_hash)
then Trust_system.Actions.Sent_old_gossip
else if
is_in_root_history parent_hash
|| Option.is_some (Lru.find outdated_root_cache parent_hash)
then (
Lru.add outdated_root_cache ~key:transition_hash ~data:() ;
Sent_useless_gossip )
else Disconnected_chain
in
Trust_system.record_envelope_sender trust_system logger sender
( Trust_system.Actions.Disconnected_chain
( action
, Some
( "received transition that was not connected to our chain \
from $sender"
Expand Down

0 comments on commit 57fdad7

Please sign in to comment.