-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Full node changes required for CAT / Standalone #8616
Conversation
This pull request introduces 3 alerts when merging b198f84 into de67c42 - view on LGTM.com new alerts:
|
chia/consensus/blockchain.py
Outdated
@@ -164,7 +169,9 @@ async def receive_block( | |||
block: FullBlock, | |||
pre_validation_result: Optional[PreValidationResult] = None, | |||
fork_point_with_peak: Optional[uint32] = None, | |||
) -> Tuple[ReceiveBlockResult, Optional[Err], Optional[uint32], List[CoinRecord]]: | |||
) -> Tuple[ | |||
ReceiveBlockResult, Optional[Err], Optional[uint32], Tuple[List[CoinRecord], Dict[bytes, List[CoinRecord]]] |
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.
where is the call to this function where you do something with the additional return values?
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.
receive_block_batch
and respond_block
in ful_node.py call this function and then pass the results to update_wallets
chia/consensus/blockchain.py
Outdated
lastest_coin_state[record.name] = record | ||
|
||
if npc_res is not None: | ||
hint_list = self.get_hint_list(npc_res) |
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 you add a type annotation here? Not sure what type this list is.
c9232ee
to
54c0eba
Compare
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.
perhaps the tuple of coin updates and new hints should be put in a new class holding state updates/subscription updates. Such a class could also do the deduplication and aggregation that you're currently doing "ad hoc" (or, sprinkled into the existing code)
ReceiveBlockResult, | ||
Optional[Err], | ||
Optional[uint32], | ||
Tuple[List[CoinRecord], Dict[bytes, Dict[bytes32, CoinRecord]]], |
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.
this data structure is quite deep. I would think it warrants its own type to add some names and constraints to how it's used.
From the code below it seems like it's coin records that were added or removed, and then hints that were added (but not removed, right?). It doesn't seem necessary to bundle these up in a tuple.
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.
I took a shortcut here, receive_block get's called on 100s of places in tests and if another arg was added in the call I would have to refactor all of those.
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.
so maybe a dedicated type for updates would make sense then. then new updates could be added without affecting this signature
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.
I'm not sure how this is passing the tests, given that the response is checked in a lot of tests.
I agree with arvid, this response is getting quite complex. Perhaps we can put all of these things into one struct (including the fork_height).
We can leave this for the future, but this is a pretty important method, so it would be good to keep it simple
@@ -174,18 +183,13 @@ async def receive_block( | |||
""" |
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.
it would probably make sense to extend this comment to describe what the last tuple in the return value is and what it can be expected to contain
chia/full_node/hint_store.py
Outdated
self.db_wrapper = db_wrapper | ||
self.coin_record_db = db_wrapper.db | ||
# the coin_id is unique, same hint can be used for multiple coins | ||
await self.coin_record_db.execute(("CREATE TABLE IF NOT EXISTS hints(coin_id blob PRIMARY KEY, hint blob)")) |
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 we ever want to support multiple hints per coin, changing this schema may be the biggest hurdle
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.
good catch, I'll add another auto-increment id column there so that coin id is not unique
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.
added
Co-authored-by: Arvid Norberg <arvid.norberg@gmail.com>
I retriggered the failing test. Is there a risk this patch slowed down the execution to cause that timing constraint to be exceeded? |
Reviewing this, I haven't found any obvious errors, but I'm also not really convinced that all new edge cases introduced by this are covered by tests. |
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.
LGTM after addressing arvid's feedback (and maybe adding a rate limit)
ReceiveBlockResult, | ||
Optional[Err], | ||
Optional[uint32], | ||
Tuple[List[CoinRecord], Dict[bytes, Dict[bytes32, CoinRecord]]], |
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.
I'm not sure how this is passing the tests, given that the response is checked in a lot of tests.
I agree with arvid, this response is getting quite complex. Perhaps we can put all of these things into one struct (including the fork_height).
We can leave this for the future, but this is a pretty important method, so it would be good to keep it simple
if fetched_block_record.header_hash == block_record.header_hash: | ||
tx_removals, tx_additions = await self.get_tx_removals_and_additions( | ||
tx_removals, tx_additions, npc_res = await self.get_tx_removals_and_additions( | ||
fetched_full_block, npc_result | ||
) |
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.
We don't run it again. If the npc_result already exists (it's Optional, and not present when syncing) then we will not run the generator. So we are guaranteed to only run it once.
@@ -1391,3 +1407,39 @@ async def request_children(self, request: wallet_protocol.RequestChildren) -> Op | |||
response = wallet_protocol.RespondChildren(states) | |||
msg = make_msg(ProtocolMessageTypes.respond_children, response) | |||
return msg | |||
|
|||
@api_request | |||
async def request_ses_hashes(self, request: wallet_protocol.RequestSESInfo): |
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.
Blockchain.get_ses_heights() is very fast since it stores these things in memory (the height of each sub-epoch)
@@ -1391,3 +1407,39 @@ async def request_children(self, request: wallet_protocol.RequestChildren) -> Op | |||
response = wallet_protocol.RespondChildren(states) | |||
msg = make_msg(ProtocolMessageTypes.respond_children, response) | |||
return msg | |||
|
|||
@api_request | |||
async def request_ses_hashes(self, request: wallet_protocol.RequestSESInfo): |
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.
Everything here seems safe and very fast. However, we should have a rate limit like other messages.
* full node changes * hint store * finish coin state tracking, mypy, flake8 * type hints * bump protocol version * change wallet tool for testing hint list * mypy * add check for state, future proof hint db for multiple hints per coin * get hint rename * clean * Update chia/consensus/blockchain.py Co-authored-by: Arvid Norberg <arvid.norberg@gmail.com> Co-authored-by: Mariano Sorgente <3069354+mariano54@users.noreply.github.com> Co-authored-by: Arvid Norberg <arvid.norberg@gmail.com>
No description provided.