Skip to content

Commit 131f9bc

Browse files
authored
fix nodes panic during synchronization (#5081)
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent 7a63a26 commit 131f9bc

File tree

8 files changed

+102
-11
lines changed

8 files changed

+102
-11
lines changed

orderer/consensus/consensus.go

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ type ConsenterSupport interface {
120120
// WriteBlock commits a block to the ledger.
121121
WriteBlock(block *cb.Block, encodedMetadataValue []byte)
122122

123+
// WriteBlockSync commits a block to the ledger.
124+
WriteBlockSync(block *cb.Block, encodedMetadataValue []byte)
125+
123126
// WriteConfigBlock commits a block to the ledger, and applies the config update inside.
124127
WriteConfigBlock(block *cb.Block, encodedMetadataValue []byte)
125128

orderer/consensus/mocks/mock_consenter_support.go

+46
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orderer/consensus/smartbft/mocks/consenter_support.go

+35-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orderer/consensus/smartbft/synchronizer.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (s *Synchronizer) synchronize() (*types.Decision, error) {
125125
if protoutil.IsConfigBlock(block) {
126126
s.Support.WriteConfigBlock(block, nil)
127127
} else {
128-
s.Support.WriteBlock(block, nil)
128+
s.Support.WriteBlockSync(block, nil)
129129
}
130130
s.Logger.Debugf("Fetched and committed block [%d] from cluster", seq)
131131
lastPulledBlock = block
@@ -141,9 +141,8 @@ func (s *Synchronizer) synchronize() (*types.Decision, error) {
141141
return nil, errors.Errorf("failed pulling block %d", seq)
142142
}
143143

144-
startSeq := startHeight
145144
s.Logger.Infof("Finished synchronizing with cluster, fetched %d blocks, starting from block [%d], up until and including block [%d]",
146-
blocksFetched, startSeq, lastPulledBlock.Header.Number)
145+
blocksFetched, startHeight, lastPulledBlock.Header.Number)
147146

148147
viewMetadata, lastConfigSqn := s.getViewMetadataLastConfigSqnFromBlock(lastPulledBlock)
149148

orderer/consensus/smartbft/synchronizer_bft.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (s *BFTSynchronizer) getBlocksFromSyncBuffer(startHeight, targetHeight uint
258258
s.Support.WriteConfigBlock(block, nil)
259259
s.Logger.Debugf("Fetched and committed config block [%d] from cluster", seq)
260260
} else {
261-
s.Support.WriteBlock(block, nil)
261+
s.Support.WriteBlockSync(block, nil)
262262
s.Logger.Debugf("Fetched and committed block [%d] from cluster", seq)
263263
}
264264
lastPulledBlock = block
@@ -277,9 +277,8 @@ func (s *BFTSynchronizer) getBlocksFromSyncBuffer(startHeight, targetHeight uint
277277
return nil, errors.Errorf("failed pulling block %d", seq)
278278
}
279279

280-
startSeq := startHeight
281280
s.Logger.Infof("Finished synchronizing with cluster, fetched %d blocks, starting from block [%d], up until and including block [%d]",
282-
blocksFetched, startSeq, lastPulledBlock.Header.Number)
281+
blocksFetched, startHeight, lastPulledBlock.Header.Number)
283282

284283
return lastPulledBlock, nil
285284
}

orderer/consensus/smartbft/synchronizer_bft_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func TestBFTSynchronizer(t *testing.T) {
306306
fakeCS.WriteConfigBlockCalls(func(b *cb.Block, m []byte) {
307307
ledger = append(ledger, b)
308308
})
309-
fakeCS.WriteBlockCalls(func(b *cb.Block, m []byte) {
309+
fakeCS.WriteBlockSyncCalls(func(b *cb.Block, m []byte) {
310310
ledger = append(ledger, b)
311311
})
312312

@@ -395,7 +395,7 @@ func TestBFTSynchronizer(t *testing.T) {
395395
require.NotNil(t, resp)
396396
require.Equal(t, *decision, resp)
397397
require.Equal(t, 102, len(ledger))
398-
require.Equal(t, 1, fakeCS.WriteBlockCallCount())
398+
require.Equal(t, 1, fakeCS.WriteBlockSyncCallCount())
399399
require.Equal(t, 1, fakeCS.WriteConfigBlockCallCount())
400400
wg.Wait()
401401
})
@@ -436,7 +436,7 @@ func TestBFTSynchronizer(t *testing.T) {
436436
fakeCS.WriteConfigBlockCalls(func(b *cb.Block, m []byte) {
437437
ledger = append(ledger, b)
438438
})
439-
fakeCS.WriteBlockCalls(func(b *cb.Block, m []byte) {
439+
fakeCS.WriteBlockSyncCalls(func(b *cb.Block, m []byte) {
440440
ledger = append(ledger, b)
441441
})
442442

@@ -533,7 +533,7 @@ func TestBFTSynchronizer(t *testing.T) {
533533
require.NotNil(t, resp)
534534
require.Equal(t, *decision, resp)
535535
require.Equal(t, 103, len(ledger))
536-
require.Equal(t, 2, fakeCS.WriteBlockCallCount())
536+
require.Equal(t, 2, fakeCS.WriteBlockSyncCallCount())
537537
require.Equal(t, 1, fakeCS.WriteConfigBlockCallCount())
538538
wg.Wait()
539539
})

orderer/consensus/smartbft/util_network_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,11 @@ func createBFTChainUsingMocks(t *testing.T, node *Node, configInfo *ConfigInfo)
515515
node.State.AddBlock(block)
516516
node.Logger.Infof("Node %d appended block number %v to ledger", node.NodeId, block.Header.Number)
517517
}).Maybe()
518+
supportMock.EXPECT().WriteBlockSync(mock.Anything, mock.Anything).Run(
519+
func(block *cb.Block, encodedMetadataValue []byte) {
520+
node.State.AddBlock(block)
521+
node.Logger.Infof("Node %d appended block number %v to ledger", node.NodeId, block.Header.Number)
522+
}).Maybe()
518523

519524
supportMock.EXPECT().WriteConfigBlock(mock.Anything, mock.Anything).Run(
520525
func(block *cb.Block, encodedMetadataValue []byte) {

orderer/mocks/common/multichannel/multichannel.go

+5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ func (mcs *ConsenterSupport) WriteBlock(block *cb.Block, encodedMetadataValue []
110110
mcs.Append(block)
111111
}
112112

113+
// WriteBlock writes data to the Blocks channel
114+
func (mcs *ConsenterSupport) WriteBlockSync(block *cb.Block, encodedMetadataValue []byte) {
115+
mcs.WriteBlock(block, encodedMetadataValue)
116+
}
117+
113118
// WriteConfigBlock calls WriteBlock
114119
func (mcs *ConsenterSupport) WriteConfigBlock(block *cb.Block, encodedMetadataValue []byte) {
115120
mcs.WriteBlock(block, encodedMetadataValue)

0 commit comments

Comments
 (0)