Page MenuHomePhabricator

[Cashtab] Detect tx confirmation via Chronik websockets
AbandonedPublic

Authored by emack on May 9 2022, 01:43.

Details

Reviewers
bytesofman
Group Reviewers
Restricted Project
Summary

This is to enable the detection of tx confirmation within Cashtab via the use of Chronik websockets. This diff is specific to Cashtab Web and Extension. A separate diff will be made for Cashtab Components as this diff matures.

Upon successful broadcast of a tx, the websocket subscribes to the hash160 of the active p2pkh address in cashtab to listen for the very first confirmation that matches the txid, at which point the tx will be deemed as completed.

Timing for the first confirmation will obviously vary for now but this'll become fairly consistent after pre-consensus takes it down to seconds. The websocket reconnects every 2 mins by default, which is ok for now given the average 10 min block times but we can revisit this after post/pre-consensus.

Getting this in will support other features such as live tracking of multi-sig signings for eCash DAOs, Point of Sale functionalities for merchants, the full metamask experience via Cashtab Components...etc.

The updates to webpack.config.js is to resolve webpack 5 conflicts which causes 'Module not found' errors with fs and assert.

Dependencies: Chronik client, assert

Test Plan
  1. npm i && npm i assert && npm start
  2. Send a 1 to 1 XEC transaction, note the websocket initialization (AddedToMemPool msg) in the console and verify confirmation notification in UI when the explorer shows at least one confirmation for this tx.
  3. Verify via console the websocket is closed upon detection of the first confirmation (i.e. no further reconnection attempts).
  4. Repeat 2 & 3 for a 1 to many XEC transaction
  5. Repeat 2 & 3 for a send eToken transaction
  6. Repeat 2 & 3 for a burn eToken transaction
  7. Verify cross browser compatibility
  8. Verify in extension plugin mode

Diff Detail

Repository
rABC Bitcoin ABC
Branch
chronikConf
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 18980
Build 37722: Build Diffcashtab-tests
Build 37721: arc lint + arc unit

Event Timeline

emack requested review of this revision.May 9 2022, 01:43

This is a good proof of concept.

In general, once we have the app on chronik, there should always be an active listening websocket connection. This will be processing:

  1. Incoming transactions
  2. Status of unconfirmed sent / received transactions
  3. Impact of outgoing txs to the utxo set

So, connecting to websockets should be done on app startup, with methods to reconnect automatically, and also fallback methods of manually refreshing the wallet using api calls in the event the websocket connection has failed for any reason. Most of the work here is designing this system. Once we have a good websocket handler, the "on new msg" function will handle things like adjusting the wallet utxo set or changing conf status of txs.

This revision now requires changes to proceed.May 16 2022, 16:31

See D11475 for a stub approach of how we will implement websockets. I think websockets will be the first part of chronik to go in, because we can get faster and better notifications before we need to do the more complicated work of switching out the utxo and transaction management.

High level principles:

  1. Websocket should be in state. Will need to change its subscriptions each time the user changes wallet.
  2. Websocket should be available everywhere in the app, so implementation should be in useWallet.js
  3. chronik should only be implemented once, and then passed to where it is used (similar to the BCH variable for bch-api).

Good proof of concept diff

Will need some retooling after other chronik features are landed (and potentially will include avalanche finality)

Please abandon