From f7589aa3bc2c3ec9200829c22ada336caa9017f4 Mon Sep 17 00:00:00 2001 From: djmil Date: Tue, 28 Nov 2023 19:03:57 +0100 Subject: [PATCH] force custodian for all TRX --- .../cordacheckers/gamestate/CommitTrx.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java b/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java index 7141c5e..5a1fa03 100644 --- a/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java +++ b/corda/workflows/src/main/java/djmil/cordacheckers/gamestate/CommitTrx.java @@ -7,6 +7,7 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import djmil.cordacheckers.VNode; import net.corda.v5.application.flows.CordaInject; import net.corda.v5.application.flows.InitiatingFlow; import net.corda.v5.application.flows.SubFlow; @@ -18,6 +19,7 @@ import net.corda.v5.base.types.MemberX500Name; import net.corda.v5.crypto.SecureHash; import net.corda.v5.ledger.utxo.UtxoLedgerService; import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; +import net.corda.v5.membership.MemberInfo; @InitiatingFlow(protocol = "gamestate-commit") public class CommitTrx implements SubFlow { @@ -25,7 +27,7 @@ public class CommitTrx implements SubFlow { private final static Logger log = LoggerFactory.getLogger(CommitTrx.class); private final UtxoSignedTransaction utxTrxCandidate; private final MemberX500Name counterpartyName; - private final MemberX500Name custodyName; + private /*final*/ MemberX500Name custodyName; public CommitTrx(UtxoSignedTransaction signedTransaction, MemberX500Name counterpartyName) { this.utxTrxCandidate = signedTransaction; @@ -61,6 +63,11 @@ public class CommitTrx implements SubFlow { final FlowSession session = flowMessaging.initiateFlow(this.counterpartyName); List sessionsList = new LinkedList(Arrays.asList(session)); + if (custodyName == null) { + custodyName = findCustodian().getName(); + log.info("GameState: [UGLY FIX] backchain validation failure for custodian"); + } + if (custodyName != null) { sessionsList.add(flowMessaging.initiateFlow(custodyName)); } @@ -73,4 +80,13 @@ public class CommitTrx implements SubFlow { log.info("GameState commit " +trxId); return trxId; } + + @Suspendable + MemberInfo findCustodian() { + return memberLookup.lookup() + .stream() + .filter(member -> VNode.isCordaCherckersCustodian(member) ) + .reduce((a,b) -> {throw new IllegalStateException("Multiple Custodian VNodes");}) + .orElseThrow( () -> new IllegalStateException("No Custodian VNode found")); + } }