Skip to content

Commit

Permalink
Add function to get pvtdata metadata by keyhash
Browse files Browse the repository at this point in the history
During validation, key-based endorsement needs to
check the endorsement based on the key hash.

In the current code, query executor exposes a function
to retrieve the private data metadata by the private raw key.
This function is meant to be used by the chaincode in a simulation.

At the validation time, this raw private key is not available to all
the peers and in the hashed rwset, only the hash of the key is available.
Hence query executer needs to expose a function that accepts
the hash of the key.

FAB-12086 #done

Change-Id: I7398865f6f28a919daff8095291492832976f4ff
Signed-off-by: manish <[email protected]>
  • Loading branch information
manish-sethi committed Sep 21, 2018
1 parent 945138e commit e5547f2
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 905 deletions.
4 changes: 4 additions & 0 deletions common/mocks/ledger/queryexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (m *MockQueryExecutor) GetPrivateData(namespace, collection, key string) ([
return nil, nil
}

func (m *MockQueryExecutor) GetPrivateDataMetadataByHash(namespace, collection string, keyhash []byte) (map[string][]byte, error) {
return nil, nil
}

func (m *MockQueryExecutor) GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([][]byte, error) {
return nil, nil
}
Expand Down
75 changes: 75 additions & 0 deletions core/chaincode/mock/tx_simulator.go

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

5 changes: 5 additions & 0 deletions core/committer/txvalidator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,11 @@ func (exec *mockQueryExecutor) GetPrivateData(namespace, collection, key string)
return args.Get(0).([]byte), args.Error(1)
}

func (exec *mockQueryExecutor) GetPrivateDataMetadataByHash(namespace, collection string, keyhash []byte) (map[string][]byte, error) {
args := exec.Called(namespace, collection, keyhash)
return args.Get(0).(map[string][]byte), args.Error(1)
}

func (exec *mockQueryExecutor) GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([][]byte, error) {
args := exec.Called(namespace, collection, keys)
return args.Get(0).([][]byte), args.Error(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (q *lockBasedQueryExecutor) GetPrivateDataMetadata(namespace, collection, k
return q.helper.getPrivateDataMetadata(namespace, collection, key)
}

// GetPrivateDataMetadataByHash implements method in interface `ledger.QueryExecutor`
func (q *lockBasedQueryExecutor) GetPrivateDataMetadataByHash(namespace, collection string, keyhash []byte) (map[string][]byte, error) {
return q.helper.getPrivateDataMetadataByHash(namespace, collection, keyhash)
}
Expand Down
2 changes: 2 additions & 0 deletions core/ledger/ledger_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ type QueryExecutor interface {
GetPrivateData(namespace, collection, key string) ([]byte, error)
// GetPrivateDataMetadata gets the metadata of a private data item identified by a tuple <namespace, collection, key>
GetPrivateDataMetadata(namespace, collection, key string) (map[string][]byte, error)
// GetPrivateDataMetadataByHash gets the metadata of a private data item identified by a tuple <namespace, collection, keyhash>
GetPrivateDataMetadataByHash(namespace, collection string, keyhash []byte) (map[string][]byte, error)
// GetPrivateDataMultipleKeys gets the values for the multiple private data items in a single call
GetPrivateDataMultipleKeys(namespace, collection string, keys []string) ([][]byte, error)
// GetPrivateDataRangeScanIterator returns an iterator that contains all the key-values between given key ranges.
Expand Down
Loading

0 comments on commit e5547f2

Please sign in to comment.