From 56a81267c8c7986f12283a87578f082013c5c21e Mon Sep 17 00:00:00 2001 From: Alexandros Filios Date: Tue, 3 Sep 2024 15:37:10 +0200 Subject: [PATCH] Wait endorsers for finality when we run FSC based endorsement Signed-off-by: Alexandros Filios --- integration/token/common/support.go | 34 +++++++++++++++++++ integration/token/fungible/support.go | 27 +++++++++++++-- integration/token/fungible/tests.go | 5 +-- .../token/fungible/topology/topology.go | 2 ++ 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/integration/token/common/support.go b/integration/token/common/support.go index 16ae2793f..52b7df95e 100644 --- a/integration/token/common/support.go +++ b/integration/token/common/support.go @@ -9,6 +9,8 @@ package common import ( "github.com/hyperledger-labs/fabric-smart-client/integration" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/common" + topology2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric/topology" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/endorser" token2 "github.com/hyperledger-labs/fabric-token-sdk/integration/token" "github.com/hyperledger-labs/fabric-token-sdk/integration/token/common/views" "github.com/hyperledger-labs/fabric-token-sdk/token" @@ -29,3 +31,35 @@ func CheckFinality(network *integration.Infrastructure, id *token2.NodeReference Expect(err).NotTo(HaveOccurred()) } } + +func CheckEndorserFinality(network *integration.Infrastructure, id *token2.NodeReference, txID string, tmsID *token.TMSID, fail bool) { + if id == nil || len(id.Id()) == 0 { + return + } + var nw, channel string + if tmsID != nil { + nw, channel = tmsID.Network, tmsID.Channel + } else { + t := getFabricTopology(network) + nw, channel = t.Name(), t.Channels[0].Name + } + _, err := network.Client(id.ReplicaName()).CallView("EndorserFinality", common.JSONMarshall(&endorser.Finality{ + TxID: txID, + Network: nw, + Channel: channel, + })) + if fail { + Expect(err).To(HaveOccurred()) + } else { + Expect(err).NotTo(HaveOccurred()) + } +} + +func getFabricTopology(network *integration.Infrastructure) *topology2.Topology { + for _, t := range network.Topologies { + if t.Type() == "fabric" { + return t.(*topology2.Topology) + } + } + panic("no fabric topology found") +} diff --git a/integration/token/fungible/support.go b/integration/token/fungible/support.go index 07fe2d24a..f071a794d 100644 --- a/integration/token/fungible/support.go +++ b/integration/token/fungible/support.go @@ -80,7 +80,15 @@ func IssueCash(network *integration.Infrastructure, wallet string, typ string, a return IssueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, nil, expectedErrorMsgs...) } +func IssueSuccessfulCash(network *integration.Infrastructure, wallet string, typ string, amount uint64, receiver *token3.NodeReference, auditor *token3.NodeReference, anonymous bool, issuer *token3.NodeReference, finalities ...*token3.NodeReference) string { + return issueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, nil, finalities, []string{}) +} + func IssueCashForTMSID(network *integration.Infrastructure, wallet string, typ string, amount uint64, receiver *token3.NodeReference, auditor *token3.NodeReference, anonymous bool, issuer *token3.NodeReference, tmsId *token2.TMSID, expectedErrorMsgs ...string) string { + return issueCashForTMSID(network, wallet, typ, amount, receiver, auditor, anonymous, issuer, tmsId, []*token3.NodeReference{}, expectedErrorMsgs) +} + +func issueCashForTMSID(network *integration.Infrastructure, wallet string, typ string, amount uint64, receiver *token3.NodeReference, auditor *token3.NodeReference, anonymous bool, issuer *token3.NodeReference, tmsId *token2.TMSID, endorsers []*token3.NodeReference, expectedErrorMsgs []string) string { targetAuditor := auditor.Id() if auditor.Id() == "issuer" || auditor.Id() == "newIssuer" { // the issuer is the auditor, choose default identity @@ -97,11 +105,16 @@ func IssueCashForTMSID(network *integration.Infrastructure, wallet string, typ s TMSID: tmsId, })) + topology.ToOptions(network.FscPlatform.Peers[0].Options).Endorser() if len(expectedErrorMsgs) == 0 { Expect(err).NotTo(HaveOccurred()) txID := common.JSONUnmarshalString(txIDBoxed) - common2.CheckFinality(network, receiver, txID, tmsId, false) - common2.CheckFinality(network, auditor, txID, tmsId, false) + for _, n := range []*token3.NodeReference{receiver, auditor} { + common2.CheckFinality(network, n, txID, tmsId, false) + } + for _, n := range endorsers { + common2.CheckEndorserFinality(network, n, txID, tmsId, false) + } return common.JSONUnmarshalString(txIDBoxed) } @@ -112,6 +125,16 @@ func IssueCashForTMSID(network *integration.Infrastructure, wallet string, typ s return "" } +func GetEndorsers(network *integration.Infrastructure, sel *token3.ReplicaSelector) []*token3.NodeReference { + endorsers := make([]*token3.NodeReference, 0) + for _, p := range network.FscPlatform.Peers { + if topology.ToOptions(p.Options).Endorser() { + endorsers = append(endorsers, sel.Get(p.Name)) + } + } + return endorsers +} + func CheckAuditedTransactions(network *integration.Infrastructure, auditor *token3.NodeReference, expected []*ttxdb.TransactionRecord, start *time.Time, end *time.Time) { txsBoxed, err := network.Client(auditor.ReplicaName()).CallView("historyAuditing", common.JSONMarshall(&views.ListAuditedTransactions{ From: start, diff --git a/integration/token/fungible/tests.go b/integration/token/fungible/tests.go index bc1cd109a..5908cd8f0 100644 --- a/integration/token/fungible/tests.go +++ b/integration/token/fungible/tests.go @@ -273,6 +273,7 @@ func TestAll(network *integration.Infrastructure, auditorId string, onAuditorRes bob := sel.Get("bob") charlie := sel.Get("charlie") manager := sel.Get("manager") + endorsers := GetEndorsers(network, sel) RegisterAuditor(network, auditor, nil) // give some time to the nodes to get the public parameters @@ -286,7 +287,7 @@ func TestAll(network *integration.Infrastructure, auditorId string, onAuditorRes Eventually(DoesWalletExist).WithArguments(network, issuer, "pineapple", views.IssuerWallet).WithTimeout(1 * time.Minute).WithPolling(15 * time.Second).Should(Equal(false)) Eventually(DoesWalletExist).WithArguments(network, alice, "", views.OwnerWallet).WithTimeout(1 * time.Minute).WithPolling(15 * time.Second).Should(Equal(true)) Eventually(DoesWalletExist).WithArguments(network, alice, "mango", views.OwnerWallet).WithTimeout(1 * time.Minute).WithPolling(15 * time.Second).Should(Equal(false)) - IssueCash(network, "", "USD", 110, alice, auditor, true, issuer) + IssueSuccessfulCash(network, "", "USD", 110, alice, auditor, true, issuer, endorsers...) t1 := time.Now() CheckBalanceAndHolding(network, alice, "", "USD", 110, auditor) CheckAuditedTransactions(network, auditor, AuditedTransactions[:1], nil, nil) @@ -681,7 +682,7 @@ func TestAll(network *integration.Infrastructure, auditorId string, onAuditorRes CheckBalanceAndHolding(network, bob, "", "EUR", 2820-sum, auditor) // Transfer With TokenSelector - IssueCash(network, "", "YUAN", 17, alice, auditor, true, issuer) + IssueSuccessfulCash(network, "", "YUAN", 17, alice, auditor, true, issuer, endorsers...) TransferCashWithSelector(network, alice, "", "YUAN", 10, bob, auditor) CheckBalanceAndHolding(network, alice, "", "YUAN", 7, auditor) CheckBalanceAndHolding(network, bob, "", "YUAN", 10, auditor) diff --git a/integration/token/fungible/topology/topology.go b/integration/token/fungible/topology/topology.go index bf0cdc43c..30fcf8c1e 100644 --- a/integration/token/fungible/topology/topology.go +++ b/integration/token/fungible/topology/topology.go @@ -13,6 +13,7 @@ import ( "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fsc/node" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/monitoring" "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/orion" + "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/endorser" "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/tracing" "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token" common2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/common" @@ -310,6 +311,7 @@ func Topology(opts common.Opts) []api.Topology { if opts.FSCBasedEndorsement { endorserTemplate := fscTopology.NewTemplate("endorser") endorserTemplate.RegisterViewFactory("GetPublicParams", &views.GetPublicParamsViewFactory{}) + endorserTemplate.RegisterViewFactory("EndorserFinality", &endorser.FinalityViewFactory{}) endorserTemplate.AddOptions( fabric.WithOrganization("Org1"), fabric2.WithEndorserRole(),