Exclude infrastructure transactions [DPP-1110] (#15121)

* Exclude infrastructure transactions

changelog_begin
changelog_end
This commit is contained in:
Simon Maxen 2022-09-29 16:22:52 +01:00 committed by GitHub
parent 0654f9978c
commit 817e6aac01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 3 deletions

View File

@ -4,6 +4,8 @@
package com.daml.lf
package transaction
import com.daml.lf.data.Ref.PackageId
object TransactionNodeStatistics {
/** Container for transaction statistics.
@ -89,10 +91,30 @@ object TransactionNodeStatistics {
* rolled back nodes (those nodes that do appear under a rollback node) on
* the other hand within a given transaction `tx`.
*/
def apply(tx: VersionedTransaction): TransactionNodeStatistics =
apply(tx.transaction)
def apply(
tx: VersionedTransaction,
excludedPackages: Set[PackageId] = Set.empty,
): TransactionNodeStatistics =
apply(tx.transaction, excludedPackages)
def apply(tx: Transaction): TransactionNodeStatistics = {
/** Calculate the node statistics unless all actions in the transaction use infrastructure packages in
* which case return Empty.
*/
def apply(
tx: Transaction,
excludedPackages: Set[PackageId],
): TransactionNodeStatistics = {
val excluded = tx.nodes.values
.collect({ case a: Node.Action => a })
.forall(_.packageIds.forall(excludedPackages.contains))
if (!excluded) {
build(tx)
} else {
TransactionNodeStatistics.Empty
}
}
private def build(tx: Transaction): TransactionNodeStatistics = {
val committed = emptyFields
val rolledBack = emptyFields
var rollbackDepth = 0

View File

@ -182,6 +182,35 @@ class TransactionNodeStatisticsSpec
}
}
}
"exclude infrastructure transactions" in {
forEvery(testCases) { (makeNode, _) =>
val builder = TxBuilder()
val node = makeNode(builder)
val excludedPackageIds = Set(node).collect({ case a: Node.Action => a.packageIds }).flatten
builder.add(node)
TransactionNodeStatistics(
builder.build(),
excludedPackageIds,
) shouldBe TransactionNodeStatistics.Empty
}
}
"only exclude transaction if all packages are infrastructure" in {
forEvery(testCases) { (makeNode, _) =>
val builder = TxBuilder()
val nonExcludedNode = makeNode(builder)
val excludedNode = makeNode(builder)
val excludedPackageIds =
Set(excludedNode).collect({ case a: Node.Action => a.packageIds }).flatten
builder.add(nonExcludedNode)
builder.add(excludedNode)
TransactionNodeStatistics(
builder.build(),
excludedPackageIds,
) should not be (TransactionNodeStatistics.Empty)
}
}
}
}