State Hash Root problem (ie) Validator not adding a block












0















A client calls rest-api then it sends data to validator, the transaction processor and validator talks, finally when the validator processes the transaction and creates a block. At this point, in my case it shows the following error log:



> sawtooth-validator-default | [2018-12-31 07:36:44.519 DEBUG   
> block_validator] Adding block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> for processing sawtooth-validator-default | [2018-12-31 07:36:44.532
> WARNING block_validator] Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
> failed validation: Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
>
> failed state root hash validation. Expected
> 08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114 but
> got 92673edb4422d913aadb6e49fa1e82688a27589ac98acdd7a8f713d6accd1f25
>
> ========================================================================
>
> sawtooth-validator-default | [2018-12-31 07:36:44.532 DEBUG
> block_validator] Removing block from processing
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a


Actual expected result is: the block should be created and added to the blockchain










share|improve this question

























  • Are returning the result of your state write operation from the TP? That could be a reason. Could you share the code?

    – 1sn0s
    Jan 24 at 16:28













  • @1sn0s yes, returning the state write operation from the TP made the problem. transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Old TP in gist gist.github.com/KarthickLinganathan/… now its been changed , managed promises in a good way

    – Gowrishankar R
    Jan 25 at 14:18


















0















A client calls rest-api then it sends data to validator, the transaction processor and validator talks, finally when the validator processes the transaction and creates a block. At this point, in my case it shows the following error log:



> sawtooth-validator-default | [2018-12-31 07:36:44.519 DEBUG   
> block_validator] Adding block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> for processing sawtooth-validator-default | [2018-12-31 07:36:44.532
> WARNING block_validator] Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
> failed validation: Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
>
> failed state root hash validation. Expected
> 08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114 but
> got 92673edb4422d913aadb6e49fa1e82688a27589ac98acdd7a8f713d6accd1f25
>
> ========================================================================
>
> sawtooth-validator-default | [2018-12-31 07:36:44.532 DEBUG
> block_validator] Removing block from processing
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a


Actual expected result is: the block should be created and added to the blockchain










share|improve this question

























  • Are returning the result of your state write operation from the TP? That could be a reason. Could you share the code?

    – 1sn0s
    Jan 24 at 16:28













  • @1sn0s yes, returning the state write operation from the TP made the problem. transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Old TP in gist gist.github.com/KarthickLinganathan/… now its been changed , managed promises in a good way

    – Gowrishankar R
    Jan 25 at 14:18
















0












0








0








A client calls rest-api then it sends data to validator, the transaction processor and validator talks, finally when the validator processes the transaction and creates a block. At this point, in my case it shows the following error log:



> sawtooth-validator-default | [2018-12-31 07:36:44.519 DEBUG   
> block_validator] Adding block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> for processing sawtooth-validator-default | [2018-12-31 07:36:44.532
> WARNING block_validator] Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
> failed validation: Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
>
> failed state root hash validation. Expected
> 08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114 but
> got 92673edb4422d913aadb6e49fa1e82688a27589ac98acdd7a8f713d6accd1f25
>
> ========================================================================
>
> sawtooth-validator-default | [2018-12-31 07:36:44.532 DEBUG
> block_validator] Removing block from processing
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a


Actual expected result is: the block should be created and added to the blockchain










share|improve this question
















A client calls rest-api then it sends data to validator, the transaction processor and validator talks, finally when the validator processes the transaction and creates a block. At this point, in my case it shows the following error log:



> sawtooth-validator-default | [2018-12-31 07:36:44.519 DEBUG   
> block_validator] Adding block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> for processing sawtooth-validator-default | [2018-12-31 07:36:44.532
> WARNING block_validator] Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
> failed validation: Block
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a
> (block_num:3,
> state:08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114,
> previous_block_id:b79c22c94151e76cefcb21ed3c374aa512bff68981bb6b677610e76a8c12a6b2211c3634deb31c0d46ec26f568ed98f27f571625d76e37ee160ca0a9c071ff37)
>
> failed state root hash validation. Expected
> 08afc967eb593120ba5db6d1db548c4b91f26801c3d290fd655a789d51753114 but
> got 92673edb4422d913aadb6e49fa1e82688a27589ac98acdd7a8f713d6accd1f25
>
> ========================================================================
>
> sawtooth-validator-default | [2018-12-31 07:36:44.532 DEBUG
> block_validator] Removing block from processing
> 5cad74473aec314bae031acece18fd2b3866ace5c53652118440204e71fc493f4e2251f76298dc7721e8476ad629e0ba0ac533b9fe925bcc63f29c1a6c60795a


