Skip to content

Commit 6813941

Browse files
author
Jason Yellick
committed
Expose ChainID for orderer common components
The orderer components have been being slowly transformed to accomodate multiple chain IDs. However, in order to utilize these components in a true multi-chain system, their external APIs must expose their backing chain IDs. This changeset adds simple Getters for the chain ids associated with the configuration manager and the rawledgers. Change-Id: I5d2ad4f88975cd271b69f8aa38225c68499c18f2 Signed-off-by: Jason Yellick <[email protected]>
1 parent f046f3c commit 6813941

File tree

8 files changed

+57
-1
lines changed

8 files changed

+57
-1
lines changed

orderer/common/blockcutter/blockcutter_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func (mcm *mockConfigManager) Apply(message *cb.ConfigurationEnvelope) error {
4242
panic("Unimplemented")
4343
}
4444

45+
func (mcm *mockConfigManager) ChainID() []byte {
46+
panic("Unimplemented")
47+
}
48+
4549
type mockConfigFilter struct {
4650
manager configtx.Manager
4751
}

orderer/common/broadcast/broadcast_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ func (mcm *mockConfigManager) Apply(message *cb.ConfigurationEnvelope) error {
5757
return mcm.applyErr
5858
}
5959

60+
func (mcm *mockConfigManager) ChainID() []byte {
61+
panic("Unimplemented")
62+
}
63+
6064
type mockConfigFilter struct {
6165
manager configtx.Manager
6266
}

orderer/common/broadcastfilter/configfilter/configfilter_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (mcm *mockConfigManager) Apply(configtx *cb.ConfigurationEnvelope) error {
3838
return mcm.err
3939
}
4040

41+
func (mcm *mockConfigManager) ChainID() []byte {
42+
panic("Unimplemented")
43+
}
44+
4145
func TestForwardNonConfig(t *testing.T) {
4246
cf := New(&mockConfigManager{})
4347
result := cf.Apply(&cb.Envelope{

orderer/common/configtx/configtx.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ type Manager interface {
4848

4949
// Validate attempts to validate a new configtx against the current config state
5050
Validate(configtx *cb.ConfigurationEnvelope) error
51+
52+
// ChainID retrieves the chain ID associated with this manager
53+
ChainID() []byte
5154
}
5255

5356
// DefaultModificationPolicyID is the ID of the policy used when no other policy can be resolved, for instance when attempting to create a new config item
@@ -81,7 +84,7 @@ func computeChainIDAndSequence(configtx *cb.ConfigurationEnvelope) ([]byte, uint
8184
item := &cb.ConfigurationItem{}
8285
err := proto.Unmarshal(signedItem.ConfigurationItem, item)
8386
if err != nil {
84-
return nil, 0, err
87+
return nil, 0, fmt.Errorf("Error unmarshaling signedItem.ConfigurationItem: %s", err)
8588
}
8689

8790
if item.LastModified > m {
@@ -295,3 +298,8 @@ func (cm *configurationManager) Apply(configtx *cb.ConfigurationEnvelope) error
295298
cm.commitHandlers()
296299
return nil
297300
}
301+
302+
// ChainID retrieves the chain ID associated with this manager
303+
func (cm *configurationManager) ChainID() []byte {
304+
return cm.chainID
305+
}

orderer/rawledger/fileledger/fileledger.go

+14
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ func New(directory string, systemGenesis *cb.Block) (rawledger.Factory, rawledge
110110
return flf, fl
111111
}
112112

113+
func (flf *fileLedgerFactory) ChainIDs() [][]byte {
114+
flf.mutex.Lock()
115+
defer flf.mutex.Unlock()
116+
ids := make([][]byte, len(flf.ledgers))
117+
118+
i := 0
119+
for key := range flf.ledgers {
120+
ids[i] = []byte(key)
121+
i++
122+
}
123+
124+
return ids
125+
}
126+
113127
func (flf *fileLedgerFactory) GetOrCreate(chainID []byte) (rawledger.ReadWriter, error) {
114128
flf.mutex.Lock()
115129
defer flf.mutex.Unlock()

orderer/rawledger/ramledger/ramledger.go

+15
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ func (rlf *ramLedgerFactory) GetOrCreate(chainID []byte) (rawledger.ReadWriter,
9595
return ch, nil
9696
}
9797

98+
func (rlf *ramLedgerFactory) ChainIDs() [][]byte {
99+
rlf.mutex.Lock()
100+
defer rlf.mutex.Unlock()
101+
ids := make([][]byte, len(rlf.ledgers))
102+
103+
i := 0
104+
for key := range rlf.ledgers {
105+
ids[i] = []byte(key)
106+
i++
107+
}
108+
109+
return ids
110+
}
111+
98112
// newChain creates a new instance of the ram ledger for a chain
99113
func newChain(maxSize int) rawledger.ReadWriter {
100114
preGenesis := &cb.Block{
@@ -145,6 +159,7 @@ func (rl *ramLedger) Iterator(startType ab.SeekInfo_StartType, specified uint64)
145159
oldest := rl.oldest
146160
// Note the two +1's here is to accomodate the 'preGenesis' block of ^uint64(0)
147161
if specified+1 < oldest.block.Header.Number+1 || specified > rl.newest.block.Header.Number+1 {
162+
logger.Debugf("Returning error iterator because specified seek was %d with oldest %d and newest %d", specified, rl.oldest.block.Header.Number, rl.newest.block.Header.Number)
148163
return &rawledger.NotFoundErrorIterator{}, 0
149164
}
150165

orderer/rawledger/rawledger.go

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
type Factory interface {
2626
// GetOrCreate gets an existing ledger (if it exists) or creates it if it does not
2727
GetOrCreate(chainID []byte) (ReadWriter, error)
28+
29+
// ChainIDs returns the chain IDs the Factory is aware of
30+
ChainIDs() [][]byte
2831
}
2932

3033
// Iterator is useful for a chain Reader to stream blocks as they are created

orderer/solo/consensus_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (mcm *mockConfigManager) Apply(message *cb.ConfigurationEnvelope) error {
5252
return mcm.applyErr
5353
}
5454

55+
func (mcm *mockConfigManager) ChainID() []byte {
56+
panic("Unimplemented")
57+
}
58+
5559
type mockConfigFilter struct {
5660
manager configtx.Manager
5761
}

0 commit comments

Comments
 (0)