Skip to content

Commit 2b6fcf4

Browse files
committed
[FAB-13056] Onboarding: systemchannel from boot block
This change set makes the system channel retrieval for onboarding be based on the content of the bootstrap block, and not in the orderer.yaml. Change-Id: I8009d079d080ac9ab855efa9dc322786605c0344 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent 713dc7a commit 2b6fcf4

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

orderer/common/cluster/replication.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const (
3030
// PullerConfigFromTopLevelConfig creates a PullerConfig from a TopLevel config,
3131
// and from a signer and TLS key cert pair.
3232
// The PullerConfig's channel is initialized to be the system channel.
33-
func PullerConfigFromTopLevelConfig(conf *localconfig.TopLevel, tlsKey, tlsCert []byte, signer crypto.LocalSigner) PullerConfig {
33+
func PullerConfigFromTopLevelConfig(systemChannel string, conf *localconfig.TopLevel, tlsKey, tlsCert []byte, signer crypto.LocalSigner) PullerConfig {
3434
return PullerConfig{
35-
Channel: conf.General.SystemChannel,
35+
Channel: systemChannel,
3636
MaxTotalBufferBytes: conf.General.Cluster.ReplicationBufferSize,
3737
Timeout: conf.General.Cluster.RPCTimeout,
3838
TLSKey: tlsKey,

orderer/common/cluster/replication_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,14 @@ func TestPullerConfigFromTopLevelConfig(t *testing.T) {
214214

215215
topLevelConfig := &localconfig.TopLevel{
216216
General: localconfig.General{
217-
SystemChannel: "system",
218217
Cluster: localconfig.Cluster{
219218
ReplicationBufferSize: 100,
220219
RPCTimeout: time.Hour,
221220
},
222221
},
223222
}
224223

225-
config := cluster.PullerConfigFromTopLevelConfig(topLevelConfig, []byte{1, 2, 3}, []byte{3, 2, 1}, signer)
224+
config := cluster.PullerConfigFromTopLevelConfig("system", topLevelConfig, []byte{1, 2, 3}, []byte{3, 2, 1}, signer)
226225
assert.Equal(t, expected, config)
227226
}
228227

orderer/common/server/onboarding.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/hyperledger/fabric/orderer/common/localconfig"
1616
"github.com/hyperledger/fabric/orderer/consensus/etcdraft"
1717
"github.com/hyperledger/fabric/protos/common"
18+
"github.com/hyperledger/fabric/protos/utils"
1819
)
1920

2021
type replicationInitiator struct {
@@ -33,8 +34,11 @@ func (ri *replicationInitiator) replicateIfNeeded() {
3334
}
3435

3536
consenterCert := etcdraft.ConsenterCertificate(ri.secOpts.Certificate)
36-
37-
pullerConfig := cluster.PullerConfigFromTopLevelConfig(ri.conf, ri.secOpts.Key, ri.secOpts.Certificate, ri.signer)
37+
systemChannelName, err := utils.GetChainIDFromBlock(ri.bootstrapBlock)
38+
if err != nil {
39+
ri.logger.Panicf("Failed extracting system channel name from bootstrap block: %v", err)
40+
}
41+
pullerConfig := cluster.PullerConfigFromTopLevelConfig(systemChannelName, ri.conf, ri.secOpts.Key, ri.secOpts.Certificate, ri.signer)
3842
puller, err := cluster.BlockPullerFromConfigBlock(pullerConfig, ri.bootstrapBlock)
3943
if err != nil {
4044
ri.logger.Panicf("Failed creating puller config from bootstrap block: %v", err)
@@ -44,7 +48,7 @@ func (ri *replicationInitiator) replicateIfNeeded() {
4448

4549
replicator := &cluster.Replicator{
4650
LedgerFactory: ri.lf,
47-
SystemChannel: ri.conf.General.SystemChannel,
51+
SystemChannel: systemChannelName,
4852
BootBlock: ri.bootstrapBlock,
4953
Logger: pullerLogger,
5054
AmIPartOfChannel: consenterCert.IsConsenterOfChannel,

orderer/common/server/onboarding_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ func TestReplicateIfNeeded(t *testing.T) {
147147
return res
148148
}
149149

150+
bootBlockWithCorruptedPayload := copyBlock(bootBlock, 100)
151+
env := &common.Envelope{}
152+
proto.Unmarshal(bootBlockWithCorruptedPayload.Data.Data[0], env)
153+
payload := &common.Payload{}
154+
proto.Unmarshal(env.Payload, payload)
155+
payload.Data = []byte{1, 2, 3}
156+
150157
deliverServer.blockResponses <- &orderer.DeliverResponse{
151158
Type: &orderer.DeliverResponse_Block{Block: bootBlock},
152159
}
@@ -201,8 +208,16 @@ func TestReplicateIfNeeded(t *testing.T) {
201208
{
202209
name: "Block puller initialization failure panics",
203210
systemLedgerHeight: 10,
204-
panicValue: "Failed creating puller config from bootstrap block: block data is nil",
205-
bootBlock: &common.Block{Header: &common.BlockHeader{Number: 10}},
211+
panicValue: "Failed creating puller config from bootstrap block: unable to decode TLS certificate PEM: ",
212+
bootBlock: bootBlockWithCorruptedPayload,
213+
conf: &localconfig.TopLevel{},
214+
secOpts: &comm.SecureOptions{},
215+
},
216+
{
217+
name: "Extraction of sytem channel name fails",
218+
systemLedgerHeight: 10,
219+
panicValue: "Failed extracting system channel name from bootstrap block: failed to retrieve channel id - block is empty",
220+
bootBlock: &common.Block{Header: &common.BlockHeader{Number: 100}},
206221
conf: &localconfig.TopLevel{},
207222
secOpts: &comm.SecureOptions{},
208223
},
@@ -238,7 +253,7 @@ func TestReplicateIfNeeded(t *testing.T) {
238253
{
239254
name: "Replication is needed, but pulling fails",
240255
panicValue: "Failed pulling system channel: " +
241-
"failed obtaining the latest block for channel system",
256+
"failed obtaining the latest block for channel testchainid",
242257
shouldConnect: true,
243258
systemLedgerHeight: 10,
244259
bootBlock: bootBlock,

0 commit comments

Comments
 (0)