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

Ms.wallet refactor #10146

Merged
merged 39 commits into from
Feb 14, 2022
Merged

Ms.wallet refactor #10146

merged 39 commits into from
Feb 14, 2022

Conversation

mariano54
Copy link
Contributor

@mariano54 mariano54 commented Feb 8, 2022

This is a significant change in how syncing works in the wallet. It is now organized as a queue where one of four things can get processed at once:

  • New puzzle hash subscription
  • New coin ID subscription
  • new_peak_wallet message
  • state_update message

The subscriptions are prioritized to ensure we don't miss data. State updates are cached by header hash (not height) and reorgs are now processed correctly. Many different bugs and race conditions are fixed by this change. Also, there is a performance improvement in untrusted sync.

A full node bug in coin store is also fixed (affected wallet protocol), where the min height was not being looked up correctly.

TODO:

  • fix flaky tests
  • Test on larger wallets, and test switching between trusted/untrusted
  • Fix oom issue (also present in main)
  • Potentially remove unnecessary fork_point argument

@mariano54 mariano54 marked this pull request as draft February 8, 2022 17:02
@lgtm-com
Copy link

lgtm-com bot commented Feb 9, 2022

This pull request introduces 1 alert when merging 9adfe90 into 3b16013 - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

Comment on lines 9 to 17
final_coin_state: List[CoinState] = []
for coin_state_entry in all_coins_state:
if coin_state_entry.spent_height is not None:
if coin_state_entry.spent_height <= fork_height:
final_coin_state.append(coin_state_entry)
elif coin_state_entry.created_height is not None:
if coin_state_entry.created_height <= fork_height:
final_coin_state.append(coin_state_entry)
return final_coin_state
Copy link
Contributor

Choose a reason for hiding this comment

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

If the function is called filter_foo, why not use filter :^)
I think this is

def accept(coin_state):
    sh = coin_state.spent_height
    if sh is not None:
        return sh <= fork_height
    ch = coin_state.created_height
    return ch is not None and ch <= fork_height

return list(filter(accept, all_coins_state))

(And I said this before, but I think half of the list casts in the code base are unnecessary.)

@lgtm-com
Copy link

lgtm-com bot commented Feb 9, 2022

This pull request introduces 1 alert when merging 9091b7d into 3b16013 - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

@mariano54 mariano54 requested a review from Yostra February 9, 2022 18:17
@lgtm-com
Copy link

lgtm-com bot commented Feb 10, 2022

This pull request introduces 1 alert when merging a0e7346 into 419f88f - view on LGTM.com

new alerts:

  • 1 for Clear-text logging of sensitive information

@lgtm-com
Copy link

lgtm-com bot commented Feb 10, 2022

This pull request introduces 2 alerts when merging de68b58 into 419f88f - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@lgtm-com
Copy link

lgtm-com bot commented Feb 10, 2022

This pull request introduces 2 alerts when merging 532c6c5 into 419f88f - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@mariano54 mariano54 marked this pull request as ready for review February 10, 2022 19:25
@mariano54 mariano54 marked this pull request as draft February 10, 2022 19:31
@lgtm-com
Copy link

lgtm-com bot commented Feb 10, 2022

This pull request introduces 2 alerts when merging cecd4fa into 419f88f - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@mariano54 mariano54 marked this pull request as ready for review February 10, 2022 20:30
@mariano54 mariano54 changed the title Ms.wallet refactor (WIP) Ms.wallet refactor Feb 10, 2022
@lgtm-com
Copy link

lgtm-com bot commented Feb 10, 2022

This pull request introduces 2 alerts when merging fa140c7 into 419f88f - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@lgtm-com
Copy link

lgtm-com bot commented Feb 11, 2022

This pull request introduces 2 alerts when merging 4fa85c9 into 231ef6f - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@@ -364,8 +364,7 @@ async def get_coin_state_by_ids(
self,
include_spent_coins: bool,
coin_ids: List[bytes32],
start_height: uint32 = uint32(0),
end_height: uint32 = uint32((2 ** 32) - 1),
min_height: uint32 = uint32(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice there's no unit test for this function, in tests/core/full_node/test_coin_store.py. It would be good to have one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, yes that would be good considering it's in the coin store.

@lgtm-com
Copy link

lgtm-com bot commented Feb 11, 2022

This pull request introduces 2 alerts when merging 7a612e3 into 231ef6f - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@esaung esaung linked an issue Feb 11, 2022 that may be closed by this pull request
@lgtm-com
Copy link

lgtm-com bot commented Feb 11, 2022

This pull request introduces 2 alerts when merging 2ee4143 into 231ef6f - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@lgtm-com
Copy link

lgtm-com bot commented Feb 12, 2022

This pull request introduces 2 alerts when merging 0af30de into e479586 - view on LGTM.com

new alerts:

  • 1 for Module is imported with 'import' and 'import from'
  • 1 for Clear-text logging of sensitive information

@mariano54
Copy link
Contributor Author

Waiting for merge @Yostra @wjblanke

peak = self.blockchain.get_peak()
if len(coin_states) > 0 and fork_height is not None:
await self.update_wallets(peak.height, fork_height, peak.header_hash, coin_states)
await self.send_peak_to_wallets()
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this change the order of state update <-> new peak messages ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah but only in the case where the full node is syncing up, which is not the usual case. It was wrong before, it should be first the new state then the new_peak_wallet

@@ -23,11 +23,11 @@ async def test_too_many_messages(self):
# Too many messages
r = RateLimiter(incoming=True)
new_tx_message = make_msg(ProtocolMessageTypes.new_transaction, bytes([1] * 40))
for i in range(3000):
for i in range(4900):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this related to the rest of the changes in some way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it is not, it was just a flaky test that needed a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[enhancement] improve and optimize light wallet sync performance
5 participants