-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Validator manager contract in solidity #4
Validator manager contract in solidity #4
Conversation
|
||
import "RLP.sol"; | ||
|
||
interface ValidatorContract { |
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 is no longer needed
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.
@enriquefynn we could check in this contract with the finished methods and have skeleton/stub methods for the others that aren't complete yet.
See this thread for source on some of my comments: https://gitter.im/ethereum/py-evm?at=5a6d73da0ad3e04b1b79d5df
// Amount of wei the validator holds | ||
uint deposit; | ||
// The address which the validator's signatures must verify to (to be later replaced with validation code) | ||
ValidatorContract validationCodeAddr; |
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.
We should store the validator account. Perhaps having the returnAddr and the validator address be the same
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.
Maybe there's no need for validationCodeAddr
anymore then. We can storeaddr
instead
var msgHash = keccak256("withdraw"); | ||
// TODO: Check this function | ||
var result = validators[_validatorIndex].validationCodeAddr.withdraw.gas(sigGasLimit)(_sig); | ||
if (result) { |
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 goes away and we assert(msg.sender == validators[_validatorIndex].address)
} | ||
} | ||
|
||
function sample(int _shardId) public constant returns(address) { |
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.
Is this meant to be getEligibleProposer?
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.
Also see ethereum/sharding#37 |
Remove validator's code and use the transaction's signature to verify the validator's identity
We should sync with the changes in this PR: ethereum/py-evm#348 This removes the validator code requirement. Also, can we prepare this to merge? Even if some of it is incomplete |
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.
Left a few comments. If any feel out of scope, please create an issue and mention it in response to my comment then we can resolve in another pull request.
Thanks for putting this together
function VMC() public { | ||
} | ||
|
||
function isStackEmpty() internal view returns(bool) { |
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 reorganize functions to this order:
constructor
fallback function (if exists)
external
public
internal
private
http://solidity.readthedocs.io/en/develop/style-guide.html#order-of-functions
function isStackEmpty() internal view returns(bool) { | ||
return emptySlotsStackTop == 0; | ||
} | ||
function stackPush(int index) internal { |
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 add space between function declarations.
address to; | ||
} | ||
|
||
mapping (int => Validator) validators; |
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.
Could you comment what the keys are for these mappings?
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.
If the keys are shard ID or period number, shouldn't this be uint?
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.
If the keys are shard ID or period number, shouldn't this be uint?
I want to do this afterwards, when I test the code gets bigger when modifying the ints to uint.
Some of those can also be packed in smaller sizes.
deposit: msg.value, | ||
addr: msg.sender | ||
}); | ||
++numValidators; |
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.
Formatting
// [TODO] Should check further if this safe or not | ||
return validators[ | ||
int( | ||
uint(keccak256(uint(block.blockhash(_period - lookAheadPeriods)) * periodLength, _shardId)) |
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.
Formatting, please indent these three lines so it is clear that the result of modulus is cast to int.
return receiptId; | ||
} | ||
|
||
function updataGasPrice(int _receiptId, uint _txGasprice) public payable returns(bool) { |
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.
/updata/update/s
)].addr; | ||
} | ||
|
||
struct HeaderVars { |
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.
HeaderVars? Is this the collation header? Can we drop "Vars" and replace with something more meaningful?
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.
That's just to pack variables used in the addHeader function
} | ||
function addHeader(int _shardId, uint _expectedPeriodNumber, bytes32 _periodStartPrevHash, | ||
bytes32 _parentCollationHash, bytes32 _txListRoot, address _collationCoinbase, | ||
bytes32 _postStateRoot, bytes32 _receiptRoot, int _collationNumber) public returns(bool) { |
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.
Always returns true? When is a false state? Can this be a void method?
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.
From the sharding spec:
addHeader(bytes header) returns bool: attempts to process a collation header, returns True on success, reverts on failure.
I think it can be a void method. We should probably clone also the spec if we start differing so much, no?
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.
Sounds good to me
data: _data | ||
}); | ||
var receiptId = numReceipts; | ||
++numReceipts; |
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'm not 100% on solidity, but if receiptId is the same reference as numReceipts then wouldn't they both be incremented?
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.
No, receiptId is a variable in memory.
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.
Sounds good
// during a future collation. Saves a `receipt ID` for this request, | ||
// also saving `msg.sender`, `msg.value`, `to`, `shard_id`, `startgas`, | ||
// `gasprice`, and `data`. | ||
function txToShard(address _to, int _shardId, uint _txStartgas, uint _txGasprice, bytes12 _data) public payable returns(int) { |
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.
Line too long, can you limit to 100 characters for review?
|
||
// Constant values | ||
uint constant periodLength = 5; | ||
int constant shardCount = 100; |
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 make shardcount public
Looks all good to me...would you all be ok with merging?? |
// if (parent_collation_hash == 0), i.e., is the genesis, | ||
// then there is no need to check. | ||
if (_parentCollationHash != 0x0) | ||
assert((_parentCollationHash == 0x0) || (collationHeaders[_shardId][_parentCollationHash].score > 0)); |
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.
_parentCollationHash == 0x0 can never be true from within this if statement, please update
data: _data | ||
}); | ||
var receiptId = numReceipts; | ||
++numReceipts; |
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.
Sounds good
Validator manager contract in solidity
Validator manager contract in solidity Former-commit-id: 5c8e92a
Update faq.md
Work in progress.
Missing: