Skip to content

Commit

Permalink
[LEDGER] merge ledgerstorage with kvledger pkg (hyperledger#942)
Browse files Browse the repository at this point in the history
* merge ledgerstorage with kvledger pkg

The ledgerstorage package encapsulates both pvtdata storage and
block storage. We needed this package as

 - we had to have 2-phase commit between pvtdata storage and block storage.
 - we had a recovery logic that was needed after a commit failure or
   peer crash between pvtdata commit and blockstore commit.
 - we treated pvtdata store as a pvt blockstore and blockstore as
   public block store.

After introducing the support for peer rollback, we removed the 2-phase
commit between requirement between the pvtdata storage and block storage.
As a result, the pvtdata storage can be ahead of blockstore. Hence, the
recovery logic was also remoted. Hence, the motivation for having
ledgerstorage package became feeble and hence, we remove it.

Signed-off-by: senthil <cendhu@gmail.com>

* address review comments

Signed-off-by: senthil <cendhu@gmail.com>
  • Loading branch information
cendhu authored Apr 18, 2020
1 parent 89eb4a3 commit ec725f9
Show file tree
Hide file tree
Showing 20 changed files with 795 additions and 876 deletions.
5 changes: 5 additions & 0 deletions core/chaincode/lifecycle/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func (c *Cache) InitializeLocalChaincodes() error {
return nil
}

// Name returns the name of the listener
func (c *Cache) Name() string {
return "lifecycle cache listener"
}

// Initialize will populate the set of currently committed chaincode definitions
// for a channel into the cache. Note, it this looks like a bit of a DRY violation
// with respect to 'Update', but, the error handling is quite different and attempting
Expand Down
5 changes: 5 additions & 0 deletions core/ledger/cceventmgmt/lsccstate_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ type KVLedgerLSCCStateListener struct {
DeployedChaincodeInfoProvider ledger.DeployedChaincodeInfoProvider
}

// Name returns the name of the listener
func (listener *KVLedgerLSCCStateListener) Name() string {
return "lscc state listener"
}

func (listener *KVLedgerLSCCStateListener) Initialize(ledgerID string, qe ledger.SimpleQueryExecutor) error {
// Noop
return nil
Expand Down
5 changes: 5 additions & 0 deletions core/ledger/confighistory/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func NewMgr(dbPath string, ccInfoProvider ledger.DeployedChaincodeInfoProvider)
return &mgr{ccInfoProvider, p}, nil
}

// Name returns the name of the listener
func (m *mgr) Name() string {
return "collection configuration history listener"
}

func (m *mgr) Initialize(ledgerID string, qe ledger.SimpleQueryExecutor) error {
// Noop
return nil
Expand Down
5 changes: 5 additions & 0 deletions core/ledger/kvledger/coll_elg_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ type collElgNotifier struct {
listeners map[string]collElgListener
}

// Name returns the name of the listener
func (n *collElgNotifier) Name() string {
return "collection eligibility listener"
}

func (n *collElgNotifier) Initialize(ledgerID string, qe ledger.SimpleQueryExecutor) error {
// Noop
return nil
Expand Down
8 changes: 4 additions & 4 deletions core/ledger/kvledger/hashcheck_pvtdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
"bytes"

"github.com/hyperledger/fabric-protos-go/ledger/rwset"
"github.com/hyperledger/fabric/common/ledger/blkstorage"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
"github.com/hyperledger/fabric/core/ledger/ledgerstorage"
"github.com/hyperledger/fabric/protoutil"
)

// constructValidAndInvalidPvtData computes the valid pvt data and hash mismatch list
// from a received pvt data list of old blocks.
func constructValidAndInvalidPvtData(reconciledPvtdata []*ledger.ReconciledPvtdata, blockStore *ledgerstorage.Store) (
func constructValidAndInvalidPvtData(reconciledPvtdata []*ledger.ReconciledPvtdata, blockStore blkstorage.BlockStore) (
map[uint64][]*ledger.TxPvtData, []*ledger.PvtdataHashMismatch, error,
) {
// for each block, for each transaction, retrieve the txEnvelope to
Expand All @@ -42,7 +42,7 @@ func constructValidAndInvalidPvtData(reconciledPvtdata []*ledger.ReconciledPvtda
return validPvtData, invalidPvtData, nil
}

func findValidAndInvalidPvtdata(reconciledPvtdata *ledger.ReconciledPvtdata, blockStore *ledgerstorage.Store) (
func findValidAndInvalidPvtdata(reconciledPvtdata *ledger.ReconciledPvtdata, blockStore blkstorage.BlockStore) (
[]*ledger.TxPvtData, []*ledger.PvtdataHashMismatch, error,
) {
var validPvtData []*ledger.TxPvtData
Expand Down Expand Up @@ -70,7 +70,7 @@ func findValidAndInvalidPvtdata(reconciledPvtdata *ledger.ReconciledPvtdata, blo
return validPvtData, invalidPvtData, nil
}

func retrieveRwsetForTx(blkNum uint64, txNum uint64, blockStore *ledgerstorage.Store) (*rwsetutil.TxRwSet, error) {
func retrieveRwsetForTx(blkNum uint64, txNum uint64, blockStore blkstorage.BlockStore) (*rwsetutil.TxRwSet, error) {
// retrieve the txEnvelope from the block store so that the hash of
// the pvtData can be retrieved for comparison
txEnvelope, err := blockStore.RetrieveTxByBlockNumTranNum(blkNum, txNum)
Expand Down
5 changes: 3 additions & 2 deletions core/ledger/kvledger/hashcheck_pvtdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import (
"github.com/hyperledger/fabric/common/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
"github.com/hyperledger/fabric/core/ledger/mock"
"github.com/hyperledger/fabric/protoutil"
"github.com/stretchr/testify/assert"
)

func TestConstructValidInvalidBlocksPvtData(t *testing.T) {
conf, cleanup := testConfig(t)
defer cleanup()
provider := testutilNewProvider(conf, t)
provider := testutilNewProvider(conf, t, &mock.DeployedChaincodeInfoProvider{})
defer provider.Close()

_, gb := testutil.NewBlockGenerator(t, "testLedger", false)
Expand Down Expand Up @@ -82,7 +83,7 @@ func TestConstructValidInvalidBlocksPvtData(t *testing.T) {
Block: blk1,
PvtData: pvtDataBlk1,
MissingPvtData: missingData}
assert.NoError(t, lg.(*kvLedger).blockStore.CommitWithPvtData(blockAndPvtData1))
assert.NoError(t, lg.(*kvLedger).commitToPvtAndBlockStore(blockAndPvtData1))

// construct pvtData from missing data in tx3, tx6, and tx7
pvtdata := []*ledger.ReconciledPvtdata{
Expand Down
Loading

0 comments on commit ec725f9

Please sign in to comment.