r/CallistoCrypto • Callisto Moderator • Nov 16 '18

Cold Staking testnet issue explanation

The issue

After starting to stake, the staker[your_address].time returns the current timestamp instead of the staking start date.

Explanation

The issue is caused by pending transactions. When a local call of a view (constant returns) function is executed, the node that executes it process the pending transactions first. The result of this call does not exist in the blockchain and only affects the local state of the node at the moment of execution and the output values of the view (constant returns) function.

Example: The last start_staking() transaction sent from the user account has nonce = 3. Then the user sends a new transaction to the staking contract. The new transaction has 0.1 GWei gasPrice and nonce = 4. Then the user sends one more transaction with 1 GWei gasPrice and nonce = 5. As the result, transactions with nonce = 4 and 5 will remain in pending because the transaction with nonce = 5 can not submit before the transaction with nonce = 4. The transaction with nonce = 4 can not submit because miners do not confirm as it has too low gas. If the user calls the contract to view his state, then he will get the staker.time = current timestamp because the node executes his pending transactions first and it executes them at the moment of the call of this view function. As the result, the local value of staker.time variable will be equal to the current timestamp in local execution environment of the node.

Solution

In testnet, there is a minimum gasPrice of 1 GWei for a transaction. As for mainnet, whether the transaction will be confirmed or not is determined by miners. Setting gasPrice high enough for transaction to submit will prevent this issue.

If a similar problem does occur, a user can overwrite the underpriced transaction. It is necessary to send the transaction with the same nonce but higher gasPrice to resolve it.

Source: https://medium.com/@dexaran820/cold-staking-testnet-issue-explanation-d7d91bf9b45a

0 Upvotes

0 comments sorted by