@@ -315,10 +315,8 @@ func buildTrustedRootsForChain(cm channelconfig.Resources) {
315
315
316
316
// setCurrConfigBlock sets the current config block of the specified channel
317
317
func (p * Peer ) setCurrConfigBlock (block * common.Block , cid string ) error {
318
- p .mutex .Lock ()
319
- defer p .mutex .Unlock ()
320
- if c , ok := p .channels [cid ]; ok {
321
- c .cb = block
318
+ if c := p .Channel (cid ); c != nil {
319
+ c .cb = block // TODO: serialization?
322
320
return nil
323
321
}
324
322
return errors .Errorf ("[channel %s] channel not associated with this peer" , cid )
@@ -344,13 +342,10 @@ func NewPeerServer(listenAddress string, serverConfig comm.ServerConfig) (*comm.
344
342
type DeliverChainManager struct {}
345
343
346
344
func (DeliverChainManager ) GetChain (chainID string ) deliver.Chain {
347
- Default .mutex .RLock ()
348
- defer Default .mutex .RUnlock ()
349
- channel , ok := Default .channels [chainID ]
350
- if ! ok {
351
- return nil
345
+ if channel := Default .Channel (chainID ); channel != nil {
346
+ return channel
352
347
}
353
- return channel
348
+ return nil
354
349
}
355
350
356
351
// fileLedgerBlockStore implements the interface expected by
@@ -379,9 +374,7 @@ type configSupport struct{}
379
374
// ConfigProto method of the returned object can be used to get the
380
375
// proto representing the channel configuration.
381
376
func (* configSupport ) GetChannelConfig (cid string ) cc.Config {
382
- Default .mutex .RLock ()
383
- defer Default .mutex .RUnlock ()
384
- channel := Default .channels [cid ]
377
+ channel := Default .Channel (cid )
385
378
if channel == nil {
386
379
peerLogger .Errorf ("[channel %s] channel not associated with this peer" , cid )
387
380
return nil
@@ -596,10 +589,17 @@ func (p *Peer) createChannel(
596
589
return nil
597
590
}
598
591
599
- func (p * Peer ) StoreForChannel (cid string ) transientstore. Store {
592
+ func (p * Peer ) Channel (cid string ) * Channel {
600
593
p .mutex .RLock ()
601
594
defer p .mutex .RUnlock ()
602
595
if c , ok := p .channels [cid ]; ok {
596
+ return c
597
+ }
598
+ return nil
599
+ }
600
+
601
+ func (p * Peer ) StoreForChannel (cid string ) transientstore.Store {
602
+ if c := p .Channel (cid ); c != nil {
603
603
return c .store
604
604
}
605
605
return nil
@@ -608,9 +608,7 @@ func (p *Peer) StoreForChannel(cid string) transientstore.Store {
608
608
// GetChannelConfig returns the channel configuration of the channel with channel ID. Note that this
609
609
// call returns nil if channel cid has not been created.
610
610
func (p * Peer ) GetChannelConfig (cid string ) channelconfig.Resources {
611
- p .mutex .RLock ()
612
- defer p .mutex .RUnlock ()
613
- if c , ok := p .channels [cid ]; ok {
611
+ if c := p .Channel (cid ); c != nil {
614
612
return c .resources
615
613
}
616
614
return nil
@@ -633,9 +631,7 @@ func (p *Peer) GetChannelsInfo() []*pb.ChannelInfo {
633
631
// GetStableChannelConfig returns the stable channel configuration of the channel with channel ID.
634
632
// Note that this call returns nil if channel cid has not been created.
635
633
func (p * Peer ) GetStableChannelConfig (cid string ) channelconfig.Resources {
636
- p .mutex .RLock ()
637
- defer p .mutex .RUnlock ()
638
- if c , ok := p .channels [cid ]; ok {
634
+ if c := p .Channel (cid ); c != nil {
639
635
return c .bundleSource .StableBundle ()
640
636
}
641
637
return nil
@@ -644,9 +640,7 @@ func (p *Peer) GetStableChannelConfig(cid string) channelconfig.Resources {
644
640
// GetCurrConfigBlock returns the cached config block of the specified channel.
645
641
// Note that this call returns nil if channel cid has not been created.
646
642
func (p * Peer ) GetCurrConfigBlock (cid string ) * common.Block {
647
- p .mutex .RLock ()
648
- defer p .mutex .RUnlock ()
649
- if c , ok := p .channels [cid ]; ok {
643
+ if c := p .Channel (cid ); c != nil {
650
644
return c .cb
651
645
}
652
646
return nil
@@ -655,33 +649,24 @@ func (p *Peer) GetCurrConfigBlock(cid string) *common.Block {
655
649
// GetLedger returns the ledger of the channel with channel ID. Note that this
656
650
// call returns nil if channel cid has not been created.
657
651
func (p * Peer ) GetLedger (cid string ) ledger.PeerLedger {
658
- p .mutex .RLock ()
659
- defer p .mutex .RUnlock ()
660
- if c , ok := p .channels [cid ]; ok {
652
+ if c := p .Channel (cid ); c != nil {
661
653
return c .ledger
662
654
}
663
655
return nil
664
656
}
665
657
666
658
// GetMSPIDs returns the ID of each application MSP defined on this channel
667
659
func (p * Peer ) GetMSPIDs (cid string ) []string {
668
- p .mutex .RLock ()
669
- defer p .mutex .RUnlock ()
670
-
671
- c , ok := p .channels [cid ]
672
- if ! ok {
673
- return nil
660
+ if c := p .Channel (cid ); c != nil {
661
+ return c .GetMSPIDs ()
674
662
}
675
-
676
- return c .GetMSPIDs ()
663
+ return nil
677
664
}
678
665
679
666
// GetPolicyManager returns the policy manager of the channel with channel ID. Note that this
680
667
// call returns nil if channel cid has not been created.
681
668
func (p * Peer ) GetPolicyManager (cid string ) policies.Manager {
682
- p .mutex .RLock ()
683
- defer p .mutex .RUnlock ()
684
- if c , ok := p .channels [cid ]; ok {
669
+ if c := p .Channel (cid ); c != nil {
685
670
return c .resources .PolicyManager ()
686
671
}
687
672
return nil
0 commit comments