Skip to content

Commit e6125e6

Browse files
committed
Address comments
Signed-off-by: senthil <cendhu@gmail.com>
1 parent 26ddffe commit e6125e6

36 files changed

+534
-565
lines changed

api/protoblocktx/block_tx.pb.go

Lines changed: 191 additions & 210 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/protoblocktx/block_tx.proto

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ message Identity {
7070

7171
oneof creator {
7272
// The full raw bytes of the creator's certificate (e.g., an X.509 certificate).
73-
bytes certificate= 2;
73+
bytes certificate = 2;
7474

7575
// An identifier for a certificate that is pre-stored or known by the committer.
7676
string certificate_id = 3;
@@ -79,19 +79,10 @@ message Identity {
7979

8080
// Represents a namespace policy.
8181
message NamespacePolicy {
82-
PolicyType type = 1; // The type of policy used.
83-
bytes policy = 2; // The policy rule.
84-
}
85-
86-
enum PolicyType {
87-
// A policy for verifying a single signature that was generated via a Threshold Signature
88-
// Scheme (TSS). In a TSS, a threshold (T) of N parties must cooperate to
89-
// collectively compute and produce the single signature.
90-
THRESHOLD_RULE = 0;
91-
92-
// A policy defined by an explicit rule that evaluates one or more required signatures.
93-
// For example: "OR('Org1MSP.admin', 'Org2MSP.admin')"
94-
SIGNATURE_RULE = 1;
82+
oneof rule {
83+
ThresholdRule threshold_rule = 1;
84+
bytes signature_rule = 2;
85+
}
9586
}
9687

9788
message ThresholdRule {
@@ -127,7 +118,7 @@ message NamespacePolicies {
127118

128119
message PolicyItem {
129120
string namespace = 1;
130-
bytes policy = 2; // This holds the complete NamespacePolicy.
121+
NamespacePolicy policy = 2;
131122
uint64 version = 3;
132123
}
133124

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go 1.24.3
99
require (
1010
github.com/cenkalti/backoff/v4 v4.3.0
1111
github.com/cockroachdb/errors v1.12.0
12-
github.com/consensys/gnark-crypto v0.14.0
12+
github.com/consensys/gnark-crypto v0.18.0
1313
github.com/docker/docker v28.0.0+incompatible
1414
github.com/docker/go-connections v0.5.0
1515
github.com/fsouza/go-dockerclient v1.12.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,8 @@ github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZe
681681
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
682682
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
683683
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
684-
github.com/consensys/gnark-crypto v0.18.1 h1:RyLV6UhPRoYYzaFnPQA4qK3DyuDgkTgskDdoGqFt3fI=
685-
github.com/consensys/gnark-crypto v0.18.1/go.mod h1:L3mXGFTe1ZN+RSJ+CLjUt9x7PNdx8ubaYfDROyp2Z8c=
684+
github.com/consensys/gnark-crypto v0.18.0 h1:vIye/FqI50VeAr0B3dx+YjeIvmc3LWz4yEfbWBpTUf0=
685+
github.com/consensys/gnark-crypto v0.18.0/go.mod h1:L3mXGFTe1ZN+RSJ+CLjUt9x7PNdx8ubaYfDROyp2Z8c=
686686
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
687687
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
688688
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=

integration/test/config_update_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313

1414
"github.com/onsi/gomega"
1515
"github.com/stretchr/testify/require"
16-
"google.golang.org/protobuf/proto"
1716

1817
"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
1918
"github.com/hyperledger/fabric-x-committer/api/protoloadgen"
@@ -88,13 +87,11 @@ func TestConfigUpdate(t *testing.T) {
8887

8988
c.AddOrUpdateNamespaces(t, types.MetaNamespaceID)
9089
metaPolicy := c.TxBuilder.TxSigner.HashSigners[types.MetaNamespaceID].GetVerificationPolicy()
91-
key := &protoblocktx.ThresholdRule{}
92-
require.NoError(t, proto.Unmarshal(metaPolicy.Policy, key))
9390
submitConfigBlock := func(endpoints []*ordererconn.Endpoint) {
9491
ordererEnv.SubmitConfigBlock(t, &workload.ConfigBlock{
9592
ChannelID: c.SystemConfig.Policy.ChannelID,
9693
OrdererEndpoints: endpoints,
97-
MetaNamespaceVerificationKey: key.PublicKey,
94+
MetaNamespaceVerificationKey: metaPolicy.GetThresholdRule().PublicKey,
9895
})
9996
}
10097
submitConfigBlock(ordererEnv.AllRealOrdererEndpoints())

loadgen/adapters/sigverifier.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/cockroachdb/errors"
1313
"golang.org/x/sync/errgroup"
14-
"google.golang.org/protobuf/proto"
1514

1615
"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
1716
"github.com/hyperledger/fabric-x-committer/api/protosigverifierservice"
@@ -101,15 +100,11 @@ func createUpdate(policy *workload.PolicyProfile) (*protosigverifierservice.Upda
101100
if ns == types.MetaNamespaceID {
102101
continue
103102
}
104-
policyBytes, err := proto.Marshal(p.GetVerificationPolicy())
105-
if err != nil {
106-
return nil, errors.Wrap(err, "failed to serialize policy")
107-
}
108103
updateMsg.NamespacePolicies.Policies = append(
109104
updateMsg.NamespacePolicies.Policies,
110105
&protoblocktx.PolicyItem{
111106
Namespace: ns,
112-
Policy: policyBytes,
107+
Policy: p.GetVerificationPolicy(),
113108
},
114109
)
115110
}

loadgen/workload/config_tx.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ func CreateConfigBlock(policy *PolicyProfile) (*common.Block, error) {
9292
MetaNamespaceVerificationKey: policyNamespaceSigner.pubKey,
9393
OrdererEndpoints: policy.OrdererEndpoints,
9494
ChannelID: policy.ChannelID,
95-
})
95+
}, genesisconfig.TwoOrgsSampleFabricX)
9696
}
9797

9898
// CreateDefaultConfigBlock creates a config block with default values.
99-
func CreateDefaultConfigBlock(conf *ConfigBlock) (*common.Block, error) {
100-
configBlock := genesisconfig.Load(genesisconfig.TwoOrgsSampleFabricX, configtest.GetDevConfigDir())
99+
func CreateDefaultConfigBlock(conf *ConfigBlock, profileName string) (*common.Block, error) {
100+
configBlock := genesisconfig.Load(profileName, configtest.GetDevConfigDir())
101101
tlsCertPath := filepath.Join(configtest.GetDevConfigDir(), "msp", "tlscacerts", "tlsroot.pem")
102102
for _, consenter := range configBlock.Orderer.ConsenterMapping {
103103
consenter.Identity = tlsCertPath

loadgen/workload/sign.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"os"
1111

1212
"github.com/cockroachdb/errors"
13-
"github.com/hyperledger/fabric-x-common/protoutil"
1413

1514
"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
1615
"github.com/hyperledger/fabric-x-committer/api/types"
@@ -132,11 +131,11 @@ func (e *HashSignerVerifier) Verify(txID string, tx *protoblocktx.Tx, nsIndex in
132131
// GetVerificationPolicy returns the verification policy.
133132
func (e *HashSignerVerifier) GetVerificationPolicy() *protoblocktx.NamespacePolicy {
134133
return &protoblocktx.NamespacePolicy{
135-
Type: protoblocktx.PolicyType_THRESHOLD_RULE,
136-
Policy: protoutil.MarshalOrPanic(&protoblocktx.ThresholdRule{
137-
Scheme: e.scheme,
138-
PublicKey: e.pubKey,
139-
}),
134+
Rule: &protoblocktx.NamespacePolicy_ThresholdRule{
135+
ThresholdRule: &protoblocktx.ThresholdRule{
136+
Scheme: e.scheme, PublicKey: e.pubKey,
137+
},
138+
},
140139
}
141140
}
142141

mock/test_exports.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313

1414
"github.com/hyperledger/fabric-protos-go-apiv2/common"
15+
"github.com/hyperledger/fabric-x-common/internaltools/configtxgen/genesisconfig"
1516
"github.com/stretchr/testify/require"
1617
"google.golang.org/grpc"
1718

@@ -179,7 +180,7 @@ func (e *OrdererTestEnv) SubmitConfigBlock(t *testing.T, conf *workload.ConfigBl
179180
if conf.MetaNamespaceVerificationKey == nil {
180181
conf.MetaNamespaceVerificationKey = e.TestConfig.MetaNamespaceVerificationKey
181182
}
182-
configBlock, err := workload.CreateDefaultConfigBlock(conf)
183+
configBlock, err := workload.CreateDefaultConfigBlock(conf, genesisconfig.TwoOrgsSampleFabricX)
183184
require.NoError(t, err)
184185
e.Orderer.SubmitBlock(t.Context(), configBlock)
185186
return configBlock

service/coordinator/coordinator_test.go

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"time"
1616

1717
"github.com/google/uuid"
18-
"github.com/hyperledger/fabric-x-common/protoutil"
1918
"github.com/stretchr/testify/assert"
2019
"github.com/stretchr/testify/require"
2120
"google.golang.org/protobuf/proto"
@@ -26,10 +25,10 @@ import (
2625
"github.com/hyperledger/fabric-x-committer/mock"
2726
"github.com/hyperledger/fabric-x-committer/service/coordinator/dependencygraph"
2827
"github.com/hyperledger/fabric-x-committer/service/vc"
28+
"github.com/hyperledger/fabric-x-committer/service/verifier/policy"
2929
"github.com/hyperledger/fabric-x-committer/utils/channel"
3030
"github.com/hyperledger/fabric-x-committer/utils/connection"
3131
"github.com/hyperledger/fabric-x-committer/utils/monitoring"
32-
"github.com/hyperledger/fabric-x-committer/utils/signature"
3332
"github.com/hyperledger/fabric-x-committer/utils/test"
3433
)
3534

@@ -157,14 +156,7 @@ func (e *coordinatorTestEnv) ensureStreamActive(t *testing.T) {
157156

158157
func (e *coordinatorTestEnv) createNamespaces(t *testing.T, blkNum int, nsIDs ...string) {
159158
t.Helper()
160-
p := &protoblocktx.NamespacePolicy{
161-
Type: protoblocktx.PolicyType_THRESHOLD_RULE,
162-
Policy: protoutil.MarshalOrPanic(&protoblocktx.ThresholdRule{
163-
Scheme: signature.Ecdsa,
164-
PublicKey: []byte("publicKey"),
165-
}),
166-
}
167-
pBytes, err := proto.Marshal(p)
159+
pBytes, err := proto.Marshal(policy.MakeECDSAThresholdRuleNsPolicy([]byte("publicKey")))
168160
require.NoError(t, err)
169161

170162
blockNum := uint64(blkNum) //nolint:gosec // int -> uint64.
@@ -258,14 +250,7 @@ func TestCoordinatorServiceValidTx(t *testing.T) {
258250

259251
preMetricsValue := test.GetIntMetricValue(t, env.coordinator.metrics.transactionReceivedTotal)
260252

261-
p := &protoblocktx.NamespacePolicy{
262-
Type: protoblocktx.PolicyType_THRESHOLD_RULE,
263-
Policy: protoutil.MarshalOrPanic(&protoblocktx.ThresholdRule{
264-
Scheme: signature.Ecdsa,
265-
PublicKey: []byte("publicKey"),
266-
}),
267-
}
268-
pBytes, err := proto.Marshal(p)
253+
pBytes, err := proto.Marshal(policy.MakeECDSAThresholdRuleNsPolicy([]byte("publicKey")))
269254
require.NoError(t, err)
270255
err = env.csStream.Send(&protocoordinatorservice.Batch{
271256
Txs: []*protocoordinatorservice.Tx{
@@ -378,14 +363,7 @@ func TestCoordinatorServiceDependentOrderedTxs(t *testing.T) {
378363
utNsVersion := uint64(0)
379364
mainKey := []byte("main-key")
380365
subKey := []byte("sub-key")
381-
p := &protoblocktx.NamespacePolicy{
382-
Type: protoblocktx.PolicyType_THRESHOLD_RULE,
383-
Policy: protoutil.MarshalOrPanic(&protoblocktx.ThresholdRule{
384-
Scheme: signature.Ecdsa,
385-
PublicKey: []byte("public-key"),
386-
}),
387-
}
388-
pBytes, err := proto.Marshal(p)
366+
pBytes, err := proto.Marshal(policy.MakeECDSAThresholdRuleNsPolicy([]byte("publicKey")))
389367
require.NoError(t, err)
390368

391369
// We send a block with a series of TXs with apparent conflicts, but all should be committed successfully if
@@ -595,13 +573,7 @@ func TestCoordinatorRecovery(t *testing.T) {
595573
// To simulate a failure scenario in which a block is partially committed, we first create block 2
596574
// with two transaction but actual block 2 is supposed to have four transactions. Once the partial block 2
597575
// is committed, we will restart the service and send a full block 2 with all four transactions.
598-
nsPolicy, err := proto.Marshal(&protoblocktx.NamespacePolicy{
599-
Type: protoblocktx.PolicyType_THRESHOLD_RULE,
600-
Policy: protoutil.MarshalOrPanic(&protoblocktx.ThresholdRule{
601-
Scheme: signature.Ecdsa,
602-
PublicKey: []byte("publicKey"),
603-
}),
604-
})
576+
nsPolicy, err := proto.Marshal(policy.MakeECDSAThresholdRuleNsPolicy([]byte("publicKey")))
605577
require.NoError(t, err)
606578
block2 := &protocoordinatorservice.Batch{
607579
Txs: []*protocoordinatorservice.Tx{

0 commit comments

Comments
 (0)