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

fix(chunks): properly handle missing block, previously causing chunk signature check to fail #3026

Merged
merged 2 commits into from
Jul 27, 2020

Conversation

birchmd
Copy link
Contributor

@birchmd birchmd commented Jul 22, 2020

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:

  • New unit test for processing a chunk with an unknown parent block

@gitpod-io
Copy link

gitpod-io bot commented Jul 22, 2020

@birchmd birchmd changed the title fix(chunks): properly handle missing block causing chunk signature check to fail fix(chunks): properly handle missing block, previously causing chunk signature check to fail Jul 23, 2020
@birchmd birchmd marked this pull request as ready for review July 23, 2020 16:55
Copy link
Collaborator

@bowenwang1996 bowenwang1996 left a comment

Choose a reason for hiding this comment

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

Looks like this should help with master as well. Should we merge into both?


// process_partial_encoded_chunk should return Ok(NeedBlock) if the chunk is
// based on a missing block.
match client.shards_mgr.process_partial_encoded_chunk(
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably better to use matches! here

@birchmd
Copy link
Contributor Author

birchmd commented Jul 23, 2020

Looks like this should help with master as well. Should we merge into both?

PartialEncodedChunkForward doesn't exist in master, only post-phase-1, so that part of the change does not apply, but the part which fixes PartialEncodedChunk would. I could make a separate PR targeting master with the relevant parts of the change, then rebase this PR on top of it. Would you like me to do that?

@bowenwang1996
Copy link
Collaborator

@birchmd sure that sounds good.

@birchmd
Copy link
Contributor Author

birchmd commented Jul 24, 2020

@bowenwang1996 Please see #3033

@birchmd birchmd force-pushed the fix-chunks-handle-missing-block branch from 98d6d5e to 705fd54 Compare July 24, 2020 17:42
@birchmd
Copy link
Contributor Author

birchmd commented Jul 24, 2020

@bowenwang1996 Successfully rebased. Please take another look.

@@ -921,6 +921,12 @@ impl ShardsManager {
return Err(Error::InvalidPartMessage);
}

// check part merkle proofs
let num_total_parts = self.runtime_adapter.num_total_parts();
Copy link
Collaborator

Choose a reason for hiding this comment

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

any reason for moving this block of code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check doesn't require looking up the epoch id. I thought it might be good to do as many check as possible before hitting the missing block error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should be the other way around: the part of the processing that happens before the signature validation we do for each received chunk.

So if someone is sending invalid chunks (or many valid chunks maliciously created for the same height), if the signature verification goes first, we will only check the signature for each of them. Otherwise we will do all the steps above. And in particular verifying the merkle path is not very cheap (though may be not too expensive compared to the sig verification).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But isn't it easier to send chunks for blocks that don't exist if we put the signature check first? All the fields could contain random bytes and we would accept the message because the parent hash is not known. If the signature check is last we will at least know this is some kind of well-formed chunk.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see your point, someone can send a message that has invalid data, but valid chunk hash and a signature.
Then I agree, checking the merkle proofs before the chunk signature is the correct approach.

@birchmd birchmd merged commit 447da9b into near:post-phase-1 Jul 27, 2020
@birchmd birchmd deleted the fix-chunks-handle-missing-block branch July 27, 2020 13:09
birchmd added a commit that referenced this pull request Jul 28, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Aug 7, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Aug 7, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Aug 21, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Aug 22, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Aug 24, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Sep 3, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Sep 17, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
birchmd added a commit that referenced this pull request Sep 28, 2020
…signature check to fail (#3026)

Description:
For partial encoded chunks, the signature check includes looking up the chunk producer, based on the epoch ID. In addition it checks whether this chunk producer has been slashed. These checks require the node to know the parent block the chunk header references, and thus fails if it is not present. This change ensures we properly catch and handle such errors since we will be able to process the chunk later when the node eventually learns about the missing block.

Testing plan:
* New unit test for processing a chunk with an unknown parent block
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.

3 participants