Skip to content

Commit 33d9934

Browse files
C0rWinadarshsaraf123
authored andcommitted
[FAB-11990] create raft chain with channel configs
Propagate Raft algorithm parameters from channel configuration into Raft chain instance. Change-Id: I8fe53dc8f3bdd98f7d2cb3c27e446688ca1c636e Signed-off-by: Artem Barger <bartem@il.ibm.com>
1 parent ddfea45 commit 33d9934

File tree

4 files changed

+77
-42
lines changed

4 files changed

+77
-42
lines changed

orderer/consensus/etcdraft/consenter.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ func (c *Consenter) HandleChain(support consensus.ConsenterSupport, metadata *co
9494
if err := proto.Unmarshal(support.SharedConfig().ConsensusMetadata(), m); err != nil {
9595
return nil, errors.Wrap(err, "failed to unmarshal consensus metadata")
9696
}
97+
98+
if m.Options == nil {
99+
return nil, errors.New("etcdraft options have not been provided")
100+
}
101+
97102
id, err := c.detectSelfID(m)
98103
if err != nil {
99104
return nil, errors.WithStack(err)
@@ -110,12 +115,11 @@ func (c *Consenter) HandleChain(support consensus.ConsenterSupport, metadata *co
110115
Storage: raft.NewMemoryStorage(),
111116
Logger: c.Logger,
112117

113-
// TODO make options for raft configurable via channel configs
114-
TickInterval: 100 * time.Millisecond,
115-
ElectionTick: 10,
116-
HeartbeatTick: 1,
117-
MaxInflightMsgs: 256,
118-
MaxSizePerMsg: 1024 * 1024, // This could potentially be deduced from max block size
118+
TickInterval: time.Duration(m.Options.TickInterval) * time.Millisecond,
119+
ElectionTick: int(m.Options.ElectionTick),
120+
HeartbeatTick: int(m.Options.HeartbeatTick),
121+
MaxInflightMsgs: int(m.Options.MaxInflightMsgs),
122+
MaxSizePerMsg: m.Options.MaxSizePerMsg,
119123

120124
Peers: peers,
121125
}

orderer/consensus/etcdraft/consenter_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ var _ = Describe("Consenter", func() {
103103
Consenters: []*etcdraftproto.Consenter{
104104
{ServerTlsCert: certBytes},
105105
},
106+
Options: &etcdraftproto.Options{
107+
TickInterval: 100,
108+
ElectionTick: 10,
109+
HeartbeatTick: 1,
110+
MaxInflightMsgs: 256,
111+
MaxSizePerMsg: 1048576,
112+
},
106113
}
107114
metadata := utils.MarshalOrPanic(m)
108115
support.SharedConfigReturns(&mockconfig.Orderer{ConsensusMetadataVal: metadata})
@@ -121,6 +128,13 @@ var _ = Describe("Consenter", func() {
121128
Consenters: []*etcdraftproto.Consenter{
122129
{ServerTlsCert: []byte("cert.orderer1.org1")},
123130
},
131+
Options: &etcdraftproto.Options{
132+
TickInterval: 100,
133+
ElectionTick: 10,
134+
HeartbeatTick: 1,
135+
MaxInflightMsgs: 256,
136+
MaxSizePerMsg: 1048576,
137+
},
124138
}
125139
metadata := utils.MarshalOrPanic(m)
126140
support.SharedConfigReturns(&mockconfig.Orderer{ConsensusMetadataVal: metadata})
@@ -131,6 +145,23 @@ var _ = Describe("Consenter", func() {
131145
Expect(chain).To(BeNil())
132146
Expect(err).To(MatchError("failed to detect own Raft ID because no matching certificate found"))
133147
})
148+
149+
It("fails to handle chain if etcdraft options have not been provided", func() {
150+
m := &etcdraftproto.Metadata{
151+
Consenters: []*etcdraftproto.Consenter{
152+
{ServerTlsCert: []byte("cert.orderer1.org1")},
153+
},
154+
}
155+
metadata := utils.MarshalOrPanic(m)
156+
support.SharedConfigReturns(&mockconfig.Orderer{ConsensusMetadataVal: metadata})
157+
158+
consenter := newConsenter(chainGetter)
159+
160+
chain, err := consenter.HandleChain(support, nil)
161+
Expect(chain).To(BeNil())
162+
Expect(err).To(MatchError("etcdraft options have not been provided"))
163+
})
164+
134165
})
135166

136167
func newConsenter(chainGetter *mocks.ChainGetter) *etcdraft.Consenter {

protos/orderer/etcdraft/configuration.pb.go

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

protos/orderer/etcdraft/configuration.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ message Consenter {
2929
// Options to be specified for all the etcd/raft nodes. These can be modified on a
3030
// per-channel basis.
3131
message Options {
32-
uint32 tick_interval = 1; // specified in miliseconds
32+
uint64 tick_interval = 1; // specified in miliseconds
3333
uint32 election_tick = 2;
3434
uint32 heartbeat_tick = 3;
3535
uint32 max_inflight_msgs = 4;

0 commit comments

Comments
 (0)