This is a monotonic counter incremented on contract instantiation.
This is used in order to generate unique trie ids for contracts.
The trie id of a new contract is calculated from hash(account_id, nonce).
The nonce is required because otherwise the following sequence would lead to
a possible collision of storage:
Create a new contract.
Terminate the contract.
Immediately recreate the contract with the same account_id.
This is bad because the contents of a trie are deleted lazily and there might be
storage of the old instantiation still in it when the new contract is created. Please
note that we can't replace the counter by the block number because the sequence above
can happen in the same block. We also can't keep the account counter in memory only
because storage is the only way to communicate across different extrinsics in the
same block.
Note
Do not use it to determine the number of contracts. It won't be decremented if
a contract is destroyed.
This is a monotonic counter incremented on contract instantiation.
This is used in order to generate unique trie ids for contracts. The trie id of a new contract is calculated from hash(account_id, nonce). The nonce is required because otherwise the following sequence would lead to a possible collision of storage:
This is bad because the contents of a trie are deleted lazily and there might be storage of the old instantiation still in it when the new contract is created. Please note that we can't replace the counter by the block number because the sequence above can happen in the same block. We also can't keep the account counter in memory only because storage is the only way to communicate across different extrinsics in the same block.
Note
Do not use it to determine the number of contracts. It won't be decremented if a contract is destroyed.