Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions node/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down
27 changes: 27 additions & 0 deletions node/consensus/consenter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}