Skip to content

Commit b817672

Browse files
author
Jason Yellick
committed
[FAB-5341] Solo should respect batchtimeout reconf
Solo currently only reads the batch timeout at startup. This is a problem, because the batch timeout may be changed dynamically through a reconfiguration transaction. This CR simply causes solo to re-query the batch timeout from the config each time the timer is initialized, rather than once at creation time. Change-Id: I493fa4edddef40821336aa610ab242a3ffe97d26 Signed-off-by: Jason Yellick <[email protected]>
1 parent 36b08c7 commit b817672

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

orderer/solo/consensus.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ var logger = logging.MustGetLogger("orderer/solo")
2929
type consenter struct{}
3030

3131
type chain struct {
32-
support multichain.ConsenterSupport
33-
batchTimeout time.Duration
34-
sendChan chan *cb.Envelope
35-
exitChan chan struct{}
32+
support multichain.ConsenterSupport
33+
sendChan chan *cb.Envelope
34+
exitChan chan struct{}
3635
}
3736

3837
// New creates a new consenter for the solo consensus scheme.
@@ -49,10 +48,9 @@ func (solo *consenter) HandleChain(support multichain.ConsenterSupport, metadata
4948

5049
func newChain(support multichain.ConsenterSupport) *chain {
5150
return &chain{
52-
batchTimeout: support.SharedConfig().BatchTimeout(),
53-
support: support,
54-
sendChan: make(chan *cb.Envelope),
55-
exitChan: make(chan struct{}),
51+
support: support,
52+
sendChan: make(chan *cb.Envelope),
53+
exitChan: make(chan struct{}),
5654
}
5755
}
5856

@@ -92,7 +90,7 @@ func (ch *chain) main() {
9290
case msg := <-ch.sendChan:
9391
batches, committers, ok := ch.support.BlockCutter().Ordered(msg)
9492
if ok && len(batches) == 0 && timer == nil {
95-
timer = time.After(ch.batchTimeout)
93+
timer = time.After(ch.support.SharedConfig().BatchTimeout())
9694
continue
9795
}
9896
for i, batch := range batches {

orderer/solo/consensus_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ func TestBatchTimer(t *testing.T) {
143143
t.Fatalf("Did not create the second batch, indicating that the timer was not appopriately reset")
144144
}
145145

146+
support.SharedConfigVal.BatchTimeoutVal, _ = time.ParseDuration("10s")
147+
syncQueueMessage(testMessage, bs, support.BlockCutterVal)
148+
select {
149+
case <-support.Blocks:
150+
t.Fatalf("Created another batch, indicating that the timer was not appopriately re-read")
151+
case <-time.After(100 * time.Millisecond):
152+
}
153+
146154
bs.Halt()
147155
select {
148156
case <-support.Blocks:
@@ -175,7 +183,7 @@ func TestBatchTimerHaltOnFilledBatch(t *testing.T) {
175183
}
176184

177185
// Change the batch timeout to be near instant, if the timer was not reset, it will still be waiting an hour
178-
bs.batchTimeout = time.Millisecond
186+
support.SharedConfigVal.BatchTimeoutVal = time.Millisecond
179187

180188
support.BlockCutterVal.CutNext = false
181189
syncQueueMessage(testMessage, bs, support.BlockCutterVal)

0 commit comments

Comments
 (0)