Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PM-3187: Emit traces from ConsensusService.
- Loading branch information
Showing
3 changed files
with
105 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 44 additions & 2 deletions
46
...nome/hotstuff/service/src/io/iohk/metronome/hotstuff/service/tracing/ConsensusEvent.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,47 @@ | ||
package io.iohk.metronome.hotstuff.service.tracing | ||
|
||
import io.iohk.metronome.hotstuff.consensus.basic.Agreement | ||
import io.iohk.metronome.hotstuff.consensus.ViewNumber | ||
import io.iohk.metronome.hotstuff.consensus.basic.{ | ||
Agreement, | ||
Event, | ||
ProtocolError | ||
} | ||
import io.iohk.metronome.hotstuff.consensus.basic.QuorumCertificate | ||
|
||
sealed trait ConsensusEvent[A <: Agreement] | ||
sealed trait ConsensusEvent[+A <: Agreement] | ||
|
||
object ConsensusEvent { | ||
|
||
/** The round ended without having reached decision. */ | ||
case class Timeout(viewNumber: ViewNumber) extends ConsensusEvent[Nothing] | ||
|
||
/** The state advanced to a new view. */ | ||
case class NewView(viewNumber: ViewNumber) extends ConsensusEvent[Nothing] | ||
|
||
/** Quorum over some block. */ | ||
case class Quorum[A <: Agreement](quorumCertificate: QuorumCertificate[A]) | ||
extends ConsensusEvent[A] | ||
|
||
/** A formally valid message was received from an earlier view number. */ | ||
case class FromPast[A <: Agreement](message: Event.MessageReceived[A]) | ||
extends ConsensusEvent[A] | ||
|
||
/** A formally valid message was received from a future view number. */ | ||
case class FromFuture[A <: Agreement](message: Event.MessageReceived[A]) | ||
extends ConsensusEvent[A] | ||
|
||
/** An event that arrived too early but got stashed and will be redelivered. */ | ||
case class Stashed[A <: Agreement]( | ||
error: ProtocolError.TooEarly[A] | ||
) extends ConsensusEvent[A] | ||
|
||
/** A rejected event. */ | ||
case class Rejected[A <: Agreement]( | ||
error: ProtocolError[A] | ||
) extends ConsensusEvent[A] | ||
|
||
/** An unexpected error in one of the background tasks. */ | ||
case class Error( | ||
error: Throwable | ||
) extends ConsensusEvent[Nothing] | ||
} |
35 changes: 34 additions & 1 deletion
35
...me/hotstuff/service/src/io/iohk/metronome/hotstuff/service/tracing/ConsensusTracers.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,40 @@ | ||
package io.iohk.metronome.hotstuff.service.tracing | ||
|
||
import cats.implicits._ | ||
import io.iohk.metronome.tracer.Tracer | ||
import io.iohk.metronome.hotstuff.consensus.basic.Agreement | ||
import io.iohk.metronome.hotstuff.consensus.ViewNumber | ||
import io.iohk.metronome.hotstuff.consensus.basic.{ | ||
Agreement, | ||
Event, | ||
ProtocolError, | ||
QuorumCertificate | ||
} | ||
|
||
case class ConsensusTracers[F[_], A <: Agreement]( | ||
timeout: Tracer[F, ViewNumber], | ||
newView: Tracer[F, ViewNumber], | ||
quorum: Tracer[F, QuorumCertificate[A]], | ||
fromPast: Tracer[F, Event.MessageReceived[A]], | ||
fromFuture: Tracer[F, Event.MessageReceived[A]], | ||
stashed: Tracer[F, ProtocolError.TooEarly[A]], | ||
rejected: Tracer[F, ProtocolError[A]], | ||
error: Tracer[F, Throwable] | ||
) | ||
|
||
object ConsensusTracers { | ||
import ConsensusEvent._ | ||
|
||
def apply[F[_], A <: Agreement]( | ||
tracer: Tracer[F, ConsensusEvent[A]] | ||
): ConsensusTracers[F, A] = | ||
ConsensusTracers[F, A]( | ||
timeout = tracer.contramap[ViewNumber](Timeout(_)), | ||
newView = tracer.contramap[ViewNumber](NewView(_)), | ||
quorum = tracer.contramap[QuorumCertificate[A]](Quorum(_)), | ||
fromPast = tracer.contramap[Event.MessageReceived[A]](FromPast(_)), | ||
fromFuture = tracer.contramap[Event.MessageReceived[A]](FromFuture(_)), | ||
stashed = tracer.contramap[ProtocolError.TooEarly[A]](Stashed(_)), | ||
rejected = tracer.contramap[ProtocolError[A]](Rejected(_)), | ||
error = tracer.contramap[Throwable](Error(_)) | ||
) | ||
} |