Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding block height check into orderer bootstrap #2594

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 88 additions & 6 deletions common/deliver/mock/block_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions common/ledger/blockledger/fileledger/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type FileLedgerBlockStore interface {
AddBlock(block *cb.Block) error
GetBlockchainInfo() (*cb.BlockchainInfo, error)
RetrieveBlocks(startBlockNumber uint64) (ledger.ResultsIterator, error)
RetrieveBlockByNumber(blockNum uint64) (*cb.Block, error)
}

// NewFileLedger creates a new FileLedger for interaction with the ledger
Expand Down Expand Up @@ -87,6 +88,7 @@ func (fl *FileLedger) Iterator(startPosition *ab.SeekPosition) (blockledger.Iter

iterator, err := fl.blockStore.RetrieveBlocks(startingBlockNumber)
if err != nil {
logger.Warnw("Failed to initialize block iterator", "blockNum", startingBlockNumber, "error", err)
return &blockledger.NotFoundErrorIterator{}, 0
}

Expand All @@ -111,3 +113,7 @@ func (fl *FileLedger) Append(block *cb.Block) error {
}
return err
}

func (fl *FileLedger) RetrieveBlockByNumber(blockNumber uint64) (*cb.Block, error) {
return fl.blockStore.RetrieveBlockByNumber(blockNumber)
}
2 changes: 2 additions & 0 deletions common/ledger/blockledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Reader interface {
Iterator(startType *ab.SeekPosition) (Iterator, uint64)
// Height returns the number of blocks on the ledger
Height() uint64
// retrieve blockByNumber
RetrieveBlockByNumber(blockNumber uint64) (*cb.Block, error)
}

// Writer allows the caller to modify the ledger
Expand Down
8 changes: 8 additions & 0 deletions common/ledger/blockledger/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
ab "github.com/hyperledger/fabric-protos-go/orderer"
"github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric/protoutil"
)

var logger = flogging.MustGetLogger("common.ledger.blockledger.util")

var closedChan chan struct{}

func init() {
Expand Down Expand Up @@ -95,3 +98,8 @@ func GetBlock(rl Reader, index uint64) *cb.Block {
}
return block
}

func GetBlockByNumber(rl Reader, blockNum uint64) (*cb.Block, error) {
logger.Debugw("Retrieving block", "blockNum", blockNum)
return rl.RetrieveBlockByNumber(blockNum)
}
5 changes: 5 additions & 0 deletions core/peer/deliverevents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ func (m *mockReader) Height() uint64 {
return args.Get(0).(uint64)
}

func (m *mockReader) RetrieveBlockByNumber(blockNum uint64) (*common.Block, error) {
args := m.Called()
return args.Get(0).(*common.Block), args.Error(1)
}

// mockChainSupport
type mockChainSupport struct {
mock.Mock
Expand Down
4 changes: 4 additions & 0 deletions core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func (flbs fileLedgerBlockStore) RetrieveBlocks(startBlockNumber uint64) (common
return flbs.GetBlocksIterator(startBlockNumber)
}

func (flbs fileLedgerBlockStore) RetrieveBlockByNumber(blockNum uint64) (*common.Block, error) {
return flbs.GetBlockByNumber(blockNum)
}

// NewConfigSupport returns
func NewConfigSupport(peer *Peer) cc.Manager {
return &configSupport{
Expand Down
100 changes: 91 additions & 9 deletions orderer/common/multichannel/mocks/read_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading