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

Full node changes required for CAT / Standalone #8616

Merged
merged 11 commits into from
Sep 29, 2021

Conversation

Yostra
Copy link
Contributor

@Yostra Yostra commented Sep 27, 2021

No description provided.

@lgtm-com
Copy link

lgtm-com bot commented Sep 27, 2021

This pull request introduces 3 alerts when merging b198f84 into de67c42 - view on LGTM.com

new alerts:

  • 3 for Unused local variable

@@ -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]]]
Copy link
Contributor

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?

Copy link
Contributor Author

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

@Yostra Yostra marked this pull request as ready for review September 28, 2021 02:32
lastest_coin_state[record.name] = record

if npc_res is not None:
hint_list = self.get_hint_list(npc_res)
Copy link
Contributor

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.

@Yostra Yostra force-pushed the standalon_validation_full_node_only branch from c9232ee to 54c0eba Compare September 29, 2021 00:47
Copy link
Contributor

@arvidn arvidn left a 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]]],
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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(
"""
Copy link
Contributor

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

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)"))
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@arvidn
Copy link
Contributor

arvidn commented Sep 29, 2021

I retriggered the failing test. Is there a risk this patch slowed down the execution to cause that timing constraint to be exceeded?
If so, we could bump it further under the understanding that we're increasing the tech debt

@arvidn
Copy link
Contributor

arvidn commented Sep 29, 2021

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.

Copy link
Contributor

@mariano54 mariano54 left a 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]]],
Copy link
Contributor

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
)
Copy link
Contributor

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):
Copy link
Contributor

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):
Copy link
Contributor

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.

@wjblanke wjblanke merged commit 4fddb5c into main Sep 29, 2021
@wjblanke wjblanke deleted the standalon_validation_full_node_only branch September 29, 2021 22:04
archiviz pushed a commit to Tranzact-Network/tranzact-blockchain that referenced this pull request Oct 6, 2021
* 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>
archiviz added a commit to Tranzact-Network/tranzact-blockchain that referenced this pull request Oct 6, 2021
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.

4 participants