Skip to content

Commit

Permalink
Use proto messages for Read-write set
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-2810

This CR:
- Introduces proto messages
- Removes custom types for read-write set in package kvledger/txmgmt/rwset
- Renames the package kvledger/txmgmt/rwset to kvledger/txmgmt/rwsetutil
  and rwset.go to rwset_builder_test.go in order to reflect the purpose
  of the remaining code better
- Modifies the other packages to use rwset from protos
  and utilities from rwsetutil package

Change-Id: Id01be87903ad30f0eea34ef4033195b17bec3e71
Signed-off-by: manish <manish.sethi@gmail.com>
  • Loading branch information
manish-sethi committed Mar 31, 2017
1 parent 3b48c41 commit 7d553a6
Show file tree
Hide file tree
Showing 23 changed files with 1,116 additions and 882 deletions.
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger/history/historydb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwset"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/core/ledger/util"
Expand Down Expand Up @@ -137,19 +137,19 @@ func (historyDB *historyDB) Commit(block *common.Block) error {
}

//preparation for extracting RWSet from transaction
txRWSet := &rwset.TxReadWriteSet{}
txRWSet := &rwsetutil.TxRwSet{}

// Get the Result from the Action and then Unmarshal
// it into a TxReadWriteSet using custom unmarshalling
if err = txRWSet.Unmarshal(respPayload.Results); err != nil {
if err = txRWSet.FromProtoBytes(respPayload.Results); err != nil {
return err
}
// for each transaction, loop through the namespaces and writesets
// and add a history record for each write
for _, nsRWSet := range txRWSet.NsRWs {
for _, nsRWSet := range txRWSet.NsRwSets {
ns := nsRWSet.NameSpace

for _, kvWrite := range nsRWSet.Writes {
for _, kvWrite := range nsRWSet.KvRwSet.Writes {
writeKey := kvWrite.Key

//composite key for history records is in the form ns~key~blockNo~tranNo
Expand Down
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hyperledger/fabric/common/ledger/util"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/kvledger/history/historydb"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwset"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
"github.com/hyperledger/fabric/core/ledger/ledgerconfig"
"github.com/hyperledger/fabric/protos/common"
putils "github.com/hyperledger/fabric/protos/utils"
Expand Down Expand Up @@ -129,19 +129,19 @@ func getTxIDandKeyWriteValueFromTran(

txID := chdr.TxId

txRWSet := &rwset.TxReadWriteSet{}
txRWSet := &rwsetutil.TxRwSet{}

// Get the Result from the Action and then Unmarshal
// it into a TxReadWriteSet using custom unmarshalling
if err = txRWSet.Unmarshal(respPayload.Results); err != nil {
if err = txRWSet.FromProtoBytes(respPayload.Results); err != nil {
return txID, nil, err
}

// look for the namespace and key by looping through the transaction's ReadWriteSets
for _, nsRWSet := range txRWSet.NsRWs {
for _, nsRWSet := range txRWSet.NsRwSets {
if nsRWSet.NameSpace == namespace {
// got the correct namespace, now find the key write
for _, kvWrite := range nsRWSet.Writes {
for _, kvWrite := range nsRWSet.KvRwSet.Writes {
if kvWrite.Key == key {
return txID, kvWrite.Value, nil
}
Expand Down

0 comments on commit 7d553a6

Please sign in to comment.