force custodian for all TRX

This commit is contained in:
djmil 2023-11-28 19:03:57 +01:00
parent 0fbfa69fa8
commit f7589aa3bc

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import djmil.cordacheckers.VNode;
import net.corda.v5.application.flows.CordaInject; import net.corda.v5.application.flows.CordaInject;
import net.corda.v5.application.flows.InitiatingFlow; import net.corda.v5.application.flows.InitiatingFlow;
import net.corda.v5.application.flows.SubFlow; 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.crypto.SecureHash;
import net.corda.v5.ledger.utxo.UtxoLedgerService; import net.corda.v5.ledger.utxo.UtxoLedgerService;
import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction; import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction;
import net.corda.v5.membership.MemberInfo;
@InitiatingFlow(protocol = "gamestate-commit") @InitiatingFlow(protocol = "gamestate-commit")
public class CommitTrx implements SubFlow<SecureHash> { public class CommitTrx implements SubFlow<SecureHash> {
@ -25,7 +27,7 @@ public class CommitTrx implements SubFlow<SecureHash> {
private final static Logger log = LoggerFactory.getLogger(CommitTrx.class); private final static Logger log = LoggerFactory.getLogger(CommitTrx.class);
private final UtxoSignedTransaction utxTrxCandidate; private final UtxoSignedTransaction utxTrxCandidate;
private final MemberX500Name counterpartyName; private final MemberX500Name counterpartyName;
private final MemberX500Name custodyName; private /*final*/ MemberX500Name custodyName;
public CommitTrx(UtxoSignedTransaction signedTransaction, MemberX500Name counterpartyName) { public CommitTrx(UtxoSignedTransaction signedTransaction, MemberX500Name counterpartyName) {
this.utxTrxCandidate = signedTransaction; this.utxTrxCandidate = signedTransaction;
@ -61,6 +63,11 @@ public class CommitTrx implements SubFlow<SecureHash> {
final FlowSession session = flowMessaging.initiateFlow(this.counterpartyName); final FlowSession session = flowMessaging.initiateFlow(this.counterpartyName);
List<FlowSession> sessionsList = new LinkedList<FlowSession>(Arrays.asList(session)); List<FlowSession> sessionsList = new LinkedList<FlowSession>(Arrays.asList(session));
if (custodyName == null) {
custodyName = findCustodian().getName();
log.info("GameState: [UGLY FIX] backchain validation failure for custodian");
}
if (custodyName != null) { if (custodyName != null) {
sessionsList.add(flowMessaging.initiateFlow(custodyName)); sessionsList.add(flowMessaging.initiateFlow(custodyName));
} }
@ -73,4 +80,13 @@ public class CommitTrx implements SubFlow<SecureHash> {
log.info("GameState commit " +trxId); log.info("GameState commit " +trxId);
return 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"));
}
} }