Skip to content

Commit

Permalink
FAB-13666 consensus migration: kafka2raft green path #3
Browse files Browse the repository at this point in the history
This is the third of four (3/4) sub-tasks that focus on
the "green" path of consensus-type migration from Kafka to Raft.

By "green" we mean that there are no failures or aborts along
the way. The 4 sub-tasks are staged in a way that minimizes
dependencies between them.

In this sub-task we introduce changes to the Kafka-base OSNs
such that they implement the entire green path, until they commit
migration and are ready to be restarted. This
change concludes all the changes needed to implement the green
path on the "Kafka" side.

See respective JIRA item for further details.

Note: some of the mocks had to be re-generated by couterfeiter to make the
unit tests build.

Change-Id: I2747f7d8017c344e9ff3bdd9dd98cbaa1480083f
Signed-off-by: Yoav Tock <tock@il.ibm.com>
  • Loading branch information
tock-ibm committed Feb 17, 2019
1 parent 8762acd commit 4950edd
Show file tree
Hide file tree
Showing 18 changed files with 2,054 additions and 1,105 deletions.
537 changes: 311 additions & 226 deletions orderer/common/broadcast/mock/channel_support.go

Large diffs are not rendered by default.

116 changes: 96 additions & 20 deletions orderer/common/broadcast/mock/channel_support_registrar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 8 additions & 14 deletions orderer/common/multichannel/blockwriter_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
SPDX-License-Identifier: Apache-2.0
*/

package multichannel
Expand All @@ -23,6 +13,8 @@ import (
"github.com/hyperledger/fabric/common/crypto"
"github.com/hyperledger/fabric/common/ledger/blockledger"
mockconfigtx "github.com/hyperledger/fabric/common/mocks/configtx"
"github.com/hyperledger/fabric/common/tools/configtxgen/configtxgentest"
"github.com/hyperledger/fabric/common/tools/configtxgen/encoder"
genesisconfig "github.com/hyperledger/fabric/common/tools/configtxgen/localconfig"
cb "github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
Expand Down Expand Up @@ -165,7 +157,9 @@ func TestWriteConfigBlock(t *testing.T) {
}

func TestGoodWriteConfig(t *testing.T) {
l := NewRAMLedger(10)
confSys := configtxgentest.Load(genesisconfig.SampleInsecureSoloProfile)
genesisBlockSys := encoder.New(confSys).GenesisBlock()
_, l := newRAMLedgerAndFactory(10, genesisconfig.TestChainID, genesisBlockSys)

bw := &BlockWriter{
support: &mockBlockWriterSupport{
Expand All @@ -176,7 +170,7 @@ func TestGoodWriteConfig(t *testing.T) {
}

ctx := makeConfigTx(genesisconfig.TestChainID, 1)
block := cb.NewBlock(1, genesisBlock.Header.Hash())
block := cb.NewBlock(1, genesisBlockSys.Header.Hash())
block.Data.Data = [][]byte{utils.MarshalOrPanic(ctx)}
consenterMetadata := []byte("foo")
bw.WriteConfigBlock(block, consenterMetadata)
Expand Down
12 changes: 11 additions & 1 deletion orderer/common/multichannel/chainsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type ChainSupport struct {
consensus.Chain
cutter blockcutter.Receiver
crypto.LocalSigner
// Needed for consensus-type migration: to execute the migration state machine correctly,
// chains need to know if they are system or standard channel.
systemChannel bool
}

func newChainSupport(
Expand All @@ -38,7 +41,6 @@ func newChainSupport(
) *ChainSupport {
// Read in the last block and metadata for the channel
lastBlock := blockledger.GetBlock(ledgerResources, ledgerResources.Height()-1)

metadata, err := utils.GetMetadataFromBlock(lastBlock, cb.BlockMetadataIndex_ORDERER)
// Assuming a block created with cb.NewBlock(), this should not
// error even if the orderer metadata is an empty byte slice
Expand All @@ -57,6 +59,9 @@ func newChainSupport(
),
}

// When ConsortiumsConfig exists, it is the system channel
_, cs.systemChannel = ledgerResources.ConsortiumsConfig()

// Set up the msgprocessor
cs.Processor = msgprocessor.NewStandardChannel(cs, msgprocessor.CreateStandardChannelFilters(cs))

Expand Down Expand Up @@ -172,3 +177,8 @@ func (cs *ChainSupport) VerifyBlockSignature(sd []*cb.SignedData, envelope *cb.C
}
return nil
}

// IsSystemChannel returns true if this is the system channel.
func (cs *ChainSupport) IsSystemChannel() bool {
return cs.systemChannel
}
Loading

0 comments on commit 4950edd

Please sign in to comment.