-
Notifications
You must be signed in to change notification settings - Fork 2.2k
rpcserver: add wallet_synced to GetInfoResponse
#10507
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
Changes from all commits
3c22c3e
d395776
b8693be
7766c1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package itest | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/lightningnetwork/lnd/lntest" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // walletSyncTestCases defines a set of tests for the wallet_synced field | ||
| // in GetInfoResponse. | ||
| var walletSyncTestCases = []*lntest.TestCase{ | ||
| { | ||
| Name: "wallet synced", | ||
| TestFunc: runTestWalletSynced, | ||
| }, | ||
| } | ||
|
|
||
| // runTestWalletSynced tests that the wallet_synced field in GetInfoResponse | ||
| // correctly reflects the wallet's sync state. It verifies that wallet_synced | ||
| // is false while the wallet is catching up to new blocks, and becomes true | ||
| // once fully synced. | ||
| func runTestWalletSynced(ht *lntest.HarnessTest) { | ||
| // Create a test node. | ||
| alice := ht.NewNodeWithCoins("Alice", nil) | ||
|
|
||
| // Verify wallet starts synced. | ||
| resp := alice.RPC.GetInfo() | ||
| require.True(ht, resp.WalletSynced) | ||
| ht.Logf("Alice wallet_synced=%v", resp.WalletSynced) | ||
|
|
||
| // Stop Alice to create a clear sync gap while we mine blocks. | ||
| require.NoError(ht, alice.Stop(), "failed to stop Alice") | ||
|
|
||
| // Mine blocks while Alice is offline. | ||
| const numBlocks = 40 | ||
| ht.Miner().MineBlocks(numBlocks) | ||
| _, minerHeight := ht.Miner().GetBestBlock() | ||
|
|
||
| // Restart Alice without waiting for full chain sync. | ||
| require.NoError( | ||
| ht, alice.Start(ht.Context()), "failed to restart Alice", | ||
| ) | ||
|
|
||
| // While Alice is behind the miner height, wallet_synced must be false. | ||
| deadline := time.Now().Add(lntest.DefaultTimeout) | ||
| for { | ||
| resp := alice.RPC.GetInfo() | ||
| if int32(resp.BlockHeight) >= minerHeight { | ||
| break | ||
| } | ||
|
|
||
| require.Falsef(ht, resp.WalletSynced, | ||
| "wallet_synced=true while behind "+ | ||
| "(nodeHeight=%v, minerHeight=%v)", | ||
| resp.BlockHeight, minerHeight) | ||
|
|
||
| if time.Now().After(deadline) { | ||
| require.Fail(ht, "timed out waiting for "+ | ||
| "node to catch up") | ||
| } | ||
|
|
||
| time.Sleep(50 * time.Millisecond) | ||
| } | ||
|
|
||
| // Final verification that wallet_synced is true. | ||
| require.Eventually(ht, func() bool { | ||
| return alice.RPC.GetInfo().WalletSynced | ||
| }, lntest.DefaultTimeout, 200*time.Millisecond, | ||
| "wallet should be synced after waiting") | ||
| } |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2118,6 +2118,10 @@ message GetInfoResponse { | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Indicates whether final htlc resolutions are stored on disk. | ||||||||||||||||||||||||||||||||||||||||||||||
| bool store_final_htlc_resolutions = 22; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Whether the wallet is fully synced to the best chain. This indicates the | ||||||||||||||||||||||||||||||||||||||||||||||
| // wallet's internal sync state with the backing chain source. | ||||||||||||||||||||||||||||||||||||||||||||||
| bool wallet_synced = 23; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about hooking this into the existing state subscription service? Lines 38 to 59 in aaaf235
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds like it would fit there, but the |
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| message GetDebugInfoRequest { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we expose the block at which the wallet is?
Then we can track this field to reach the block we're handling deposits for:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at how the newly introduced field is put together you land at
lnd/lnwallet/btcwallet/btcwallet.go
Line 1680 in 9a83b38
So your example would collapse to