Uploaded image for project: 'Fabric'
  1. Fabric
  2. FAB-17414

As a chaincode author, I need JSON serialized deterministically

    XMLWordPrintable

Details

    • Documentation
    • Status: Backlog
    • Medium
    • Resolution: Unresolved
    • None
    • None
    • fabric-docs, fabric-samples
    • None

    Description

      Given the prevalence of JSON in user chaincode, and the criticality of deterministic serialization when saving state in chaincode, users need guidance around deterministic JSON serialization. This is especially true in v2.0 since chaincode may be different across peers, perhaps even implemented in different languages.

      Especially problematic is order of JSON elements, since the JSON spec does not guarantee an order. Go Marshal() (https://golang.org/pkg/encoding/json/#Marshal) happens to sort map elements, but this is an implementation detail that may change in the future. Javascript ( https://github.com/nodejs/node/issues/15628 ) and Java perform no such ordering. And all three languages would certainly produce different results for the same modeled JSON object.

      Minimally the concern needs to be well documented. Perhaps some recommendations could be made for using deterministic libraries (e.g. https://github.com/BridgeAR/safe-stable-stringify/ ). Or perhaps given the prevalence and criticality, the chaincode programming model itself could provide consistent serialization utilities across the languages.

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            denyeart David Enyeart
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated: