Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(wallet): Beignet Migration #1450

Merged
merged 63 commits into from
Jan 29, 2024
Merged

refactor(wallet): Beignet Migration #1450

merged 63 commits into from
Jan 29, 2024

Conversation

coreyphillips
Copy link
Collaborator

@coreyphillips coreyphillips commented Jan 2, 2024

Description

This PR migrates a majority of the on-chain wallet logic out of Bitkit.

Implementation details:

Instead of migrating existing user wallet data to match Beignet's data structure I've opted instead to map Bitkit's existing data structure to Beignet's using the setWalletData & getWalletData methods. The mapping can be seen here in UPDATE_WALLET_DATA. This allows all existing calls to Bitkit's store/state to remain intact and reduces the footprint of this PR.
Effectively, everything in the wallet store here is mapped accordingly with the exception of header, exchangeRates & feeEstimates that Beignet uses, but is stored elsewhere in Bitkit.

This PR is meant to act as a 1:1 migration. Updating Bitkit to use the higher level tx and fee API's from Beignet will arrive in a separate PR once this migration is complete.

Regarding the tests. I'm honestly not sure how we should proceed here. I'll need @limpbrains input on the damage I've inflicted once he returns.

Type of change

  • Refactoring (improving code without creating new functionality)

Migrates a majority of the on-chain wallet logic out of Bitkit.
@coreyphillips coreyphillips marked this pull request as draft January 3, 2024 21:26
@pwltr
Copy link
Collaborator

pwltr commented Jan 4, 2024

Will start posting as I go now for the initial click-through test:

  • When restoring the onchain wallet I have to pull-to-refresh for the balance to show up, seems to be a regression:
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-04.at.16.28.37.mp4

@pwltr
Copy link
Collaborator

pwltr commented Jan 4, 2024

It looks like it's overpaying fees 2x:

  • 1 input, 2 outputs, segwit = 141 bytes
  • "Normal" setting on regtest should be 2sats/vbyte = 282 sats fee

Simulator Screenshot - iPhone 15 Pro - 2024-01-04 at 16 53 42
Simulator Screenshot - iPhone 15 Pro - 2024-01-04 at 16 53 40

@pwltr
Copy link
Collaborator

pwltr commented Jan 4, 2024

Coming from the main scanner and "Paste QR Code" the "total required" in coin selection is not updated correctly, seems to be a regression:

EDIT: it works with max amount but not when I type in a custom amount
EDIT2: same when coming from "clipboard ease-of-use" feature

image

Also the review screen is broken thereafter, looks like SendTransaction is not updated in this case:

image

@pwltr
Copy link
Collaborator

pwltr commented Jan 4, 2024

Electrum Server settings falsely say "disconnected", when I switch to my local regtest the balance doesn't update (to 0) no matter what:

EDIT: also when I kill my local regtest network it doesn't give me the toasts for 'disconnected' & 'reconnected', regression (I am cross-testing everything with current master)

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-04.at.17.28.13.mp4

@coreyphillips
Copy link
Collaborator Author

coreyphillips commented Jan 4, 2024

This is intentional and due to a check added here. Some Electrum servers will not broadcast such low fee transactions for small transactions at 1 satPerVByte. This can sometimes be seen on our own regtest server as well for small 1 satPerVByte txs. We can tweak the min byte size lower, but need to be careful to avoid failed broadcasts.

@pwltr
Copy link
Collaborator

pwltr commented Jan 4, 2024

Some Electrum servers will not broadcast such low fee transactions for small transactions at 1 satPerVByte.

That's not the case here, this is a 2 sat/vbyte transaction. If I put a higher fee rate it is still overpaying:

image

Should be 141 * 5 = 705

@coreyphillips
Copy link
Collaborator Author

Electrum Server settings falsely say "disconnected", when I switch to my local regtest the balance doesn't update (to 0) no matter what:

EDIT: also when I kill my local regtest network it doesn't give me the toasts for 'disconnected' & 'reconnected', regression (I am cross-testing everything with current master)

I'll add an update to the Electrum config component to wipe the transaction history and balance/utxo information when specifying a new server on regtest.

yarn.lock Outdated Show resolved Hide resolved
src/store/actions/wallet.ts Outdated Show resolved Hide resolved
src/store/reducers/wallet.ts Outdated Show resolved Hide resolved
@pwltr
Copy link
Collaborator

pwltr commented Jan 4, 2024

If I try to change address types it's crashing with:

image

# Conflicts:
#	src/components/Money.tsx
#	src/utils/lightning/index.ts
Updates beignet to 0.0.5.
Adjusts several methods accordinly.
Updates fee calculations on Amount screen for coin control.
Updated getCurrentAddressIndex method to work with beignet.
Removed unneeded params.
Bumps beignet version to 0.0.6.
@coreyphillips
Copy link
Collaborator Author

@limpbrains Electrum is now handled through the beignet library. Any thoughts on how the tests should be re-wired to handle this update in Bitkit?

@limpbrains
Copy link
Collaborator

Looks like electrum instance is already available through getOnChainWalletElectrum. So I believe waiting for connection and closing it after tests would be enought.

@limpbrains
Copy link
Collaborator

limpbrains commented Jan 11, 2024

