We are back with another video demo, this time we present the Fee Contract, one of our four Genesis Contracts
In the previous demo we featured the Transfer Contract, designed to streamline DUSK and other on-chain asset transfers in a privacy environment. Today we demonstrate the Fee Contract, or Reward Distribution Contract. As the contract name entails, the Fee Contract handles the distribution of block rewards amongst the consensus participants: block generator and provisioners.
Taking a look at our simplified technical framework, we can see that the Fee Contract resides in the blockchain layer.
This Technical Framework shows the different layers and components of the Dusk Network. Read more about how it all ties together.
Contract benefits
The Fee Contract call is part of the Coinbase transaction, which is the last transaction in a block, and is responsible for the distribution of block rewards amongst the consensus participants. Each consecutive block reward is split amongst the Generator responsible for forging the block and the Provisioners responsible for finalizing the block. The contract is designed to limit the number of reward withdrawals as otherwise (if rewards were distributed after every block), each block would have been responsible for tens of new outputs created solely for the purpose of rewarding consensus participants. Without this mechanism, a lot of state storage would be consumed on these reward payouts.
Distributing functionality
The Fee Contract is called every time a block is accepted onto the blockchain (~6 seconds). The Block Generator instantly receives its reward through this function, while at the same time the Provisioner reward allocation is updated. The reason why the Generator receives its reward instantly, is because there is only 1 involved and rewarded per block and the pseudonymous identity of the Generator is obfuscated.
Allowance withdrawal
This function is used by Provisioners to retrieve their DUSK allocation from the contract. When called, it removes an amount the Provisioner is withdrawing from his/her balance on the contract storage and creates a Phoenix output to the equivalent amount on the DUSK Transfer Contract destined to the one-time address specified by the Provisioner. This function is consciously designed to save space on the blockchain. Alternatively, were it not for the Fee Contract, we would have an entire Provisioner set receiving their rewards as separate Phoenix outputs on the DUSK Transfer Contract every block!
Tech demo
In the demo we see interaction between our golang node (running with a gRPC client) on the one hand, and the RUSK server (containing a gRPC server) on the other. Upon our request, RUSK will load up the correct contract and start the VM execution, after which both the Generator and the Provisioner are rewarded with DUSK.
Watch our demo and see the Fee contract in action!
This demo does not yet show integration with the state transition function in which the fee contract receives the correct ‘spent gas’ amounts for transactions in a block, as a result of calling contracts on the network. And even though gas is already properly calculated, it is not subtracted from the fee output for demo purposes: the entire fee output is consumed.
Gas is basically a unit of computation you pay when executing a contract, whereas the transaction fee is the money used to cover the gas you spend.
Gas = what you pay for computation
Fee = what you send initially to be sure you can cover the gas
Up Next: Staking and Blind Bid Contracts
In our next demo developer Jules will highlight the other two genesis contracts that revolve around consensus. He will explain how both Generators and Provisioners have to stake an amount of DUSK in order to participate in our consensus.