Unverified Commit 407c8fa1 authored by Jason Yellick's avatar Jason Yellick Committed by Artem Barger
Browse files

FAB-14037 Remove unreachable code



There are some untestable and unreachable code paths in the encoder
because it's not actually possible to fail to generate a genesis block.
The signature reports that it can return an error but has no cases where
it returns a non-nil error.  This CR simply removes that dead code.

Change-Id: I9559bf4a8f518ac3f97fb1256e9306e975ec1ce2
Signed-off-by: default avatarJason Yellick <jyellick@us.ibm.com>
parent df3ef22a
......@@ -31,9 +31,9 @@ func MakeGenesisBlock(chainID string) (*cb.Block, error) {
logger.Panicf("Error creating channel config: %s", err)
}
gb, err := genesis.NewFactoryImpl(channelGroup).Block(chainID)
if err != nil || gb == nil {
return gb, err
gb := genesis.NewFactoryImpl(channelGroup).Block(chainID)
if gb == nil {
return gb, nil
}
txsFilter := util.NewTxValidationFlagsSetValue(len(gb.Data.Data), peer.TxValidationCode_VALID)
......@@ -72,5 +72,5 @@ func MakeGenesisBlockFromMSPs(chainID string, appMSPConf, ordererMSPConf *msppro
channelGroup.Groups[channelconfig.OrdererGroupKey].Groups[ordererOrgID] = ordererOrg
channelGroup.Groups[channelconfig.ApplicationGroupKey].Groups[appOrgID] = applicationOrg
return genesis.NewFactoryImpl(channelGroup).Block(chainID)
return genesis.NewFactoryImpl(channelGroup).Block(chainID), nil
}
......@@ -31,7 +31,7 @@ const (
// Factory facilitates the creation of genesis blocks.
type Factory interface {
// Block returns a genesis block for a given channel ID.
Block(channelID string) (*cb.Block, error)
Block(channelID string) *cb.Block
}
type factory struct {
......@@ -44,7 +44,7 @@ func NewFactoryImpl(channelGroup *cb.ConfigGroup) Factory {
}
// Block constructs and returns a genesis block for a given channel ID.
func (f *factory) Block(channelID string) (*cb.Block, error) {
func (f *factory) Block(channelID string) *cb.Block {
payloadChannelHeader := utils.MakeChannelHeader(cb.HeaderType_CONFIG, msgVersion, channelID, epoch)
payloadSignatureHeader := utils.MakeSignatureHeader(nil, utils.CreateNonceOrPanic())
utils.SetTxID(payloadChannelHeader, payloadSignatureHeader)
......@@ -58,5 +58,5 @@ func (f *factory) Block(channelID string) (*cb.Block, error) {
block.Metadata.Metadata[cb.BlockMetadataIndex_LAST_CONFIG] = utils.MarshalOrPanic(&cb.Metadata{
Value: utils.MarshalOrPanic(&cb.LastConfig{Index: 0}),
})
return block, nil
return block
}
/*
Copyright IBM Corp. 2017 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 genesis
......@@ -26,13 +16,12 @@ import (
func TestBasicSanity(t *testing.T) {
impl := NewFactoryImpl(cb.NewConfigGroup())
_, err := impl.Block("testchainid")
assert.NoError(t, err, "Basic sanity fails")
impl.Block("testchainid")
}
func TestForTransactionID(t *testing.T) {
impl := NewFactoryImpl(cb.NewConfigGroup())
block, _ := impl.Block("testchainid")
block := impl.Block("testchainid")
configEnv, _ := utils.ExtractEnvelope(block, 0)
configEnvPayload, _ := utils.ExtractPayload(configEnv)
configEnvPayloadChannelHeader, _ := utils.UnmarshalChannelHeader(configEnvPayload.GetHeader().ChannelHeader)
......
/*
Copyright IBM Corp. 2016 All Rights Reserved.
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
......@@ -463,18 +463,10 @@ func New(config *genesisconfig.Profile) *Bootstrapper {
// GenesisBlock produces a genesis block for the default test chain id
func (bs *Bootstrapper) GenesisBlock() *cb.Block {
block, err := genesis.NewFactoryImpl(bs.channelGroup).Block(genesisconfig.TestChainID)
if err != nil {
logger.Panicf("Error creating genesis block from channel group: %s", err)
}
return block
return genesis.NewFactoryImpl(bs.channelGroup).Block(genesisconfig.TestChainID)
}
// GenesisBlockForChannel produces a genesis block for a given channel ID
func (bs *Bootstrapper) GenesisBlockForChannel(channelID string) *cb.Block {
block, err := genesis.NewFactoryImpl(bs.channelGroup).Block(channelID)
if err != nil {
logger.Panicf("Error creating genesis block from channel group: %s", err)
}
return block
return genesis.NewFactoryImpl(bs.channelGroup).Block(channelID)
}
......@@ -508,8 +508,7 @@ func TestPeerConfiger_SubmittingOrdererGenesis(t *testing.T) {
conf.Application = nil
cg, err := encoder.NewChannelGroup(conf)
assert.NoError(t, err)
block, err := genesis.NewFactoryImpl(cg).Block("mytestchainid")
assert.NoError(t, err)
block := genesis.NewFactoryImpl(cg).Block("mytestchainid")
blockBytes := utils.MarshalOrPanic(block)
// Failed path: wrong parameter type
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment