The ledgerutil compare command allows administrators to compare channel snapshots from two different peers. Although channel snapshots from the same height should be identical across peers, if the snapshot files indicate different state hashes (as seen in _snapshot_signable_metadata.json file from each snapshot) then it indicates that at least one of the peers state databases is not correct relative to the blockchain and may have gotten corrupted.

The ledgerutil compare utility will output a set of JSON files if the snapshots are not identical to assist with troubleshooting in these situations. Two output JSON files will include any key/value differences sorted by key (one for public key/value differences and one for private key/value differences), another JSON file will include any key/value differences (public or private) sorted by block and transaction height so that you can identify the height where a divergence may have first occurred.

The output files may help an administrator to understand the scope of a state database issue and identify which keys are impacted. Snapshots from additional peers can be compared to determine which peer has incorrect state. The block and transaction height of the first difference can be used as a reference point when looking at the peer’s logs to understand what may have happened to the state database at that time.


The ledgerutil command has one subcommand

  • compare

ledgerutil compare

usage: ledgerutil compare [<flags>] <snapshotPath1> <snapshotPath2>

Compare channel snapshots from two different peers.

      --help                 Show context-sensitive help (also try --help-long
                             and --help-man).
  -o, --outputDir=OUTPUTDIR  Snapshot comparison json results output directory.
                             Default is the current directory.
  -f, --firstDiffs=10        Maximum number of differences to record in
                             first_diffs_by_height.json. Requesting a report
                             with many differences may result in a large amount
                             of memory usage. Defaults to 10. If set to 0, will
                             not produce first_diffs_by_height.json.

  <snapshotPath1>  First ledger snapshot directory.
  <snapshotPath2>  Second ledger snapshot directory.

Example Usage

ledgerutil compare example

Here is an example of the ledgerutil compare command.

  • Compare snapshots from two different peers for mychannel at snapshot height 5.

    ledgerutil compare -o ./compare_output -f 10 ./peer0.org1.example.com/snapshots/completed/mychannel/5 ./peer1.org1.example.com/snapshots/completed/mychannel/5
    Both snapshot public state and private state hashes were the same. No results were generated.

    The response above indicates that the snapshots are identical. If the snapshots were not identical, the command results will indicate where the comparison output files are written, for example:

    Successfully compared snapshots. Results saved to compare_output/mychannel_5_comparison. Total differences found: 3
  • Note that both snapshot locations must be accessible by the command, for example by mounting volumes from two different peers, or by copying the snapshots to a common location.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.