Skip to content

Commit

Permalink
[FAB-1618]Cleanup ledger interfaces
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1618

Ledger interfaces changed, all ledger interfaces have
commit block method, this commit cleanup the interfaces.

Change-Id: I5df56a1ec5cb71e2474e3b5daeea6642842bc762
Signed-off-by: grapebaba <281165273@qq.com>
  • Loading branch information
GrapeBaBa committed Jan 23, 2017
1 parent 627c094 commit 2f6844a
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion core/committer/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import "github.com/hyperledger/fabric/protos/common"
type Committer interface {

// Commit block to the ledger
CommitBlock(block *common.Block) error
Commit(block *common.Block) error

// Get recent block sequence number
LedgerHeight() (uint64, error)
Expand Down
4 changes: 2 additions & 2 deletions core/committer/committer_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func NewLedgerCommitter(ledger ledger.PeerLedger, validator txvalidator.Validato
return &LedgerCommitter{ledger: ledger, validator: validator}
}

// CommitBlock commits block to into the ledger
func (lc *LedgerCommitter) CommitBlock(block *common.Block) error {
// Commit commits block to into the ledger
func (lc *LedgerCommitter) Commit(block *common.Block) error {
// Validate and mark invalid transactions
logger.Debug("Validating block")
lc.validator.Validate(block)
Expand Down
2 changes: 1 addition & 1 deletion core/committer/committer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestKVLedgerBlockStorage(t *testing.T) {
simRes, _ := simulator.GetTxSimulationResults()
block1 := testutil.ConstructBlock(t, [][]byte{simRes}, true)

err = committer.CommitBlock(block1)
err = committer.Commit(block1)
assert.NoError(t, err)

height, err = committer.LedgerHeight()
Expand Down
4 changes: 2 additions & 2 deletions core/ledger/kvledger/example/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func ConstructCommitter(ledger ledger.PeerLedger) *Committer {
return &Committer{ledger}
}

// CommitBlock commits the block
func (c *Committer) CommitBlock(rawBlock *common.Block) error {
// Commit commits the block
func (c *Committer) Commit(rawBlock *common.Block) error {
logger.Debugf("Committer validating the block...")
if err := c.ledger.Commit(rawBlock); err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions core/ledger/kvledger/example/main/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func initApp() {
accounts[3]: 100})
handleError(err, true)
rawBlock := consenter.ConstructBlock(tx)
err = committer.CommitBlock(rawBlock)
err = committer.Commit(rawBlock)
handleError(err, true)
printBlocksInfo(rawBlock)
logger.Debug("Exiting initApp()")
Expand All @@ -119,7 +119,7 @@ func transferFunds() {
rawBlock := consenter.ConstructBlock(tx1, tx2)

// act as committing peer to commit the Raw Block
err = committer.CommitBlock(rawBlock)
err = committer.Commit(rawBlock)
handleError(err, true)
printBlocksInfo(rawBlock)
logger.Debug("Exiting transferFunds")
Expand All @@ -139,7 +139,7 @@ func tryDoubleSpend() {
tx2, err := app.TransferFunds("account1", "account4", 50)
handleError(err, true)
rawBlock := consenter.ConstructBlock(tx1, tx2)
err = committer.CommitBlock(rawBlock)
err = committer.Commit(rawBlock)
handleError(err, true)
printBlocksInfo(rawBlock)
logger.Debug("Exiting tryDoubleSpend()")
Expand Down
4 changes: 2 additions & 2 deletions core/ledger/kvledger/marble_example/main/marble_example.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func initApp() {
tx, err := marbleApp.CreateMarble(marble)
handleError(err, true)
rawBlock := consenter.ConstructBlock(tx)
err = committer.CommitBlock(rawBlock)
err = committer.Commit(rawBlock)
handleError(err, true)
printBlocksInfo(rawBlock)
}
Expand All @@ -92,7 +92,7 @@ func transferMarble() {
tx1, err := marbleApp.TransferMarble([]string{"marble1", "jerry"})
handleError(err, true)
rawBlock := consenter.ConstructBlock(tx1)
err = committer.CommitBlock(rawBlock)
err = committer.Commit(rawBlock)
handleError(err, true)
printBlocksInfo(rawBlock)
}
Expand Down
6 changes: 2 additions & 4 deletions core/ledger/ledger_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ type Ledger interface {
GetBlocksIterator(startBlockNumber uint64) (ResultsIterator, error)
// Close closes the ledger
Close()
// Commit adds a new block
Commit(block *common.Block) error
}

// OrdererLedger implements methods required by 'orderer ledger'
type OrdererLedger interface {
Ledger
// CommitBlock adds a new block
CommitBlock(block *common.Block) error
}

// PeerLedgerProvider provides handle to ledger instances
Expand Down Expand Up @@ -91,8 +91,6 @@ type PeerLedger interface {
// A client can obtain more than one 'HistoryQueryExecutor's for parallel execution.
// Any synchronization should be performed at the implementation level if required
NewHistoryQueryExecutor() (HistoryQueryExecutor, error)
// Commits block into the ledger
Commit(block *common.Block) error
//Prune prunes the blocks/transactions that satisfy the given policy
Prune(policy PrunePolicy) error
}
Expand Down
4 changes: 2 additions & 2 deletions core/ledger/ordererledger/fs_ordererledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (rl *fsBasedOrdererLedger) Close() {
rl.blockStore.Shutdown()
}

// CommitBlock adds a new block
func (rl *fsBasedOrdererLedger) CommitBlock(block *common.Block) error {
// Commit adds a new block
func (rl *fsBasedOrdererLedger) Commit(block *common.Block) error {
return rl.blockStore.AddBlock(block)
}
2 changes: 1 addition & 1 deletion core/ledger/ordererledger/fs_ordererledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestOrdererLedger(t *testing.T) {
// Construct test blocks and add to orderer ledger
blocks := testutil.ConstructTestBlocks(t, 10)
for _, block := range blocks {
ordererLedger.CommitBlock(block)
ordererLedger.Commit(block)
}

// test GetBlockchainInfo()
Expand Down
2 changes: 1 addition & 1 deletion gossip/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ func (s *GossipStateProviderImpl) AddPayload(payload *proto.Payload) error {
}

func (s *GossipStateProviderImpl) commitBlock(block *common.Block, seqNum uint64) error {
if err := s.committer.CommitBlock(block); err != nil {
if err := s.committer.Commit(block); err != nil {
s.logger.Errorf("Got error while committing(%s)\n", err)
return err
}
Expand Down

0 comments on commit 2f6844a

Please sign in to comment.