Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cl0 transaction tracking #987

Draft
wants to merge 1 commit into
base: feature/cl0_transaction_tracking
Choose a base branch
from

Conversation

effects-ai
Copy link
Contributor

No description provided.

validationErrorsR <- Ref[F].of(Vector.empty[(Artifact, ValidationError, Instant)])
} yield
new ValidationErrorStorage[F, Artifact, ValidationError] {
override def addValidationError(artifact: Artifact, errors: ValidationError): F[Unit] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

override modifier is wrongly used. it overrides nothing as this code implements the trait, not overrides it or any parent class.

import weaver.SimpleIOSuite

object ValidationErrorStorageSuite extends SimpleIOSuite {
implicit val eq: Eq[IndexedSeq[(Int, String)]] = Eq.instance((a, b) => a == b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how it differs from expect.same?

override protected val prefixPath: InternalUrlPrefix = "/currency"

override protected val public: HttpRoutes[F] = HttpRoutes.of[F] {
case GET -> Root / "validation-errors" =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it shouldn't be a sub-resource of /snapshot/events/validation-errors but if it is currency-framework specific then maybe currency/snapshot-event-validation-errors or something more specific 🤔

WDYT?

@@ -43,7 +45,8 @@ object HttpApi {
nodeVersion: TessellationVersion,
httpCfg: HttpConfig,
maybeDataApplication: Option[BaseDataApplicationL0Service[F]],
maybeMetagraphVersion: Option[MetagraphVersion]
maybeMetagraphVersion: Option[MetagraphVersion],
currencySnapshotValidationErrorStorage: ValidationErrorStorage[F, CurrencySnapshotEvent, Option[BlockRejectionReason]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically it doesn't store snapshot validation errors. These are errors of snapshot events so inputs for creating the currency snapshot.

@effects-ai effects-ai force-pushed the cl0_transaction_tracking branch from 46fb287 to acfa1c7 Compare December 13, 2024 21:09
@@ -356,7 +356,7 @@ lazy val rosetta = (project in file("modules/rosetta"))
lazy val dagL1 = (project in file("modules/dag-l1"))
.enablePlugins(AshScriptPlugin)
.enablePlugins(JavaAppPackaging)
.dependsOn(kernel, shared % "compile->compile;test->test", nodeShared, testShared % Test)
.dependsOn(kernel, shared % "compile->compile;test->test", nodeShared % "compile->compile;test->test", testShared % Test)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need it? we already have a testShared module so there should be no point to share test phase of nodeShared 🤔


implicit val encoder: Encoder[ValidationErrorStorageEntry[CurrencySnapshotEvent, Option[BlockRejectionReason]]] =
new Encoder[ValidationErrorStorageEntry[CurrencySnapshotEvent, Option[BlockRejectionReason]]] {
override def apply(a: ValidationErrorStorageEntry[CurrencySnapshotEvent, Option[BlockRejectionReason]]): Json = Json.obj(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Encoder does not implement a default implementation of apply, so you don't override it, but just implement it. override modifier is wrongly used here

Comment on lines +30 to +32
case currency.BlockEvent(value) => value.asJson
case currency.DataApplicationBlockEvent(_) => Json.Null
case currency.CurrencyMessageEvent(_) => Json.Null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why other events are ignored?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are place holders, will be removed with actual error codes.

Comment on lines +13 to +17
trait ValidationErrorStorage[F[_], Artifact, ValidationError] {
def addValidationError(artifact: Artifact, errors: ValidationError): F[Unit]
def addValidationErrors(errors: NonEmptyList[(Artifact, ValidationError)]): F[Unit]
def allValidationErrors: F[Vector[ValidationErrorStorageEntry[Artifact, ValidationError]]]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of repeating the same name over and over, it may be:

trait ValidationErrorStorage ... {
  def add(artifact: Artifact, error: ValidationError): ...
  def add(artifact: Artifact, errors: NonEmptyList[ValidationError]): ...
  def get: F[Vector[...]]
}

validationErrorsR <- Ref[F].of(Vector.empty[ValidationErrorStorageEntry[Artifact, ValidationError]])
} yield
new ValidationErrorStorage[F, Artifact, ValidationError] {
override def addValidationError(artifact: Artifact, error: ValidationError): F[Unit] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, you don't override a default implementation but just providing the first implementation, so it overrides nothing

new ValidationErrorStorage[F, Artifact, ValidationError] {
override def addValidationError(artifact: Artifact, error: ValidationError): F[Unit] =
for {
timestamp <- Clock[F].realTimeInstant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you ever match errors for equality? how the timestamp is gonna by used? those timestamps are local timestamps and won't match any other timestamp in the network

Comment on lines +41 to +45
val (headArtifact, headError) = errors.head
errors.foldLeft(addValidationError(headArtifact, headError)) {
case (acc, (artifact, error)) =>
acc >> addValidationError(artifact, error)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of extracting the head and violating DRY rule, you can put an empty unit in the fold as a zero value and fold over all elements then. you can also use traverse probably, that would be easier than reducing values like that, since F is a monad and you can chain computations

@effects-ai effects-ai marked this pull request as draft December 19, 2024 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants