Skip to content

Commit

Permalink
Merge "Expose ChainID for orderer common components"
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborh-da authored and Gerrit Code Review committed Nov 28, 2016
2 parents 7513984 + 6813941 commit 69a3aa6
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions orderer/common/blockcutter/blockcutter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (mcm *mockConfigManager) Apply(message *cb.ConfigurationEnvelope) error {
panic("Unimplemented")
}

func (mcm *mockConfigManager) ChainID() []byte {
panic("Unimplemented")
}

type mockConfigFilter struct {
manager configtx.Manager
}
Expand Down
4 changes: 4 additions & 0 deletions orderer/common/broadcast/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func (mcm *mockConfigManager) Apply(message *cb.ConfigurationEnvelope) error {
return mcm.applyErr
}

func (mcm *mockConfigManager) ChainID() []byte {
panic("Unimplemented")
}

type mockConfigFilter struct {
manager configtx.Manager
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (mcm *mockConfigManager) Apply(configtx *cb.ConfigurationEnvelope) error {
return mcm.err
}

func (mcm *mockConfigManager) ChainID() []byte {
panic("Unimplemented")
}

func TestForwardNonConfig(t *testing.T) {
cf := New(&mockConfigManager{})
result := cf.Apply(&cb.Envelope{
Expand Down
10 changes: 9 additions & 1 deletion orderer/common/configtx/configtx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type Manager interface {

// Validate attempts to validate a new configtx against the current config state
Validate(configtx *cb.ConfigurationEnvelope) error

// ChainID retrieves the chain ID associated with this manager
ChainID() []byte
}

// 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
Expand Down Expand Up @@ -81,7 +84,7 @@ func computeChainIDAndSequence(configtx *cb.ConfigurationEnvelope) ([]byte, uint
item := &cb.ConfigurationItem{}
err := proto.Unmarshal(signedItem.ConfigurationItem, item)
if err != nil {
return nil, 0, err
return nil, 0, fmt.Errorf("Error unmarshaling signedItem.ConfigurationItem: %s", err)
}

if item.LastModified > m {
Expand Down Expand Up @@ -295,3 +298,8 @@ func (cm *configurationManager) Apply(configtx *cb.ConfigurationEnvelope) error
cm.commitHandlers()
return nil
}

// ChainID retrieves the chain ID associated with this manager
func (cm *configurationManager) ChainID() []byte {
return cm.chainID
}
14 changes: 14 additions & 0 deletions orderer/rawledger/fileledger/fileledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ func New(directory string, systemGenesis *cb.Block) (rawledger.Factory, rawledge
return flf, fl
}

func (flf *fileLedgerFactory) ChainIDs() [][]byte {
flf.mutex.Lock()
defer flf.mutex.Unlock()
ids := make([][]byte, len(flf.ledgers))

i := 0
for key := range flf.ledgers {
ids[i] = []byte(key)
i++
}

return ids
}

func (flf *fileLedgerFactory) GetOrCreate(chainID []byte) (rawledger.ReadWriter, error) {
flf.mutex.Lock()
defer flf.mutex.Unlock()
Expand Down
15 changes: 15 additions & 0 deletions orderer/rawledger/ramledger/ramledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ func (rlf *ramLedgerFactory) GetOrCreate(chainID []byte) (rawledger.ReadWriter,
return ch, nil
}

func (rlf *ramLedgerFactory) ChainIDs() [][]byte {
rlf.mutex.Lock()
defer rlf.mutex.Unlock()
ids := make([][]byte, len(rlf.ledgers))

i := 0
for key := range rlf.ledgers {
ids[i] = []byte(key)
i++
}

return ids
}

// newChain creates a new instance of the ram ledger for a chain
func newChain(maxSize int) rawledger.ReadWriter {
preGenesis := &cb.Block{
Expand Down Expand Up @@ -145,6 +159,7 @@ func (rl *ramLedger) Iterator(startType ab.SeekInfo_StartType, specified uint64)
oldest := rl.oldest
// Note the two +1's here is to accomodate the 'preGenesis' block of ^uint64(0)
if specified+1 < oldest.block.Header.Number+1 || specified > rl.newest.block.Header.Number+1 {
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)
return &rawledger.NotFoundErrorIterator{}, 0
}

Expand Down
3 changes: 3 additions & 0 deletions orderer/rawledger/rawledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
type Factory interface {
// GetOrCreate gets an existing ledger (if it exists) or creates it if it does not
GetOrCreate(chainID []byte) (ReadWriter, error)

// ChainIDs returns the chain IDs the Factory is aware of
ChainIDs() [][]byte
}

// Iterator is useful for a chain Reader to stream blocks as they are created
Expand Down
4 changes: 4 additions & 0 deletions orderer/solo/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (mcm *mockConfigManager) Apply(message *cb.ConfigurationEnvelope) error {
return mcm.applyErr
}

func (mcm *mockConfigManager) ChainID() []byte {
panic("Unimplemented")
}

type mockConfigFilter struct {
manager configtx.Manager
}
Expand Down

0 comments on commit 69a3aa6

Please sign in to comment.