One of the main features of SKALE Network is node rotation, and this is performed through a BLS Snapshot process. Briefly, if node A
leaves a SKALE Chain for any reason (e.g. random rotation, node exit, etc.), another node B
will be chosen to replace it. Once node B
is chosen, it needs all the information about previous blocks, transactions, etc. from the SKALE chain.
SKALE Network solves this by periodically performing snapshots of the SKALE chain file system on each node so that nodes can share the latest snapshot with incoming node B
.
Additionally, a node can be restarted from a snapshot it the node was offline for a long period of time, if it cannot catch up with other nodes using SKALE Consensus' catch-up algorithm.
Skaled uses the btrfs file system to create snapshots.
SKALE Chain nodes perform snapshots once the current block timestamp crosses a boundary in T seconds, where TsnapshotInterval is a configurable number defined in the node config file. After creating the snapshot, each node calculates it's hash and passes it to stateRoot. If the first block on the SKALE chain occurred at TfirstBlock, then the first snapshot will be performed once another block's timestamp crosses the boundary ([TfirstBlock / TsnapshotInterval] + 1) * TsnapshotInterval.
To start from a snapshot, a node must confirm whether a snapshot is valid. To prevent downloading of snapshots from malicious nodes, the following procedure was designed:
- Node
A
chooses a random node from SKALE chain and requests the last snapshot block number. - Node
A
requests all nodes from the SKALE chain to send a snapshot hash signed with its corresponding BLS key. - Once node
A
receives all hashes and signatures,A
tries to choose a hashH
similar on at least 2/3 + 1 nodes, thenA
collects their BLS signatures into one and verifies it. (If steps 1 – 3 fails, a node will not start.) - Node
A
chooses a random node from those 2/3 + 1 nodes and downloads a snapshot from it, computes its hash and confirms whether it is similar toH
. If it is similar then a node starts from this snapshot, otherwise nodeA
will attempt to download a snapshot from another node.
NOTE: stateRoot is needed to determine whether there are any node software issues. Each time a new block is passed from consensus, a node compares its own stateRoot with the stateRoot of the incoming block (so snapshot hashes of the last block from different nodes are compared). If the stateRoots fail to match, then a software issue is assumed and the node must restart from a snapshot.
Parameters
blockNumber
: a block number, or the string "latest"autoCreate
:Boolean
, create snapshot if it does not exist
Returns
dataSize
: integer, the size of snapshot in bytesmaxAllowedChunkSize
: integer, the maximum chunk size in bytes
Example
// Request
curl -X POST --data '{ "jsonrpc": "2.0", "method": "skale_getSnapshot", "params": { "blockNumber": "latest", "autoCreate": false }, "id": 73 }'
// Result
{
"id": 73,
"dataSize": 12345,
"maxAllowedChunkSize": 1234
}
Returns a snapshot fragment.
Parameters
blockNumber
: a block number, or the string "latest"from
: a block numbersize
: integer, the size of fragment in bytesisBinary
:Boolean
Returns
size
: integer, the size of chunk in bytesdata
:base64
, btrfs data
Example
// Request
curl -X POST --data '{ "jsonrpc": "2.0", "method": "skale_downloadSnapshotFragment", "params": { "blockNumber": "latest", "from": 0, "size": 1024, "isBinary": false }, "id": 73 }'
// Result
{
"id": 73,
"size": 1234,
"data": "base64 here"
}
Returns signature of snapshot hash on given block number.
Parameters
blockNumber
: a block number
Returns
X
: string, X coordinate of signatureY
: string, Y coordinate of signaturehelper
: integer, minimum number such that Y=(X+helper)^3 is a square in Fqhash
: string, hash of a snapshot on given block numbersignerIndex
: integer, receiver's index in SKALE chain
Example
// Request
curl -X POST --data '{ "jsonrpc": "2.0", "method": "skale_getSnapshotSignature", "params": { "blockNumber": 14 }, "id": 73 }'
// Result
{
"id": 73,
"X": 3213213131313566131315664653132135156165496800065461326,
"Y": 3164968456435613216549864300564646631198986113213166,
"helper": 1,
"hash": aef45664dcb5636,
"signerIndex": 1
}
Returns the latest snapshotted block's number.
Parameters
NULL
Returns
blockNumber
: integer, the latest snapshotted block's number
Example
// Request
curl -X POST --data '{ "jsonrpc": "2.0", "method": "skale_getLatestSnapshotBlockNumber", "params": { }, "id": 73 }'
// Result
{
"id": 73,
"blockNumber": 15
}