From 438700e6a2f05aa1092b58fe87c75fc7cbccacbe Mon Sep 17 00:00:00 2001 From: Artem Barger Date: Thu, 26 Jan 2017 13:36:19 -0500 Subject: [PATCH] [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 --- core/peer/peer.go | 4 ++++ gossip/state/state.go | 9 +-------- gossip/state/state_test.go | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/core/peer/peer.go b/core/peer/peer.go index 0179e8ea028..4c0ae33ab72 100644 --- a/core/peer/peer.go +++ b/core/peer/peer.go @@ -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) } diff --git a/gossip/state/state.go b/gossip/state/state.go index b6c6b497f85..03d2fc91ea4 100644 --- a/gossip/state/state.go +++ b/gossip/state/state.go @@ -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, @@ -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, diff --git a/gossip/state/state_test.go b/gossip/state/state_test.go index d25794fdcb7..7443cda6979 100644 --- a/gossip/state/state_test.go +++ b/gossip/state/state_test.go @@ -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}