Page MenuHomePhabricator

[Cashtab, chronik-client] Add and implement ws methods to support mobile app backgrounding
ClosedPublic

Authored by bytesofman on Tue, Nov 18, 20:30.

Details

Summary

Mobile apps may control the behavior of websocket connections in unpredictable ways when an app is "backgrounded," e.g. when the user locks the screen or switches to a different app.

Because we cannot be sure how the OS will control the websocket in this condition, we should handle the connection and this event at the app level.

Because some low-level websocket handling is required to accomplish this, we wrap an effective practical solution in convenient public methods, tested in chronik-client.

These methods are implemented in Cashtab

Test Plan

npm test to confirm we do not break existing behavior, ./start-android.sh and check logs through backgrounding, receive a tx after lock screen and unlock to confirm ws connection is live

Logs:

image.png (340×299 px, 46 KB)

Receive a tx after coming back from backgrounding, and notification appears

Diff Detail

Repository
rABC Bitcoin ABC
Branch
android-handle-idling
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 35106
Build 69671: Build Diffcashtab-tests
Build 69670: arc lint + arc unit

Event Timeline

Tail of the build log:

[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  42% (9/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  47% (10/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  52% (11/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  57% (12/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  61% (13/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  66% (14/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  71% (15/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  76% (16/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  80% (17/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  85% (18/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  90% (19/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects:  95% (20/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects: 100% (21/21)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Counting objects: 100% (21/21), done.        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:   9% (1/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  18% (2/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  27% (3/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  36% (4/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  45% (5/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  54% (6/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  63% (7/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  72% (8/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  81% (9/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects:  90% (10/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects: 100% (11/11)        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Compressing objects: 100% (11/11), done.        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': remote: Total 11 (delta 10), reused 0 (delta 0), pack-reused 0        
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:   9% (1/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  18% (2/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  27% (3/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  36% (4/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  45% (5/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  54% (6/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  63% (7/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  72% (8/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  81% (9/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects:  90% (10/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects: 100% (11/11)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Receiving objects: 100% (11/11), 3.31 KiB | 3.31 MiB/s, done.
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:   0% (0/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  10% (1/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  20% (2/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  30% (3/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  40% (4/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  50% (5/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  60% (6/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  70% (7/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  80% (8/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas:  90% (9/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas: 100% (10/10)
[20:30:58]i: VCS root 'Bitcoin ABC Staging': Resolving deltas: 100% (10/10), completed with 10 local objects.
[20:30:59]i: VCS root 'Bitcoin ABC Staging': From ssh://reviews.bitcoinabc.org:2221/source/bitcoin-abc-staging
[20:30:59]i: VCS root 'Bitcoin ABC Staging':  * [new tag]               phabricator/base/56660 -> phabricator/base/56660
[20:30:59]i: VCS root 'Bitcoin ABC Staging':  * [new tag]               phabricator/diff/56660 -> phabricator/diff/56660
[20:31:00]i: Done collecting changes for 'Bitcoin ABC Staging': 1 changes collected 1 changes persisted, total time: 6s,845ms, persisting time: 6ms
[20:31:01] : Compute revision for 'Bitcoin ABC Staging'
[20:31:01] :	 [Compute revision for 'Bitcoin ABC Staging'] Upper limit revision: 44f08d88fe834e7fbf8e1b69f693c5a90ebdce63
[20:31:01]i:	 [Compute revision for 'Bitcoin ABC Staging'] MaxModId = 87168
[20:31:01] :	 [Compute revision for 'Bitcoin ABC Staging'] Computed revision: 44f08d88fe834e7fbf8e1b69f693c5a90ebdce63
[20:31:01]W: Build was removed from the queue with comment: This build has not been started because some of the builds it depends on failed to start

Tail of the build log:

> mock-chronik-client@3.1.0 build
> tsc

/work/modules/ecash-lib-wasm /work/abc-ci-builds/cashtab-tests
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /work/modules/avalanche-lib-wasm/Cargo.toml
workspace: /work/Cargo.toml
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
    Updating crates.io index
    Updating git repository `https://github.com/LogosFoundation/bitcoinsuite`
warning: spurious network error (3 tries remaining): unexpected http status code: 502; class=Http (34)
error: failed to get `bitcoinsuite-chronik-client` as a dependency of package `explorer-exe v0.1.0 (/work/web/explorer/explorer-exe)`

Caused by:
  failed to load source for dependency `bitcoinsuite-chronik-client`

Caused by:
  Unable to update https://github.com/LogosFoundation/bitcoinsuite?rev=840b0a7#840b0a7b

Caused by:
  failed to clone into: /root/.cargo/git/db/bitcoinsuite-09d4f04b771209c7

Caused by:
  revision 840b0a7bab8005d5ff3a16455b97573345a89633 not found

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  SSL error: unknown error; class=Ssl (16)
Failed opening './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_browser.js: No such file or directory
./build-wasm.sh: line 39: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 40: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.wasm: No such file or directory
./build-wasm.sh: line 41: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 43: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.d.ts: No such file or directory
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_nodejs.js: No such file or directory
Build cashtab-tests failed with exit code 2

Tail of the build log:

> tsc

/work/modules/ecash-lib-wasm /work/abc-ci-builds/cashtab-tests
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /work/modules/avalanche-lib-wasm/Cargo.toml
workspace: /work/Cargo.toml
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
    Updating crates.io index
    Updating git repository `https://github.com/LogosFoundation/bitcoinsuite`
warning: spurious network error (3 tries remaining): unexpected http status code: 500; class=Http (34)
warning: spurious network error (2 tries remaining): unexpected http status code: 502; class=Http (34)
warning: spurious network error (1 tries remaining): unexpected http status code: 500; class=Http (34)
error: failed to get `bitcoinsuite-chronik-client` as a dependency of package `explorer-exe v0.1.0 (/work/web/explorer/explorer-exe)`

Caused by:
  failed to load source for dependency `bitcoinsuite-chronik-client`

Caused by:
  Unable to update https://github.com/LogosFoundation/bitcoinsuite?rev=840b0a7#840b0a7b

Caused by:
  failed to clone into: /root/.cargo/git/db/bitcoinsuite-09d4f04b771209c7

Caused by:
  revision 840b0a7bab8005d5ff3a16455b97573345a89633 not found

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  unexpected http status code: 500; class=Http (34)
Failed opening './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_browser.js: No such file or directory
./build-wasm.sh: line 39: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 40: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.wasm: No such file or directory
./build-wasm.sh: line 41: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 43: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.d.ts: No such file or directory
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_nodejs.js: No such file or directory
Build cashtab-tests failed with exit code 2

Tail of the build log:

> tsc

/work/modules/ecash-lib-wasm /work/abc-ci-builds/cashtab-tests
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /work/modules/avalanche-lib-wasm/Cargo.toml
workspace: /work/Cargo.toml
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
    Updating crates.io index
    Updating git repository `https://github.com/LogosFoundation/bitcoinsuite`
warning: spurious network error (3 tries remaining): unexpected http status code: 500; class=Http (34)
warning: spurious network error (2 tries remaining): unexpected http status code: 500; class=Http (34)
warning: spurious network error (1 tries remaining): unexpected http status code: 500; class=Http (34)
error: failed to get `bitcoinsuite-chronik-client` as a dependency of package `explorer-exe v0.1.0 (/work/web/explorer/explorer-exe)`

Caused by:
  failed to load source for dependency `bitcoinsuite-chronik-client`

Caused by:
  Unable to update https://github.com/LogosFoundation/bitcoinsuite?rev=840b0a7#840b0a7b

Caused by:
  failed to clone into: /root/.cargo/git/db/bitcoinsuite-09d4f04b771209c7

Caused by:
  revision 840b0a7bab8005d5ff3a16455b97573345a89633 not found

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  unexpected http status code: 500; class=Http (34)
Failed opening './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_browser.js: No such file or directory
./build-wasm.sh: line 39: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 40: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.wasm: No such file or directory
./build-wasm.sh: line 41: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 43: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.d.ts: No such file or directory
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_nodejs.js: No such file or directory
Build cashtab-tests failed with exit code 2

Tail of the build log:

> tsc

/work/modules/ecash-lib-wasm /work/abc-ci-builds/cashtab-tests
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /work/modules/avalanche-lib-wasm/Cargo.toml
workspace: /work/Cargo.toml
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
    Updating crates.io index
    Updating git repository `https://github.com/LogosFoundation/bitcoinsuite`
warning: spurious network error (3 tries remaining): unexpected http status code: 500; class=Http (34)
warning: spurious network error (2 tries remaining): unexpected http status code: 500; class=Http (34)
warning: spurious network error (1 tries remaining): unexpected http status code: 500; class=Http (34)
error: failed to get `bitcoinsuite-chronik-client` as a dependency of package `explorer-exe v0.1.0 (/work/web/explorer/explorer-exe)`

Caused by:
  failed to load source for dependency `bitcoinsuite-chronik-client`

Caused by:
  Unable to update https://github.com/LogosFoundation/bitcoinsuite?rev=840b0a7#840b0a7b

Caused by:
  failed to clone into: /root/.cargo/git/db/bitcoinsuite-09d4f04b771209c7

Caused by:
  revision 840b0a7bab8005d5ff3a16455b97573345a89633 not found

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  unexpected http status code: 500; class=Http (34)
Failed opening './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_browser.js: No such file or directory
./build-wasm.sh: line 39: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 40: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.wasm: No such file or directory
./build-wasm.sh: line 41: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 43: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.d.ts: No such file or directory
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_nodejs.js: No such file or directory
Build cashtab-tests failed with exit code 2

Tail of the build log:

Run `npm audit` for details.

> mock-chronik-client@3.1.0 build
> tsc

/work/modules/ecash-lib-wasm /work/abc-ci-builds/cashtab-tests
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /work/modules/avalanche-lib-wasm/Cargo.toml
workspace: /work/Cargo.toml
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
    Updating crates.io index
    Updating git repository `https://github.com/LogosFoundation/bitcoinsuite`
error: failed to get `bitcoinsuite-chronik-client` as a dependency of package `explorer-exe v0.1.0 (/work/web/explorer/explorer-exe)`

Caused by:
  failed to load source for dependency `bitcoinsuite-chronik-client`

Caused by:
  Unable to update https://github.com/LogosFoundation/bitcoinsuite?rev=840b0a7#840b0a7b

Caused by:
  failed to clone into: /root/.cargo/git/db/bitcoinsuite-09d4f04b771209c7

Caused by:
  revision 840b0a7bab8005d5ff3a16455b97573345a89633 not found

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  SSL error: unknown error; class=Ssl (16)
Failed opening './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_browser.js: No such file or directory
./build-wasm.sh: line 39: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 40: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.wasm: No such file or directory
./build-wasm.sh: line 41: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.js: No such file or directory
./build-wasm.sh: line 43: ../ecash-lib/src/ffi/ecash_lib_wasm_bg_browser.d.ts: No such file or directory
error: failed reading './target/wasm32-unknown-unknown/release-wasm/ecash_lib_wasm.wasm'

Caused by:
    No such file or directory (os error 2)
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm_bg.wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.d.ts': No such file or directory
mv: cannot stat '../ecash-lib/src/ffi/ecash_lib_wasm.js': No such file or directory
sed: can't read ../ecash-lib/src/ffi/ecash_lib_wasm_nodejs.js: No such file or directory
Build cashtab-tests failed with exit code 2
Fabien requested changes to this revision.Wed, Nov 19, 08:32
Fabien added a subscriber: Fabien.

I understand the problem but I don't think this is a good approach for several reasons:

  • It uses low level ws state that should be handled by chronik-client, if anything made accessible
  • We have a keepalive already, and websocket has pings which seems a better/cleaner option
  • You have events when the app goes to/resumes from background. Why do you need to check the ws status at all ? Can't you just blindly resubscribe? Do you get twice the notifications if subscribed twice to the same things ?
cashtab/src/wallet/useWallet.ts
1028

why do you need this ?

This revision now requires changes to proceed.Wed, Nov 19, 08:32
bytesofman marked an inline comment as done.

It uses low level ws state that should be handled by chronik-client, if anything made accessible

I'm not really sure how we could accomplish this. The websocket needs to be configured by the app dev. We have always set it in state so we can update the websocket in response to app events, for example like changing the active wallet. But, we could stop looking for so much specific state info when we reconnect.

We have a keepalive already, and websocket has pings which seems a better/cleaner option

Indeed. However, when an app is backgrounded, the websocket nevertheless disconnects, and it does not automatically reconnect when the app is unbackgrounded. This would be nice to handle in chronik-client but I'm not sure how to listen for this event in chronik-client, or if it's even practical to do so there, as the whole backgrounded event is a mobile app thing. I don't think we want capacitor as a dep in chronik-client.

You have events when the app goes to/resumes from background. Why do you need to check the ws status at all ? Can't you just blindly resubscribe? Do you get twice the notifications if subscribed twice to the same things ?

Yes, this is a good point. A lot of this code was used in debugging to try and figure out exactly what is going on. In observation, it's always the same thing that comes up. So, it could be simplified to just handle this. I'll do some more tests and see how it could be improved / simplified.

cashtab/src/wallet/useWallet.ts
1028

unrelated to this diff, which is just recreating the ws that used to exist -- but yes we probably can lose or modify this now

it's used to update blockheight on utxos, so we do not try to spend immature coinbase rewards

at some point it was also used for tx finality but that is now on the tx websocket

bytesofman marked an inline comment as done.

reconnect instead of creating a new ws on backgrounding

review for further simplifications

We have a keepalive already, and websocket has pings which seems a better/cleaner option

Indeed. However, when an app is backgrounded, the websocket nevertheless disconnects, and it does not automatically reconnect when the app is unbackgrounded. This would be nice to handle in chronik-client but I'm not sure how to listen for this event in chronik-client, or if it's even practical to do so there, as the whole backgrounded event is a mobile app thing. I don't think we want capacitor as a dep in chronik-client.

If we need to dig into the low level to get the info we should at least have this implemented in the chronik-client and add a new method ws.alive() or something like that

add pause and resume methods to chronik-client, implement in cashtab

bytesofman retitled this revision from [Cashtab] Re-create websocket connection after app is backgrounded to [Cashtab, chronik-client] Add and implement ws methods to support mobile app backgrounding.Thu, Nov 20, 19:23
bytesofman edited the summary of this revision. (Show Details)
bytesofman edited the test plan for this revision. (Show Details)
modules/chronik-client/src/ChronikClient.ts
1055 ↗(On Diff #56704)

should we return false in this case ? So an app can do:

if (!ws.resume()) {
  ws.close();
  // create a new ws connection
}
bytesofman added inline comments.
modules/chronik-client/src/ChronikClient.ts
1055 ↗(On Diff #56704)

maybe but we are getting pretty complex here in covering hypothetical use cases.

A ws would only be manuallyClosed if a user called the close() method. Current behavior is, in this case, the user should know they need to create a new websocket.

The manuallyClosed flag is itself ... something that needs improvement. We currently do not have a robust system for cycling through chronik websockets, as the websocket usually does not throw an error when it fails; so most websocket switches happen because we see an API failure from the URL. The manuallyClosed flag is used to make sure we can close() a websocket without auto-triggering attempted reconnects to different servers.

In general, we don't really expect manuallyClosed to ever be set unless the user wanted the websocket closed and does not want it back. I think it's too complex for someone calling resume to also conditionally handle if close() was called ... by themselves.

I think it's clear enough for this level of abstraction that a user may pause() and resume() but not close() and resume()

This revision is now accepted and ready to land.Thu, Nov 20, 22:12