From acf3298784e73258867529975b1b702fb1a5375d Mon Sep 17 00:00:00 2001 From: Alessandro Sorniotti Date: Fri, 27 Jan 2017 11:59:55 +0100 Subject: [PATCH] [FAB-1862] - send block event after commit This change set ensures that block events are generated only *after* the block has been committed to the ledger (and not before as it was the case previously). Change-Id: I25bab47cc7d69b6e804fc605cf7710dca0050d21 Signed-off-by: Alessandro Sorniotti --- core/committer/committer_impl.go | 10 ++++++++++ core/deliverservice/client.go | 5 ----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/committer/committer_impl.go b/core/committer/committer_impl.go index 34bd520c964..514964a690b 100644 --- a/core/committer/committer_impl.go +++ b/core/committer/committer_impl.go @@ -17,8 +17,11 @@ limitations under the License. package committer import ( + "fmt" + "github.com/hyperledger/fabric/core/committer/txvalidator" "github.com/hyperledger/fabric/core/ledger" + "github.com/hyperledger/fabric/events/producer" "github.com/hyperledger/fabric/protos/common" pb "github.com/hyperledger/fabric/protos/peer" "github.com/op/go-logging" @@ -60,6 +63,13 @@ func (lc *LedgerCommitter) Commit(block *common.Block) error { if err := lc.ledger.Commit(block); err != nil { return err } + + // send block event *after* the block has been committed + if err := producer.SendProducerBlockEvent(block); err != nil { + logger.Errorf("Error sending block event %s", err) + return fmt.Errorf("Error sending block event %s", err) + } + return nil } diff --git a/core/deliverservice/client.go b/core/deliverservice/client.go index fcbcef2932d..5c601ee8f0e 100644 --- a/core/deliverservice/client.go +++ b/core/deliverservice/client.go @@ -22,7 +22,6 @@ import ( "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric/core/committer" - "github.com/hyperledger/fabric/events/producer" gossipcommon "github.com/hyperledger/fabric/gossip/common" gossip_proto "github.com/hyperledger/fabric/gossip/proto" "github.com/hyperledger/fabric/gossip/service" @@ -219,10 +218,6 @@ func (d *DeliverService) readUntilClose() { // Gossip messages with other nodes logger.Debugf("Gossiping block [%d], peers number [%d]", seqNum, numberOfPeers) service.GetGossipService().Gossip(gossipMsg) - if err = producer.SendProducerBlockEvent(t.Block); err != nil { - logger.Errorf("Error sending block event %s", err) - } - default: logger.Warning("Received unknown: ", t) return