Skip to content

Commit 39bd8e2

Browse files
author
Jason Yellick
committed
[FAB-1568] Add orderer shared config ingresspolicy
https://jira.hyperledger.org/browse/FAB-1568 This is the third a series meant to enable broadcast filtering based on policy. This changeset adds an IngressPolicy orderer configuration item, which references a policy by name. It is not currently used, but will eventually be used by the signature filter. Change-Id: I52598fa395d95112accfd8baa69c9be3d9cd6bdd Signed-off-by: Jason Yellick <[email protected]>
1 parent 0587bb2 commit 39bd8e2

File tree

7 files changed

+111
-51
lines changed

7 files changed

+111
-51
lines changed

orderer/common/sharedconfig/sharedconfig.go

+18
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const (
4545

4646
// KafkaBrokersKey is the cb.ConfigurationItem type key name for the KafkaBrokers message
4747
KafkaBrokersKey = "KafkaBrokers"
48+
49+
// IngressPolicyKey is the cb.ConfigurationItem type key name for the IngressPolicy message
50+
IngressPolicyKey = "IngressPolicy"
4851
)
4952

5053
var logger = logging.MustGetLogger("orderer/common/sharedconfig")
@@ -71,6 +74,9 @@ type Manager interface {
7174
// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
7275
// used for ordering
7376
KafkaBrokers() []string
77+
78+
// IngressPolicy returns the name of the policy to validate incoming broadcast messages against
79+
IngressPolicy() string
7480
}
7581

