1

I'm encountering an error when i try to update two assets that are related to the same asset. I'm getting the error after the upgrade from HL Composer v0.18.1 to v0.19.4.

Here the models:

asset Order identified by pullID {
  o String pullID
  --> PackCase caseNumber optional
}

asset PackCase identified by caseNumber{
    o String caseNumber
    --> Order[] orders optional
}

I want to associate Order1 and Order2 to Packcase1. To do this i use this method in transaction processor, which insert the order into the packcase.orders array and update the reference of order.casenumber simmultaneously:

function AssociatePackCaseToOrder(tx){

    tx.order.caseNumber = tx.packCase;
    tx.packCase.orders.push(tx.order);

    return getAssetRegistry(namespaceAsset+'.Order')
    .then(function(ordersRegistry){
        return ordersRegistry.update(tx.order)
        .then(function(){
            console.info("Order Updated");
            return getAssetRegistry(namespaceAsset+'.PackCase')
            .then(function(packCaseRegistry){
                return packCaseRegistry.update(tx.packCase)
                .then(function(){
                    console.info("PackCase Updated");
                })
            })
        })
    })
}

But when i try to invoke this method two times sequentially i get this error:

Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error:
Error: 8 RESOURCE_EXHAUSTED: received trailing metadata size exceeds limit",
"stack":"Error: Error trying invoke business network. Error: No valid responses from any peers.
Response from attempted peer comms was an error: Error: 8 RESOURCE_EXHAUSTED: received trailing metadata size exceeds limit
at _initializeChannel.then.then.then.then.catch (/usr/lib/node_modules/composer-rest-server/node_modules/composer-connector-hlfv1/lib/hlfconnection.js:967:34)
at <anonymous>

Does anyone know what could be the reason of the error?

Leonardo Carraro
  • 1,532
  • 1
  • 11
  • 24

1 Answers1

3

I think there's a problem in your code, and RESOURCE_EXHAUSTED (which is likely to come from grpc message size limits) - possibly the first line where you're assigning an object to a String.

Currently (though you've not posted the transaction model) you're trying to associate an Order (or collection of) with a PackCase - your code shows its one transaction at a time (you update the registry per resource). The code shown below, adds the casenumber reference to the Order and pushes the Order ID (FQ identifier) into the array on PackCase.

So with a model like this:

asset Order identified by pullID {
  o String pullID
  o String caseNumber optional
  --> PackCase packcase optional // this would make more sense naming-wise
}

asset PackCase identified by caseNumber {
    o String caseNumber
    --> Order[] orders optional    
    // o Order[] orders optional   // alternative, see below.
}

transaction acpto {
  --> Order order
  --> PackCase packCase
}

your transaction code is like this:

/**
     * Associate the Packcase to order
     * @param {org.acme.mynetwork.acpto} tx - the tx to be processed
     * @transaction
**/



function AssociatePackCaseToOrder(tx){

   var namespaceAsset = 'org.acme.mynetwork';
    tx.order.caseNumber = tx.packCase.getIdentifier(); // eg. '1'
   console.log(" case ref is " +  tx.packCase.getIdentifier() ); 
   console.log(" order ref is " +  tx.order.getIdentifier() );

 //  tx.order.pullID  = tx.order.getIdentifier(); // because its a relationship, will still have the FQ identifer hence commented out FYI


    if(tx.packCase.orders == null) {
        tx.packCase.orders  = []; // initialise
    }

    tx.packCase.orders.push(tx.order);

    return getAssetRegistry(namespaceAsset+'.Order')
    .then(function(ordersRegistry){
        return ordersRegistry.update(tx.order)
        .then(function(){
            console.info("Order Updated");
            return getAssetRegistry(namespaceAsset+'.PackCase')
            .then(function(packCaseRegistry){
                return packCaseRegistry.update(tx.packCase)
                .then(function(){
                    console.info("PackCase Updated");
                })
            })
        })
    })
}

Your method: --> Order[] orders optional

{
      "$class": "org.acme.mynetwork.PackCase",
      "caseNumber": "5",
      "orders": [
        "resource:org.acme.mynetwork.Order#1",
        "resource:org.acme.mynetwork.Order#2",
        "resource:org.acme.mynetwork.Order#3"
      ]
    }

alternative Order[] orders optional:

after submitting 3 transactions for Order 1, Order 2 and Order 3, you get this in the PackCase asset:

{
  "$class": "org.acme.mynetwork.PackCase",
  "caseNumber": "3",
  "orders": [
    {
      "$class": "org.acme.mynetwork.Order", 
      "pullID": "1",
      "caseNumber": "3"
    },
    {
      "$class": "org.acme.mynetwork.Order",
      "pullID": "2",
      "caseNumber": "3"
    }
    {
      "$class": "org.acme.mynetwork.Order",
      "pullID": "3",
      "caseNumber": "3"
    }
  ]
}

Suffice to say, the Order casenumber is updated with the case reference number from PackCase.

Paul O'Mahony
  • 6,740
  • 1
  • 10
  • 15
  • Thanks for the answer, it helped me to find the problem. I was referencing the assets one each other too many time, creating a loop of references.For this reason when i was trying to update the asset in the transaction processor, it wasn't able to handle the object. I resolved by replacing the reference field with a string that contains the ID of the asset. – Leonardo Carraro May 15 '18 at 13:47