Skip to content

Commit dd86d89

Browse files
authored
Introduce MspEndorser (hyperledger#201)
#### Type of change - Improvement (improvement to code, performance, etc) #### Description - Introduce `MspEndorser` to endorser transactions using a local MSP - Refactor sigtest and the loadgen to apply the "endorsement" terminology - Endorser -> creates endorsement protobuf - Signer -> creates a binary signature - Fix issues from previous PRs #### Related issues - required for hyperledger#188 --------- Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
1 parent 2316615 commit dd86d89

38 files changed

Lines changed: 528 additions & 556 deletions

cmd/config/app_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func TestReadConfigLoadGen(t *testing.T) {
382382
Policy: &workload.PolicyProfile{
383383
ChannelID: "mychannel",
384384
NamespacePolicies: map[string]*workload.Policy{
385-
workload.GeneratedNamespaceID: {
385+
workload.DefaultGeneratedNamespaceID: {
386386
Scheme: signature.Ecdsa, Seed: 10,
387387
},
388388
committerpb.MetaNamespaceID: {

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,6 @@ github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5 h1:RPW
918918
github.com/hyperledger/fabric-lib-go v1.1.3-0.20240523144151-25edd1eaf5f5/go.mod h1:SHNCq8AB0VpHAmvJEtdbzabv6NNV1F48JdmDihasBjc=
919919
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7 h1:sQ5qv8vQQfwewa1JlCiSCC8dLElmaU2/frLolpgibEY=
920920
github.com/hyperledger/fabric-protos-go-apiv2 v0.3.7/go.mod h1:bJnwzfv03oZQeCc863pdGTDgf5nmCy6Za3RAE7d2XsQ=
921-
github.com/hyperledger/fabric-x-common v0.0.0-20251202124918-fc1bdd9f047a h1:6FKsx199DERm0lfSdzzExMPWrKRQic85y6gv9bDJLn4=
922-
github.com/hyperledger/fabric-x-common v0.0.0-20251202124918-fc1bdd9f047a/go.mod h1:7u/Yz8y3/88VX2JmqSOr2YVKm6qDtLbFc8PGZimP3V4=
923-
github.com/hyperledger/fabric-x-common v0.0.0-20251210111950-8c4f7df01875 h1:WsRxbhGgMXvduVIMn7Um5jqp9LRVLqLZo+Tbj0vhY4o=
924-
github.com/hyperledger/fabric-x-common v0.0.0-20251210111950-8c4f7df01875/go.mod h1:EDNayd2HEao22yv6ThvWfDKT2+cIR0Qplq3E/lgWwpA=
925921
github.com/hyperledger/fabric-x-common v0.0.0-20251211114026-4c950db7778e h1:5eDnbhRxekkH3l7w1xHmxW9m48HUSlzke+ZHRlm/PeM=
926922
github.com/hyperledger/fabric-x-common v0.0.0-20251211114026-4c950db7778e/go.mod h1:EDNayd2HEao22yv6ThvWfDKT2+cIR0Qplq3E/lgWwpA=
927923
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=

integration/runner/runtime.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838
"github.com/hyperledger/fabric-x-committer/utils/signature"
3939
"github.com/hyperledger/fabric-x-committer/utils/signature/sigtest"
4040
"github.com/hyperledger/fabric-x-committer/utils/test"
41-
"github.com/hyperledger/fabric-x-committer/utils/test/apptest"
4241
)
4342

4443
type (
@@ -75,16 +74,6 @@ type (
7574
CredFactory *test.CredentialsFactory
7675
}
7776

78-
// Crypto holds crypto material for a namespace.
79-
Crypto struct {
80-
Namespace string
81-
Profile *workload.Policy
82-
HashSigner *workload.PolicySignerVerifier
83-
NsSigner *sigtest.NsSigner
84-
PubKey []byte
85-
PubKeyPath string
86-
}
87-
8877
// Config represents the runtime configuration.
8978
Config struct {
9079
NumVerifiers int
@@ -154,7 +143,7 @@ func NewRuntime(t *testing.T, conf *Config) *CommitterRuntime {
154143
CommittedBlock: make(chan *common.Block, 100),
155144
seedForCryptoGen: rand.New(rand.NewSource(10)),
156145
}
157-
c.AddOrUpdateNamespaces(t, committerpb.MetaNamespaceID, workload.GeneratedNamespaceID, "1", "2", "3")
146+
c.AddOrUpdateNamespaces(t, committerpb.MetaNamespaceID, workload.DefaultGeneratedNamespaceID, "1", "2", "3")
158147

159148
t.Log("Making DB env")
160149
if conf.DBConnection == nil {
@@ -406,7 +395,7 @@ func (c *CommitterRuntime) MakeAndSendTransactionsToOrderer(
406395
if expectedStatus != nil && expectedStatus[i] == applicationpb.Status_ABORTED_SIGNATURE_INVALID {
407396
tx.Endorsements = make([]*applicationpb.Endorsements, len(namespaces))
408397
for nsIdx := range namespaces {
409-
tx.Endorsements[nsIdx] = apptest.CreateEndorsementsForThresholdRule([]byte("dummy"))[0]
398+
tx.Endorsements[nsIdx] = sigtest.CreateEndorsementsForThresholdRule([]byte("dummy"))[0]
410399
}
411400
}
412401
txs[i] = c.TxBuilder.MakeTx(tx)
@@ -525,7 +514,7 @@ func (c *CommitterRuntime) ValidateExpectedResultsInCommittedBlock(t *testing.T,
525514

526515
ctx, cancel := context.WithTimeout(t.Context(), 1*time.Minute)
527516
defer cancel()
528-
apptest.EnsurePersistedTxStatus(ctx, t, c.CoordinatorClient, persistedTxIDs, persistedTxIDsStatus)
517+
test.EnsurePersistedTxStatus(ctx, t, c.CoordinatorClient, persistedTxIDs, persistedTxIDsStatus)
529518

530519
if len(expected.TxIDs) == 0 || c.config.CrashTest {
531520
return

integration/test/config_update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestConfigUpdate(t *testing.T) {
8686
lgMetaTx := c.TxBuilder.MakeTx(metaTx)
8787

8888
c.AddOrUpdateNamespaces(t, committerpb.MetaNamespaceID)
89-
metaPolicy := c.TxBuilder.TxSigner.Policy(committerpb.MetaNamespaceID).VerificationPolicy()
89+
metaPolicy := c.TxBuilder.TxEndorser.Policy(committerpb.MetaNamespaceID).VerificationPolicy()
9090
submitConfigBlock := func(endpoints []*commontypes.OrdererEndpoint) {
9191
ordererEnv.SubmitConfigBlock(t, &workload.ConfigBlock{
9292
ChannelID: c.SystemConfig.Policy.ChannelID,

integration/test/namespace_lifecycle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ func TestCreateUpdateNamespace(t *testing.T) {
2929
})
3030
c.Start(t, runner.FullTxPath)
3131

32-
policyBytesNs1, err := proto.Marshal(c.TxBuilder.TxSigner.Policy("1").VerificationPolicy())
32+
policyBytesNs1, err := proto.Marshal(c.TxBuilder.TxEndorser.Policy("1").VerificationPolicy())
3333
require.NoError(t, err)
34-
policyBytesNs2, err := proto.Marshal(c.TxBuilder.TxSigner.Policy("2").VerificationPolicy())
34+
policyBytesNs2, err := proto.Marshal(c.TxBuilder.TxEndorser.Policy("2").VerificationPolicy())
3535
require.NoError(t, err)
3636

3737
tests := []struct {

loadgen/adapters/sigverifier.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (c *SvAdapter) RunWorkload(ctx context.Context, txStream *workload.StreamWi
8282
}
8383

8484
func createUpdate(policy *workload.PolicyProfile) (*servicepb.VerifierUpdates, error) {
85-
txSigner := workload.NewTxSignerVerifier(policy)
85+
txEndorser := workload.NewTxEndorserVerifier(policy)
8686

8787
envelopeBytes, err := workload.CreateConfigEnvelope(policy)
8888
if err != nil {
@@ -93,15 +93,15 @@ func createUpdate(policy *workload.PolicyProfile) (*servicepb.VerifierUpdates, e
9393
Envelope: envelopeBytes,
9494
},
9595
NamespacePolicies: &applicationpb.NamespacePolicies{
96-
Policies: make([]*applicationpb.PolicyItem, 0, len(txSigner.AllNamespaces())),
96+
Policies: make([]*applicationpb.PolicyItem, 0, len(txEndorser.AllNamespaces())),
9797
},
9898
}
9999

100-
for _, ns := range txSigner.AllNamespaces() {
100+
for _, ns := range txEndorser.AllNamespaces() {
101101
if ns == committerpb.MetaNamespaceID {
102102
continue
103103
}
104-
policyBytes, err := proto.Marshal(txSigner.Policy(ns).VerificationPolicy())
104+
policyBytes, err := proto.Marshal(txEndorser.Policy(ns).VerificationPolicy())
105105
if err != nil {
106106
return nil, errors.Wrap(err, "failed to serialize policy")
107107
}

loadgen/client_test_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func DefaultClientConf() *ClientConfig {
5151
ReadWriteCount: workload.NewConstantDistribution(2),
5252
Policy: &workload.PolicyProfile{
5353
NamespacePolicies: map[string]*workload.Policy{
54-
workload.GeneratedNamespaceID: {
54+
workload.DefaultGeneratedNamespaceID: {
5555
Scheme: signature.Ecdsa,
5656
Seed: 10,
5757
},

loadgen/workload/config_tx.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func CreateConfigBlock(policy *PolicyProfile) (*common.Block, error) {
8585
return block, nil
8686
}
8787

88-
txSigner := NewTxSignerVerifier(policy)
89-
metaPolicy := txSigner.Policy(committerpb.MetaNamespaceID)
88+
txEndorser := NewTxEndorserVerifier(policy)
89+
metaPolicy := txEndorser.Policy(committerpb.MetaNamespaceID)
9090
return CreateDefaultConfigBlock(&ConfigBlock{
9191
MetaNamespaceVerificationKey: metaPolicy.VerificationPolicy().GetThresholdRule().GetPublicKey(),
9292
OrdererEndpoints: policy.OrdererEndpoints,
@@ -103,11 +103,13 @@ func CreateDefaultConfigBlock(conf *ConfigBlock, profileName string) (*common.Bl
103103
defer func() {
104104
_ = os.RemoveAll(target)
105105
}()
106-
return CreateConfigBlockWithCrypto(target, conf, profileName)
106+
return CreateDefaultConfigBlockWithCrypto(target, conf, profileName)
107107
}
108108

109-
// CreateConfigBlockWithCrypto creates a config block with crypto material.
110-
func CreateConfigBlockWithCrypto(targetPath string, conf *ConfigBlock, profileName string) (*common.Block, error) {
109+
// CreateDefaultConfigBlockWithCrypto creates a config block with crypto material.
110+
func CreateDefaultConfigBlockWithCrypto(
111+
targetPath string, conf *ConfigBlock, profileName string,
112+
) (*common.Block, error) {
111113
orgs := make([]cryptogen.OrganizationParameters, 0, int(conf.PeerOrganizationCount)+len(conf.OrdererEndpoints))
112114

113115
ordererOrgsMap := make(map[uint32][]cryptogen.OrdererEndpoint)
@@ -151,7 +153,7 @@ func CreateConfigBlockWithCrypto(targetPath string, conf *ConfigBlock, profileNa
151153
metaKey := conf.MetaNamespaceVerificationKey
152154
if len(metaKey) == 0 {
153155
// We must supply a valid meta namespace key.
154-
_, metaKey = sigtest.NewSignatureFactory(signature.Ecdsa).NewKeys()
156+
_, metaKey = sigtest.NewKeyPair(signature.Ecdsa)
155157
}
156158

157159
return cryptogen.CreateDefaultConfigBlockWithCrypto(cryptogen.ConfigBlockParameters{

loadgen/workload/conflicts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"math/rand"
1212

1313
"github.com/hyperledger/fabric-x-committer/api/applicationpb"
14-
"github.com/hyperledger/fabric-x-committer/utils/test/apptest"
14+
"github.com/hyperledger/fabric-x-committer/utils/signature/sigtest"
1515
)
1616

1717
// Dependency types.
@@ -64,7 +64,7 @@ func (g *signTxModifier) Modify(tx *applicationpb.Tx) {
6464
// Pre-assigning prevents TxBuilder from re-signing the TX.
6565
tx.Endorsements = make([]*applicationpb.Endorsements, len(tx.Namespaces))
6666
for i := range len(tx.Namespaces) {
67-
tx.Endorsements[i] = apptest.CreateEndorsementsForThresholdRule(g.invalidSignature)[0]
67+
tx.Endorsements[i] = sigtest.CreateEndorsementsForThresholdRule(g.invalidSignature)[0]
6868
}
6969
}
7070
}

loadgen/workload/namespace.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func CreateLoadGenNamespacesTX(policy *PolicyProfile) (*servicepb.LoadGenTx, err
2121
if txbErr != nil {
2222
return nil, txbErr
2323
}
24-
tx, err := CreateNamespacesTxFromSigner(txb.TxSigner, 0)
24+
tx, err := CreateNamespacesTxFromEndorser(txb.TxEndorser, 0)
2525
if err != nil {
2626
return nil, err
2727
}
@@ -32,24 +32,24 @@ func CreateLoadGenNamespacesTX(policy *PolicyProfile) (*servicepb.LoadGenTx, err
3232
func CreateNamespacesTX(
3333
policy *PolicyProfile, metaNamespaceVersion uint64, includeNS ...string,
3434
) (*applicationpb.Tx, error) {
35-
signer := NewTxSignerVerifier(policy)
36-
return CreateNamespacesTxFromSigner(signer, metaNamespaceVersion, includeNS...)
35+
endorser := NewTxEndorserVerifier(policy)
36+
return CreateNamespacesTxFromEndorser(endorser, metaNamespaceVersion, includeNS...)
3737
}
3838

39-
// CreateNamespacesTxFromSigner creating the transaction containing the requested namespaces into the MetaNamespace.
40-
func CreateNamespacesTxFromSigner(
41-
signer *TxSignerVerifier, metaNamespaceVersion uint64, includeNS ...string,
39+
// CreateNamespacesTxFromEndorser creating the transaction containing the requested namespaces into the MetaNamespace.
40+
func CreateNamespacesTxFromEndorser(
41+
endorser *TxEndorserVerifier, metaNamespaceVersion uint64, includeNS ...string,
4242
) (*applicationpb.Tx, error) {
4343
if len(includeNS) == 0 {
44-
includeNS = signer.AllNamespaces()
44+
includeNS = endorser.AllNamespaces()
4545
}
4646

4747
readWrites := make([]*applicationpb.ReadWrite, 0, len(includeNS))
4848
for _, ns := range includeNS {
4949
if ns == committerpb.MetaNamespaceID {
5050
continue
5151
}
52-
policyBytes, err := proto.Marshal(signer.Policy(ns).VerificationPolicy())
52+
policyBytes, err := proto.Marshal(endorser.Policy(ns).VerificationPolicy())
5353
if err != nil {
5454
return nil, errors.Wrap(err, "failed to serialize namespace policy")
5555
}

0 commit comments

Comments
 (0)