Skip to content

Commit bcef154

Browse files
committed
[FAB-2915] Set 'last block cut' to proper value
https://jira.hyperledger.org/browse/FAB-2915 Both the "last persisted offset" and the "last cut block" fields need to be set to their proper values before a restarted chain can resume operation. We were taking care of the former, but not the latter. This changeset fixes that. Change-Id: If688947d49566c88b416d7abb6f0e5b8aa42d977 Signed-off-by: Kostas Christidis <[email protected]>
1 parent b7166b7 commit bcef154

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

orderer/kafka/orderer.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,16 @@ func getLastOffsetPersisted(metadata *cb.Metadata, chainID string) int64 {
105105
// be satisfied by both the actual and the mock object and will allow
106106
// us to retrieve these constructors.
107107
func newChain(consenter testableConsenter, support multichain.ConsenterSupport, lastOffsetPersisted int64) *chainImpl {
108-
logger.Debugf("[channel: %s] Starting chain with last persisted offset: %d", support.ChainID(), lastOffsetPersisted)
108+
lastCutBlock := support.Height() - 1
109+
logger.Debugf("[channel: %s] Starting chain with last persisted offset %d and last recorded block %d",
110+
support.ChainID(), lastOffsetPersisted, lastCutBlock)
109111
return &chainImpl{
110112
consenter: consenter,
111113
support: support,
112114
partition: newChainPartition(support.ChainID(), rawPartition),
113115
batchTimeout: support.SharedConfig().BatchTimeout(),
114116
lastOffsetPersisted: lastOffsetPersisted,
117+
lastCutBlock: lastCutBlock,
115118
producer: consenter.prodFunc()(support.SharedConfig().KafkaBrokers(), consenter.kafkaVersion(), consenter.retryOptions(), consenter.tlsConfig()),
116119
halted: false, // Redundant as the default value for booleans is false but added for readability
117120
exitChan: make(chan struct{}),

orderer/mocks/multichain/multichain.go

+9
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type ConsenterSupport struct {
4545
// ChainIDVal is the value returned by ChainID()
4646
ChainIDVal string
4747

48+
// HeightVal is the value returned by Height()
49+
HeightVal uint64
50+
4851
// NextBlockVal stores the block created by the most recent CreateNextBlock() call
4952
NextBlockVal *cb.Block
5053

@@ -83,6 +86,7 @@ func (mcs *ConsenterSupport) WriteBlock(block *cb.Block, _committers []filter.Co
8386
umtxs[i] = utils.UnmarshalEnvelopeOrPanic(block.Data.Data[i])
8487
}
8588
mcs.Batches <- umtxs
89+
mcs.HeightVal++
8690
if encodedMetadataValue != nil {
8791
block.Metadata.Metadata[cb.BlockMetadataIndex_ORDERER] = utils.MarshalOrPanic(&cb.Metadata{Value: encodedMetadataValue})
8892
}
@@ -95,6 +99,11 @@ func (mcs *ConsenterSupport) ChainID() string {
9599
return mcs.ChainIDVal
96100
}
97101

102+
// Height returns the number of blocks of the chain this specific consenter instance is associated with
103+
func (mcs *ConsenterSupport) Height() uint64 {
104+
return mcs.HeightVal
105+
}
106+
98107
// Sign returns the bytes passed in
99108
func (mcs *ConsenterSupport) Sign(message []byte) ([]byte, error) {
100109
return message, nil

orderer/multichain/chainsupport.go

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type ConsenterSupport interface {
7070
CreateNextBlock(messages []*cb.Envelope) *cb.Block
7171
WriteBlock(block *cb.Block, committers []filter.Committer, encodedMetadataValue []byte) *cb.Block
7272
ChainID() string // ChainID returns the chain ID this specific consenter instance is associated with
73+
Height() uint64 // Returns the number of blocks on the chain this specific consenter instance is associated with
7374
}
7475

7576
// ChainSupport provides a wrapper for the resources backing a chain
@@ -258,3 +259,7 @@ func (cs *chainSupport) WriteBlock(block *cb.Block, committers []filter.Committe
258259
}
259260
return block
260261
}
262+
263+
func (cs *chainSupport) Height() uint64 {
264+
return cs.Reader().Height()
265+
}

0 commit comments

Comments
 (0)