Skip to content

Commit

Permalink
KV / integrity checker: conflate Disputed, InvalidLedgerTime and …
Browse files Browse the repository at this point in the history
…`Inconsistent` rejection reasons [KVL-1059] (#10515)

* Integrity checker: conflate Disputed, InvalidLedgerTime and Inconsistent

CHANGELOG_BEGIN
CHANGELOG_END

* RejectionReasonNormalizer -> CommandRejectionRedesignNormalizer
  • Loading branch information
fabiotudone-da authored Aug 9, 2021
1 parent 55ed83c commit 23168a8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object UpdateNormalizer {
private val MandatoryNormalizers = List(
RecordTimeNormalizer,
RejectionReasonDescriptionNormalizer,
CommandRejectionRedesignNormalizer,
ConfigurationChangeRejectionNormalizer,
)

Expand Down Expand Up @@ -72,7 +73,24 @@ object RejectionReasonDescriptionNormalizer extends UpdateNormalizer {
}
}

/** Rejection reason strings should always be ignored as they can change arbitrarily. */
/** Rejection reasons `Disputed`, `InvalidLedgerTime` and `Inconsistent` are being conflated
* as their usage has been re-designed in SDK 1.16.0-snapshot.20210727.7476.0.b5e9d861 [KVL-1015].
*/
object CommandRejectionRedesignNormalizer extends UpdateNormalizer {
override def normalize(update: Update): Update = update match {
case commandRejected @ Update.CommandRejected(_, _, reason) =>
val newReason = reason match {
case RejectionReasonV0.Disputed(description) =>
RejectionReasonV0.Inconsistent(description)
case RejectionReasonV0.InvalidLedgerTime(description) =>
RejectionReasonV0.Inconsistent(description)
case _ => reason
}
commandRejected.copy(reason = newReason)
case _ => update
}
}

object ConfigurationChangeRejectionNormalizer extends UpdateNormalizer {
override def normalize(update: Update): Update = update match {
case u: Update.ConfigurationChangeRejected => u.copy(rejectionReason = "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ import com.daml.lf.data.Relation.Relation
import com.daml.lf.data.{Ref, Time}
import com.daml.lf.transaction.test.TransactionBuilder
import com.daml.lf.transaction.{BlindingInfo, CommittedTransaction, NodeId}
import org.scalatest.Assertion
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.wordspec.AsyncWordSpec

import scala.concurrent.Future

final class StateUpdateComparisonSpec
extends AsyncWordSpec
with TableDrivenPropertyChecks
Expand Down Expand Up @@ -48,16 +51,16 @@ final class StateUpdateComparisonSpec
RejectionReasonV0.SubmitterCannotActViaParticipant("a") -> RejectionReasonV0
.SubmitterCannotActViaParticipant("b"),
)
forAll(rejectionReasons) { case (left, right) =>
ReadServiceStateUpdateComparison
.compareUpdates(
aCommandRejectedUpdate.copy(reason = left),
aCommandRejectedUpdate.copy(reason = right),
expectedUpdateNormalizers = Iterable.empty,
actualUpdateNormalizers = Iterable.empty,
)
.map(_ => succeed)
}
forAll(rejectionReasons)(compareCommandRejectionReasons)
}

"conflate Disputed, InvalidLedgerTime and Inconsistent for CommandRejected updates" in {
val rejectionReasons = Table(
("Left", "Right"),
RejectionReasonV0.Disputed("a") -> RejectionReasonV0.Inconsistent("a"),
RejectionReasonV0.InvalidLedgerTime("a") -> RejectionReasonV0.Inconsistent("a"),
)
forAll(rejectionReasons)(compareCommandRejectionReasons)
}

"ignore blinding info for TransactionAccepted updates" in {
Expand Down Expand Up @@ -135,7 +138,7 @@ final class StateUpdateComparisonSpec
private lazy val aKeyMaintainer = "maintainer"
private lazy val aDummyValue = TransactionBuilder.record("field" -> "value")

def buildATransaction(withFetchAndLookupByKeyNodes: Boolean): CommittedTransaction = {
private def buildATransaction(withFetchAndLookupByKeyNodes: Boolean): CommittedTransaction = {
val builder = new TransactionBuilder()
val create1 = create("#someContractId")
val create2 = create("#otherContractId")
Expand Down Expand Up @@ -177,4 +180,17 @@ final class StateUpdateComparisonSpec
TransactionBuilder.record(maintainer -> key)
},
)

private def compareCommandRejectionReasons(
left: RejectionReasonV0,
right: RejectionReasonV0,
): Future[Assertion] =
ReadServiceStateUpdateComparison
.compareUpdates(
aCommandRejectedUpdate.copy(reason = left),
aCommandRejectedUpdate.copy(reason = right),
expectedUpdateNormalizers = Iterable.empty,
actualUpdateNormalizers = Iterable.empty,
)
.map(_ => succeed)
}

0 comments on commit 23168a8

Please sign in to comment.