diff --git a/sharding/contracts/sharding_manager.go b/sharding/contracts/sharding_manager.go index ca0bf0c9f..b04ae675b 100644 --- a/sharding/contracts/sharding_manager.go +++ b/sharding/contracts/sharding_manager.go @@ -16,10 +16,10 @@ import ( ) // SMCABI is the input ABI used to generate the binding from. -const SMCABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentVote\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"},{\"name\":\"_period\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"},{\"name\":\"_chunkRoot\",\"type\":\"bytes32\"}],\"name\":\"submitVote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"deregisterNotary\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"registerNotary\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"notaryRegistry\",\"outputs\":[{\"name\":\"deregisteredPeriod\",\"type\":\"uint256\"},{\"name\":\"poolIndex\",\"type\":\"uint256\"},{\"name\":\"deposited\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"},{\"name\":\"_period\",\"type\":\"uint256\"},{\"name\":\"_chunkRoot\",\"type\":\"bytes32\"}],\"name\":\"addHeader\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"lastSubmittedCollation\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"lastApprovedCollation\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"releaseNotary\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"notaryPool\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"}],\"name\":\"getNotaryInCommittee\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"collationRecords\",\"outputs\":[{\"name\":\"chunkRoot\",\"type\":\"bytes32\"},{\"name\":\"proposer\",\"type\":\"address\"},{\"name\":\"isElected\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"notaryPoolLength\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"shardId\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"chunkRoot\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"period\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"proposerAddress\",\"type\":\"address\"}],\"name\":\"HeaderAdded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"notary\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"poolIndex\",\"type\":\"uint256\"}],\"name\":\"NotaryRegistered\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"notary\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"poolIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"deregisteredPeriod\",\"type\":\"uint256\"}],\"name\":\"NotaryDeregistered\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"notary\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"poolIndex\",\"type\":\"uint256\"}],\"name\":\"NotaryReleased\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"shardId\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"chunkRoot\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"period\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"notaryAddress\",\"type\":\"address\"}],\"name\":\"VoteSubmitted\",\"type\":\"event\"}]" +const SMCABI = "[{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"currentVote\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"},{\"name\":\"_period\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"},{\"name\":\"_chunkRoot\",\"type\":\"bytes32\"}],\"name\":\"submitVote\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"deregisterNotary\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"}],\"name\":\"hasVoted\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"registerNotary\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"notaryRegistry\",\"outputs\":[{\"name\":\"deregisteredPeriod\",\"type\":\"uint256\"},{\"name\":\"poolIndex\",\"type\":\"uint256\"},{\"name\":\"deposited\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"},{\"name\":\"_period\",\"type\":\"uint256\"},{\"name\":\"_chunkRoot\",\"type\":\"bytes32\"}],\"name\":\"addHeader\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"lastSubmittedCollation\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"lastApprovedCollation\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"releaseNotary\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"notaryPool\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"},{\"name\":\"_index\",\"type\":\"uint256\"}],\"name\":\"getNotaryInCommittee\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"uint256\"}],\"name\":\"getVoteCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"},{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"collationRecords\",\"outputs\":[{\"name\":\"chunkRoot\",\"type\":\"bytes32\"},{\"name\":\"proposer\",\"type\":\"address\"},{\"name\":\"isElected\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"notaryPoolLength\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"shardId\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"chunkRoot\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"period\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"proposerAddress\",\"type\":\"address\"}],\"name\":\"HeaderAdded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"notary\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"poolIndex\",\"type\":\"uint256\"}],\"name\":\"NotaryRegistered\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"notary\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"poolIndex\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"deregisteredPeriod\",\"type\":\"uint256\"}],\"name\":\"NotaryDeregistered\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"notary\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"poolIndex\",\"type\":\"uint256\"}],\"name\":\"NotaryReleased\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"shardId\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"chunkRoot\",\"type\":\"bytes32\"},{\"indexed\":false,\"name\":\"period\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"notaryAddress\",\"type\":\"address\"}],\"name\":\"VoteSubmitted\",\"type\":\"event\"}]" // SMCBin is the compiled bytecode used for deploying new contracts. -const SMCBin = `0x608060405234801561001057600080fd5b50610c43806100206000396000f3006080604052600436106100c45763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630c8da4cc81146100c95780634f33ffa0146100f357806358377bd11461011657806368e9513e1461012b5780636bdd32711461013357806375bd99121461017457806383ceeabe1461019257806397d369a2146101aa5780639910851d146101c2578063a81f4510146101d7578063b09f427e1461020b578063e9e0b68314610226578063f6f67d3614610269575b600080fd5b3480156100d557600080fd5b506100e160043561027e565b60408051918252519081900360200190f35b3480156100ff57600080fd5b50610114600435602435604435606435610290565b005b34801561012257600080fd5b50610114610436565b610114610561565b34801561013f57600080fd5b50610154600160a060020a0360043516610710565b604080519384526020840192909252151582820152519081900360600190f35b34801561018057600080fd5b50610114600435602435604435610733565b34801561019e57600080fd5b506100e1600435610885565b3480156101b657600080fd5b506100e1600435610897565b3480156101ce57600080fd5b506101146108a9565b3480156101e357600080fd5b506101ef6004356109d5565b60408051600160a060020a039092168252519081900360200190f35b34801561021757600080fd5b506101ef6004356024356109fd565b34801561023257600080fd5b50610241600435602435610a92565b60408051938452600160a060020a039092166020840152151582820152519081900360600190f35b34801561027557600080fd5b506100e1610adc565b60036020526000908152604090205481565b60008085101580156102a25750606485105b15156102ad57600080fd5b6005430484146102bc57600080fd5b60008581526005602052604090205484146102d657600080fd5b608783106102e357600080fd5b6000858152600460209081526040808320878452909152902054821461030857600080fd5b600160a060020a03331660009081526001602052604090206002015460ff16151561033257600080fd5b61033c8584610ae2565b1561034657600080fd5b33600160a060020a031661035a86856109fd565b600160a060020a03161461036d57600080fd5b6103778584610b05565b61038085610b29565b9050605a81106103e4576000858152600660209081526040808320879055600482528083208784529091529020600101805474ff00000000000000000000000000000000000000001916740100000000000000000000000000000000000000001790555b6040805183815260208101869052600160a060020a03331681830152905186917fc99370212b708f699fb6945a17eb34d0fc1ccd5b45d88f4d9682593a45d6e833919081900360600190a25050505050565b33600160a060020a038116600090815260016020819052604082209081015460029091015490919060ff16151561046c57600080fd5b82600160a060020a031660008381548110151561048557fe5b600091825260209091200154600160a060020a0316146104a457600080fd5b6104ac610b3e565b50600160a060020a038216600090815260016020526040902060054304908190556104d682610b61565b60008054839081106104e457fe5b600091825260209182902001805473ffffffffffffffffffffffffffffffffffffffff191690556002805460001901905560408051600160a060020a0386168152918201849052818101839052517f90e5afdc8fd31453dcf6e37154fa117ddf3b0324c96c65015563df9d5e4b5a759181900360600190a1505050565b33600160a060020a03811660009081526001602052604081206002015460ff161561058b57600080fd5b34683635c9adc5dea00000146105a057600080fd5b6105a8610b3e565b6105b0610bd2565b156106135750600254600080546001810182559080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03841617905561065c565b61061b610bd9565b90508160008281548110151561062d57fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b60028054600190810182556040805160608101825260008082526020808301878152838501868152600160a060020a038a168452918690529390912091518255915192810192909255519101805460ff1916911515919091179055600a5481106106c85760018101600a555b60408051600160a060020a03841681526020810183905281517fa4fe15c53db34d35a5117acc26c27a2653dc68e2dadfc21ed211e38b7864d7a7929181900390910190a15050565b600160208190526000918252604090912080549181015460029091015460ff1683565b600083101580156107445750606483105b151561074f57600080fd5b60054304821461075e57600080fd5b600083815260056020526040902054821161077857600080fd5b610780610b3e565b604080516060808201835283825233600160a060020a03908116602080850182815260008688018181528b8252600484528882208b8352845288822097518855915160019097018054925173ffffffffffffffffffffffffffffffffffffffff19909316979095169690961774ff000000000000000000000000000000000000000019167401000000000000000000000000000000000000000091151591909102179092558784526005808352858520439190910490556003825284842093909355835185815290810186905280840192909252915185927f2d0a86178d2fd307b47be157a766e6bee19bc26161c32f9781ee0e818636f09c928290030190a2505050565b60056020526000908152604090205481565b60066020526000908152604090205481565b33600160a060020a038116600090815260016020819052604090912080820154600290910154909160ff9091161515146108e257600080fd5b600160a060020a038216600090815260016020526040902054151561090657600080fd5b600160a060020a038216600090815260016020526040902054613f0001600543041161093157600080fd5b600160a060020a03821660008181526001602081905260408083208381559182018390556002909101805460ff1916905551683635c9adc5dea000009082818181858883f1935050505015801561098c573d6000803e3d6000fd5b5060408051600160a060020a03841681526020810183905281517faee20171b64b7f3360a142659094ce929970d6963dcea8c34a9bf1ece8033680929181900390910190a15050565b60008054829081106109e357fe5b600091825260209091200154600160a060020a0316905081565b60008080808080600543049450600b54851115610a1e57600a549350610a24565b60095493505b6040805160001960058802018040808352602083018b90528284018c90529251918290036060019091209094509092508490811515610a5f57fe5b069050600081815481101515610a7157fe5b600091825260209091200154600160a060020a031698975050505050505050565b600460209081526000928352604080842090915290825290208054600190910154600160a060020a0381169074010000000000000000000000000000000000000000900460ff1683565b60025481565b60009182526003602052604090912054600160ff9290920360020a900481161490565b600091825260036020526040909120805460ff9290920360020a9091176001019055565b60009081526003602052604090205460ff1690565b600b546005430490811015610b5257610b5e565b600a54600955600b8190555b50565b6008546007541415610ba757600780546001810182556000919091527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68801819055610bc6565b806007600854815481101515610bb957fe5b6000918252602090912001555b50600880546001019055565b6008541590565b60006001600854111515610bec57600080fd5b600880546000190190819055600780549091908110610c0757fe5b90600052602060002001549050905600a165627a7a7230582025e4cd50e9d13e755d9e6ea3c2abfa8998c6141cc47c803fe8a649cade7c12140029` +const SMCBin = `0x608060405234801561001057600080fd5b50610ca0806100206000396000f3006080604052600436106100da5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630c8da4cc81146100df5780634f33ffa01461010957806358377bd11461012c57806364390ff11461014157806368e9513e146101705780636bdd32711461017857806375bd9912146101b957806383ceeabe146101d757806397d369a2146101ef5780639910851d14610207578063a81f45101461021c578063b09f427e14610250578063b2c2f2e81461026b578063e9e0b68314610283578063f6f67d36146102c6575b600080fd5b3480156100eb57600080fd5b506100f76004356102db565b60408051918252519081900360200190f35b34801561011557600080fd5b5061012a6004356024356044356064356102ed565b005b34801561013857600080fd5b5061012a610493565b34801561014d57600080fd5b5061015c6004356024356105be565b604080519115158252519081900360200190f35b61012a6105e1565b34801561018457600080fd5b50610199600160a060020a0360043516610790565b604080519384526020840192909252151582820152519081900360600190f35b3480156101c557600080fd5b5061012a6004356024356044356107b3565b3480156101e357600080fd5b506100f7600435610905565b3480156101fb57600080fd5b506100f7600435610917565b34801561021357600080fd5b5061012a610929565b34801561022857600080fd5b50610234600435610a55565b60408051600160a060020a039092168252519081900360200190f35b34801561025c57600080fd5b50610234600435602435610a7d565b34801561027757600080fd5b506100f7600435610b12565b34801561028f57600080fd5b5061029e600435602435610b27565b60408051938452600160a060020a039092166020840152151582820152519081900360600190f35b3480156102d257600080fd5b506100f7610b71565b60036020526000908152604090205481565b60008085101580156102ff5750606485105b151561030a57600080fd5b60054304841461031957600080fd5b600085815260056020526040902054841461033357600080fd5b6087831061034057600080fd5b6000858152600460209081526040808320878452909152902054821461036557600080fd5b600160a060020a03331660009081526001602052604090206002015460ff16151561038f57600080fd5b61039985846105be565b156103a357600080fd5b33600160a060020a03166103b78685610a7d565b600160a060020a0316146103ca57600080fd5b6103d48584610b77565b6103dd85610b12565b9050605a8110610441576000858152600660209081526040808320879055600482528083208784529091529020600101805474ff00000000000000000000000000000000000000001916740100000000000000000000000000000000000000001790555b6040805183815260208101869052600160a060020a03331681830152905186917fc99370212b708f699fb6945a17eb34d0fc1ccd5b45d88f4d9682593a45d6e833919081900360600190a25050505050565b33600160a060020a038116600090815260016020819052604082209081015460029091015490919060ff1615156104c957600080fd5b82600160a060020a03166000838154811015156104e257fe5b600091825260209091200154600160a060020a03161461050157600080fd5b610509610b9b565b50600160a060020a0382166000908152600160205260409020600543049081905561053382610bbe565b600080548390811061054157fe5b600091825260209182902001805473ffffffffffffffffffffffffffffffffffffffff191690556002805460001901905560408051600160a060020a0386168152918201849052818101839052517f90e5afdc8fd31453dcf6e37154fa117ddf3b0324c96c65015563df9d5e4b5a759181900360600190a1505050565b60009182526003602052604090912054600160ff9290920360020a900481161490565b33600160a060020a03811660009081526001602052604081206002015460ff161561060b57600080fd5b34683635c9adc5dea000001461062057600080fd5b610628610b9b565b610630610c2f565b156106935750600254600080546001810182559080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0384161790556106dc565b61069b610c36565b9050816000828154811015156106ad57fe5b9060005260206000200160006101000a815481600160a060020a030219169083600160a060020a031602179055505b60028054600190810182556040805160608101825260008082526020808301878152838501868152600160a060020a038a168452918690529390912091518255915192810192909255519101805460ff1916911515919091179055600a5481106107485760018101600a555b60408051600160a060020a03841681526020810183905281517fa4fe15c53db34d35a5117acc26c27a2653dc68e2dadfc21ed211e38b7864d7a7929181900390910190a15050565b600160208190526000918252604090912080549181015460029091015460ff1683565b600083101580156107c45750606483105b15156107cf57600080fd5b6005430482146107de57600080fd5b60008381526005602052604090205482116107f857600080fd5b610800610b9b565b604080516060808201835283825233600160a060020a03908116602080850182815260008688018181528b8252600484528882208b8352845288822097518855915160019097018054925173ffffffffffffffffffffffffffffffffffffffff19909316979095169690961774ff000000000000000000000000000000000000000019167401000000000000000000000000000000000000000091151591909102179092558784526005808352858520439190910490556003825284842093909355835185815290810186905280840192909252915185927f2d0a86178d2fd307b47be157a766e6bee19bc26161c32f9781ee0e818636f09c928290030190a2505050565b60056020526000908152604090205481565b60066020526000908152604090205481565b33600160a060020a038116600090815260016020819052604090912080820154600290910154909160ff90911615151461096257600080fd5b600160a060020a038216600090815260016020526040902054151561098657600080fd5b600160a060020a038216600090815260016020526040902054613f000160054304116109b157600080fd5b600160a060020a03821660008181526001602081905260408083208381559182018390556002909101805460ff1916905551683635c9adc5dea000009082818181858883f19350505050158015610a0c573d6000803e3d6000fd5b5060408051600160a060020a03841681526020810183905281517faee20171b64b7f3360a142659094ce929970d6963dcea8c34a9bf1ece8033680929181900390910190a15050565b6000805482908110610a6357fe5b600091825260209091200154600160a060020a0316905081565b60008080808080600543049450600b54851115610a9e57600a549350610aa4565b60095493505b6040805160001960058802018040808352602083018b90528284018c90529251918290036060019091209094509092508490811515610adf57fe5b069050600081815481101515610af157fe5b600091825260209091200154600160a060020a031698975050505050505050565b60009081526003602052604090205460ff1690565b600460209081526000928352604080842090915290825290208054600190910154600160a060020a0381169074010000000000000000000000000000000000000000900460ff1683565b60025481565b600091825260036020526040909120805460ff9290920360020a9091176001019055565b600b546005430490811015610baf57610bbb565b600a54600955600b8190555b50565b6008546007541415610c0457600780546001810182556000919091527fa66cc928b5edb82af9bd49922954155ab7b0942694bea4ce44661d9a8736c68801819055610c23565b806007600854815481101515610c1657fe5b6000918252602090912001555b50600880546001019055565b6008541590565b60006001600854111515610c4957600080fd5b600880546000190190819055600780549091908110610c6457fe5b90600052602060002001549050905600a165627a7a723058209e7734f55959c6ab2c5139ab8c4ad232e25e9ec5c53f4d3db0cbc291b52289a10029` // DeploySMC deploys a new Ethereum contract, binding an instance of SMC to it. func DeploySMC(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *SMC, error) { @@ -178,7 +178,7 @@ func (_SMC *SMCTransactorRaw) Transact(opts *bind.TransactOpts, method string, p // CollationRecords is a free data retrieval call binding the contract method 0xe9e0b683. // -// Solidity: function collationRecords( uint256, uint256) constant returns(chunkRoot bytes32, proposer address, isElected bool) +// Solidity: function cgollationRecords( uint256, uint256) constant returns(chunkRoot bytes32, proposer address, isElected bool) func (_SMC *SMCCaller) CollationRecords(opts *bind.CallOpts, arg0 *big.Int, arg1 *big.Int) (struct { ChunkRoot [32]byte Proposer common.Address @@ -268,6 +268,58 @@ func (_SMC *SMCCallerSession) GetNotaryInCommittee(_shardId *big.Int, _index *bi return _SMC.Contract.GetNotaryInCommittee(&_SMC.CallOpts, _shardId, _index) } +// GetVoteCount is a free data retrieval call binding the contract method 0xb2c2f2e8. +// +// Solidity: function getVoteCount(_shardId uint256) constant returns(uint256) +func (_SMC *SMCCaller) GetVoteCount(opts *bind.CallOpts, _shardId *big.Int) (*big.Int, error) { + var ( + ret0 = new(*big.Int) + ) + out := ret0 + err := _SMC.contract.Call(opts, out, "getVoteCount", _shardId) + return *ret0, err +} + +// GetVoteCount is a free data retrieval call binding the contract method 0xb2c2f2e8. +// +// Solidity: function getVoteCount(_shardId uint256) constant returns(uint256) +func (_SMC *SMCSession) GetVoteCount(_shardId *big.Int) (*big.Int, error) { + return _SMC.Contract.GetVoteCount(&_SMC.CallOpts, _shardId) +} + +// GetVoteCount is a free data retrieval call binding the contract method 0xb2c2f2e8. +// +// Solidity: function getVoteCount(_shardId uint256) constant returns(uint256) +func (_SMC *SMCCallerSession) GetVoteCount(_shardId *big.Int) (*big.Int, error) { + return _SMC.Contract.GetVoteCount(&_SMC.CallOpts, _shardId) +} + +// HasVoted is a free data retrieval call binding the contract method 0x64390ff1. +// +// Solidity: function hasVoted(_shardId uint256, _index uint256) constant returns(bool) +func (_SMC *SMCCaller) HasVoted(opts *bind.CallOpts, _shardId *big.Int, _index *big.Int) (bool, error) { + var ( + ret0 = new(bool) + ) + out := ret0 + err := _SMC.contract.Call(opts, out, "hasVoted", _shardId, _index) + return *ret0, err +} + +// HasVoted is a free data retrieval call binding the contract method 0x64390ff1. +// +// Solidity: function hasVoted(_shardId uint256, _index uint256) constant returns(bool) +func (_SMC *SMCSession) HasVoted(_shardId *big.Int, _index *big.Int) (bool, error) { + return _SMC.Contract.HasVoted(&_SMC.CallOpts, _shardId, _index) +} + +// HasVoted is a free data retrieval call binding the contract method 0x64390ff1. +// +// Solidity: function hasVoted(_shardId uint256, _index uint256) constant returns(bool) +func (_SMC *SMCCallerSession) HasVoted(_shardId *big.Int, _index *big.Int) (bool, error) { + return _SMC.Contract.HasVoted(&_SMC.CallOpts, _shardId, _index) +} + // LastApprovedCollation is a free data retrieval call binding the contract method 0x97d369a2. // // Solidity: function lastApprovedCollation( uint256) constant returns(uint256) diff --git a/sharding/contracts/sharding_manager.sol b/sharding/contracts/sharding_manager.sol index dcfd4228c..ba2062e61 100644 --- a/sharding/contracts/sharding_manager.sol +++ b/sharding/contracts/sharding_manager.sol @@ -205,15 +205,23 @@ contract SMC { emit VoteSubmitted(_shardId, _chunkRoot, _period, msg.sender); } - /// To keep track of notary size in between periods, we call updateNotarySampleSize - /// before notary registration/deregistration so correct size can be applied next period - function updateNotarySampleSize() internal { - uint currentPeriod = block.number / PERIOD_LENGTH; - if (currentPeriod < sampleSizeLastUpdatedPeriod) { - return; - } - currentPeriodNotarySampleSize = nextPeriodNotarySampleSize; - sampleSizeLastUpdatedPeriod = currentPeriod; + /// Returns total vote count of currentVote + /// the vote count is stored in the last byte of currentVote + function getVoteCount(uint _shardId) public view returns (uint) { + uint votes = uint(currentVote[_shardId]); + // Extra the last byte of currentVote + return votes % 256; + } + + /// Check if a bit is set, this function is used to check + /// if a notary has casted the vote. Right shift currentVote by index + /// and AND with 1, return true if voted, false if not + function hasVoted(uint _shardId, uint _index) public view returns (bool) { + uint votes = uint(currentVote[_shardId]); + // Shift currentVote to right by given index + votes = votes >> (255 - _index); + // AND 1 to neglect everything but bit 0, then compare to 1 + return votes & 1 == 1; } /// Check if the empty slots stack is empty @@ -231,6 +239,17 @@ contract SMC { ++emptySlotsStackTop; } + /// To keep track of notary size in between periods, we call updateNotarySampleSize + /// before notary registration/deregistration so correct size can be applied next period + function updateNotarySampleSize() internal { + uint currentPeriod = block.number / PERIOD_LENGTH; + if (currentPeriod < sampleSizeLastUpdatedPeriod) { + return; + } + currentPeriodNotarySampleSize = nextPeriodNotarySampleSize; + sampleSizeLastUpdatedPeriod = currentPeriod; + } + /// Get one uint out of the empty slots stack for notary index function stackPop() internal returns(uint) { require(emptySlotsStackTop > 1); @@ -238,36 +257,17 @@ contract SMC { return emptySlotsStack[emptySlotsStackTop]; } - /// Check if a bit is set, this function is used to check - /// if a notary has casted the vote. Right shift currentVote by index - /// and AND with 1, return true if voted, false if not - function hasVoted(uint _shardId, uint _index) internal returns (bool) { - uint votes = uint(currentVote[_shardId]); - // Shift currentVote to right by given index - votes = votes >> (255 - _index); - // AND 1 to neglect everything but bit 0, then compare to 1 - return votes & 1 == 1; - } - /// Set the index bit to one, notary uses this function to cast its vote, /// after the notary casts its vote, we increase currentVote's count by 1 function castVote(uint _shardId, uint _index) internal { uint votes = uint(currentVote[_shardId]); - // Get the bitfield by shifting 1 to the index field + // Get the bitfield by shifting 1 to the index uint indexToFlag = 2 ** (255 - _index); - // OR with currentVote to set index to 1 + // OR with currentVote to cast notary index to 1 votes = votes | indexToFlag; // Update vote count votes++; currentVote[_shardId] = bytes32(votes); } - - /// Returns total vote count of currentVote - /// the vote count is stored in the last byte of currentVote - function getVoteCount(uint _shardId) internal returns (uint) { - uint votes = uint(currentVote[_shardId]); - // Extra the last byte of currentVote - return votes % 256; - } } \ No newline at end of file diff --git a/sharding/contracts/sharding_manager_test.go b/sharding/contracts/sharding_manager_test.go index 68b842d20..3daa33989 100644 --- a/sharding/contracts/sharding_manager_test.go +++ b/sharding/contracts/sharding_manager_test.go @@ -574,7 +574,7 @@ func TestNormalAddHeader(t *testing.T) { backend.Commit() } - // Proposer adds header consists of shard 0, period 1 and chunkroot 0xA + // Proposer adds header consists shard 0, period 1 and chunkroot 0xA period1 := big.NewInt(1) shard0 := big.NewInt(0) chunkRoot := [32]byte{'A'} @@ -602,7 +602,7 @@ func TestNormalAddHeader(t *testing.T) { backend.Commit() } - // Proposer adds header consists of shard 0, period 2 and chunkroot 0xB + // Proposer adds header consists shard 0, period 2 and chunkroot 0xB period2 := big.NewInt(2) chunkRoot = [32]byte{'B'} _, err = smc.AddHeader(txOpts, shard0, period2, chunkRoot) @@ -621,7 +621,7 @@ func TestNormalAddHeader(t *testing.T) { t.Errorf("Chunkroot mismatched. Want: %v, Got: %v", chunkRoot, cr) } - // Proposer adds header consists of shard 1, period 2 and chunkroot 0xC + // Proposer adds header consists shard 1, period 2 and chunkroot 0xC shard1 := big.NewInt(1) chunkRoot = [32]byte{'C'} _, err = smc.AddHeader(txOpts, shard1, period2, chunkRoot) @@ -649,7 +649,7 @@ func TestAddTwoHeadersAtSamePeriod(t *testing.T) { backend.Commit() } - // Proposer adds header consists of shard 0, period 1 and chunkroot 0xA + // Proposer adds header consists shard 0, period 1 and chunkroot 0xA period1 := big.NewInt(1) shard0 := big.NewInt(0) chunkRoot := [32]byte{'A'} @@ -726,3 +726,79 @@ func TestAddHeadersAtWrongPeriod(t *testing.T) { t.Errorf("Chunkroot mismatched. Want: %v, Got: %v", chunkRoot, cr) } } + +func TestSubmitVote(t *testing.T) { + addr := crypto.PubkeyToAddress(mainKey.PublicKey) + backend := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: accountBalance2000Eth}}) + txOpts := bind.NewKeyedTransactor(mainKey) + txOpts.Value = notaryDeposit + _, _, smc, _ := deploySMCContract(backend, mainKey) + + // Notary 0 registers + smc.RegisterNotary(txOpts) + backend.Commit() + + // Fast forward to the next period to submit header. Period 1 + for i := 0; i < int(sharding.PeriodLength); i++ { + backend.Commit() + } + + // Proposer adds header consists shard 0, period 1 and chunkroot 0xA + period1 := big.NewInt(1) + shard0 := big.NewInt(0) + index0 := big.NewInt(0) + chunkRoot := [32]byte{'A'} + txOpts.Value = big.NewInt(0) + _, err := smc.AddHeader(txOpts, shard0, period1, chunkRoot) + if err != nil { + t.Fatalf("Proposer adds header failed: %v", err) + } + backend.Commit() + + // Notary 0 votes on header + c, err := smc.GetVoteCount(&bind.CallOpts{}, shard0) + if err != nil { + t.Fatalf("Get notary vote count failed: %v", err) + } + if c.Cmp(big.NewInt(0)) != 0 { + t.Errorf("Incorrect notary vote count, want: 0, got: %v", c) + } + + _, err = smc.SubmitVote(txOpts, shard0, period1, index0, chunkRoot) + backend.Commit() + if err != nil { + t.Fatalf("Notary submits vote failed: %v", err) + } + + // Check notary 0's vote is correctly casted + v, err := smc.HasVoted(&bind.CallOpts{}, shard0, index0) + t.Log(v) + if err != nil { + t.Fatalf("Check notary's vote failed: %v", err) + } + if v == false { + t.Errorf("Notary's indexd bit did not cast to 1 in index %v", index0) + } + c, err = smc.GetVoteCount(&bind.CallOpts{}, shard0) + if c.Cmp(big.NewInt(1)) != 0 { + t.Errorf("Incorrect notary vote count, want: 1, got: %v", c) + } + + // Check header's submitted with the current period, should be period 1 + p, err := smc.LastSubmittedCollation(&bind.CallOpts{}, shard0) + if err != nil { + t.Fatalf("Get period of last submitted header failed: %v", err) + } + if p.Cmp(big.NewInt(1)) != 0 { + t.Errorf("Incorrect period submitted, want: 1, got: %v", p) + } + + // Check header's approved with the current period, should be period 0 + p, err = smc.LastApprovedCollation(&bind.CallOpts{}, shard0) + if err != nil { + t.Fatalf("Get period of last approved header failed: %v", err) + } + if p.Cmp(big.NewInt(0)) != 0 { + t.Errorf("Incorrect period submitted, want: 0, got: %v", p) + } +}