Skip to content

Commit

Permalink
[FAB-14634] Write raw blocks if evicted
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yacovm committed Mar 13, 2019
1 parent aa14c14 commit af193e2
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 15 deletions.
6 changes: 6 additions & 0 deletions orderer/common/multichannel/chainsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ func (cs *ChainSupport) Sequence() uint64 {
return cs.ConfigtxValidator().Sequence()
}

// Append appends a new block to the ledger in its raw form,
// unlike WriteBlock that also mutates its metadata.
func (cs *ChainSupport) Append(block *cb.Block) error {
return cs.ledgerResources.ReadWriter.Append(block)
}

// VerifyBlockSignature verifies a signature of a block.
// It has an optional argument of a configuration envelope
// which would make the block verification to use validation rules
Expand Down
4 changes: 4 additions & 0 deletions orderer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ type ConsenterSupport interface {
// IsSystemChannel returns true if this is the system channel.
// The chain needs to know if it is system or standard for consensus-type migration.
IsSystemChannel() bool

// Append appends a new block to the ledger in its raw form,
// unlike WriteBlock that also mutates its metadata.
Append(block *cb.Block) error
}
2 changes: 1 addition & 1 deletion orderer/consensus/etcdraft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ func (c *Chain) newEvictionSuspector() *evictionSuspector {
return &evictionSuspector{
amIInChannel: ConsenterCertificate(c.opts.Cert).IsConsenterOfChannel,
evictionSuspicionThreshold: c.opts.EvictionSuspicion,
writeBlock: c.support.WriteBlock,
writeBlock: c.support.Append,
createPuller: c.createPuller,
height: c.support.Height,
triggerCatchUp: c.triggerCatchup,
Expand Down
7 changes: 5 additions & 2 deletions orderer/consensus/etcdraft/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ type evictionSuspector struct {
height func() uint64
amIInChannel cluster.SelfMembershipPredicate
halt func()
writeBlock func(block *common.Block, metadata []byte)
writeBlock func(block *common.Block) error
triggerCatchUp func(sn *raftpb.Snapshot)
halted bool
}
Expand Down Expand Up @@ -573,7 +573,10 @@ func (es *evictionSuspector) confirmSuspicion(cumulativeSuspicion time.Duration)
for seq := nextBlock; seq <= lastConfigBlock.Header.Number; seq++ {
es.logger.Infof("Pulling block %d", seq)
block := puller.PullBlock(seq)
es.writeBlock(block, nil)
err := es.writeBlock(block)
if err != nil {
es.logger.Panicf("Failed writing block %d to the ledger: %v", block.Header.Number, err)
}
}

es.logger.Infof("Pulled all blocks up to eviction block.")
Expand Down
4 changes: 2 additions & 2 deletions orderer/consensus/etcdraft/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ func TestEvictionSuspector(t *testing.T) {
t.Run(testCase.description, func(t *testing.T) {
committedBlocks := make(chan *common.Block, 2)

commitBlock := func(block *common.Block, metadata []byte) {
assert.Nil(t, metadata)
commitBlock := func(block *common.Block) error {
committedBlocks <- block
return nil
}

es := &evictionSuspector{
Expand Down
5 changes: 5 additions & 0 deletions orderer/consensus/kafka/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3792,3 +3792,8 @@ func (c *mockConsenterSupport) Height() uint64 {
func (c *mockConsenterSupport) IsSystemChannel() bool {
return false
}

func (c *mockConsenterSupport) Append(block *cb.Block) error {
c.Called(block)
return nil
}
89 changes: 81 additions & 8 deletions orderer/consensus/mocks/mock_consenter_support.go

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

11 changes: 9 additions & 2 deletions orderer/mocks/common/multichannel/multichannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func (mcs *ConsenterSupport) WriteBlock(block *cb.Block, encodedMetadataValue []
if encodedMetadataValue != nil {
block.Metadata.Metadata[cb.BlockMetadataIndex_ORDERER] = protoutil.MarshalOrPanic(&cb.Metadata{Value: encodedMetadataValue})
}
mcs.HeightVal++
mcs.Blocks <- block
mcs.Append(block)
}

// WriteConfigBlock calls WriteBlock
Expand Down Expand Up @@ -170,3 +169,11 @@ func (mcs *ConsenterSupport) VerifyBlockSignature(_ []*protoutil.SignedData, _ *
func (mcs *ConsenterSupport) IsSystemChannel() bool {
return mcs.SystemChannelVal
}

// Append appends a new block to the ledger in its raw form,
// unlike WriteBlock that also mutates its metadata.
func (mcs *ConsenterSupport) Append(block *cb.Block) error {
mcs.HeightVal++
mcs.Blocks <- block
return nil
}

0 comments on commit af193e2

Please sign in to comment.