Actual expected result is: the block should be created and added to the blockchain







javascript hyperledger-sawtooth






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 9:06









Frank C.

5,88532639




5,88532639










asked Dec 31 '18 at 11:06









Gowrishankar RGowrishankar R

33




33













  • Are returning the result of your state write operation from the TP? That could be a reason. Could you share the code?

    – 1sn0s
    Jan 24 at 16:28













  • @1sn0s yes, returning the state write operation from the TP made the problem. transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Old TP in gist gist.github.com/KarthickLinganathan/… now its been changed , managed promises in a good way

    – Gowrishankar R
    Jan 25 at 14:18





















  • Are returning the result of your state write operation from the TP? That could be a reason. Could you share the code?

    – 1sn0s
    Jan 24 at 16:28













  • @1sn0s yes, returning the state write operation from the TP made the problem. transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Old TP in gist gist.github.com/KarthickLinganathan/… now its been changed , managed promises in a good way

    – Gowrishankar R
    Jan 25 at 14:18



















Are returning the result of your state write operation from the TP? That could be a reason. Could you share the code?

– 1sn0s
Jan 24 at 16:28







Are returning the result of your state write operation from the TP? That could be a reason. Could you share the code?

– 1sn0s
Jan 24 at 16:28















@1sn0s yes, returning the state write operation from the TP made the problem. transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Old TP in gist gist.github.com/KarthickLinganathan/… now its been changed , managed promises in a good way

– Gowrishankar R
Jan 25 at 14:18







@1sn0s yes, returning the state write operation from the TP made the problem. transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Old TP in gist gist.github.com/KarthickLinganathan/… now its been changed , managed promises in a good way

– Gowrishankar R
Jan 25 at 14:18














2 Answers
2






active

oldest

votes


















1














The validator will send your TP the same transaction request multiple times. If your TP sets data on the chain with a different address and/or data hash than the validator fails the transaction. It does this for security but it has implications to your TP.



Your TP must not create addresses or data in the TP that given the same input would produce different output. The TP address and data set in the transaction must be deterministic.



If you are generating some unique bit of information (such as time or encryption) then you should do that in the client before sending it to the TP.



Updated:



As pointed out, the data being stored is an associative structure. Because the order in the native association is not deterministic, it is likely the root issue. Adding another protobuf structure to capture the name/value and adding that to an ordered array before saving the data (set) to the chain will solve that.



As per the documentation:




Data structures which don’t enforce ordered serialization (e.g. sets,
maps, dicts) should be avoided.







share|improve this answer


























  • Hi Frank, Even after not creating or generating any address, Still we are getting the same error.

    – Gowrishankar R
    Jan 1 at 8:01













  • The data you set at the address, does the TP create any of the content or is it identical to the payload sent in the transaction?

    – Frank C.
    Jan 1 at 8:53













  • let address="d990b8c7eac5759277b2ac7664935e3782e34d26b56aa22f21c7fc988e9f13e238353a"; It was like the below before later i changed to the above one. // let address = NAMESPACE[2] + hash(payload.id).substring(0, 64); //console.log("address :",address)

    – Gowrishankar R
    Jan 1 at 9:58













  • What about the data itself that you put at that address?

    – Frank C.
    Jan 1 at 13:30











  • {"Location":"test","Latitude":1,"Longitude":8} is the data we are storing at that address

    – Gowrishankar R
    Jan 3 at 11:34



















0














The above mentioned state root problem is because of transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Manage to write the promises correctly solved my problem.



