Skip to content

Commit

Permalink
kvutils: Remove the deprecated v1_4 bridge for ledger state access. (
Browse files Browse the repository at this point in the history
…#7500)

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
SamirTalwar authored Sep 28, 2020
1 parent c5d1453 commit 5f33c7e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import scala.concurrent.{ExecutionContext, Future}
* Defines how the validator/committer can access the backing store of the ledger to perform
* read/write operations in a transaction.
*
* This trait changed API in v1.5. To access the older version, use [[LedgerStateAccess.v1_4]].
*
* @tparam LogResult type of the offset used for a log entry
*/
trait LedgerStateAccess[LogResult] {
Expand All @@ -31,36 +29,6 @@ trait LedgerStateAccess[LogResult] {
)(implicit executionContext: ExecutionContext): Future[T]
}

object LedgerStateAccess {

/**
* Defines how the validator/committer can access the backing store of the ledger to perform
* read/write operations in a transaction.
*
* @tparam LogResult type of the offset used for a log entry
*/
@deprecated("To be removed in v1.6.", since = "v1.5")
trait v1_4[LogResult] {
self =>

/**
* Performs read and write operations on the backing store in a single atomic transaction.
*
* @param body operations to perform
* @tparam T return type of the body
*/
def inTransaction[T](body: LedgerStateOperations.v1_4[LogResult] => Future[T]): Future[T]

def modernize(): LedgerStateAccess[LogResult] = new LedgerStateAccess[LogResult] {
override def inTransaction[T](
body: LedgerStateOperations[LogResult] => Future[T],
)(implicit ignored: ExecutionContext): Future[T] =
self.inTransaction(operations => body(operations.modernize()))
}
}

}

/**
* Defines how the validator/committer can access the backing store of the ledger.
*
Expand Down Expand Up @@ -188,76 +156,4 @@ object LedgerStateOperations {
type Key = Bytes
type Value = Bytes

/**
* Defines how the validator/committer can access the backing store of the ledger.
*
* @tparam LogResult type of the offset used for a log entry
*/
@deprecated("To be removed in v1.6.", since = "v1.5")
trait v1_4[LogResult] {
self =>

/**
* Reads value of a single key from the backing store.
*
* @param key key to look up data for
* @return value corresponding to requested key or None in case it does not exist
*/
def readState(key: Key): Future[Option[Value]]

/**
* Reads values of a set of keys from the backing store.
*
* @param keys list of keys to look up data for
* @return values corresponding to the requested keys, in the same order as requested
*/
def readState(keys: Seq[Key]): Future[Seq[Option[Value]]]

/**
* Writes a single key-value pair to the backing store. In case the key already exists its value is overwritten.
*/
def writeState(key: Key, value: Value): Future[Unit]

/**
* Writes a list of key-value pairs to the backing store. In case a key already exists its value is overwritten.
*/
def writeState(keyValuePairs: Seq[(Key, Value)]): Future[Unit]

/**
* Writes a single log entry to the backing store. The implementation may return Future.failed in case the key
* (i.e., the log entry ID) already exists.
*
* @return offset of the latest log entry
*/
def appendToLog(key: Key, value: Value): Future[LogResult]

def modernize(): LedgerStateOperations[LogResult] = new LedgerStateOperations[LogResult] {
override def readState(key: Key)(
implicit executionContext: ExecutionContext
): Future[Option[Value]] =
self.readState(key)

override def readState(keys: Seq[Key])(
implicit executionContext: ExecutionContext
): Future[Seq[Option[Value]]] =
self.readState(keys)

override def writeState(key: Key, value: Value)(
implicit executionContext: ExecutionContext
): Future[Unit] =
self.writeState(key, value)

override def writeState(
keyValuePairs: Seq[(Key, Value)]
)(implicit executionContext: ExecutionContext): Future[Unit] =
self.writeState(keyValuePairs)

override def appendToLog(
key: Key,
value: Value,
)(implicit executionContext: ExecutionContext): Future[LogResult] =
self.appendToLog(key, value)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -330,42 +330,6 @@ object SubmissionValidator {
)
}

@deprecated("To be removed in v1.6.", since = "v1.5")
def create_v1_4[LogResult](
ledgerStateAccess: LedgerStateAccess.v1_4[LogResult],
allocateNextLogEntryId: () => DamlLogEntryId = () => allocateRandomLogEntryId(),
checkForMissingInputs: Boolean = false,
stateValueCache: Cache[Bytes, DamlStateValue] = Cache.none,
engine: Engine,
metrics: Metrics,
): SubmissionValidator[LogResult] =
new_v1_4(
ledgerStateAccess,
processSubmission(new KeyValueCommitting(engine, metrics, inStaticTimeMode = false)),
allocateNextLogEntryId,
checkForMissingInputs,
stateValueCache,
metrics,
)

@deprecated("To be removed in v1.6.", since = "v1.5")
private[validator] def new_v1_4[LogResult](
ledgerStateAccess: LedgerStateAccess.v1_4[LogResult],
processSubmission: SubmissionValidator.ProcessSubmission,
allocateLogEntryId: () => DamlLogEntryId,
checkForMissingInputs: Boolean,
stateValueCache: Cache[Bytes, DamlStateValue],
metrics: Metrics,
): SubmissionValidator[LogResult] =
new SubmissionValidator(
ledgerStateAccess.modernize(),
processSubmission,
allocateLogEntryId,
checkForMissingInputs,
stateValueCache,
metrics,
)

// Internal method to enable proper command dedup in sandbox with static time mode
private[daml] def createForTimeMode[LogResult](
ledgerStateAccess: LedgerStateAccess[LogResult],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.daml.ledger.validator.ValidationFailed.{MissingInputState, Validation
import com.daml.lf.data.Time.Timestamp
import com.daml.lf.engine.Engine
import com.daml.metrics.Metrics
import com.github.ghik.silencer.silent
import com.google.protobuf.{ByteString, Empty}
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito.{times, verify, when}
Expand All @@ -27,7 +26,6 @@ import org.scalatest.{AsyncWordSpec, Inside, Matchers}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.Try

@silent("deprecated \\(since v1\\.5\\): To be removed in v1\\.6\\.")
class SubmissionValidatorSpec extends AsyncWordSpec with Matchers with Inside {
"validate" should {
"return success in case of no errors during processing of submission" in {
Expand Down Expand Up @@ -289,46 +287,6 @@ class SubmissionValidatorSpec extends AsyncWordSpec with Matchers with Inside {
}
}
}

"work with v1.4 LedgerStateAccess" in {
val mockStateOperations = mock[LedgerStateOperations.v1_4[Int]]
when(mockStateOperations.modernize()).thenCallRealMethod()
val expectedLogResult: Int = 3
when(mockStateOperations.readState(any[Seq[Bytes]]()))
.thenReturn(Future.successful(Seq(Some(aStateValue()))))
val logEntryValueCaptor = captor[Bytes]
val logEntryIdCaptor = captor[Bytes]
when(
mockStateOperations.appendToLog(logEntryIdCaptor.capture(), logEntryValueCaptor.capture()))
.thenReturn(Future.successful(expectedLogResult))
val expectedLogEntryId = aLogEntryId()
val mockLogEntryIdGenerator = mockFunctionReturning(expectedLogEntryId)
val metrics = new Metrics(new MetricRegistry)
val instance = SubmissionValidator.new_v1_4(
ledgerStateAccess = new FakeStateAccess.v1_4(mockStateOperations),
processSubmission = SubmissionValidator
.processSubmission(new KeyValueCommitting(Engine.DevEngine(), metrics)),
allocateLogEntryId = mockLogEntryIdGenerator,
checkForMissingInputs = false,
stateValueCache = Cache.none,
metrics = metrics,
)
instance
.validateAndCommit(anEnvelope(), "aCorrelationId", newRecordTime(), aParticipantId())
.map {
inside(_) {
case Right(actualLogResult) =>
actualLogResult should be(expectedLogResult)
verify(mockLogEntryIdGenerator, times(1)).apply()
verify(mockStateOperations, times(0))
.writeState(any[RawKeyValuePairs]())
logEntryValueCaptor.getAllValues should have size 1
logEntryIdCaptor.getAllValues should have size 1
logEntryIdCaptor.getValue should be(expectedLogEntryId.toByteString)
logEntryValueCaptor.getValue should not be logEntryIdCaptor.getValue
}
}
}
}
}

Expand Down Expand Up @@ -383,18 +341,4 @@ object SubmissionValidatorSpec {
body(mockStateOperations)
}

object FakeStateAccess {

@silent("deprecated \\(since v1\\.5\\): To be removed in v1\\.6\\.")
private[SubmissionValidatorSpec] class v1_4[LogResult](
mockStateOperations: LedgerStateOperations.v1_4[LogResult],
) extends LedgerStateAccess.v1_4[LogResult] {
override def inTransaction[T](
body: LedgerStateOperations.v1_4[LogResult] => Future[T],
): Future[T] =
body(mockStateOperations)
}

}

}

0 comments on commit 5f33c7e

Please sign in to comment.