Skip to content

Commit acf3298

Browse files
committed
[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 <[email protected]>
1 parent 62eac5b commit acf3298

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

core/committer/committer_impl.go

+10
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ limitations under the License.
1717
package committer
1818

1919
import (
20+
"fmt"
21+
2022
"github.com/hyperledger/fabric/core/committer/txvalidator"
2123
"github.com/hyperledger/fabric/core/ledger"
24+
"github.com/hyperledger/fabric/events/producer"
2225
"github.com/hyperledger/fabric/protos/common"
2326
pb "github.com/hyperledger/fabric/protos/peer"
2427
"github.com/op/go-logging"
@@ -60,6 +63,13 @@ func (lc *LedgerCommitter) Commit(block *common.Block) error {
6063
if err := lc.ledger.Commit(block); err != nil {
6164
return err
6265
}
66+
67+
// send block event *after* the block has been committed
68+
if err := producer.SendProducerBlockEvent(block); err != nil {
69+
logger.Errorf("Error sending block event %s", err)
70+
return fmt.Errorf("Error sending block event %s", err)
71+
}
72+
6373
return nil
6474
}
6575

core/deliverservice/client.go

-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/golang/protobuf/proto"
2424
"github.com/hyperledger/fabric/core/committer"
25-
"github.com/hyperledger/fabric/events/producer"
2625
gossipcommon "github.com/hyperledger/fabric/gossip/common"
2726
gossip_proto "github.com/hyperledger/fabric/gossip/proto"
2827
"github.com/hyperledger/fabric/gossip/service"
@@ -219,10 +218,6 @@ func (d *DeliverService) readUntilClose() {
219218
// Gossip messages with other nodes
220219
logger.Debugf("Gossiping block [%d], peers number [%d]", seqNum, numberOfPeers)
221220
service.GetGossipService().Gossip(gossipMsg)
222-
if err = producer.SendProducerBlockEvent(t.Block); err != nil {
223-
logger.Errorf("Error sending block event %s", err)
224-
}
225-
226221
default:
227222
logger.Warning("Received unknown: ", t)
228223
return

0 commit comments

Comments
 (0)