@@ -25,7 +25,7 @@ import (
25
25
"github.com/hyperledger/fabric/orderer/common/sharedconfig"
26
26
"github.com/hyperledger/fabric/orderer/rawledger"
27
27
cb "github.com/hyperledger/fabric/protos/common"
28
- ab "github.com/hyperledger/fabric/protos/orderer "
28
+ "github.com/hyperledger/fabric/protos/utils "
29
29
"github.com/op/go-logging"
30
30
31
31
"github.com/golang/protobuf/proto"
@@ -59,48 +59,18 @@ type multiLedger struct {
59
59
sysChain * systemChain
60
60
}
61
61
62
- // getConfigTx, this should ultimately be done more intelligently, but for now, we search the whole chain for txs and pick the last config one
63
62
func getConfigTx (reader rawledger.Reader ) * cb.Envelope {
64
- var lastConfigTx * cb.Envelope
65
-
66
- it , _ := reader .Iterator (& ab.SeekPosition {Type : & ab.SeekPosition_Oldest {}})
67
- // Iterate over the blockchain, looking for config transactions, track the most recent one encountered
68
- // this will be the transaction which is returned
69
- for {
70
- select {
71
- case <- it .ReadyChan ():
72
- block , status := it .Next ()
73
- if status != cb .Status_SUCCESS {
74
- logger .Fatalf ("Error parsing blockchain at startup: %v" , status )
75
- }
76
- // ConfigTxs should always be by themselves
77
- if len (block .Data .Data ) != 1 {
78
- continue
79
- }
80
-
81
- maybeConfigTx := & cb.Envelope {}
82
-
83
- err := proto .Unmarshal (block .Data .Data [0 ], maybeConfigTx )
84
-
85
- if err != nil {
86
- logger .Fatalf ("Found data which was not an envelope: %s" , err )
87
- }
88
-
89
- payload := & cb.Payload {}
90
- if err = proto .Unmarshal (maybeConfigTx .Payload , payload ); err != nil {
91
- logger .Fatalf ("Unable to unmarshal transaction payload: %s" , err )
92
- }
93
-
94
- if payload .Header .ChainHeader .Type != int32 (cb .HeaderType_CONFIGURATION_TRANSACTION ) {
95
- continue
96
- }
97
-
98
- logger .Debugf ("Found configuration transaction for chain %x at block %d" , payload .Header .ChainHeader .ChainID , block .Header .Number )
99
- lastConfigTx = maybeConfigTx
100
- default :
101
- return lastConfigTx
102
- }
63
+ lastBlock := rawledger .GetBlock (reader , reader .Height ()- 1 )
64
+ index , err := utils .GetLastConfigurationIndexFromBlock (lastBlock )
65
+ if err != nil {
66
+ logger .Panicf ("Chain did not have appropriately encoded last configuration in its latest block: %s" , err )
103
67
}
68
+ configBlock := rawledger .GetBlock (reader , index )
69
+ if configBlock == nil {
70
+ logger .Panicf ("Configuration block does not exist" )
71
+ }
72
+
73
+ return utils .ExtractEnvelopeOrPanic (configBlock , 0 )
104
74
}
105
75
106
76
// NewManagerImpl produces an instance of a Manager
@@ -126,16 +96,16 @@ func NewManagerImpl(ledgerFactory rawledger.Factory, consenters map[string]Conse
126
96
127
97
if sharedConfigManager .ChainCreators () != nil {
128
98
if ml .sysChain != nil {
129
- logger .Fatalf ("There appear to be two system chains %x and %x " , ml .sysChain .support .ChainID (), chainID )
99
+ logger .Fatalf ("There appear to be two system chains %s and %s " , ml .sysChain .support .ChainID (), chainID )
130
100
}
131
- logger .Debugf ("Starting with system chain: %x " , chainID )
101
+ logger .Debugf ("Starting with system chain: %s " , chainID )
132
102
chain := newChainSupport (createSystemChainFilters (ml , configManager ), configManager , policyManager , backingLedger , sharedConfigManager , consenters )
133
103
ml .chains [string (chainID )] = chain
134
104
ml .sysChain = newSystemChain (chain )
135
105
// We delay starting this chain, as it might try to copy and replace the chains map via newChain before the map is fully built
136
106
defer chain .start ()
137
107
} else {
138
- logger .Debugf ("Starting chain: %x " , chainID )
108
+ logger .Debugf ("Starting chain: %s " , chainID )
139
109
chain := newChainSupport (createStandardFilters (configManager ), configManager , policyManager , backingLedger , sharedConfigManager , consenters )
140
110
ml .chains [string (chainID )] = chain
141
111
chain .start ()
0 commit comments