Skip to content

Commit 438700e

Browse files
committed
[FAB-1872]: Commit genessis block, joining chain.
Currently genesis block is not get committed into the ledger while chain is created, therefore the delivery client asks from the ordering service to bring blocks starting from the sequence zero. The zero sequence blocks is actually the configuration block which simple fails validation, because configuration block sequence expected to come in increasing order. This commit takes care to get genesis block committed right after chain created for the first time. NOTE: we do not need to "re-commit" this block in case peer get restarted. Change-Id: I82d6830f540b1772e4134ce380428b0189af9fe3 Signed-off-by: Artem Barger <[email protected]>
1 parent cc5c14d commit 438700e

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

core/peer/peer.go

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ func CreateChainFromBlock(cb *common.Block) error {
212212
return err
213213
}
214214

215+
if err := ledger.Commit(cb); err != nil {
216+
peerLogger.Errorf("Unable to get genesis block committed into the ledger, chainID %v", cid)
217+
return err
218+
}
215219
return createChain(cid, ledger, cb)
216220
}
217221

gossip/state/state.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ func NewGossipStateProvider(chainID string, g gossip.Gossip, committer committer
112112
return nil
113113
}
114114

115-
//if the ledger is empty, we need a block from orderer
116-
//so don't expect height+1 but expect 0
117-
next := height
118-
if height > 0 {
119-
next = height + 1
120-
}
121-
122115
s := &GossipStateProviderImpl{
123116
chainID: chainID,
124117

@@ -133,7 +126,7 @@ func NewGossipStateProvider(chainID string, g gossip.Gossip, committer committer
133126

134127
stopFlag: 0,
135128
// Create a queue for payload received
136-
payloads: NewPayloadsBuffer(next),
129+
payloads: NewPayloadsBuffer(height + 1),
137130

138131
committer: committer,
139132

gossip/state/state_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func TestNewGossipStateProvider_SendingManyMessages(t *testing.T) {
294294

295295
msgCount := 10
296296

297-
for i := 0; i < msgCount; i++ {
297+
for i := 1; i <= msgCount; i++ {
298298
rawblock := pcomm.NewBlock(uint64(i), []byte{})
299299
if bytes, err := pb.Marshal(rawblock); err == nil {
300300
payload := &proto.Payload{uint64(i), "", bytes}

0 commit comments

Comments
 (0)