-
Notifications
You must be signed in to change notification settings - Fork 8
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
add get_confirmations() RPC and add to dashboard #56
add get_confirmations() RPC and add to dashboard #56
Conversation
Addresses Neptune-Crypto#6. (partial) Server: * implement get_confirmations RPC * return confirmations field in get_dashboard_overview_data RPC * add wallet_state::get_latest_balance_height() * add block_height to tuple returned from wallet_state::get_balance_history Dashboard: * display confirmations in overview screens * change confirmations field from usize to u64
I'm afraid Alan and I gave you some wrong information. The description in #6 says " The number of blocks (=confirmations) since the most recent balance update". If the last balance update is a outgoing transaction (UTXOs being spent), then any of the wallet's monitored UTXOs could have been spent, not just the last one. The monitored UTXOs are ordered by the blockheight at which they were received, and this ordering does not change. The I would suggest:
|
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.
Please see previous comment
Addresses Neptune-Crypto#56 (comment) 1. rewrite get_latest_balance_height() to find latest spent utxo anywhere in list of monitored_utxos. 2. change type of Confirmations field from u64 to BlockHeight in server and Dashboard.
Done. I think. Please review. ;-) duh, whoops! nice catch on that. Now that you point it out, of course the list must be traversed to find latest spent utxo. I do wonder though if it could be possible to store the latest spent in the wallet to make this lookup o(1). Anyway I still tried to make the fn as efficient as possible given that it is called by the Dashboard overview. Maybe premature optimization, I dunno.
I didn't see such a test in wallet_state.rs. Perhaps I need to look elsewhere, or maybe you can point me to one. Anyway, I've run out of time tonight, so will look at that next coding session. We can keep the PR open.
haven't looked into this yet. I will take a look and if it seems simple/clear and it works I will do it, else leave for a followup PR.
yes! That was my initial instinct, but I was a bit confused because the Dashboard was initially written to accept a u64 and BlockHeight::sub() returns i128. And I wasn't sure how pedantic we are being about BlockHeight vs say BlockCount. ie, a strict interpretation could say that a Height is only to be used in context of a count from block 0. Anyway, with your blessing I changed it to use BlockHeight everywhere in latest commit. extra: I added an impl Display for Sign that just prints "-" if sign is negative. This helped me debug print a list of utxo's with amount and I figure it may be worth keeping, but happy to remove if you don't like it. |
Addresses Neptune-Crypto#56 (comment) 1. rewrite get_latest_balance_height() to find latest spent utxo anywhere in list of monitored_utxos. 2. change type of Confirmations field from u64 to BlockHeight in server and Dashboard.
74e2897
to
b92b064
Compare
We can shoehorn a test of this function into an existing test by adding a few asserts and verifying ensuring that also the light state is updated correctly in the test. This test can be used for test-driven development of (what I believe is) a correct implementation of the method `get_latest_balance_height`. Notice, though, that this test assumes that this method is a method on the `GlobalState` struct and not, as previously, on wallet state. Cf. Neptune-Crypto#56.
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.
With respect to the testing, you can shoehorn tests of the get_latest_balance_height
into the existing test wallet_state_prune_abandoned_mutxos
. It's a bit intricate because the test previously didn't update all parts of the state as it would under real execution, so I modified the test to verify what I consider correct behavior for this new function. If you want to do test-driven development of this new function, feel free to cherry-pick this commit :)
Note that this modified test also checks for the correct behavior of property "3" in my above comment.
Verify that the block in question belongs to the canonical chain.
Also note that this modified test requires you to move the method get_latest_balance_height
from wallet_state.rs
to the file containing GlobalState
.
Sorry about our confusion of types for BlockHeight, block count etc. The data structures are not set in stone, and neither is what we store in the database. So if you want to add anything there, feel free to suggest such changes. But maybe for now, you just want to get this functionality working and then we can revisit e.g. the wallet DB when you have a better overview?
Tip: Inspect the MonitoredUtxo
data model and see what methods it has available. You can use existing methods to solve property "3".
thx! super helpful comments. I'm away today, but will continue on it over the weekend. |
Addresses Neptune-Crypto#6 and Neptune-Crypto#28 block_height.rs: * display BlockHeight as u64 to get rid of ugly leading zeros. wallet_state.rs: * add block height to missing membership_proof warning message * remove get_balance_history() (moved to wallet/mod.rs) wallet/mod.rs: * log time taken in get_latest_balance_height(). * rework get_latest_balance_height to find max(confirmed_in_block) ignoring any utxo not on current tip. * add get_balance_history() and rework to ignore any utxo not on current tip. (issue Neptune-Crypto#28) lib.rs: * add 2 fn to time any fn call: time_fn_call() and time_fn_call_async() rpc_server.rs: * call ::get_balance_history() on global state, not wallet_state.
I think this is ready for another review. See commit messages for summary of changes. |
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.
Looks very good.
Addresses: Neptune-Crypto#56 (comment) Changes: 1. remove test environment detection in ::get_latest_balance_height() 2. decorate wallet_state_prune_abandoned_mutxos() with #[traced_test] The net effect is that: 1. The decorated test case will display debug!() log output. 2. Any other test cases will not.
Addresses #56 (comment) 1. rewrite get_latest_balance_height() to find latest spent utxo anywhere in list of monitored_utxos. 2. change type of Confirmations field from u64 to BlockHeight in server and Dashboard.
We can shoehorn a test of this function into an existing test by adding a few asserts and verifying ensuring that also the light state is updated correctly in the test. This test can be used for test-driven development of (what I believe is) a correct implementation of the method `get_latest_balance_height`. Notice, though, that this test assumes that this method is a method on the `GlobalState` struct and not, as previously, on wallet state. Cf. #56.
Addresses #6. (partial)
The major objective of this PR is adding the
get_confirmations
RPC. A secondary objective is displaying the confirmations field in overview screen of the Dashboard. Other changes are ancillary.Server:
implement get_confirmations
RPCget_dashboard_overview_data
RPCwallet_state::get_latest_balance_height()
block_height
to tuple returned fromwallet_state::get_balance_history
Dashboard:
usize
tou64
Notes:
get_confirmations()
RPC function has been simplified and made more efficient than the prototype here.get_latest_balance_height()
will need to be modified to take into account unsynced/abandoned utxo. There is already Balance history does not agree with balance #28 for this, so I think it is best to do in a follow-up PR. Also, I'm not yet certain of the correct fix, as I did try to simply filter out byutxo.is_abandoned
inget_balance_history()
and that did not solve the balance/history sync issue. suggestions welcome.get_latest_balance_height()
and just calling itget_latest_balance()
. However the amount field requires an additional call+loop and since there is no present need, I decided to keep it as simple/fast as possible.block_height
field to values returned fromwallet_state::get_balance_history()
. That fn is no longer called fromget_confirmations()
however I left theblock_height
field in place because I think it would be useful to callers of theget_history()
RPC. I think it would be useful to display the height in Dashboard history, but decided to leave that change for a follow-up PR. Anyway, this note explains that diff.BlockHeight
type which the compiler treats asi128
. But it doesn't really make sense for a height to be signed. Also,i128
andu128
both seem like overkill... how many blocks are we anticipating? Isu64
not enough? The dashboard was previously usingusize
forconfirmations
field, which seems a bit loose as it could beu32
on some platform, so I changed it tou64
and also my reasoning is less data over the wire vsu128
. But I would rather just be consistent with a single type (based onu64
?) used everywhere to represent block heights. Perhaps the RPC and Dashboard should all be using theBlockHeight
forconfirmations
field rather than a primitive type. thoughts?Testing:
synced balance
synced balance
with top-most balance inHistory
screen. The history screen balance is higher thansynced balance
. This is wrong but expected until Balance history does not agree with balance #28 is fixed.I wanted to create a unit test for
get_confirmations
RPC however it is unclear to me how to do so. There are a few unit tests in rpc_server.rs, but afaict none of them setup a wallet with a non-zero balance which would be a requirement for my test(s). If someone could provide such a setup fn, I would happily make use of it.