From b8176724736fe91dba5d3b1d3c22761918b157fd Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Mon, 17 Jul 2017 10:55:52 -0400 Subject: [PATCH] [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 --- orderer/solo/consensus.go | 16 +++++++--------- orderer/solo/consensus_test.go | 10 +++++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/orderer/solo/consensus.go b/orderer/solo/consensus.go index 84879f7dc1f..1cb76722707 100644 --- a/orderer/solo/consensus.go +++ b/orderer/solo/consensus.go @@ -29,10 +29,9 @@ var logger = logging.MustGetLogger("orderer/solo") type consenter struct{} type chain struct { - support multichain.ConsenterSupport - batchTimeout time.Duration - sendChan chan *cb.Envelope - exitChan chan struct{} + support multichain.ConsenterSupport + sendChan chan *cb.Envelope + exitChan chan struct{} } // New creates a new consenter for the solo consensus scheme. @@ -49,10 +48,9 @@ func (solo *consenter) HandleChain(support multichain.ConsenterSupport, metadata func newChain(support multichain.ConsenterSupport) *chain { return &chain{ - batchTimeout: support.SharedConfig().BatchTimeout(), - support: support, - sendChan: make(chan *cb.Envelope), - exitChan: make(chan struct{}), + support: support, + sendChan: make(chan *cb.Envelope), + exitChan: make(chan struct{}), } } @@ -92,7 +90,7 @@ func (ch *chain) main() { case msg := <-ch.sendChan: batches, committers, ok := ch.support.BlockCutter().Ordered(msg) if ok && len(batches) == 0 && timer == nil { - timer = time.After(ch.batchTimeout) + timer = time.After(ch.support.SharedConfig().BatchTimeout()) continue } for i, batch := range batches { diff --git a/orderer/solo/consensus_test.go b/orderer/solo/consensus_test.go index f43e1c1f6ca..93bedf29515 100644 --- a/orderer/solo/consensus_test.go +++ b/orderer/solo/consensus_test.go @@ -143,6 +143,14 @@ func TestBatchTimer(t *testing.T) { t.Fatalf("Did not create the second batch, indicating that the timer was not appopriately reset") } + support.SharedConfigVal.BatchTimeoutVal, _ = time.ParseDuration("10s") + syncQueueMessage(testMessage, bs, support.BlockCutterVal) + select { + case <-support.Blocks: + t.Fatalf("Created another batch, indicating that the timer was not appopriately re-read") + case <-time.After(100 * time.Millisecond): + } + bs.Halt() select { case <-support.Blocks: @@ -175,7 +183,7 @@ func TestBatchTimerHaltOnFilledBatch(t *testing.T) { } // Change the batch timeout to be near instant, if the timer was not reset, it will still be waiting an hour - bs.batchTimeout = time.Millisecond + support.SharedConfigVal.BatchTimeoutVal = time.Millisecond support.BlockCutterVal.CutNext = false syncQueueMessage(testMessage, bs, support.BlockCutterVal)