Fix badly versioned empty tx (#10596)

* build correctly versioned empty tx

* dont call normalizeTx from Engine.validate

* dont recalc the tx-version in normalizeTx; just assume it is correct

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
nickchapman-da 2021-08-17 13:58:58 +01:00 committed by GitHub
parent d92440471c
commit aec601f929
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 12 deletions

View File

@ -222,7 +222,7 @@ class Engine(val config: EngineConfig = new EngineConfig(LanguageVersion.StableV
(rtx, _) = result
validationResult <-
transaction.Validation
.isReplayedBy(transaction.Normalization.normalizeTx(tx), rtx)
.isReplayedBy(tx, rtx)
.fold(
e => ResultError(Error.Validation.ReplayMismatch(e)),
_ => ResultDone.Unit,

View File

@ -274,7 +274,7 @@ object TransactionBuilder {
// not valid transactions.
val Empty: Tx.Transaction =
VersionedTransaction(
TransactionVersion.minNodeVersion,
TransactionVersion.minVersion, // A normalized empty tx is V10
HashMap.empty,
ImmArray.empty,
)

View File

@ -45,17 +45,9 @@ class Normalization[Nid, Cid] {
def normalizeTx(vtx: VTX): VTX = {
vtx match {
case VersionedTransaction(_, nodes, roots) =>
// TODO: Normalized version calc should be shared with code in asVersionedTransaction
val version = roots.iterator.foldLeft(TransactionVersion.minVersion) { (acc, nodeId) =>
import scala.Ordering.Implicits.infixOrderingOps
nodes(nodeId).optVersion match {
case Some(version) => acc max version
case None => acc max TransactionVersion.minExceptions
}
}
case VersionedTransaction(_, nodes, _) =>
VersionedTransaction(
version,
vtx.version,
nodes.map { case (k, v) =>
(k, normNode(v))
},