apply(transactionRequest, context) {
var payload=cbor.decode(transactionRequest.payload)
if (!payload.action) {
throw new InvalidTransaction("Payload doesn't contain the
action");
}
if (!payload.data) {
throw new InvalidTransaction("Payload doesn't contain the Data");
}
let action = payload.action;
let address = NAMESPACE + hash(payload.data.productID).substring(0,
64);
switch (action) {
case "updateProduct":
return context.getState([address])
.then((possibleAddressValues)=>{
let stateValue = possibleAddressValues[address];
if (stateValue && stateValue.length) {
let value = JSON.parse(cbor.decode(stateValue));
console.log("decoded values : ",value)
if (payload.data.price) {
value.price = payload["data"]["price"]
}
if (payload.data.itemsInInventory) {
value.itemsInInventory = payload["data"]["itemsInInventory"]
}
console.log("values after updating status : ",value)
let entries = {
[address]: cbor.encode(JSON.stringify(value))
}
return context.setState(entries);

}else{
throw new InvalidTransaction("there is no Product for given Product ID : ",payload.data.purchaseId);
}
})
.catch((err)=>{
console.log(new Date()+"Error while getting and setting confirm status for Product ID : ",payload.purchaseId );
})
break;
default:
throw new InvalidTransaction("The action is Invalid or not supported by this transaction processor");
}
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986720%2fstate-hash-root-problem-ie-validator-not-adding-a-block%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The validator will send your TP the same transaction request multiple times. If your TP sets data on the chain with a different address and/or data hash than the validator fails the transaction. It does this for security but it has implications to your TP.



    Your TP must not create addresses or data in the TP that given the same input would produce different output. The TP address and data set in the transaction must be deterministic.



    If you are generating some unique bit of information (such as time or encryption) then you should do that in the client before sending it to the TP.



    Updated:



    As pointed out, the data being stored is an associative structure. Because the order in the native association is not deterministic, it is likely the root issue. Adding another protobuf structure to capture the name/value and adding that to an ordered array before saving the data (set) to the chain will solve that.



    As per the documentation:




    Data structures which don’t enforce ordered serialization (e.g. sets,
    maps, dicts) should be avoided.







    share|improve this answer


























    • Hi Frank, Even after not creating or generating any address, Still we are getting the same error.

      – Gowrishankar R
      Jan 1 at 8:01













    • The data you set at the address, does the TP create any of the content or is it identical to the payload sent in the transaction?

      – Frank C.
      Jan 1 at 8:53













    • let address="d990b8c7eac5759277b2ac7664935e3782e34d26b56aa22f21c7fc988e9f13e238353a"; It was like the below before later i changed to the above one. // let address = NAMESPACE[2] + hash(payload.id).substring(0, 64); //console.log("address :",address)

      – Gowrishankar R
      Jan 1 at 9:58













    • What about the data itself that you put at that address?

      – Frank C.
      Jan 1 at 13:30











    • {"Location":"test","Latitude":1,"Longitude":8} is the data we are storing at that address

      – Gowrishankar R
      Jan 3 at 11:34
















    1














    The validator will send your TP the same transaction request multiple times. If your TP sets data on the chain with a different address and/or data hash than the validator fails the transaction. It does this for security but it has implications to your TP.



    Your TP must not create addresses or data in the TP that given the same input would produce different output. The TP address and data set in the transaction must be deterministic.



    If you are generating some unique bit of information (such as time or encryption) then you should do that in the client before sending it to the TP.



    Updated:



    As pointed out, the data being stored is an associative structure. Because the order in the native association is not deterministic, it is likely the root issue. Adding another protobuf structure to capture the name/value and adding that to an ordered array before saving the data (set) to the chain will solve that.



    As per the documentation:




    Data structures which don’t enforce ordered serialization (e.g. sets,
    maps, dicts) should be avoided.







    share|improve this answer


























    • Hi Frank, Even after not creating or generating any address, Still we are getting the same error.

      – Gowrishankar R
      Jan 1 at 8:01













    • The data you set at the address, does the TP create any of the content or is it identical to the payload sent in the transaction?

      – Frank C.
      Jan 1 at 8:53













    • let address="d990b8c7eac5759277b2ac7664935e3782e34d26b56aa22f21c7fc988e9f13e238353a"; It was like the below before later i changed to the above one. // let address = NAMESPACE[2] + hash(payload.id).substring(0, 64); //console.log("address :",address)

      – Gowrishankar R
      Jan 1 at 9:58













    • What about the data itself that you put at that address?

      – Frank C.
      Jan 1 at 13:30











    • {"Location":"test","Latitude":1,"Longitude":8} is the data we are storing at that address

      – Gowrishankar R
      Jan 3 at 11:34














    1












    1








    1







    The validator will send your TP the same transaction request multiple times. If your TP sets data on the chain with a different address and/or data hash than the validator fails the transaction. It does this for security but it has implications to your TP.



    Your TP must not create addresses or data in the TP that given the same input would produce different output. The TP address and data set in the transaction must be deterministic.



    If you are generating some unique bit of information (such as time or encryption) then you should do that in the client before sending it to the TP.



    Updated:



    As pointed out, the data being stored is an associative structure. Because the order in the native association is not deterministic, it is likely the root issue. Adding another protobuf structure to capture the name/value and adding that to an ordered array before saving the data (set) to the chain will solve that.



    As per the documentation:




    Data structures which don’t enforce ordered serialization (e.g. sets,
    maps, dicts) should be avoided.







    share|improve this answer















    The validator will send your TP the same transaction request multiple times. If your TP sets data on the chain with a different address and/or data hash than the validator fails the transaction. It does this for security but it has implications to your TP.



    Your TP must not create addresses or data in the TP that given the same input would produce different output. The TP address and data set in the transaction must be deterministic.



    If you are generating some unique bit of information (such as time or encryption) then you should do that in the client before sending it to the TP.



    Updated:



    As pointed out, the data being stored is an associative structure. Because the order in the native association is not deterministic, it is likely the root issue. Adding another protobuf structure to capture the name/value and adding that to an ordered array before saving the data (set) to the chain will solve that.



    As per the documentation:




    Data structures which don’t enforce ordered serialization (e.g. sets,
    maps, dicts) should be avoided.








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 4 at 9:22

























    answered Dec 31 '18 at 11:41









    Frank C.Frank C.

    5,88532639




    5,88532639













    • Hi Frank, Even after not creating or generating any address, Still we are getting the same error.

      – Gowrishankar R
      Jan 1 at 8:01













    • The data you set at the address, does the TP create any of the content or is it identical to the payload sent in the transaction?

      – Frank C.
      Jan 1 at 8:53













    • let address="d990b8c7eac5759277b2ac7664935e3782e34d26b56aa22f21c7fc988e9f13e238353a"; It was like the below before later i changed to the above one. // let address = NAMESPACE[2] + hash(payload.id).substring(0, 64); //console.log("address :",address)

      – Gowrishankar R
      Jan 1 at 9:58













    • What about the data itself that you put at that address?

      – Frank C.
      Jan 1 at 13:30











    • {"Location":"test","Latitude":1,"Longitude":8} is the data we are storing at that address

      – Gowrishankar R
      Jan 3 at 11:34



















    • Hi Frank, Even after not creating or generating any address, Still we are getting the same error.

      – Gowrishankar R
      Jan 1 at 8:01













    • The data you set at the address, does the TP create any of the content or is it identical to the payload sent in the transaction?

      – Frank C.
      Jan 1 at 8:53













    • let address="d990b8c7eac5759277b2ac7664935e3782e34d26b56aa22f21c7fc988e9f13e238353a"; It was like the below before later i changed to the above one. // let address = NAMESPACE[2] + hash(payload.id).substring(0, 64); //console.log("address :",address)

      – Gowrishankar R
      Jan 1 at 9:58













    • What about the data itself that you put at that address?

      – Frank C.
      Jan 1 at 13:30











    • {"Location":"test","Latitude":1,"Longitude":8} is the data we are storing at that address

      – Gowrishankar R
      Jan 3 at 11:34

















    Hi Frank, Even after not creating or generating any address, Still we are getting the same error.

    – Gowrishankar R
    Jan 1 at 8:01







    Hi Frank, Even after not creating or generating any address, Still we are getting the same error.

    – Gowrishankar R
    Jan 1 at 8:01















    The data you set at the address, does the TP create any of the content or is it identical to the payload sent in the transaction?

    – Frank C.
    Jan 1 at 8:53







    The data you set at the address, does the TP create any of the content or is it identical to the payload sent in the transaction?

    – Frank C.
    Jan 1 at 8:53















    let address="d990b8c7eac5759277b2ac7664935e3782e34d26b56aa22f21c7fc988e9f13e238353a"; It was like the below before later i changed to the above one. // let address = NAMESPACE[2] + hash(payload.id).substring(0, 64); //console.log("address :",address)

    – Gowrishankar R
    Jan 1 at 9:58







    let address="d990b8c7eac5759277b2ac7664935e3782e34d26b56aa22f21c7fc988e9f13e238353a"; It was like the below before later i changed to the above one. // let address = NAMESPACE[2] + hash(payload.id).substring(0, 64); //console.log("address :",address)

    – Gowrishankar R
    Jan 1 at 9:58















    What about the data itself that you put at that address?

    – Frank C.
    Jan 1 at 13:30





    What about the data itself that you put at that address?

    – Frank C.
    Jan 1 at 13:30













    {"Location":"test","Latitude":1,"Longitude":8} is the data we are storing at that address

    – Gowrishankar R
    Jan 3 at 11:34





    {"Location":"test","Latitude":1,"Longitude":8} is the data we are storing at that address

    – Gowrishankar R
    Jan 3 at 11:34













    0














    The above mentioned state root problem is because of transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Manage to write the promises correctly solved my problem.



    apply(transactionRequest, context) {
    var payload=cbor.decode(transactionRequest.payload)
    if (!payload.action) {
    throw new InvalidTransaction("Payload doesn't contain the
    action");
    }
    if (!payload.data) {
    throw new InvalidTransaction("Payload doesn't contain the Data");
    }
    let action = payload.action;
    let address = NAMESPACE + hash(payload.data.productID).substring(0,
    64);
    switch (action) {
    case "updateProduct":
    return context.getState([address])
    .then((possibleAddressValues)=>{
    let stateValue = possibleAddressValues[address];
    if (stateValue && stateValue.length) {
    let value = JSON.parse(cbor.decode(stateValue));
    console.log("decoded values : ",value)
    if (payload.data.price) {
    value.price = payload["data"]["price"]
    }
    if (payload.data.itemsInInventory) {
    value.itemsInInventory = payload["data"]["itemsInInventory"]
    }
    console.log("values after updating status : ",value)
    let entries = {
    [address]: cbor.encode(JSON.stringify(value))
    }
    return context.setState(entries);

    }else{
    throw new InvalidTransaction("there is no Product for given Product ID : ",payload.data.purchaseId);
    }
    })
    .catch((err)=>{
    console.log(new Date()+"Error while getting and setting confirm status for Product ID : ",payload.purchaseId );
    })
    break;
    default:
    throw new InvalidTransaction("The action is Invalid or not supported by this transaction processor");
    }
    }





    share|improve this answer






























      0














      The above mentioned state root problem is because of transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Manage to write the promises correctly solved my problem.



      apply(transactionRequest, context) {
      var payload=cbor.decode(transactionRequest.payload)
      if (!payload.action) {
      throw new InvalidTransaction("Payload doesn't contain the
      action");
      }
      if (!payload.data) {
      throw new InvalidTransaction("Payload doesn't contain the Data");
      }
      let action = payload.action;
      let address = NAMESPACE + hash(payload.data.productID).substring(0,
      64);
      switch (action) {
      case "updateProduct":
      return context.getState([address])
      .then((possibleAddressValues)=>{
      let stateValue = possibleAddressValues[address];
      if (stateValue && stateValue.length) {
      let value = JSON.parse(cbor.decode(stateValue));
      console.log("decoded values : ",value)
      if (payload.data.price) {
      value.price = payload["data"]["price"]
      }
      if (payload.data.itemsInInventory) {
      value.itemsInInventory = payload["data"]["itemsInInventory"]
      }
      console.log("values after updating status : ",value)
      let entries = {
      [address]: cbor.encode(JSON.stringify(value))
      }
      return context.setState(entries);

      }else{
      throw new InvalidTransaction("there is no Product for given Product ID : ",payload.data.purchaseId);
      }
      })
      .catch((err)=>{
      console.log(new Date()+"Error while getting and setting confirm status for Product ID : ",payload.purchaseId );
      })
      break;
      default:
      throw new InvalidTransaction("The action is Invalid or not supported by this transaction processor");
      }
      }





      share|improve this answer




























        0












        0








        0







        The above mentioned state root problem is because of transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Manage to write the promises correctly solved my problem.



        apply(transactionRequest, context) {
        var payload=cbor.decode(transactionRequest.payload)
        if (!payload.action) {
        throw new InvalidTransaction("Payload doesn't contain the
        action");
        }
        if (!payload.data) {
        throw new InvalidTransaction("Payload doesn't contain the Data");
        }
        let action = payload.action;
        let address = NAMESPACE + hash(payload.data.productID).substring(0,
        64);
        switch (action) {
        case "updateProduct":
        return context.getState([address])
        .then((possibleAddressValues)=>{
        let stateValue = possibleAddressValues[address];
        if (stateValue && stateValue.length) {
        let value = JSON.parse(cbor.decode(stateValue));
        console.log("decoded values : ",value)
        if (payload.data.price) {
        value.price = payload["data"]["price"]
        }
        if (payload.data.itemsInInventory) {
        value.itemsInInventory = payload["data"]["itemsInInventory"]
        }
        console.log("values after updating status : ",value)
        let entries = {
        [address]: cbor.encode(JSON.stringify(value))
        }
        return context.setState(entries);

        }else{
        throw new InvalidTransaction("there is no Product for given Product ID : ",payload.data.purchaseId);
        }
        })
        .catch((err)=>{
        console.log(new Date()+"Error while getting and setting confirm status for Product ID : ",payload.purchaseId );
        })
        break;
        default:
        throw new InvalidTransaction("The action is Invalid or not supported by this transaction processor");
        }
        }





        share|improve this answer















        The above mentioned state root problem is because of transaction processor code written in Javascript which has few promises made promise chain issue in setting the state. Manage to write the promises correctly solved my problem.



        apply(transactionRequest, context) {
        var payload=cbor.decode(transactionRequest.payload)
        if (!payload.action) {
        throw new InvalidTransaction("Payload doesn't contain the
        action");
        }
        if (!payload.data) {
        throw new InvalidTransaction("Payload doesn't contain the Data");
        }
        let action = payload.action;
        let address = NAMESPACE + hash(payload.data.productID).substring(0,
        64);
        switch (action) {
        case "updateProduct":
        return context.getState([address])
        .then((possibleAddressValues)=>{
        let stateValue = possibleAddressValues[address];
        if (stateValue && stateValue.length) {
        let value = JSON.parse(cbor.decode(stateValue));
        console.log("decoded values : ",value)
        if (payload.data.price) {
        value.price = payload["data"]["price"]
        }
        if (payload.data.itemsInInventory) {
        value.itemsInInventory = payload["data"]["itemsInInventory"]
        }
        console.log("values after updating status : ",value)
        let entries = {
        [address]: cbor.encode(JSON.stringify(value))
        }
        return context.setState(entries);

        }else{
        throw new InvalidTransaction("there is no Product for given Product ID : ",payload.data.purchaseId);
        }
        })
        .catch((err)=>{
        console.log(new Date()+"Error while getting and setting confirm status for Product ID : ",payload.purchaseId );
        })
        break;
        default:
        throw new InvalidTransaction("The action is Invalid or not supported by this transaction processor");
        }
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 25 at 14:33

























        answered Jan 25 at 14:26









        Gowrishankar RGowrishankar R

        33




        33






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986720%2fstate-hash-root-problem-ie-validator-not-adding-a-block%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas