[engine] SKALE mirror and balance sync tools #2350
Ticket(s) / Related Merge Requests
- Front front!1987 (closed)
- Docs docs!92 (closed)
- Helm helm-charts!93 (closed)
- Terraform minds/infrastructure/minds-terraform!40 (merged)
Summary of Changes
- Mirror all offchain transactions between custodial wallets on the SKALE network
- Introduces a balance sync runner that will run periodically and output if there is a discrepancy (only checks a user once every 6 hours)
- Provides tools for synchronizing balance.
Testing Considerations
For CLI commands - see https://developers.minds.com/docs/walk-throughs/blockchain/#generate-wallet-for-user
Wire
Wire tokens between two users - check the tokens were actually sent. See video below for a visual guide.
Withdraw Creation
Withdraw debiting happens AFTER submission as a TX moves from PENDING to PENDING_APPROVAL - on prod this happens when the TX has X amount of confirmations but on sandbox, the job listening for new withdrawals doesn't work. To test, log in as sandbox admin, and take an existing TXID 0xbce7a41dfefd3eac451de721a5dea570f3763863f90e035b668c96bdfa94004a
Input it into the "Manually add by Transaction ID" in the withdrawal console.
Go to my remote withdrawal console - hit Force Confirm
.
You should see a TX moving from nemofin's wallet to the escrow wallet
Video of this process below.
Withdrawal Rejection
After doing the above, hit Reject
on the withdrawal at my remote withdrawal console.
You should see a TX moving from the escrow wallet to nemofin's wallet
Video of this below
Network Boost Creation
Create a boost - you should see tokens move from your wallet to the boost escrow user
You can get your user's wallet address from the printKeys
command in the CLI - see docs) - you can put the address into the block explorer to see the activity of your wallet.
Video of this process below
Network Boost Accept
When accepting a boost from the admin panel, the funds should move from the the boost escrow user, to the boost handler users wallet.
See video below
Network Boost Reject
When you reject a boost an the admin user, the funds should move from the boost escrow user, back to the users wallet that you are rejecting. To get this user wallet, you may have to use the printKeys function of the CLI.
See video below
Peer Boost Creation
To create a peer boost, make a boost offer to another channel you own. On creation, tokens should be sent from your wallet, to the the boost escrow user.
Video below
Peer Boost Accept
When accepting a peer boost, tokens should move from the the boost escrow user to the user who you are accepting the boost with - you may have to use the CLI to get the wallet address and check the explorer yourself.
Video below.
Peer Boost Reject
When rejecting a peer boost, tokens should move from the the boost escrow user BACK to the user who initially made the offer - you may have to use the CLI to get the wallet address and check the explorer yourself.
Video below.
Buy Plus / Pro
Hard to test on sandbox - you need to send yourself enough tokens on the SKALE network to buy Plus (either get them from the balance sync user, or send yourself some tokens via Metamask and use the syncOffchainBalance
CLI function, then go to /plus
and buy. The funds should move from your users wallet to the main Minds user.
You can repeat this for Pro.
php cli.php Skale syncOffchainBalance --username=username
Video below.
Rewards
First, check everything is in sync (long operation)
php cli.php Skale syncAllSkale --dryRun
If it's not, you need to sync first, so do:
# If theres many to sync
php cli.php Skale syncAllSkale
# If there's just a few it's easier to do them one by one
php cli.php Skale syncSkaleBalance --username=nemofin
Interpolate yesterday's date into these CQL commands and run them all in Cassandra
INSERT INTO minds.token_rewards (user_guid, reward_type, date, multiplier, payout_tx, score, token_amount, tokenomics_version) VALUES (991463054707265537, 'engagement', '2022-07-28', 1, null, 1, 1000, 2);
INSERT INTO minds.token_rewards (user_guid, reward_type, date, multiplier, payout_tx, score, token_amount, tokenomics_version) VALUES (1003026063363674113, 'engagement', '2022-07-28', 1, null, 1, 1000, 2);
INSERT INTO minds.token_rewards (user_guid, reward_type, date, multiplier, payout_tx, score, token_amount, tokenomics_version) VALUES (1269338472028573705, 'engagement', '2022-07-28', 1, null, 1, 1000, 2);
INSERT INTO minds.token_rewards (user_guid, reward_type, date, multiplier, payout_tx, score, token_amount, tokenomics_version) VALUES (1338490664446332943, 'engagement', '2022-07-28', 1, null, 1, 1000, 2);
INSERT INTO minds.token_rewards (user_guid, reward_type, date, multiplier, payout_tx, score, token_amount, tokenomics_version) VALUES (991438404115763219, 'engagement', '2022-07-28', 1, null, 1, 1000, 2);
INSERT INTO minds.token_rewards (user_guid, reward_type, date, multiplier, payout_tx, score, token_amount, tokenomics_version) VALUES (991483947709894668, 'engagement', '2022-07-28', 1, null, 1, 1000, 2);
INSERT INTO minds.token_rewards (user_guid, reward_type, date, multiplier, payout_tx, score, token_amount, tokenomics_version) VALUES (1002952989368913934, 'engagement', '2022-07-28', 1, null, 1, 1000, 2);
Then run
php cli.php Rewards sync
To check nothing went out of sync - run (and wait)
php cli.php Skale syncAllSkale --dryRun
No output means nothing is out of Sync. You can check the wallets of any individual users or the rewards distributor to see outgoing txs
Blockchain Transactions Event Stream
Fire a bunch of transactions first, then run:
php /var/www/Minds/engine/cli.php EventStreams --subscription=Core\\Blockchain\\Skale\\EventStreams\\SkaleBalanceCheckEventStreamsSubscription
Note the rewards sync job we DOES NOT WAIT FOR CONFIRMATION so if this job is running as that runs, it WILL show a balance discrepancy - wait 10 seconds after a tx before running.
Deployment Considerations
To discuss in more depth.
- Config values need to be set up.
- Cronjob needs deploying for the balance sync job.
- Users will need to be decided/set up
- A sufficient supply of tokens and sFuel will need to be sent to the users configured for:
-
balance_sync_user_guid
- Needs to be able to sync the entire network worth of offchain tokens. -
sfuel_distributor_user_guid
- Needs to have enough sFuel to distribute when requested by all custodial user wallets. -
boost_escrow_user_guid
- Needs enough balance to cover existing boosts in queue . -
withdrawal_escrow_user_guid
- Needs enough balance to cover existing withdrawals in the queue. -
rewards_distributor_user_guid
- Needs enough balance to cover Rewards
-
- Alter Cassandra table (do we want to alter views too?).
- Bootstapping development env docs should be followed as it's more or less the same process for production.
- When the balance sync job will need to be run - it is going to take a significant amount of time.
Everything will need a thorough test in staging.
Regression Scope
Effects all points of the site that send offchain transactions.
- boosts
- boost offers
- wire
- withdrawals
- purchases
Platform Affected (web, mobile, etc)
Engine
Developer Testing Completed
Unit and manual
Screenshots / Screen Recording
Pre front-end changes and wait for confirmation for escrow
- Wire https://streamable.com/8ywqk5
- Withdrawal Creation https://streamable.com/sa7qme
- Withdraw Rejection https://streamable.com/8bu2o4
- Network Boost Creation https://streamable.com/hknyaq
- Network Boost Accept https://streamable.com/kc7gcf
- Network Boost Reject https://streamable.com/9nearo
- Peer Boost Creation https://streamable.com/j51n2t
- Peer Boost Accept https://streamable.com/eljzni
- Peer Boost Reject https://streamable.com/wz3j6k
- Buy Plus (Lifetime) https://streamable.com/w9afms
- Buy Pro (Lifetime) https://streamable.com/uwc7bf
- Rewards https://streamable.com/c1o0gt
Post front-end changes and wait for confirmation for escrow
- Wire https://streamable.com/9m5r38
- Withdrawal Creation https://streamable.com/cwlkp5
- Withdraw Rejection https://streamable.com/7ewkco
- Network Boost Creation https://streamable.com/nzgpni
- Network Boost Accept https://streamable.com/v4adis
- Network Boost Reject https://streamable.com/9gszfi
- Peer Boost Creation https://streamable.com/girh35
- Peer Boost Accept https://streamable.com/btpdrn
- Peer Boost Reject https://streamable.com/tkkaxp
- Buy Plus (Lifetime) - nothing has changed that could make this behave differently from v1 videos
- Buy Pro (Lifetime) - nothing has changed that could make this behave differently from v1 videos
- Rewards - nothing has changed that could make this behave differently from v1 videos
Does this impact
-
Localization -
Dark/light mode -
Guest mode
Definition of Done Checklist
-
The Acceptance Criteria has been met -
Code is tested: Testing includes unit/spec, E2E/automated and manual testing -
Merge requests description has been filled out