Skip to content

Commit

Permalink
Rename BlindingInfo fields (digital-asset#2883)
Browse files Browse the repository at this point in the history
  • Loading branch information
rautenrieth-da authored Sep 17, 2019
1 parent 035bcf7 commit b97ef28
Show file tree
Hide file tree
Showing 15 changed files with 81 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ class EngineTest extends WordSpec with Matchers with EitherValues with BazelRunf
"events are collected" in {
val Right(blindingInfo) =
Blinding.checkAuthorizationAndBlind(tx, Set(party))
val events = Event.collectEvents(tx, blindingInfo.explicitDisclosure)
val events = Event.collectEvents(tx, blindingInfo.disclosure)
val partyEvents = events.events.values.toList.filter(_.witnesses contains party)
partyEvents.size shouldBe 1
partyEvents(0) match {
Expand Down Expand Up @@ -647,7 +647,7 @@ class EngineTest extends WordSpec with Matchers with EitherValues with BazelRunf
"events are collected" in {
val Right(blindingInfo) =
Blinding.checkAuthorizationAndBlind(tx, Set(alice))
val events = Event.collectEvents(tx, blindingInfo.explicitDisclosure)
val events = Event.collectEvents(tx, blindingInfo.disclosure)
val partyEvents = events.events.values.toList.filter(_.witnesses contains alice)
partyEvents.size shouldBe 1
partyEvents(0) match {
Expand Down Expand Up @@ -977,7 +977,7 @@ class EngineTest extends WordSpec with Matchers with EitherValues with BazelRunf
val Right(tx) = interpretResult
val Right(blindingInfo) =
Blinding.checkAuthorizationAndBlind(tx, Set(bob))
val events = Event.collectEvents(tx, blindingInfo.explicitDisclosure)
val events = Event.collectEvents(tx, blindingInfo.disclosure)
val partyEvents = events.filter(_.witnesses contains bob)
partyEvents.roots.length shouldBe 1
val bobExercise = partyEvents.events(partyEvents.roots(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ object BlindingCoder {
nodeIdWriter: Transaction.NodeId => String): proto.Blindinginfo.BlindingInfo = {
val builder = proto.Blindinginfo.BlindingInfo.newBuilder()

val localImplicit = blindingInfo.localImplicitDisclosure.map(nodeParties => {
val localImplicit = blindingInfo.localDivulgence.map(nodeParties => {
val b1 = proto.Blindinginfo.NodeParties.newBuilder()
b1.setNodeId(nodeIdWriter(nodeParties._1))
b1.addAllParties(nodeParties._2.toSet[String].asJava)
b1.build()
})

val explicit = blindingInfo.explicitDisclosure.map(nodeParties => {
val explicit = blindingInfo.disclosure.map(nodeParties => {
val b1 = proto.Blindinginfo.NodeParties.newBuilder()
b1.setNodeId(nodeIdWriter(nodeParties._1))
b1.addAllParties(nodeParties._2.toSet[String].asJava)
b1.build()
})

val global = blindingInfo.globalImplicitDisclosure.map(contractParties => {
val global = blindingInfo.globalDivulgence.map(contractParties => {
val b1 = proto.Blindinginfo.ContractParties.newBuilder()
b1.setContractId(contractParties._1.coid)
b1.addAllParties(contractParties._2.toSet[String].asJava)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,30 @@ import com.digitalasset.daml.lf.data.Ref.Party
import com.digitalasset.daml.lf.data.Relation.Relation
import com.digitalasset.daml.lf.value.Value.AbsoluteContractId

/** This gives implicit and explicit divulgence info. Explicit
* disclosure (also known as simply "disclosure") tells us which
* nodes to communicate to which parties, while implicit disclosure
* (also known as "divulgence") tells us what to communicate to
/** This gives disclosure and divulgence info.
*
* "Disclosure" tells us which nodes to communicate to which parties.
* See also https://docs.daml.com/concepts/ledger-model/ledger-privacy.html
*
* "Divulgence" tells us what to communicate to
* each participant node so that they can perform post-commit
* validation. Note that implicit disclosure can also divulge
* validation. Note that divulgence can also divulge
* absolute contract ids -- e.g. contract ids that were created
* _outside_ this transaction.
* See also https://docs.daml.com/concepts/ledger-model/ledger-privacy.html#divulgence-when-non-stakeholders-see-contracts
*/
case class BlindingInfo(
/** Also simply known as "disclosure" */
explicitDisclosure: Relation[Transaction.NodeId, Party],
/** Also known as "divulgence" */
localImplicitDisclosure: Relation[Transaction.NodeId, Party],
globalImplicitDisclosure: Relation[AbsoluteContractId, Party]) {
/** Disclosure, specified in terms of local node IDs */
disclosure: Relation[Transaction.NodeId, Party],
/** Divulgence, specified in terms of local node IDs */
localDivulgence: Relation[Transaction.NodeId, Party],
/**
* Divulgence, specified in terms of absolute contract IDs.
* Note that if this info was produced by blinding a transaction
* containing only absolute contract ids, this map may also
* contain contracts produced in the same transaction.
*/
globalDivulgence: Relation[AbsoluteContractId, Party]) {
def localDisclosure: Relation[Transaction.NodeId, Party] =
Relation.union(explicitDisclosure, localImplicitDisclosure)
Relation.union(disclosure, localDivulgence)
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DamlOnXTransactionService private (val indexService: IndexService, paralle
TransactionConversion
.genToFlatTransaction(
transactionWithEventIds,
blindingInfo.explicitDisclosure.map {
blindingInfo.disclosure.map {
case (nodeId, parties) =>
nodeIdToEventId(trans.transactionId, nodeId) -> parties
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ final case class IndexState(
transactionId = u.transactionId,
workflowId = u.transactionMeta.workflowId,
transaction = u.transaction,
explicitDisclosure = blindingInfo.explicitDisclosure,
localImplicitDisclosure = blindingInfo.localImplicitDisclosure,
globalImplicitDisclosure = blindingInfo.globalImplicitDisclosure,
disclosure = blindingInfo.disclosure,
localDivulgence = blindingInfo.localDivulgence,
glovalDivulgence = blindingInfo.globalDivulgence,
referencedContracts = u.divulgedContracts.map(c => c.contractId -> c.contractInst)
)
.fold(_ => Left(SequencingError), { newActiveContracts =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Projections {
// the parent of this node (if there was one).
// Note that we're using blinding info instead of repeating the authorization
// logic from [[Ledger.enrichTransaction]] here.
val witnesses = blindingInfo.explicitDisclosure(nodeId)
val witnesses = blindingInfo.disclosure(nodeId)
(
(witnesses -- alreadyWitnessed).foldLeft(perPartyRoots) {
case (ppr, p) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private[kvutils] case class ProcessTransactionSubmission(
key -> DamlStateValue.newBuilder.setContractState(cs).build
}),
// Update contract state of divulged contracts
sequence2(blindingInfo.globalImplicitDisclosure.map {
sequence2(blindingInfo.globalDivulgence.map {
case (absCoid, parties) =>
val key = absoluteContractIdToStateKey(absCoid)
getContractState(key).flatMap { cs =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ class JdbcIndexer private[index] (

val blindingInfo = Blinding.blind(transaction.mapContractId(cid => cid: ContractId))

val mappedDisclosure = blindingInfo.explicitDisclosure.map {
val mappedDisclosure = blindingInfo.disclosure.map {
case (nodeId, parties) =>
SandboxEventIdFormatter.fromTransactionId(transactionId, nodeId) -> parties
}

val mappedLocalImplicitDisclosure = blindingInfo.localImplicitDisclosure.map {
val mappedLocalDivulgence = blindingInfo.localDivulgence.map {
case (nodeId, parties) =>
SandboxEventIdFormatter.fromTransactionId(transactionId, nodeId) -> parties
}

assert(blindingInfo.localImplicitDisclosure.isEmpty)
assert(blindingInfo.localDivulgence.isEmpty)

val pt = PersistenceEntry.Transaction(
LedgerEntry.Transaction(
Expand All @@ -241,8 +241,8 @@ class JdbcIndexer private[index] (
.mapNodeId(SandboxEventIdFormatter.fromTransactionId(transactionId, _)),
mappedDisclosure
),
mappedLocalImplicitDisclosure,
blindingInfo.globalImplicitDisclosure,
mappedLocalDivulgence,
blindingInfo.globalDivulgence,
divulgedContracts.map(c => c.contractId -> c.contractInst)
)
ledgerDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ class ActiveLedgerStateManager[ALS](initialState: => ALS)(
transactionId: TransactionIdString,
workflowId: Option[WorkflowId],
transaction: GenTransaction.WithTxValue[Nid, AbsoluteContractId],
explicitDisclosure: Relation[Nid, Party],
localImplicitDisclosure: Relation[Nid, Party],
globalImplicitDisclosure: Relation[AbsoluteContractId, Party],
referencedContracts: List[(Value.AbsoluteContractId, AbsoluteContractInst)])
disclosure: Relation[Nid, Party],
localDivulgence: Relation[Nid, Party],
globalDivulgence: Relation[AbsoluteContractId, Party],
divulgedContracts: List[(Value.AbsoluteContractId, AbsoluteContractInst)])
: Either[Set[SequencingError], ALS] = {
// NOTE(RC): `globalImplicitDisclosure` was meant to refer to contracts created in previous transactions.
// However, because we have translated relative to absolute IDs at this point, `globalImplicitDisclosure`
Expand Down Expand Up @@ -111,7 +111,7 @@ class ActiveLedgerStateManager[ALS](initialState: => ALS)(
case Some(_: DivulgedContract) =>
// Contract divulged in the past
None
case None if referencedContracts.exists(_._1 == cid) =>
case None if divulgedContracts.exists(_._1 == cid) =>
// Contract is going to be divulged in this transaction
None
case None =>
Expand All @@ -136,9 +136,9 @@ class ActiveLedgerStateManager[ALS](initialState: => ALS)(
.union(nc.stakeholders)
.union(nc.key.map(_.maintainers).getOrElse(Set.empty))
val absCoid = SandboxEventIdFormatter.makeAbsCoid(transactionId)(nc.coid)
val withoutStakeHolders = localImplicitDisclosure
val withoutStakeHolders = localDivulgence
.getOrElse(nodeId, Set.empty) diff nc.stakeholders
val withStakeHolders = localImplicitDisclosure
val withStakeHolders = localDivulgence
.getOrElse(nodeId, Set.empty)

assert(withoutStakeHolders == withStakeHolders)
Expand All @@ -150,10 +150,10 @@ class ActiveLedgerStateManager[ALS](initialState: => ALS)(
workflowId = workflowId,
contract = nc.coinst.mapValue(
_.mapContractId(SandboxEventIdFormatter.makeAbsCoid(transactionId))),
witnesses = explicitDisclosure(nodeId),
witnesses = disclosure(nodeId),
// we need to `getOrElse` here because the `Nid` might include absolute
// contract ids, and those are never present in the local disclosure.
divulgences = (localImplicitDisclosure
divulgences = (localDivulgence
.getOrElse(nodeId, Set.empty) diff nc.stakeholders).toList
.map(p => p -> transactionId)
.toMap,
Expand Down Expand Up @@ -207,9 +207,9 @@ class ActiveLedgerStateManager[ALS](initialState: => ALS)(
}
}

val divulgedContracts = globalImplicitDisclosure -- st.archivedIds
val divulgedContractIds = globalDivulgence -- st.archivedIds
st.mapAcs(
_ divulgeAlreadyCommittedContracts (transactionId, divulgedContracts, referencedContracts))
_ divulgeAlreadyCommittedContracts (transactionId, divulgedContractIds, divulgedContracts))
.mapAcs(_ addParties st.parties)
.result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ case class InMemoryActiveLedgerState(
transactionId: TransactionIdString,
workflowId: Option[WorkflowId],
transaction: GenTransaction.WithTxValue[Nid, AbsoluteContractId],
explicitDisclosure: Relation[Nid, Party],
localImplicitDisclosure: Relation[Nid, Party],
globalImplicitDisclosure: Relation[AbsoluteContractId, Party],
disclosure: Relation[Nid, Party],
localDivulgence: Relation[Nid, Party],
glovalDivulgence: Relation[AbsoluteContractId, Party],
referencedContracts: List[(Value.AbsoluteContractId, AbsoluteContractInst)]
): Either[Set[SequencingError], InMemoryActiveLedgerState] =
acManager.addTransaction(
let,
transactionId,
workflowId,
transaction,
explicitDisclosure,
localImplicitDisclosure,
globalImplicitDisclosure,
disclosure,
localDivulgence,
glovalDivulgence,
referencedContracts)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ class InMemoryLedger(
trId,
transactionMeta.workflowId,
mappedTx,
blindingInfo.explicitDisclosure,
blindingInfo.localImplicitDisclosure,
blindingInfo.globalImplicitDisclosure,
blindingInfo.disclosure,
blindingInfo.localDivulgence,
blindingInfo.globalDivulgence,
List.empty
)
acsRes match {
Expand All @@ -178,7 +178,7 @@ class InMemoryLedger(
val recordTx = mappedTx
.mapNodeId(SandboxEventIdFormatter.fromTransactionId(trId, _))
val recordBlinding =
blindingInfo.explicitDisclosure.map {
blindingInfo.disclosure.map {
case (nid, parties) =>
(SandboxEventIdFormatter.fromTransactionId(trId, nid), parties)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ private class SqlLedger(

val blindingInfo = Blinding.blind(transaction)

val mappedDisclosure = blindingInfo.explicitDisclosure
val mappedDisclosure = blindingInfo.disclosure
.map {
case (nodeId, parties) =>
SandboxEventIdFormatter.fromTransactionId(transactionId, nodeId) -> parties
}

val mappedLocalImplicitDisclosure = blindingInfo.localImplicitDisclosure.map {
val mappedLocalDivulgence = blindingInfo.localDivulgence.map {
case (k, v) => SandboxEventIdFormatter.fromTransactionId(transactionId, k) -> v
}

Expand Down Expand Up @@ -266,8 +266,8 @@ private class SqlLedger(
mappedTx,
mappedDisclosure
),
mappedLocalImplicitDisclosure,
blindingInfo.globalImplicitDisclosure,
mappedLocalDivulgence,
blindingInfo.globalDivulgence,
List.empty
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ private class JdbcLedgerDao(
private def updateActiveContractSet(
offset: Long,
tx: Transaction,
localImplicitDisclosure: Relation[EventId, Party],
globalImplicitDisclosure: Relation[AbsoluteContractId, Party],
localDivulgence: Relation[EventId, Party],
globalDivulgence: Relation[AbsoluteContractId, Party],
divulgedContracts: List[(Value.AbsoluteContractId, AbsoluteContractInst)])(
implicit connection: Connection): Option[RejectionReason] = tx match {
case Transaction(
Expand Down Expand Up @@ -462,8 +462,8 @@ private class JdbcLedgerDao(
workflowId,
transaction,
disclosure,
localImplicitDisclosure,
globalImplicitDisclosure,
localDivulgence,
globalDivulgence,
divulgedContracts
)

Expand Down Expand Up @@ -556,17 +556,17 @@ private class JdbcLedgerDao(
le match {
case PersistenceEntry.Transaction(
tx,
localImplicitDisclosure,
globalImplicitDisclosure,
localDivulgence,
globalDivulgence,
divulgedContracts) =>
Try {
storeTransaction(offset, tx)

updateActiveContractSet(
offset,
tx,
localImplicitDisclosure,
globalImplicitDisclosure,
localDivulgence,
globalDivulgence,
divulgedContracts)
.flatMap { rejectionReason =>
// we need to rollback the existing sql transaction
Expand Down Expand Up @@ -1245,7 +1245,7 @@ object JdbcLedgerDao {
protected[JdbcLedgerDao] def SQL_IMPLICITLY_INSERT_PARTIES: String

// Note: the SQL backend may receive divulgence information for the same (contract, party) tuple
// more than once through BlindingInfo.globalImplicitDisclosure.
// more than once through BlindingInfo.globalDivulgence.
// The ledger offsets for the same (contract, party) tuple should always be increasing, and the database
// stores the offset at which the contract was first disclosed.
// We therefore don't need to update anything if there is already some data for the given (contract, party) tuple.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ object PersistenceEntry {
final case class Rejection(entry: LedgerEntry.Rejection) extends PersistenceEntry
final case class Transaction(
entry: LedgerEntry.Transaction,
localImplicitDisclosure: Relation[EventId, Party],
globalImplicitDisclosure: Relation[AbsoluteContractId, Party],
localDivulgence: Relation[EventId, Party],
globalDivulgence: Relation[AbsoluteContractId, Party],
divulgedContracts: List[(Value.AbsoluteContractId, AbsoluteContractInst)]
) extends PersistenceEntry
final case class Checkpoint(entry: LedgerEntry.Checkpoint) extends PersistenceEntry
Expand Down
Loading

0 comments on commit b97ef28

Please sign in to comment.