7682
type ordererConfig struct {
@@ -79,6 +85,7 @@ type ordererConfig struct {
7985
batchTimeout time.Duration
8086
chainCreators []string
8187
kafkaBrokers []string
88+
ingressPolicy string
8289
}
8390

8491
// ManagerImpl is an implementation of Manager and configtx.ConfigHandler
@@ -123,6 +130,11 @@ func (pm *ManagerImpl) KafkaBrokers() []string {
123130
return pm.config.kafkaBrokers
124131
}
125132

133+
// IngressPolicy returns the name of the policy to validate incoming broadcast messages against
134+
func (pm *ManagerImpl) IngressPolicy() string {
135+
return pm.config.ingressPolicy
136+
}
137+
126138
// BeginConfig is used to start a new configuration proposal
127139
func (pm *ManagerImpl) BeginConfig() {
128140
if pm.pendingConfig != nil {
@@ -194,6 +206,12 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
194206
return fmt.Errorf("Unmarshaling error for ChainCreator: %s", err)
195207
}
196208
pm.pendingConfig.chainCreators = chainCreators.Policies
209+
case IngressPolicyKey:
210+
ingressPolicy := &ab.IngressPolicy{}
211+
if err := proto.Unmarshal(configItem.Value, ingressPolicy); err != nil {
212+
return fmt.Errorf("Unmarshaling error for IngressPolicy: %s", err)
213+
}
214+
pm.pendingConfig.ingressPolicy = ingressPolicy.Name
197215
case KafkaBrokersKey:
198216
kafkaBrokers := &ab.KafkaBrokers{}
199217
if err := proto.Unmarshal(configItem.Value, kafkaBrokers); err != nil {

orderer/common/sharedconfig/sharedconfig_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,44 @@ func TestKafkaBrokers(t *testing.T) {
298298
return
299299
}
300300
}
301+
302+
func TestIngressPolicy(t *testing.T) {
303+
endPolicy := "foo"
304+
invalidMessage :=
305+
&cb.ConfigurationItem{
306+
Type: cb.ConfigurationItem_Orderer,
307+
Key: IngressPolicyKey,
308+
Value: []byte("Garbage Data"),
309+
}
310+
validMessage := &cb.ConfigurationItem{
311+
Type: cb.ConfigurationItem_Orderer,
312+
Key: IngressPolicyKey,
313+
Value: utils.MarshalOrPanic(&ab.IngressPolicy{Name: endPolicy}),
314+
}
315+
m := NewManagerImpl()
316+
m.BeginConfig()
317+
318+
err := m.ProposeConfig(validMessage)
319+
if err != nil {
320+
t.Fatalf("Error applying valid config: %s", err)
321+
}
322+
323+
m.CommitConfig()
324+
m.BeginConfig()
325+
326+
err = m.ProposeConfig(invalidMessage)
327+
if err == nil {
328+
t.Fatalf("Should have failed on invalid message")
329+
}
330+
331+
err = m.ProposeConfig(validMessage)
332+
if err != nil {
333+
t.Fatalf("Error re-applying valid config: %s", err)
334+
}
335+
336+
m.CommitConfig()
337+
338+
if nowPolicy := m.IngressPolicy(); nowPolicy != endPolicy {
339+
t.Fatalf("IngressPolicy should have ended as %s but was %s", endPolicy, nowPolicy)
340+
}
341+
}

orderer/mocks/sharedconfig/sharedconfig.go

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type Manager struct {
3131
ChainCreatorsVal []string
3232
// KafkaBrokersVal is returned as the result of KafkaBrokers()
3333
KafkaBrokersVal []string
34+
// IngressPolicyVal is returned as the result of IngressPolicy()
35+
IngressPolicyVal string
3436
}
3537

3638
// ConsensusType returns the ConsensusTypeVal
@@ -57,3 +59,8 @@ func (scm *Manager) ChainCreators() []string {
5759
func (scm *Manager) KafkaBrokers() []string {
5860
return scm.KafkaBrokersVal
5961
}
62+
63+
// IngressPolicy returns the IngressPolicyVal
64+
func (scm *Manager) IngressPolicy() string {
65+
return scm.IngressPolicyVal
66+
}

orderer/multichain/systemchain_test.go

+6-30
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ package multichain
1919
import (
2020
"reflect"
2121
"testing"
22-
"time"
2322

2423
"github.com/hyperledger/fabric/common/policies"
2524
coreutil "github.com/hyperledger/fabric/core/util"
2625
"github.com/hyperledger/fabric/orderer/common/bootstrap/provisional"
2726
"github.com/hyperledger/fabric/orderer/common/filter"
2827
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
28+
mocksharedconfig "github.com/hyperledger/fabric/orderer/mocks/sharedconfig"
2929
cb "github.com/hyperledger/fabric/protos/common"
3030
ab "github.com/hyperledger/fabric/protos/orderer"
3131
"github.com/hyperledger/fabric/protos/utils"
@@ -47,41 +47,17 @@ func (mpm *mockPolicyManager) GetPolicy(id string) (policies.Policy, bool) {
4747
return mpm.mp, mpm.mp != nil
4848
}
4949

50-
type mockSharedConfig struct {
51-
chainCreators []string
52-
}
53-
54-
func (msc *mockSharedConfig) ConsensusType() string {
55-
panic("Unimplemented")
56-
}
57-
58-
func (msc *mockSharedConfig) BatchSize() *ab.BatchSize {
59-
panic("Unimplemented")
60-
}
61-
62-
func (msc *mockSharedConfig) BatchTimeout() time.Duration {
63-
panic("Unimplemented")
64-
}
65-
66-
func (msc *mockSharedConfig) ChainCreators() []string {
67-
return msc.chainCreators
68-
}
69-
70-
func (msc *mockSharedConfig) KafkaBrokers() []string {
71-
panic("Unimplemented")
72-
}
73-
7450
type mockSupport struct {
7551
mpm *mockPolicyManager
76-
msc *mockSharedConfig
52+
msc *mocksharedconfig.Manager
7753
chainID string
7854
queue []*cb.Envelope
7955
}
8056

8157
func newMockSupport(chainID string) *mockSupport {
8258
return &mockSupport{
8359
mpm: &mockPolicyManager{},
84-
msc: &mockSharedConfig{},
60+
msc: &mocksharedconfig.Manager{},
8561
chainID: chainID,
8662
}
8763
}
@@ -129,7 +105,7 @@ func TestGoodProposal(t *testing.T) {
129105
newChainID := "NewChainID"
130106

131107
mcc := newMockChainCreator()
132-
mcc.ms.msc.chainCreators = []string{provisional.AcceptAllPolicyKey}
108+
mcc.ms.msc.ChainCreatorsVal = []string{provisional.AcceptAllPolicyKey}
133109
mcc.ms.mpm.mp = &mockPolicy{}
134110

135111
chainCreateTx := &cb.ConfigurationItem{
@@ -214,7 +190,7 @@ func TestProposalWithMissingPolicy(t *testing.T) {
214190
newChainID := "NewChainID"
215191

216192
mcc := newMockChainCreator()
217-
mcc.ms.msc.chainCreators = []string{provisional.AcceptAllPolicyKey}
193+
mcc.ms.msc.ChainCreatorsVal = []string{provisional.AcceptAllPolicyKey}
218194

219195
chainCreateTx := &cb.ConfigurationItem{
220196
Key: utils.CreationPolicyKey,
@@ -238,7 +214,7 @@ func TestProposalWithBadDigest(t *testing.T) {
238214

239215
mcc := newMockChainCreator()
240216
mcc.ms.mpm.mp = &mockPolicy{}
241-
mcc.ms.msc.chainCreators = []string{provisional.AcceptAllPolicyKey}
217+
mcc.ms.msc.ChainCreatorsVal = []string{provisional.AcceptAllPolicyKey}
242218

243219
chainCreateTx := &cb.ConfigurationItem{
244220
Key: utils.CreationPolicyKey,

protos/orderer/ab.pb.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/configuration.pb.go

+33-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/configuration.proto

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ message CreationPolicy {
6161
bytes digest = 2;
6262
}
6363

64+
// IngressPolicy is the name of the policy which incoming Broadcast messages are filtered against
65+
message IngressPolicy {
66+
string name = 1;
67+
}
68+
6469
message ChainCreators {
6570
// A list of policies, any of which may be specified as the chain creation
6671
// policy in a chain creation request

0 commit comments

Comments
 (0)