hashport-validator
hashport-validator copied to clipboard
Keep the data for validator's fee collection in the DB
High-level spec link
Description:
-
Create a new DB table, that will keep the data for:
- Validator’s address.
- Supported Native Assets Address (asset per row).
- Native Asset’s network ID.
- Fee amount (per validator per native asset). Will be incremental - once a transfer is done the fee of the transfer will be added to the current fee amount column. The result from the sum will be updated in the DB fee amount column.
- Ex: the initial fee of the validator Alice for asset MATIC will be 0. When the user burns 90 WMATIC for transfer to another nonnative network with a fee = 10%, each validator will share a fee of 9 MATIC. The user will transfer 81 WMATIC. Each validator will receive 1 MATIC fee, so the validator Alice will have 0 from the DB + 1 from the fee = 1 as total. The next transfer is for 900 WMATIC, so the validator Alice will receive 10 MATIC as a fee. After adding the 1 MATIC from the DB, the result will be 11 MATIC.
- Majority of signatures (Ex [5/9]) for the Merkle tree’s root validation.
- Keep all the data from the Merkle tree. We will go for the re-build the Merkle tree per transfer and store it with an updated fee, on pulling - pass the data from the DB:
- Keep all nodes including the root.
- The signatures, once the majority of validators signed the Merkle tree root.
-
Adding a new asset - will trigger a new record in the validator’s DB and the Merkle tree will be rebuilt by keeping the current dataset (fee amount) and adding the new asset: Check on after validator’s restart for a new native asset in the config and compare it with the current records in the DB
-
Separate DB table to keep the indexes of the Merkle tree
- Per validator.
- Asset address.
- Network ID.
- Leaf index. Based on the leaf’s index, we will be able to get the intermediate hashes for the Merkle tree and pass them later to the Router (Smart Contract).
-
On initialization:
- Fee to collect = 0
- Root hash.
- Nodes/validators hashes.
Example: LimeChain Merkle tree: github & github2
Subtasks:
- [ ] Add the new table to the current DB structure
- [ ] Fill with the initial data based on the config
- [ ] Implement methods for data maintenance (select, insert, update, delete)
- [ ] unit tests, docks, PR reviews & fixes