I'm trying to run e2e tests and they are failing because of Error: Peer's feerate much too low. Actual: 253. Our expected lower limit: 7500

We need a way to set fees during e2e tests.
Or please change regtest network fees to

	onchain: {
		fast: 4,
		normal: 2,
		slow: 1,
		minimum: 1,
	},

Also, now we have 2 places where we fetch fees from mempool.space: in beignet and in bitkit getFeeEstimates function. This is confusing.

We also have fee override in dev settings, would be nice to have to working again

@limpbrains
Copy link
Collaborator

Send flow doesn't work for me

Simulator.Screen.Recording.-.iPhone.14.Pro.-.2024-01-11.at.10.53.32.mp4

@coreyphillips
Copy link
Collaborator Author

@limpbrains Fix incoming for the send flow.

@limpbrains
Copy link
Collaborator

All e2e tests are now working on my machine!
Also I've fixed detox not exiting issue by adding forceExit, so I think b2c789a should be reverted

@coreyphillips
Copy link
Collaborator Author

coreyphillips commented Jan 25, 2024

All e2e tests are now working on my machine! Also I've fixed detox not exiting issue by adding forceExit, so I think b2c789a should be reverted

Nice! Reverted here.

@limpbrains
Copy link
Collaborator

While using the wallet I often can see
TypeError: Cannot read property 'blockchainScripthash_getHistoryBatch' of undefined looks like a bug

@limpbrains
Copy link
Collaborator

My wallet only has 2 incoming transactions for 2 first addresses. I've sent some sats to address with index 19. Wallet can't see it. pull-to-refresh doesn't help. If I go to Address Viewer and tap check balances, it works and it finds the output

@coreyphillips
Copy link
Collaborator Author

coreyphillips commented Jan 25, 2024

My wallet only has 2 incoming transactions for 2 first addresses. I've sent some sats to address with index 19. Wallet can't see it. pull-to-refresh doesn't help. If I go to Address Viewer and tap check balances, it works and it finds the output

This is consistent with the master branch of Bitkit, but needs to be addressed/expanded on in the beignet library. Specifically, the gap limit is respected in that it will not let the user create more than 20 empty addresses, but the look-ahead is limited to one in order to reduce the number of queries made to Electrum on startup. However, we should be able to adjust this to suit our needs. For example, we may want to increase the look-ahead to 20 when restoring from a seed and bring it back down to 1 thereafter. We could also bring the look-ahead back to 20 when pulling to refresh, etc. So these params will need to be added in beignet for us to utilize in Bitkit accordingly.

Copy link
Collaborator

@limpbrains limpbrains left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are passing, I can't find any major issues. I think we can merge it.
Or maybe @pwltr wants to take another look

src/screens/Wallets/Send/Amount.tsx Show resolved Hide resolved
@pwltr
Copy link
Collaborator

pwltr commented Jan 29, 2024

I can't switch Electrum server and the UI is behaving buggy still:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.14.36.mp4

@pwltr
Copy link
Collaborator

pwltr commented Jan 29, 2024

Fee calculation is still off and sometimes shown incorrectly in the UI, also having issues sending transactions:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.24.36.mp4

Coin selection UI is showing 2 utxos at first and then only one:

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.25.46.mp4
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-01-29.at.14.32.51.mp4

Also 'max' button font should be orange

@pwltr
Copy link
Collaborator

pwltr commented Jan 29, 2024

Coming from the main scanner and "Paste QR Code" the "total required" in coin selection is not updated correctly, seems to be a regression:

EDIT: it works with max amount but not when I type in a custom amount EDIT2: same when coming from "clipboard ease-of-use" feature

Seems to be still the case

@coreyphillips coreyphillips merged commit dcfe943 into master Jan 29, 2024
3 of 4 checks passed
@coreyphillips coreyphillips deleted the beignet-migration branch January 29, 2024 14:20
@JeanlChristophe
Copy link

From a new wallet, using testnet I have received funds with a bech32 address. However, when I change to Native Segwit or legacy and try to send sats, there is $0.00 available.

@JeanlChristophe
Copy link

@coreyphillips Corey, I don't understand why the issues Phil raised last month still exist. Yet it was merged.

@coreyphillips
Copy link
Collaborator Author

coreyphillips commented Feb 21, 2024

@coreyphillips Corey, I don't understand why the issues Phil raised last month still exist. Yet it was merged.

What issue are you referring to? The custom Electrum server UI issue is the only one I know of as being unresolved, is considered minor and will take some time to resolve once we address the more immediate bugs/issues.

@pwltr
Copy link
Collaborator

pwltr commented Feb 21, 2024

@coreyphillips

This one is a major issue:

Coming from the main scanner and "Paste QR Code" the "total required" in coin selection is not updated correctly, seems to be a regression

This one is still there, sending tx seems fine, fees are off in calculation and UI shows something different from calc also:

Fee calculation is still off and sometimes shown incorrectly in the UI, also having issues sending transactions

and the mentioned Electrum UI bugs:

I can't switch Electrum server and the UI is behaving buggy still

Comment here is more up-to-date

@JeanlChristophe JeanlChristophe added this to the Beignet milestone Feb 23, 2024
@JeanlChristophe JeanlChristophe added the bug Something isn't working label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants