-
Notifications
You must be signed in to change notification settings - Fork 260
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
Add merkleblock and proof of work check #153
Conversation
@pebble8888 |
// invalid bits | ||
return false | ||
} | ||
if target == UInt256.zero { |
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.
guard
is better than if
.
This adapts to the following validations.
@@ -103,6 +103,24 @@ public class PeerGroup: PeerDelegate { | |||
} | |||
|
|||
public func peer(_ peer: Peer, didReceiveMerkleBlockMessage message: MerkleBlockMessage, hash: Data) { | |||
if !ProofOfWork.isValidProofOfWork(blockHash: hash, bits: message.bits) { |
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.
Please use guard
I fixed it for the code review comment. |
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
Thanks! |
Requirements
Description of the Change
Add merkleblock message validity check.
You should look out that the validity check here is not enough to insert to the local database.
Moreover you need timestamp check and etc.
UInt256 is for PoW difficulty check.
This implementation is large for it.
I have not enough time to amend this PR unfortunately.
If the implementation doesn't match your design, please reject it or pick up what you need.
Alternate Designs
This check is implemented in BreadWallet.
I don't know we should check which message received.
Benefits
Prevent interpolation and attack.
Possible Drawbacks
Code maintainavility.
If a valid message is dropped, comment out the message check logic.
I tested some message is passed in test net.
Applicable Issues
None