diff --git a/src/bin_dal_node/daemon.ml b/src/bin_dal_node/daemon.ml index 974828fba2016c3c6fdaa182cf2a3cb3f4cbb86a..5b4fef7778ccd0dc3ad7566875d269fb1dccbb4f 100644 --- a/src/bin_dal_node/daemon.ml +++ b/src/bin_dal_node/daemon.ml @@ -444,7 +444,8 @@ module Handler = struct cells_of_level (* This functions counts, for each slot, the number of shards attested by the bakers. *) - let get_attestable_slots attestations committee ~number_of_slots is_attested = + let attested_shards_per_slot attestations committee ~number_of_slots + is_attested = let count_per_slot = Array.make number_of_slots 0 in List.iter (fun (_tb_slot, delegate_opt, _attestation_op, dal_attestation_opt) -> @@ -479,8 +480,8 @@ module Handler = struct Node_context.fetch_committee node_ctxt ~level:attestation_level in let attestations = get_attestations () in - let attestable_slots = - get_attestable_slots + let attested_shards_per_slot = + attested_shards_per_slot attestations committee ~number_of_slots:parameters.Types.number_of_slots @@ -491,9 +492,23 @@ module Handler = struct / parameters.cryptobox_parameters.redundancy_factor in let should_be_attested index = - let num_attested_shards = attestable_slots.(index) in + let num_attested_shards = attested_shards_per_slot.(index) in num_attested_shards >= threshold in + let contains_traps = + let store = Node_context.get_store node_ctxt in + let traps_store = Store.traps store in + let published_level = + Int32.(sub block_level (of_int parameters.attestation_lag)) + in + fun pkh index -> + if published_level <= 1l then false + else + Store.Traps.find traps_store ~level:published_level + |> List.exists (fun Store.Traps.{delegate; slot_index; _} -> + index = slot_index + && Signature.Public_key_hash.equal delegate pkh) + in let*! () = List.iter_s (fun (_, delegate_opt, _attestation_op, dal_attestation_opt) -> @@ -522,10 +537,17 @@ module Handler = struct should_be_attested index && not (is_attested bitset index) then - Event.emit_warn_attester_did_not_attest_slot - ~attester:delegate - ~slot_index:index - ~attested_level:block_level + if not (contains_traps delegate index) then + Event.emit_warn_attester_did_not_attest_slot + ~attester:delegate + ~slot_index:index + ~attested_level:block_level + else + Event + .emit_attester_did_not_attest_slot_because_of_traps + ~attester:delegate + ~slot_index:index + ~attested_level:block_level else Lwt.return_unit) (0 -- (parameters.number_of_slots - 1))) | None | Some _ -> diff --git a/src/bin_dal_node/event.ml b/src/bin_dal_node/event.ml index 86f7721ca01fb7f80ca4c8061e99a71f57b17002..2955718e7d4a38297635f9163d3d7bab08bdd268 100644 --- a/src/bin_dal_node/event.ml +++ b/src/bin_dal_node/event.ml @@ -757,14 +757,27 @@ open struct ~section ~name:"attester_did_not_attest_slot" ~msg: - "At level {attested_level}, slot index {slot_index} was attested but \ - shards from {attester} are missing" + "At level {attested_level}, slot index {slot_index} was sufficiently \ + attested, but shards from {attester} are missing" ~level:Warning ("attester", Signature.Public_key_hash.encoding) ("slot_index", Data_encoding.int31) ("attested_level", Data_encoding.int32) ~pp1:Signature.Public_key_hash.pp_short + let attester_did_not_attest_slot_because_of_traps = + declare_3 + ~section + ~name:"attester_did_not_attest_slot_with_traps" + ~msg: + "At level {attested_level}, slot index {slot_index} was sufficiently \ + attested, but {attester} did not attest because of traps" + ~level:Notice + ("attester", Signature.Public_key_hash.encoding) + ("slot_index", Data_encoding.int31) + ("attested_level", Data_encoding.int32) + ~pp1:Signature.Public_key_hash.pp_short + let trap_injection = declare_5 ~section @@ -1079,6 +1092,12 @@ let emit_warn_attester_did_not_attest_slot ~attester ~slot_index ~attested_level = emit warn_attester_did_not_attest_slot (attester, slot_index, attested_level) +let emit_attester_did_not_attest_slot_because_of_traps ~attester ~slot_index + ~attested_level = + emit + attester_did_not_attest_slot_because_of_traps + (attester, slot_index, attested_level) + let emit_trap_injection ~delegate ~published_level ~attested_level ~slot_index ~shard_index = emit