Weekly Dev Update #46
THORChain Weekly Dev Update for Week 01–08 June 2020
Summary
The team spent the week preparing the public testnet.
Testnet 1
The first testnet prepared ended in a consensus failure, which the team hadn’t seen before, but put it down to a change in node configuration. The testnet had a large amount of testnet funds on it, so the team spent the time investing in building a tool to enable a hard fork to a new version. The team eventually realised that the current tendermint infrastructure is not suitable for hard forking THORChain. This is because when a hard fork happens, the entire blockchain is replayed from scratch (block 1) and in the case of THORChain, previously spent txOuts will be respent. This is a known issue for Tendermint (to set an optional height to replay from) and is here: https://github.com/tendermint/tendermint/issues/4646
The team have a solution and will implement it, but prefer to include Tendermint’s official fix when ready. The team was ultimately able to recover funds from the TSS vaults, and are confident that should a chain-halt happen on mainnet, a hard fork can be pushed to recover the state. Assuming the hard fork is *non-malicious* then all node operators should upgrade, since all of their funds would be locked up and the only way to get their funds back would be to restart the chain in a manner that is non-malicious.
Testnet 2
The team then deployed a second testnet on 08 June, which was publicly announced. This testnet ended in being intentionally shut down (by stopping all nodes) due to two issues which had cascading problems, but ultimately easily fixed.
The root cause was that one of the nodes was restarted (this is fine, because the network only needs 67% online), but it was unable to download the TSS address book (the addresses of the other nodes) so it could not key-sign TSS. This meant that 3 out of every 4 outbound transactions could not be completed until that node was removed from the TSS party. The other 3 nodes (who were all connected) were then able to complete all pending transactions. Users of the testnet would notice that swaps were going through fine (10 seconds) but then delayed for 10mins for around 25 min periods. A second issue which caused pending transactions to be retried but not accounted for, allowed THORChain to double-spend outbound transactions. This then caused THORChain to go insolvent and Midgard’s data to underflow.
The fixes are:
- Save the address book in local storage for all nodes (WIP: add function to export the p2p address for every successful tss operation)
- Mark transactions and all retries as complete when one is successful. ([bugfix] txout outhash marks all tx outs)
Once the TSS issue is fixed, testnet can be re-launched. These issues so far hadn’t been seen in testing before, but are very likely to arise in a public test environment. The team will keep launching public testnets until it extremely reliable.
Dynamic Network Fees
This has been pushed to THORChain and now follows this logic:
- THORNodes regularly report on gas fees used in each chain, and a trailing average of gas fees is stored in THORChain.
- Users are now charged 3*the trailing average gas fee, but in RUNE, which is moved to the Reserve.
- THORNodes are instructed to use a gas price of 1.5*the trailing average.
- The stakers are reimbursed an amount of 2*the gas used, in RUNE, paid to the pool.
Example:
- The trailing average for gas fees on Bitcoin is 10 sat/byte, using 2500 sats each transaction.
- A user swapping to Bitcoin is charged 7500 sats, which is moved to the Reserve in RUNE.
- The nodes will use 15 sats/byte for outgoing transactions, with a final cost of 15 * 250 bytes = 3750 sats, which is deducted from the Bitcoin pool (and thus all Bitcoin stakers pay for the gas).
- The Bitcoin stakers are then paid back 7500 Sats in RUNE, which causes arbitrage and for at least 3750 Sats to be recovered from the market, making the Bitcoin stakers whole.
The realisation is then:
- During periods of Bitcoin mempool saturation it will be *expensive* to buy Bitcoin. Bitcoin buyers will be paying at least 3 times the cost of a normal transaction, which could be anywhere from $3 to $90 (based off historical gas prices). This will drive up swap sizes, since small swaps will be net-negative.
- This will then drive arbitrage volume to wrapped Bitcoin alternatives, where fees will be much less (Ethereum: 20–60c, Binance Chain: 1–3c). Traders will be able to arbitrage Bitcoin using cheap wrapped alternatives, re-balancing back to L1 Bitcoin when fees are reduced, or arbitrage deltas are worth it. This will have an interesting effect on the wrapped Bitcoin ecosystem, where for the first time there exists a tangible financial reason to trade into alternatives, choosing on the trust-convenience continuum.
THORNode
Bugfixes from testnets, as well as implementing Dynamic Network Fees.
- Resolve “[ADD] Dynamic network fees”
- [bugfix] chain block height takes priority over current store position
- [documentation] remove old ‘setup’ documentaiton, its no longer used
- [bugfix] unstaking requires 24 hrs
- Resolve “[ADD] bifrost to report chain specific network fee”
- Fix unmarshal binance
- Add missing data to genesis file
- [bugfix] reset observer data on endblock
- [bugfix] fix export/import
- [bugfix] Hard fork height support
- Resolve “[FIX] when ragnarok get trigged forgo the check to ignore tx older than 300 blocks”
- 494-issue clean up the alias file
- 504-issue bifrost should not restart from 0, commit scan pos even there is no tx
- [bugfix] Leave with node address
- [bugfix] gas pool event rune amt should reflect pool change[bugfix] txout outhash marks all tx outs
Midgard
Bugfixes and feature requests as required for the clients.
- Resolve “Add eth and btc address”
- Resolve “ADD: dateLastStaked to /v1/stakers/staker/<address>/pools endpoint”
- Resolve “Convert blockReward in /network endpoint to int”
- Resolve “Remove Genesis”
- Resolve “Invalid pool status”
- [bugfix] remove python install to build docker image
- Resolve “Consider zero standby nodes”
- Resolve “FEATURE: add catching_up flag to health endpoint”
- Update standbyAvg
- fix-height-last-staked
- Update health endpoint
Clients
BEPSwap Client
Numerous UI/UX tweaks from testnet feedback:
https://gitlab.com/thorchain/bepswap/bepswap-web-ui/-/merge_requests
ASGARDEX Client
Ongoing work to port in the user interface.
ASGARDEX Libraries
https://gitlab.com/thorchain/asgardex-common
asgardex-midgard
is the new name for the Midgard API client required by all ASGARDEX clients.asgardex-crypto
has been scoped and will control all crypto-related functions, including handling thorchain keystore files.
Community Work
The community are building out:
- THORNode telegram bot: https://github.com/block42-blockchain-company/thornode-telegram-bot
- THORChain community explorer: thorchain.community
- THORChain arbitrage bots: https://gitlab.com/thorchain/trade-bots
In addition, the team are also talking with a mobile wallet provider as well as potentially a team to build a blockchain exporter
Audits
The team have receive the first draft of the Kudelski audit, with no major issues found.
Gauntlet are preparing their final THORChain report.
Next Milestones
The testnet is being re-deployed and will be made public soon. Chaosnet is expected once testnet has been fully-validated in several environments. There currently isn’t any known blockers to Chaosnet release.
Community
To keep up to date, please monitor community channels, particularly Telegram and Twitter:
- Twitter: https://twitter.com/thorchain_org
- Telegram Community: https://t.me/thorchain_org
- Telegram Announcements: https://t.me/thorchain
- Reddit: https://reddit.com/r/thorchain
- Github: https://github.com/thorchain
- Medium: https://medium.com/thorchain