Ledger Snapshots in Hyperledger Fabric -2.3

Rangesh Sripathi
2 min readJan 11, 2021

--

Pre-requisites : Basic Knowledge about Blockchain and Hypereldger.

Introduction:

When a new peer is joined to an organization ,it’s essential that the ledger data is restored in-order to qualify for endorsement and query the channel. Now this process may be time consuming and its proportional to the volume of data channel has seen in the network. Snapshots helps in such scenario where a peer can join the channel from the specified block number/height rather than starting from block number 0.

Consideration for Snapshots :

a) Join a peer based upon selected block number instead building from 0th block.

b)If your endorsement requests or queries don’t require the latest block commits.

Limitation of Snapshots:

a) It is not possible for peer to query or endorse before the mentioned block number /height of the snapshot, since peer would not have the listed blocks.

b)Private data is not included in Snapshots

c)It is not possible to use the reset, rollback, or rebuild-dbs commands on peers that have joined a channel using a snapshot since the peer would not have all the block files required for the operations.

Hands-on Joining channel by Snapshots

Lets get started and we would be using test-network provided in fabric samples(https://hyperledger-fabric.readthedocs.io/en/latest/test_network.html). In the example below we will spin 2 Org and Org3 would make utilization of snapshot.

Below is the snapshot from test-network provided in fabric samples.

  1. Get the ledger height /block number :
peer snapshot submitrequest -c mychannel -b 6 --peerAddress 127.0.0.1:7051

Response would be similar to below

Blockchain info: {"height":6,"currentBlockHash":"JgK9lcaPUaNmFb5Mp1qe1SVMsx3o/22Ct4+n5tejcXCw=","previousBlockHash":"f8lZXoAn3gaF86zrFq7L1DzW2aKuabH9Ow6SIE5Y04a4="}

2. Submit Snapshot to Peer :

peer snapshot submitrequest -c mychannel -b 6 --peerAddress peer0.org1.example.com:7051 --tlsRootCertFile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt

In the above query, we have requested peer0 to take snapshot from block number 6.

3. Copy the snapshot from peer0 container , Snapshots are default stored in

/var/hyperledger/production/snapshots/channelname/completed/blocknumber/

We can also look up core.yaml for Snapshots storage.

4. Join the peer by snapshot path

peer channel joinbysnapshot --snapshotpath /snapshots/mychannel/completed/6/

This will ensure that peer is joined by snapshot to the channel.

Reference :

https://hyperledger-fabric.readthedocs.io/en/latest/peer_ledger_snapshot.html

https://hyperledger-fabric.readthedocs.io/en/latest/commands/peersnapshot.html

--

--