forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added submission validator (digital-asset#4437)
CHANGELOG_BEGIN CHANGELOG_END
- Loading branch information
Showing
8 changed files
with
616 additions
and
45 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
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
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
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
84 changes: 84 additions & 0 deletions
84
...articipant-state/kvutils/src/main/scala/com/daml/ledger/validator/LedgerStateAccess.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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2020 The DAML Authors. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.validator | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
trait LedgerStateAccess { | ||
|
||
/** | ||
* Performs read and write operations on the backing store in a single atomic transaction. | ||
* @param body operations to perform | ||
* @tparam T type of result returned after execution | ||
*/ | ||
def inTransaction[T](body: LedgerStateOperations => Future[T]): Future[T] | ||
|
||
/** | ||
* @return ID of the participant accessing the backing store. | ||
*/ | ||
def participantId: String | ||
} | ||
|
||
trait LedgerStateOperations { | ||
type Key = Array[Byte] | ||
type Value = Array[Byte] | ||
|
||
/** | ||
* 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. | ||
*/ | ||
def appendToLog(key: Key, value: Value): Future[Unit] | ||
} | ||
|
||
/** | ||
* Implements non-batching read and write operations on the backing store based on batched implementations. | ||
*/ | ||
abstract class BatchingLedgerStateOperations(implicit executionContext: ExecutionContext) | ||
extends LedgerStateOperations { | ||
override def readState(key: Key): Future[Option[Value]] = | ||
readState(Seq(key)).map(_.head) | ||
|
||
override def writeState(key: Key, value: Value): Future[Unit] = | ||
writeState(Seq((key, value))) | ||
} | ||
|
||
/** | ||
* Implements batching read and write operations on the backing store based on non-batched implementations. | ||
*/ | ||
abstract class NonBatchingLedgerStateOperations(implicit executionContext: ExecutionContext) | ||
extends LedgerStateOperations { | ||
override def readState(keys: Seq[Key]): Future[Seq[Option[Value]]] = | ||
Future.sequence(keys.map(readState)) | ||
|
||
override def writeState(keyValuePairs: Seq[(Key, Value)]): Future[Unit] = | ||
Future | ||
.sequence(keyValuePairs.map { | ||
case (key, value) => writeState(key, value) | ||
}) | ||
.map(_ => ()) | ||
} |
Oops, something went wrong.