Skip to content

Commit

Permalink
SequenceSpec WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-da committed Jan 12, 2022
1 parent a947c55 commit a0d20ec
Show file tree
Hide file tree
Showing 4 changed files with 443 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private[bridge] object ConflictCheckingLedgerBridge {
private[validate] type Validation[T] = Either[Rejection, T]
private[validate] type AsyncValidation[T] = Future[Validation[T]]
private[validate] type KeyInputs = Map[Key, LfTransaction.KeyInput]
private[validate] type UpdatedKeys = Map[Key, Option[ContractId]]

// Conflict checking stages
private[validate] type PrepareSubmission = Submission => AsyncValidation[PreparedSubmission]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

package com.daml.ledger.sandbox.bridge.validate

import com.daml.ledger.sandbox.bridge.validate.ConflictCheckingLedgerBridge.{KeyInputs, UpdatedKeys}
import com.daml.ledger.sandbox.domain.Submission
import com.daml.lf.data.Ref
import com.daml.lf.transaction.BlindingInfo
import com.daml.lf.transaction.Transaction.{KeyInput => TxKeyInput}
import com.daml.platform.store.appendonlydao.events
import com.daml.platform.store.appendonlydao.events.Key

// A submission that has been prepared for conflict checking
sealed trait PreparedSubmission extends Product with Serializable {
Expand All @@ -17,9 +16,9 @@ sealed trait PreparedSubmission extends Product with Serializable {

// A transaction submission bundled with all its precomputed effects.
final case class PreparedTransactionSubmission(
keyInputs: Map[Key, TxKeyInput],
keyInputs: KeyInputs,
inputContracts: Set[events.ContractId],
updatedKeys: Map[Key, Option[events.ContractId]],
updatedKeys: UpdatedKeys,
consumedContracts: Set[events.ContractId],
blindingInfo: BlindingInfo,
transactionInformees: Set[Ref.Party],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ private[validate] class SequenceImpl(
) extends Sequence {
private[this] implicit val logger: ContextualizedLogger = ContextualizedLogger.get(getClass)

@volatile private var offsetIdx = fromOffset(initialLedgerEnd)
@volatile private var sequencerQueueState = SequencerState()(bridgeMetrics)
@volatile private var allocatedParties = initialAllocatedParties
@volatile private var ledgerConfiguration = initialLedgerConfiguration
@volatile private[validate] var offsetIdx = fromOffset(initialLedgerEnd)
@volatile private[validate] var sequencerQueueState = SequencerState()(bridgeMetrics)
@volatile private[validate] var allocatedParties = initialAllocatedParties
@volatile private[validate] var ledgerConfiguration = initialLedgerConfiguration

override def apply(): Validation[(Offset, PreparedSubmission)] => Iterable[(Offset, Update)] =
in => {
Expand Down Expand Up @@ -114,31 +114,29 @@ private[validate] class SequenceImpl(
config: Configuration,
) = {
val recordTime = timeProvider.getCurrentTimestamp
val configUpdate =
if (recordTime > maxRecordTime)
if (recordTime > maxRecordTime)
Update.ConfigurationChangeRejected(
recordTime = recordTime,
submissionId = submissionId,
participantId = participantId,
proposedConfiguration = config,
rejectionReason = s"Configuration change timed out: $recordTime > $maxRecordTime",
)
else {
val expectedGeneration = ledgerConfiguration.map(_.generation).map(_ + 1L)
if (expectedGeneration.forall(_ == config.generation)) {
ledgerConfiguration = Some(config)
configChangedSuccess(c, participantId, timeProvider.getCurrentTimestamp)
} else
Update.ConfigurationChangeRejected(
recordTime = recordTime,
submissionId = submissionId,
participantId = participantId,
proposedConfiguration = config,
rejectionReason = s"Configuration change timed out: $maxRecordTime > $recordTime",
rejectionReason =
s"Generation mismatch: expected=$expectedGeneration, actual=${config.generation}",
)
else {
val expectedGeneration = ledgerConfiguration.map(_.generation).map(_ + 1L)
if (expectedGeneration.forall(_ == config.generation)) {
ledgerConfiguration = Some(config)
configChangedSuccess(c, participantId, timeProvider.getCurrentTimestamp)
} else
Update.ConfigurationChangeRejected(
recordTime = recordTime,
submissionId = submissionId,
participantId = participantId,
proposedConfiguration = config,
rejectionReason =
s"Generation mismatch: expected=$expectedGeneration, actual=${config.generation}",
)
}
configUpdate
}
}

private def sequentialTransactionValidation(
Expand Down
Loading

0 comments on commit a0d20ec

Please sign in to comment.