forked from openethereum/parity-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 12
Queue malice reports and fix the unit tests. #129
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
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f2caaab
Update the test validator set contract.
afck 384a046
Add maliceReportedForBlock to test contract.
afck 2d71048
Add back benign report check.
afck 952316b
Fix reportBenign ABI.
afck c1584d4
Explicitly check malice report in the test.
afck 883a3b2
Queue malice reports
DemiMarie 059dd35
Queue reports even if transaction creation was successful.
afck 35cec09
Fix malice report nonce addr; disable transactions.
afck 83ab917
Make the unit tests work again.
afck 68a3710
Retry sending queued malice reports.
afck 81f156b
Fix malice report block numbers.
afck bee4986
added a constant to limit resending of returned reports
vkomenda 82bc65f
skip at least one block when reporting malicious validators
vkomenda 539cf15
restored instantaneous malicious reports
vkomenda 78f02fa
Filter malice reports more aggressively.
afck 4e29baf
Update test contracts: add isValidatorBanned.
afck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| [ | ||
| {"constant":false,"inputs":[{"name":"validator","type":"address"},{"name":"blockNumber","type":"uint256"},{"name":"proof","type":"bytes"}],"name":"reportMalicious","outputs":[],"payable":false,"type":"function"}, | ||
| {"constant":false,"inputs":[{"name":"validator","type":"address"},{"name":"blockNumber","type":"uint256"}],"name":"reportBenign","outputs":[],"payable":false,"type":"function"} | ||
| { "constant": false, "inputs": [ { "name": "validator", "type": "address" }, { "name": "blockNum", "type": "uint256" }, { "name": "", "type": "bytes" } ], "name": "reportMalicious", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, | ||
| {"constant":false,"inputs":[{"name":"validator","type":"address"},{"name":"blockNumber","type":"uint256"}],"name":"reportBenign","outputs":[],"payable":false,"type":"function"}, | ||
| { "constant": true, "inputs": [ { "name": "validator", "type": "address" }, { "name": "blockNum", "type": "uint256" } ], "name": "maliceReportedForBlock", "outputs": [ { "name": "", "type": "address[]" } ], "payable": false, "stateMutability": "view", "type": "function" } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| getValidators | ||
| initiateChange | ||
| emitInitiateChangeCallable | ||
| emitInitiateChange | ||
| maliceReportedForBlock | ||
| finalizeChange | ||
| InitiateChange |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ contract TestList { | |
| ]; | ||
|
|
||
| mapping(address => uint) indices; | ||
| // Should remain 0 because `reportBenign` is no longer used. | ||
| mapping(bytes32 => address[]) maliceReported; | ||
| address public disliked; | ||
|
|
||
| event InitiateChange(bytes32 indexed parentHash, address[] newSet); | ||
|
|
@@ -28,27 +28,48 @@ contract TestList { | |
| return validators; | ||
| } | ||
|
|
||
| function setValidators(address[] memory _validators) public { | ||
| validators = _validators; | ||
| emit InitiateChange(blockhash(block.number - 1), validators); | ||
| } | ||
|
|
||
| // Removes a validator from the list. | ||
| function reportMalicious(address validator) public { | ||
| validators[indices[validator]] = validators[validators.length-1]; | ||
| delete indices[validator]; | ||
| delete validators[validators.length-1]; | ||
| validators.length--; | ||
| function reportMalicious(address validator, uint256 blockNum, bytes calldata) external { | ||
| maliceReported[keccak256(abi.encode(validator, blockNum))].push(msg.sender); | ||
| if (validators[indices[validator]] == validator) { | ||
| validators[indices[validator]] = validators[validators.length-1]; | ||
| delete indices[validator]; | ||
| delete validators[validators.length-1]; | ||
| validators.length--; | ||
| } | ||
| } | ||
|
|
||
| // Returns the list of all validators that reported the given validator as malicious for the given block. | ||
| function maliceReportedForBlock(address validator, uint256 blockNum) public view returns(address[] memory) { | ||
| return maliceReported[keccak256(abi.encode(validator, blockNum))]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation: spaces should be replaced with tabs. |
||
| } | ||
|
|
||
| // Benign validator behaviour report. Kept here for regression testing. | ||
| function reportBenign(address validator) public { | ||
| function reportBenign(address validator, uint256) public { | ||
| disliked = validator; | ||
| } | ||
|
|
||
| // Checks if `emitInitiateChange` can be called. | ||
| function emitInitiateChangeCallable() pure public returns (bool) { | ||
| return true; | ||
| function emitInitiateChangeCallable() view public returns (bool) { | ||
| return block.number > 0; | ||
| } | ||
|
|
||
| // Emits an `InitiateChange` event in production code. Does nothing in the test. | ||
| function emitInitiateChange() pure public {} | ||
| // Checks if a validator has been removed. | ||
| function isValidatorBanned(address validator) view public returns (bool) { | ||
| return validators[indices[validator]] != validator; | ||
| } | ||
|
|
||
| // Emits an `InitiateChange` event. | ||
| function emitInitiateChange() public { | ||
| emit InitiateChange(blockhash(block.number - 1), validators); | ||
| } | ||
|
|
||
| // Applies a validator set change in production code. Does nothing in the test. | ||
| function finalizeChange() pure public {} | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we really need this function here? Seems it is not called anywhere.
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's called here, in the test.