Thursday, February 14, 2019

Nano How 2: Blocks and Lattices

tl:dr: The Nano block lattice is made up of blocks. Each complete transaction requires two blocks representing send and receive. Changing your representative requires only a single block. A block contains all the information required for managing your Nano and are signed with a private key so only the owner can make changes. They are assigned a unique code called a hash.

What is a block?

Blocks are one of the fundamental concepts in cryptocurrency, they are groups of data that are linked together and usually include the data that represents transactions and interactions. These blocks are verified by the network and committed into a distributed ledger after being confirmed. For example, in Bitcoin, blocks are verified and committed to the ledger through the mining process, and each block is linked to the next to form a chain.

Blocks in Nano

The Nano ledger is different; instead of a single chain for the whole ledger (where each block contains multiple transactions), in Nano each account has its own chain of blocks which are woven together through the process of making transactions to create a block lattice. The blocks in a Nano chain represent the changes that its owner, who holds the private key, has made to their account. These changes take one of the following forms:

  • A send block, which is signaled by a resulting lower balance in the chain.
  • A receive block, which results in a higher balance in the chain.
  • An open block, the first in every chain.
  • A change block, used to choose a new representative (future Nano How).
  • An epoch block (future Nano How).

Fig 1. Comparison between Bitcoin Blockchain and Nano Block Lattice

How does it work?

Originally Nano had 4 different block types: Open, Send, Receive and Change, each with slightly different layouts. However, these have been merged into a single block type called a State block. Each state block contains all the details of that single account, including the account’s address and balance, as well as details to help place the block in the correct position in its chain. A block is then authorised by a signature, created using the block details and the account’s private key.

Fig. 2 Components that go into a state block

The most recent block is called the head or frontier block as its at the front. With the introduction of state blocks it means that you only need this frontier block to know everything about the current state of account (apart from its pending blocks).

With all this data grouped together it is easy to make changes:

  • To send some Nano, you just include the destination address in the block and reduce the accounts balance by the amount you are sending.
  • To receive Nano sent to you, you include the hash (the unique id) of the send block from the sender and increase your balance by this new amount.
  • To change your representative you just change the address in the representative field and include `0000000000000000000000000000000000000000000000000000000000000000` to trigger the change.

Notice that the amount transacted is not directly present in any block. To obtain this value, you need to subtract the block’s balance value, from the previous block’s balance.

Each block needs a proof of work value; this is the resulting value following a time consuming mathematical calculation and will be discussed in detail in a future Nano How), The basis of this system is that it is hard to generate the value but easy to check if the value is valid. Interestingly, the proof of work value is actually not included in the signature of the block and could be calculated after the block is generated (but it needs to be present before the block is broadcast).

An example of a state block:

{"block":"{"type":"state", "account":"xrb_3igf8hd4sjshoibbbkeitmgkp1o6ug4xads43j6e4gqkj5xk5o83j8ja9php", "previous": "597395E83BD04DF8EF30AF04234EAAFE0606A883CF4AEAD2DB8196AAF5C4444F", "representative":"xrb_3p1asma84n8k84joneka776q4egm5wwru3suho9wjsfyuem8j95b3c78nw8j", "balance":"3000000000000000000000000000001", "link":"5C2FBB148E006A8E8BA7A75DD86C9FE00C83F5FFDBFD76EAA09531071436B6AF", "signature":"D7975EE2F6FAE1FC7DA336FB9DD5F7E30FC1A6825021194E614F0588073D1A4901E34E3CAE8739F1DE2FD85A73D2A0B26F8BE6539E0548C9A45E1C1887BFFC05", "work":"0000000000000000"}"}

It is important to note that the nodes in the network check the blocks to make sure that all the details line up and will reject an incorrect block - it is not possible to just create a new block with a larger balance then has been sent to you.

Why does Nano have a Send and Receive block?

Every account has its own chain and this chain can only be changed with blocks signed by the private key. Therefore when someone sends you Nano they create a new block with a reduced balance and a destination address but they can not change your chain, instead the funds remain in limbo (known as pending) until you create a corresponding receive block and increase your balance proportionally. There is no limit to how long the funds can stay pending.

Links and further reading

Next Time

Nano How 3: Light Wallets - How do they work?

Thanks

Thanks to all the feedback and also to /u/DotcomL for revisions and proofreading.



No comments:

Post a Comment