@@ -8,7 +8,6 @@ package committer
88
99import (
1010 "context"
11- "fmt"
1211 "runtime/debug"
1312 "sync"
1413 "time"
@@ -27,7 +26,7 @@ const (
2726 ConfigTXPrefix = "configtx_"
2827)
2928
30- var logger = flogging .MustGetLogger ("fabric-sdk.committer " )
29+ var logger = flogging .MustGetLogger ("fabric-sdk.Committer " )
3130
3231type Metrics interface {
3332 EmitKey (val float32 , event ... string )
@@ -43,7 +42,7 @@ type Network interface {
4342 Ledger (channel string ) (driver.Ledger , error )
4443}
4544
46- type committer struct {
45+ type Committer struct {
4746 channel string
4847 network Network
4948 finality Finality
@@ -58,12 +57,12 @@ type committer struct {
5857 publisher events.Publisher
5958}
6059
61- func New (channel string , network Network , finality Finality , waitForEventTimeout time.Duration , quiet bool , metrics Metrics , publisher events.Publisher ) (* committer , error ) {
60+ func New (channel string , network Network , finality Finality , waitForEventTimeout time.Duration , quiet bool , metrics Metrics , publisher events.Publisher ) (* Committer , error ) {
6261 if len (channel ) == 0 {
63- panic ("expected a channel, got empty string" )
62+ return nil , errors . Errorf ("expected a channel, got empty string" )
6463 }
6564
66- d := & committer {
65+ d := & Committer {
6766 channel : channel ,
6867 network : network ,
6968 waitForEventTimeout : waitForEventTimeout ,
@@ -79,7 +78,7 @@ func New(channel string, network Network, finality Finality, waitForEventTimeout
7978}
8079
8180// Commit commits the transactions in the block passed as argument
82- func (c * committer ) Commit (block * common.Block ) error {
81+ func (c * Committer ) Commit (block * common.Block ) error {
8382 for i , tx := range block .Data .Data {
8483
8584 env , err := protoutil .UnmarshalEnvelope (tx )
@@ -100,27 +99,31 @@ func (c *committer) Commit(block *common.Block) error {
10099
101100 var event TxEvent
102101
103- c .metrics .EmitKey (0 , "committer " , "start" , "Commit" , chdr .TxId )
102+ c .metrics .EmitKey (0 , "Committer " , "start" , "Commit" , chdr .TxId )
104103 switch common .HeaderType (chdr .Type ) {
105104 case common .HeaderType_CONFIG :
106105 if logger .IsEnabledFor (zapcore .DebugLevel ) {
107106 logger .Debugf ("[%s] Config transaction received: %s" , c .channel , chdr .TxId )
108107 }
109- c .handleConfig (block , i , env )
108+ if err := c .handleConfig (block , i , env ); err != nil {
109+ return err
110+ }
110111 case common .HeaderType_ENDORSER_TRANSACTION :
111112 if logger .IsEnabledFor (zapcore .DebugLevel ) {
112113 logger .Debugf ("[%s] Endorser transaction received: %s" , c .channel , chdr .TxId )
113114 }
114115 if len (block .Metadata .Metadata ) < int (common .BlockMetadataIndex_TRANSACTIONS_FILTER ) {
115116 return errors .Errorf ("block metadata lacks transaction filter" )
116117 }
117- c .handleEndorserTransaction (block , i , & event , env , chdr )
118+ if err := c .handleEndorserTransaction (block , i , & event , env , chdr ); err != nil {
119+ return err
120+ }
118121 default :
119122 if logger .IsEnabledFor (zapcore .DebugLevel ) {
120123 logger .Debugf ("[%s] Received unhandled transaction type: %s" , c .channel , chdr .Type )
121124 }
122125 }
123- c .metrics .EmitKey (0 , "committer " , "end" , "Commit" , chdr .TxId )
126+ c .metrics .EmitKey (0 , "Committer " , "end" , "Commit" , chdr .TxId )
124127
125128 c .notify (event )
126129
@@ -135,9 +138,9 @@ func (c *committer) Commit(block *common.Block) error {
135138// IsFinal takes in input a transaction id and waits for its confirmation
136139// with the respect to the passed context that can be used to set a deadline
137140// for the waiting time.
138- func (c * committer ) IsFinal (ctx context.Context , txID string ) error {
139- c .metrics .EmitKey (0 , "committer " , "start" , "IsFinal" , txID )
140- defer c .metrics .EmitKey (0 , "committer " , "end" , "IsFinal" , txID )
141+ func (c * Committer ) IsFinal (ctx context.Context , txID string ) error {
142+ c .metrics .EmitKey (0 , "Committer " , "start" , "IsFinal" , txID )
143+ defer c .metrics .EmitKey (0 , "Committer " , "end" , "IsFinal" , txID )
141144
142145 if logger .IsEnabledFor (zapcore .DebugLevel ) {
143146 logger .Debugf ("Is [%s] final?" , txID )
@@ -217,7 +220,7 @@ func (c *committer) IsFinal(ctx context.Context, txID string) error {
217220 }
218221 time .Sleep (100 * time .Millisecond )
219222 default :
220- panic ( fmt . Sprintf ("invalid status code, got %c " , vd ) )
223+ return errors . Errorf ("invalid status code, got [%c] " , vd )
221224 }
222225 } else {
223226 logger .Errorf ("Is [%s] final? Failed getting transaction status from vault" , txID )
@@ -229,7 +232,7 @@ func (c *committer) IsFinal(ctx context.Context, txID string) error {
229232 return c .listenTo (ctx , txID , c .waitForEventTimeout )
230233}
231234
232- func (c * committer ) addListener (txid string , ch chan TxEvent ) {
235+ func (c * Committer ) addListener (txid string , ch chan TxEvent ) {
233236 c .mutex .Lock ()
234237 defer c .mutex .Unlock ()
235238
@@ -242,7 +245,7 @@ func (c *committer) addListener(txid string, ch chan TxEvent) {
242245 c .listeners [txid ] = ls
243246}
244247
245- func (c * committer ) deleteListener (txid string , ch chan TxEvent ) {
248+ func (c * Committer ) deleteListener (txid string , ch chan TxEvent ) {
246249 c .mutex .Lock ()
247250 defer c .mutex .Unlock ()
248251
@@ -259,7 +262,7 @@ func (c *committer) deleteListener(txid string, ch chan TxEvent) {
259262 }
260263}
261264
262- func (c * committer ) notify (event TxEvent ) {
265+ func (c * Committer ) notify (event TxEvent ) {
263266 c .mutex .Lock ()
264267 defer c .mutex .Unlock ()
265268
@@ -287,14 +290,13 @@ func (c *committer) notify(event TxEvent) {
287290}
288291
289292// notifyChaincodeListeners notifies the chaincode event to the registered chaincode listeners.
290- func (c * committer ) notifyChaincodeListeners (event * ChaincodeEvent ) error {
293+ func (c * Committer ) notifyChaincodeListeners (event * ChaincodeEvent ) {
291294 c .publisher .Publish (event )
292- return nil
293295}
294296
295- func (c * committer ) listenTo (ctx context.Context , txid string , timeout time.Duration ) error {
296- c .metrics .EmitKey (0 , "committer " , "start" , "listenTo" , txid )
297- defer c .metrics .EmitKey (0 , "committer " , "end" , "listenTo" , txid )
297+ func (c * Committer ) listenTo (ctx context.Context , txid string , timeout time.Duration ) error {
298+ c .metrics .EmitKey (0 , "Committer " , "start" , "listenTo" , txid )
299+ defer c .metrics .EmitKey (0 , "Committer " , "end" , "listenTo" , txid )
298300
299301 if logger .IsEnabledFor (zapcore .DebugLevel ) {
300302 logger .Debugf ("Listen to finality of [%s]" , txid )
0 commit comments