Weekly Dev Update #41
THORChain Weekly Dev Update for Week 30–04 Apr 2020
Summary
Ecosystem work
There are now multiple teams working on the THORChain ecosystem:
- Block42 Telegram Bot: https://github.com/block42-blockchain-company/thornode-telegram-bot
- Balancer Bot Team: http://coloxxol.xyz/balancer/
- Kudelski: TSS audit
- Gauntlet: Economic Analysis
- Mehow: Rune Calculator (thorchain.community)
- Rebase Foundation: https://rebase.foundation/network/thorchain/
- THORChain: THORNode, Midgard, ASGARDEX
This is how a project reaches self-sustainment in community work and THORChain is getting closer to this point every week.
Event Handler
THORChain emits an event everytime something happens with funds (swap, stake, withdrawal etc) and this is consumed by Midgard in order to make it easy for third-party services to display data.
The first implementation of an Event Handler was a custom implementation and works fine, however the team have since decided to refactor in the official CosmosSDK event module since it has better developer tooling. In the long term it means less code, less attack surface and better feature support. In the short term it means 1–2 weeks of refactoring the current code and how Midgard is streamed event data.
Performance Improvements
After completing initial benchmarking, the team have finished refactoring how the Key-Value Store is utilised, ensuring optimal “setting and getting” of keys that are updated when logic happens. The general principle is the more granular a key can be referred to, the less times it will be updated in changes.
Additionally, a lot of unused code and old CLI methods have been cleaned out.
Heimdal Update
Previously the state machine did not give out block rewards every block, instead waiting for a swap to be processed. This was done to make it simpler to test in Heimdall (test infrastructure), but the team have bit the bullet and implemented block rewards every block, and the necessary changes in Heimdall. This was significantly complex, because there is now a time-dependent process (blocks) being tested alongside an event-dependent process (swaps). The solution was to refactor Heimdall to absorb blocks as events and make them both event-dependent.
Bitcoin Re-org Protection
The team implemented the necessary infrastructure to respond to Bitcoin block (PoW) re-organisation events. If anything changes in a re-org, then the nodes can submit Errata Transactions to return the system to solvency.
THORNode Merge Requests
- [bugfix] high performance improvements
- [cleanup] remove pool index
- 447-issue leave half a RUNE worth of gasAsset when it is last unstake
- [refactor] use a single func for signer auth
- [cleanup] remove old cli queries
- [cleanup] remove staker pool
- 446-issue remove some unused method
- 441-issue remove ValidateMetadata
- [refactor] remove list all node accounts
- [security] limit memo length
- [refactor] replace pool staker with staker
- 448-issue update the logic to detect yggdrasil return
- [refactor] save final observed tx when consensus is reached
- [bugfix] fetch tx marker for ygg returns
- [refactor] Move slashpoints to its own key in kvstore
- Resolve “[FIX] Remove keeper_mock_*, the mocking we use for test before we create dummy kvstore”
- 451-issue update chains field in vault
- [bugfix] allow current block for keygen/keysign queries
- 453-issue remove memo from the unit test
- [infra] setup smoke tests on self hosted gitlab runner
- [feature] block rewards are given on every block
- Resolve “[ADD] bitcoin re-org detect and send errata when required”
- Resolve “[ADD] bitcoin re-org detect and send errata when required”
- Resolve “Enable errata handler”
- Resolve “[ADD] Aggregate events per block”
- [feature] query historical data
- Resolve “Fix query complete events for empty chain gas events”
- Resolve “[FIX] Update pool event”
- Resolve “Fix query complete events by chain”
Midgard
Work on Midgard to mature out the service, fix bugs and update to new event structures from THORChain.
- Resolve “Remove unused code from api package”
- Resolve “Order by date option for `/v1/txs` endpoint”
- Resolve “Implement parallel Thorchain Scanner”
- Resolve “Fix /v1/txs count and add tests”
- Resolve “ADD: Support for Errata events”
- Resolve “Add some details and metrics about scanners in /v1/health”
- Resolve “Move GetNetworkInfo logic to usecase layer”
- [infra] switch to using our own gitlab runners
- Resolve “GetNetworkInfo Cleanup”
- Resolve “Update mockserver”
In addition to this, the team released a simple Midgard explorer to help visualise the data available:
http://midgard-explorer.herokuapp.com (note the HTTP url)

Clients
Work has begun on the ASGARDEX electron app that will be the primary interface to the chain. ASGARDEX implements the Byzantine module which ensures verified and trustless queries from the THORChain network.
The repo is here:
The interface borrows most of the existing BEPSwap client code:


ASGARDEX will support multi-chain addresses, all derived from a single BIP32 root key:
- Bitcoin (BECH32)
- Ethereum
- Binance Chain
- THORChain
The user only needs one asset type to begin interacting with THORChain. This is one example flow:
- Load wallet, connect BTC Ledger
- Swap BTC into RUNE
- Stake BTC & RUNE
Audit
Code Review: Complete
Economic Review: Completed most of THORChain's economic architecture
TSS Audit: begun work
Next Milestones
The updated testnet is in the final stages of testing. 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