diff --git a/node/consensus/consensus.go b/node/consensus/consensus.go index 14df3f61..83aa98b8 100644 --- a/node/consensus/consensus.go +++ b/node/consensus/consensus.go @@ -106,6 +106,14 @@ func (c *Consensus) Stop() { c.Metrics.Stop() } +func (c *Consensus) SoftStop() { + c.BFT.Stop() + c.Synchronizer.stop() + c.Net.Stop() + c.Metrics.Stop() + c.Logger.Warnf("Soft stop: pending restart") +} + func (c *Consensus) OnConsensus(channel string, sender uint64, request *orderer.ConsensusRequest) error { msg := &smartbftprotos.Message{} if err := proto.Unmarshal(request.Payload, msg); err != nil { @@ -575,6 +583,7 @@ func (c *Consensus) Deliver(proposal smartbft_types.Proposal, signatures []smart if hdr.Num == hdr.DecisionNumOfLastConfigBlock { c.lastConfigBlockNum = hdr.AvailableCommonBlocks[len(hdr.AvailableCommonBlocks)-1].Header.Number c.decisionNumOfLastConfigBlock = hdr.Num + go c.SoftStop() // TODO apply reconfig after deliver } c.stateLock.Unlock() diff --git a/node/consensus/consenter_test.go b/node/consensus/consenter_test.go index a820eb8d..9b81fa99 100644 --- a/node/consensus/consenter_test.go +++ b/node/consensus/consenter_test.go @@ -11,11 +11,14 @@ import ( "github.com/hyperledger/fabric-protos-go-apiv2/common" arma_types "github.com/hyperledger/fabric-x-orderer/common/types" + "github.com/hyperledger/fabric-x-orderer/common/utils" + "github.com/hyperledger/fabric-x-orderer/node/comm/tlsgen" "github.com/hyperledger/fabric-x-orderer/node/consensus" "github.com/hyperledger/fabric-x-orderer/node/consensus/mocks" "github.com/hyperledger/fabric-x-orderer/node/consensus/state" "github.com/hyperledger/fabric-x-orderer/testutil" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestConsenter(t *testing.T) { @@ -108,3 +111,27 @@ func createConsenter(s *state.State, logger arma_types.Logger) *consensus.Consen return consenter } + +func TestConsensusSoftStop(t *testing.T) { + ca, err := tlsgen.NewCA() + require.NoError(t, err) + + genesis := utils.EmptyGenesisBlock("arma") + setup := setupConsensusTest(t, ca, 1, genesis) + + // submit request and verify block is committed + err = createAndSubmitRequest(setup.consensusNodes[0], setup.batcherNodes[0].sk, 1, 1, digest123, 1, 1) + require.NoError(t, err) + + b := <-setup.listeners[0].c + require.Equal(t, uint64(1), b.Header.Number) + + // perform soft stop + setup.consensusNodes[0].SoftStop() + + // submitting new requests should now fail + err = createAndSubmitRequest(setup.consensusNodes[0], setup.batcherNodes[0].sk, 1, 1, digest124, 1, 2) + require.Error(t, err) + + setup.consensusNodes[0].Stop() +}