Why cant getPrivateDataByPartialCompositeKey and putState be used in single transaction.


Sumitvedpathak@...
 

Hi Folks,
I am working on Auction application, where i have three organizations. Any org can create an Auction for an asset, but cannot bid. Other organizations can bid for an asset. All bids associated to an Asset should be seen only by an asset owner, and based on the bids, highest bid will be selected an asset will be assigned to new owner.
Now in order to see all bids by owner, i am using getPrivateDataByPartialCompositeKey method, this works perfectly fine, and no issues.
But while closing bids, i need to extract the all the list from getPrivateDataByPartialCompositeKey, choose highest bid by iterating, and then update using putState an asset with the highest bid and assign an new owner. 
Here i receive an error 
Error: endorsement failure during invoke. response: status:500 message:"error in simulation: transaction returned with failure: Error: PUT_STATE failed: transaction ID: 35c9fae2....: txid [35c9fae2....]: Transaction has already performed queries on pvt data. Writes are not allowed"
From the error looks like this is not allowed. But why?  getPrivateDataByPartialCompositeKey is nothing but read operation from Private store and putState is an write operation on StateDb, which are all different identity and the object which i am reading are bids and updating an asset object, which are two completely different objects. 

Regards,
Sumit


Yacov
 

Recall, that regardless if a peer has private data or not for some transaction, it still validates the transaction by performing endorsement policy checks, and multi-version concurrency control checks.
 
Also, note that private data also hashes keys, not just values, and that getPrivateDataByPartialCompositeKey iterates over the pre-images of the keys, not the hashes of the keys, but not all peers have the pre-images by definition and mechanism of private data.
 
Now, if you have a transaction where you performed a range query by key, even the peer that endorsed that transaction has the pre-images other peers may not have the pre-images, hence they will not be able to re-run the same range query at validation time.
 
To prevent peers from forking their state, Fabric forbids writes if there was a private data range query.
 

----- Original message -----
From: Sumitvedpathak@...
Sent by: fabric@...
To: fabric@...
Cc:
Subject: [EXTERNAL] [Hyperledger Fabric] Why cant getPrivateDataByPartialCompositeKey and putState be used in single transaction.
Date: Thu, Sep 2, 2021 6:43 PM
 
Hi Folks, I am working on Auction application, where i have three organizations. Any org can create an Auction for an asset, but cannot bid. Other organizations can bid for an asset. All bids associated to an Asset should be seen only by an ZjQcmQRYFpfptBannerStart
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd
Hi Folks,
I am working on Auction application, where i have three organizations. Any org can create an Auction for an asset, but cannot bid. Other organizations can bid for an asset. All bids associated to an Asset should be seen only by an asset owner, and based on the bids, highest bid will be selected an asset will be assigned to new owner.
Now in order to see all bids by owner, i am using getPrivateDataByPartialCompositeKey method, this works perfectly fine, and no issues.
But while closing bids, i need to extract the all the list from getPrivateDataByPartialCompositeKey, choose highest bid by iterating, and then update using putState an asset with the highest bid and assign an new owner. 
Here i receive an error 
Error: endorsement failure during invoke. response: status:500 message:"error in simulation: transaction returned with failure: Error: PUT_STATE failed: transaction ID: 35c9fae2....: txid [35c9fae2....]: Transaction has already performed queries on pvt data. Writes are not allowed"
From the error looks like this is not allowed. But why?  getPrivateDataByPartialCompositeKey is nothing but read operation from Private store and putState is an write operation on StateDb, which are all different identity and the object which i am reading are bids and updating an asset object, which are two completely different objects. 

Regards,
Sumit
 



David Enyeart
 

To resolve this, you can first query the chaincode to find the keys that need to be updated, and then pass those keys to a 2nd chaincode invocation that does the updates.
Just be aware that in the interim it is technically possible that another transaction may have updated these keys or added other keys that should be considered in the query results (this is what Fabric is checking for if you query/update in a single transaction). If this is not a concern in your specific application, then you should be able to use this approach.


Dave Enyeart


"Yacov" ---09/02/2021 11:54:27 AM---Recall, that regardless if a peer has private data or not for some transaction, it still validates t

From: "Yacov" <yacovm@...>
To: Sumitvedpathak@...
Cc: fabric@...
Date: 09/02/2021 11:54 AM
Subject: [EXTERNAL] Re: [Hyperledger Fabric] Why cant getPrivateDataByPartialCompositeKey and putState be used in single transaction.
Sent by: fabric@...





Recall, that regardless if a peer has private data or not for some transaction, it still validates the transaction by performing endorsement policy checks, and multi-version concurrency control checks. Also, note that private data also hashes ZjQcmQRYFpfptBannerStart 
This Message Is From an External Sender
This message came from outside your organization.
ZjQcmQRYFpfptBannerEnd
Recall, that regardless if a peer has private data or not for some transaction, it still validates the transaction by performing endorsement policy checks, and multi-version concurrency control checks.
 
Also, note that private data also hashes keys, not just values, and that getPrivateDataByPartialCompositeKey iterates over the pre-images of the keys, not the hashes of the keys, but not all peers have the pre-images by definition and mechanism of private data.
 
Now, if you have a transaction where you performed a range query by key, even the peer that endorsed that transaction has the pre-images other peers may not have the pre-images, hence they will not be able to re-run the same range query at validation time.
 
To prevent peers from forking their state, Fabric forbids writes if there was a private data range query.

 
    ----- Original message -----
    From: Sumitvedpathak@...
    Sent by: fabric@...
    To: fabric@...
    Cc:
    Subject: [EXTERNAL] [Hyperledger Fabric] Why cant getPrivateDataByPartialCompositeKey and putState be used in single transaction.
    Date: Thu, Sep 2, 2021 6:43 PM

    Hi Folks, I am working on Auction application, where i have three organizations. Any org can create an Auction for an asset, but cannot bid. Other organizations can bid for an asset. All bids associated to an Asset should be seen only by an ZjQcmQRYFpfptBannerStart
     
    This Message Is From an External Sender
    This message came from outside your organization.
    ZjQcmQRYFpfptBannerEnd
    Hi Folks,
    I am working on Auction application, where i have three organizations. Any org can create an Auction for an asset, but cannot bid. Other organizations can bid for an asset. All bids associated to an Asset should be seen only by an asset owner, and based on the bids, highest bid will be selected an asset will be assigned to new owner.
    Now in order to see all bids by owner, i am using getPrivateDataByPartialCompositeKey method, this works perfectly fine, and no issues.
    But while closing bids, i need to extract the all the list from
    getPrivateDataByPartialCompositeKey, choose highest bid by iterating, and then update using putState an asset with the highest bid and assign an new owner.
    Here i receive an error  
      Error: endorsement failure during invoke. response: status:500 message:"error in simulation: transaction returned with failure: Error: PUT_STATE failed: transaction ID: 35c9fae2....: txid [35c9fae2....]: Transaction has already performed queries on pvt data. Writes are not allowed"
    From the error looks like this is not allowed. But why?  getPrivateDataByPartialCompositeKey is nothing but read operation from Private store and putState is an write operation on StateDb, which are all different identity and the object which i am reading are bids and updating an asset object, which are two completely different objects.

    Regards,
    Sumit