-
Notifications
You must be signed in to change notification settings - Fork 684
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
fix(chunks): properly handle missing block, previously causing chunk signature check to fail #3026
Conversation
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 like this should help with master as well. Should we merge into both?
chain/client/src/client.rs
Outdated
|
||
// 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( |
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.
probably better to use matches!
here
|
@birchmd sure that sounds good. |
@bowenwang1996 Please see #3033 |
98d6d5e
to
705fd54
Compare
@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(); |
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.
any reason for moving this block of code?
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 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.
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 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).
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.
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.
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 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.
…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
…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
…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
…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
…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
…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
…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
…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
…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
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: