Skip to content

Commit 99c886f

Browse files
feat(iota-core, iota-types): Enable misbehavior report creation (#9363)
# Description of change This PR enables the creation of the MisbehaviorReport consensus message, as their submission to consensus in order to disseminate it with the rest of the committee. ## Links to any relevant issues Be sure to reference any related issues by adding `fixes #(issue)`. ## How the change has been tested - [x] Basic tests (linting, compilation, formatting, unit/integration tests) - [ ] Patch-specific tests (correctness, functionality coverage) - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have checked that new and existing unit tests pass locally with my changes ### Release Notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [x] Protocol: Enables misbehavior report creation and dissemination. - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --------- Co-authored-by: Andrew <[email protected]>
1 parent 22d653c commit 99c886f

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

crates/iota-core/src/checkpoints/checkpoint_output.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ impl<T: SubmitToConsensus + ReconfigurationInitiator> CheckpointOutput
123123
.set(checkpoint_seq as i64);
124124
}
125125

126+
// We also send misbehavior reports to consensus at this point. Misbehavior
127+
// reports containing proofs of misbehaviour can be send whenever the
128+
// misbehavior is detected, but we choose to send the ones that include only
129+
// unprovable counts at this point, due to periodicity reasons and to ensure a
130+
// (approximate) synchronization with the score updates.
131+
let misbehavior_report = epoch_store.scorer.current_local_metrics_count.to_report();
132+
let transaction = ConsensusTransaction::new_misbehavior_report(
133+
epoch_store.name,
134+
&misbehavior_report,
135+
checkpoint_seq,
136+
);
137+
self.sender
138+
.submit_to_consensus(&vec![transaction], epoch_store)?;
139+
126140
if checkpoint_timestamp >= self.next_reconfiguration_timestamp_ms {
127141
// close_epoch is ok if called multiple times
128142
self.sender.close_epoch(epoch_store);

crates/iota-core/src/checkpoints/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,8 @@ impl CheckpointBuilder {
13811381

13821382
batch.write()?;
13831383

1384-
// Send all checkpoint sigs to consensus.
1384+
// Send all checkpoint sigs to consensus. The messages including
1385+
// MisbehaviorReports are also sent in this step.
13851386
for (summary, contents) in &new_checkpoints {
13861387
self.output
13871388
.checkpoint_created(summary, contents, &self.epoch_store, &self.store)

crates/iota-types/src/messages_consensus.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use serde::{Deserialize, Serialize};
2020

2121
use crate::{
2222
base_types::{
23-
AuthorityName, CommitRound, ConciseableName, ObjectID, ObjectRef, SequenceNumber,
24-
TransactionDigest,
23+
AuthorityName, ConciseableName, ObjectID, ObjectRef, SequenceNumber, TransactionDigest,
2524
},
2625
crypto::{AuthoritySignature, DefaultHash},
2726
digests::{ConsensusCommitDigest, Digest},
@@ -91,10 +90,10 @@ pub enum ConsensusTransactionKey {
9190
NewJWKFetched(Box<(AuthorityName, JwkId, JWK)>),
9291
RandomnessDkgMessage(AuthorityName),
9392
RandomnessDkgConfirmation(AuthorityName),
94-
// If a validator submits more than one report for the same round, we update the
95-
// scoring metrics using the maximum reported metric, so CommitRound is sufficient to
96-
// identify a report from a single AuthorityName.
97-
MisbehaviorReport(AuthorityName, CommitRound),
93+
// If a validator submits more than one report for the same checkpoint, we update the
94+
// scoring metrics using the maximum reported metric, so the checkpoint sequence number is
95+
// sufficient to identify a report from a single AuthorityName.
96+
MisbehaviorReport(AuthorityName, u64 /* checkpoint_seq */),
9897
// New entries should be added at the end to preserve serialization compatibility. DO NOT
9998
// CHANGE THE ORDER OF EXISTING ENTRIES!
10099
}
@@ -107,8 +106,13 @@ impl Debug for ConsensusTransactionKey {
107106
write!(f, "CheckpointSignature({:?}, {:?})", name.concise(), seq)
108107
}
109108
Self::EndOfPublish(name) => write!(f, "EndOfPublish({:?})", name.concise()),
110-
Self::MisbehaviorReport(name, round) => {
111-
write!(f, "MisbehaviorReport({:?},{:?})", name.concise(), round)
109+
Self::MisbehaviorReport(name, checkpoint_seq) => {
110+
write!(
111+
f,
112+
"MisbehaviorReport({:?},{:?})",
113+
name.concise(),
114+
checkpoint_seq
115+
)
112116
}
113117
Self::CapabilityNotification(name, generation) => write!(
114118
f,
@@ -268,7 +272,11 @@ pub enum ConsensusTransactionKind {
268272
// of `RandomnessDkgMessages` have been received locally, to complete the key generation
269273
// process. Contents are a serialized `fastcrypto_tbls::dkg::Confirmation`.
270274
RandomnessDkgConfirmation(AuthorityName, Vec<u8>),
271-
MisbehaviorReport(AuthorityName, VersionedMisbehaviorReport, CommitRound),
275+
MisbehaviorReport(
276+
AuthorityName,
277+
VersionedMisbehaviorReport,
278+
u64, // checkpoint_seq
279+
),
272280
// New entries should be added at the end to preserve serialization compatibility. DO NOT
273281
// CHANGE THE ORDER OF EXISTING ENTRIES!
274282
}
@@ -563,10 +571,10 @@ impl ConsensusTransaction {
563571
}
564572
}
565573

566-
pub fn new_misbehavior_report_v1(
574+
pub fn new_misbehavior_report(
567575
authority: AuthorityName,
568-
report: &MisbehaviorsV1<Vec<u64>>,
569-
round: CommitRound,
576+
report: &VersionedMisbehaviorReport,
577+
checkpoint_seq: u64,
570578
) -> Self {
571579
let serialized_report =
572580
bcs::to_bytes(report).expect("report serialization should not fail");
@@ -577,8 +585,8 @@ impl ConsensusTransaction {
577585
tracking_id,
578586
kind: ConsensusTransactionKind::MisbehaviorReport(
579587
authority,
580-
VersionedMisbehaviorReport::V1(report.clone()),
581-
round,
588+
report.clone(),
589+
checkpoint_seq,
582590
),
583591
}
584592
}
@@ -603,8 +611,8 @@ impl ConsensusTransaction {
603611
ConsensusTransactionKind::EndOfPublish(authority) => {
604612
ConsensusTransactionKey::EndOfPublish(*authority)
605613
}
606-
ConsensusTransactionKind::MisbehaviorReport(authority, _, round) => {
607-
ConsensusTransactionKey::MisbehaviorReport(*authority, *round)
614+
ConsensusTransactionKind::MisbehaviorReport(authority, _, checkpoint_seq) => {
615+
ConsensusTransactionKey::MisbehaviorReport(*authority, *checkpoint_seq)
608616
}
609617
ConsensusTransactionKind::CapabilityNotificationV1(cap) => {
610618
ConsensusTransactionKey::CapabilityNotification(cap.authority, cap.generation)

0 commit comments

Comments
 (0)