Skip to content

Commit af193e2

Browse files
committed
[FAB-14634] Write raw blocks if evicted
This change set adds Append() to the consenter support, and changes the eviction logic to use Append() instead of WriteBlock, so that the blocks that are pulled from OSNs are not changed and are written as is into the ledger. Change-Id: I76abe64990f1855b53dadb0655c5830169ef7ed1 Signed-off-by: yacovm <yacovm@il.ibm.com>
1 parent aa14c14 commit af193e2

File tree

8 files changed

+113
-15
lines changed

8 files changed

+113
-15
lines changed

orderer/common/multichannel/chainsupport.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ func (cs *ChainSupport) Sequence() uint64 {
207207
return cs.ConfigtxValidator().Sequence()
208208
}
209209

210+
// Append appends a new block to the ledger in its raw form,
211+
// unlike WriteBlock that also mutates its metadata.
212+
func (cs *ChainSupport) Append(block *cb.Block) error {
213+
return cs.ledgerResources.ReadWriter.Append(block)
214+
}
215+
210216
// VerifyBlockSignature verifies a signature of a block.
211217
// It has an optional argument of a configuration envelope
212218
// which would make the block verification to use validation rules

orderer/consensus/consensus.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,8 @@ type ConsenterSupport interface {
115115
// IsSystemChannel returns true if this is the system channel.
116116
// The chain needs to know if it is system or standard for consensus-type migration.
117117
IsSystemChannel() bool
118+
119+
// Append appends a new block to the ledger in its raw form,
120+
// unlike WriteBlock that also mutates its metadata.
121+
Append(block *cb.Block) error
118122
}

orderer/consensus/etcdraft/chain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ func (c *Chain) newEvictionSuspector() *evictionSuspector {
13101310
return &evictionSuspector{
13111311
amIInChannel: ConsenterCertificate(c.opts.Cert).IsConsenterOfChannel,
13121312
evictionSuspicionThreshold: c.opts.EvictionSuspicion,
1313-
writeBlock: c.support.WriteBlock,
1313+
writeBlock: c.support.Append,
13141314
createPuller: c.createPuller,
13151315
height: c.support.Height,
13161316
triggerCatchUp: c.triggerCatchup,

orderer/consensus/etcdraft/util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ type evictionSuspector struct {
519519
height func() uint64
520520
amIInChannel cluster.SelfMembershipPredicate
521521
halt func()
522-
writeBlock func(block *common.Block, metadata []byte)
522+
writeBlock func(block *common.Block) error
523523
triggerCatchUp func(sn *raftpb.Snapshot)
524524
halted bool
525525
}
@@ -573,7 +573,10 @@ func (es *evictionSuspector) confirmSuspicion(cumulativeSuspicion time.Duration)
573573
for seq := nextBlock; seq <= lastConfigBlock.Header.Number; seq++ {
574574
es.logger.Infof("Pulling block %d", seq)
575575
block := puller.PullBlock(seq)
576-
es.writeBlock(block, nil)
576+
err := es.writeBlock(block)
577+
if err != nil {
578+
es.logger.Panicf("Failed writing block %d to the ledger: %v", block.Header.Number, err)
579+
}
577580
}
578581

579582
es.logger.Infof("Pulled all blocks up to eviction block.")

orderer/consensus/etcdraft/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ func TestEvictionSuspector(t *testing.T) {
445445
t.Run(testCase.description, func(t *testing.T) {
446446
committedBlocks := make(chan *common.Block, 2)
447447

448-
commitBlock := func(block *common.Block, metadata []byte) {
449-
assert.Nil(t, metadata)
448+
commitBlock := func(block *common.Block) error {
450449
committedBlocks <- block
450+
return nil
451451
}
452452

453453
es := &evictionSuspector{

orderer/consensus/kafka/chain_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,3 +3792,8 @@ func (c *mockConsenterSupport) Height() uint64 {
37923792
func (c *mockConsenterSupport) IsSystemChannel() bool {
37933793
return false
37943794
}
3795+
3796+
func (c *mockConsenterSupport) Append(block *cb.Block) error {
3797+
c.Called(block)
3798+
return nil
3799+
}

orderer/consensus/mocks/mock_consenter_support.go

Lines changed: 81 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

orderer/mocks/common/multichannel/multichannel.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ func (mcs *ConsenterSupport) WriteBlock(block *cb.Block, encodedMetadataValue []
102102
if encodedMetadataValue != nil {
103103
block.Metadata.Metadata[cb.BlockMetadataIndex_ORDERER] = protoutil.MarshalOrPanic(&cb.Metadata{Value: encodedMetadataValue})
104104
}
105-
mcs.HeightVal++
106-
mcs.Blocks <- block
105+
mcs.Append(block)
107106
}
108107

109108
// WriteConfigBlock calls WriteBlock
@@ -170,3 +169,11 @@ func (mcs *ConsenterSupport) VerifyBlockSignature(_ []*protoutil.SignedData, _ *
170169
func (mcs *ConsenterSupport) IsSystemChannel() bool {
171170
return mcs.SystemChannelVal
172171
}
172+
173+
// Append appends a new block to the ledger in its raw form,
174+
// unlike WriteBlock that also mutates its metadata.
175+
func (mcs *ConsenterSupport) Append(block *cb.Block) error {
176+
mcs.HeightVal++
177+
mcs.Blocks <- block
178+
return nil
179+
}

0 commit comments

Comments
 (0)