Skip to content

Commit

Permalink
Move activeness check of globalKeyInputs into archive (#9610)
Browse files Browse the repository at this point in the history
* Move activeness check of globalKeyInputs into archive

This is semantically equivalent but it seems slightly simpler and more
importantly it leads to slightly nicer semantics by reducing the
number of cases where we have to worry about accidentally skipping an
activeness check.

changelog_begin
changelog_end

* s/optCid/keyMapping/

changelog_begin
changelog_end

* review feedback

changelog_begin
changelog_end
  • Loading branch information
cocreature authored May 7, 2021
1 parent 5c28de3 commit ab29f7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1298,13 +1298,9 @@ private[lf] object SBuiltin {
case None =>
// Check if we have a cached global key result.
onLedger.ptx.globalKeyInputs.get(gkey) match {
case Some(optCid) =>
val optActiveCid = optCid match {
case KeyActive(cid) if onLedger.ptx.consumedBy.contains(cid) => KeyInactive
case _ => optCid
}
onLedger.ptx = onLedger.ptx.copy(keys = onLedger.ptx.keys.updated(gkey, optActiveCid))
operation.handleKnownInputKey(machine, gkey, optActiveCid)
case Some(keyMapping) =>
onLedger.ptx = onLedger.ptx.copy(keys = onLedger.ptx.keys.updated(gkey, keyMapping))
operation.handleKnownInputKey(machine, gkey, keyMapping)
case None =>
// if we cannot find it here, send help, and make sure to update [[PartialTransaction.key]] after
// that.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,11 @@ private[lf] case class PartialTransaction(
keys = mbKey match {
case Some(kWithM) if consuming =>
val gkey = GlobalKey(templateId, kWithM.key)
keys.get(gkey) match {
keys.get(gkey).orElse(globalKeyInputs.get(gkey)) match {
// An archive can only mark a key as inactive
// if it was brought into scope before.
case Some(KeyActive(cid)) if cid == targetId => keys.updated(gkey, KeyInactive)
case Some(KeyActive(cid)) if cid == targetId =>
keys.updated(gkey, KeyInactive)
// If the key was not in scope or mapped to a different cid, we don’t change keys. Instead we will do
// an activeness check when looking it up later.
case _ => keys
Expand Down

0 comments on commit ab29f7c

Please sign in to comment.