What does the bond
mean? Somehow it can be translated as building up a strong binding
relationship with a PoS network. If you want to put your tokens “at stake”, you must bond
them first. But what does the bond actually do? What’s the difference between substrate
and darwinia-network
?
Account abstractions for bond
– Stash
and Controller
Stash Key: The Stash account is meant to hold large amounts of funds. Its private key should be as secure as possible in a cold wallet.
Controller Key: The Controller account signals choices on behalf of the Stash account, like payout preferences, but should only hold a minimal amount of funds to pay transaction fees. Its private key should be secure as it can affect validator settings, but will be used somewhat regularly for validator maintenance.
Bond in Substrate
Let’s have a look at the following codes:
1 | fn bond(origin, |
It’s really simple. Take the origin account as a stash and lock up value
of its balance. controller
will be the account that controls it. value
must be more than the minimum_balance
specified by T::Currency
. The dispatch origin for this call must be Signed by the stash account.
As we all know, “Verify First, Write Last” should be obeyed on Substrate, so verify wheather stash has been bonded and wheather controller has been paired already First. Make sure the value
is bigger than the minimum_balance
or the account would be a dust account that should be cleaned.
Then bond the stash
and the controller
.
1 | <Bonded<T>>::insert(&stash, &controller); |
Set the Reward Destination:
1 | <Payee<T>>::insert(&stash, payee); |
Fianlly update the ledger.
1 | let stash_balance = T::Currency::free_balance(&stash); |
Note if value
is larger than stash_balance
, the bond should not faill and will bond all the balances in the stash account to the controller.
bond
doesn’t mean transfer tokens to the controller
account. The tokens are still at the stash
account. Howerever, the Staking Ledger’s active item will become the minium between the value
and the stash_balance
.
Bond in Darwinia
The bond
operation in darwinia-network is almost the same as the bond
operation in substrate. However, there are also something different between them. As darwinia has two tokens – ring
and kton
, the bond
operation should be able to handle both tokens.
1 | match value { |
There are also a special rule in darwinia-network: Users can choose to lock RING for 3-36 months in the process of Staking, and the system will offer a KTON token as reward for users participating in Staking. So we need bond_helper_in_ring
and bond_helper_in_kton
.
1 | fn bond_helper_in_ring( |
As the code shows, bond_helper_in_ring
computes the kton
should return and update the ledger.
bond_helper_in_kton
is simper, it just updates the ledger.
1 | fn bond_helper_in_kton( |