mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
Exclude infrastructure transactions [DPP-1110] (#15121)
* Exclude infrastructure transactions changelog_begin changelog_end
This commit is contained in:
parent
0654f9978c
commit
817e6aac01
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user