Skip to content

Commit

Permalink
[FAB-1872]: Commit genessis block, joining chain.
Browse files Browse the repository at this point in the history
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 <bartem@il.ibm.com>
  • Loading branch information
C0rWin committed Jan 26, 2017
1 parent cc5c14d commit 438700e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
4 changes: 4 additions & 0 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ func CreateChainFromBlock(cb *common.Block) error {
return err
}

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

Expand Down
9 changes: 1 addition & 8 deletions gossip/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ func NewGossipStateProvider(chainID string, g gossip.Gossip, committer committer
return nil
}

//if the ledger is empty, we need a block from orderer
//so don't expect height+1 but expect 0
next := height
if height > 0 {
next = height + 1
}

s := &GossipStateProviderImpl{
chainID: chainID,

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

stopFlag: 0,
// Create a queue for payload received
payloads: NewPayloadsBuffer(next),
payloads: NewPayloadsBuffer(height + 1),

committer: committer,

Expand Down
2 changes: 1 addition & 1 deletion gossip/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestNewGossipStateProvider_SendingManyMessages(t *testing.T) {

msgCount := 10

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

0 comments on commit 438700e

Please sign in to comment.