diff --git a/cmd/geth/shardingcmd.go b/cmd/geth/shardingcmd.go index 65899ae2fd74..5e49140c88ef 100644 --- a/cmd/geth/shardingcmd.go +++ b/cmd/geth/shardingcmd.go @@ -17,7 +17,7 @@ var ( Flags: []cli.Flag{utils.DataDirFlag, utils.PasswordFileFlag, utils.NetworkIdFlag}, Category: "SHARDING COMMANDS", Description: ` -The Geth sharding client connects to a running geth node in sharding mode. This feature is a work in progress. +Launches a sharding client that connects to a running geth node and proposes collations to a Validator Manager Contract. This feature is a work in progress. `, } ) diff --git a/sharding/client.go b/sharding/client.go index 740aa3b4db44..80d85cfaa826 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -1,13 +1,18 @@ package sharding import ( + "context" "fmt" "io/ioutil" + "math/big" "strings" "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" @@ -72,22 +77,34 @@ func (c *Client) Start() error { return err } - // TODO: Wait to be selected as collator in goroutine? + // Deposit 100ETH into the validator set in the VMC. Checks if account + // is already a validator in the VMC (in the case the client restarted). + // Once that's done we can subscribe to block headers. + // + // TODO: this function should store the validator's VMC index as a property + // in the client's struct + if err := joinValidatorSet(c); err != nil { + return err + } + // Listens to block headers from the geth node and if we are an eligible + // proposer, we fetch pending transactions and propose a collation + if err := subscribeBlockHeaders(c); err != nil { + return err + } return nil } // Wait until sharding client is shutdown. func (c *Client) Wait() { - // TODO: Blocking lock. + log.Info("Sharding client has been shutdown...") } -// dialRPC endpoint to node. -func dialRPC(endpoint string) (*rpc.Client, error) { - if endpoint == "" { - endpoint = node.DefaultIPCEndpoint(clientIdentifier) - } - return rpc.Dial(endpoint) +// WatchCollationHeaders checks the logs for add_header func calls +// and updates the head collation of the client. We can probably store +// this as a property of the client struct +func (c *Client) WatchCollationHeaders() { + } // UnlockAccount will unlock the specified account using utils.PasswordFileFlag or empty string if unset. @@ -105,3 +122,49 @@ func (c *Client) unlockAccount(account accounts.Account) error { return c.keystore.Unlock(account, pass) } + +func (c *Client) createTXOps(value *big.Int) (bind.TransactOpts, error) { + + accounts := c.keystore.Accounts() + if len(accounts) == 0 { + return bind.TransactOpts{}, fmt.Errorf("no accounts found") + } + + if err := c.unlockAccount(accounts[0]); err != nil { + return bind.TransactOpts{}, fmt.Errorf("unable to unlock account 0: %v", err) + } + + if value.Cmp(big.NewInt(0)) == 0 { + return bind.TransactOpts{ + From: accounts[0].Address, + Signer: func(signer types.Signer, addr common.Address, tx *types.Transaction) (*types.Transaction, error) { + networkID, err := c.client.NetworkID(context.Background()) + if err != nil { + return nil, fmt.Errorf("unable to fetch networkID: %v", err) + } + return c.keystore.SignTx(accounts[0], tx, networkID /* chainID */) + }, + }, nil + } + + return bind.TransactOpts{ + From: accounts[0].Address, + Value: value, + Signer: func(signer types.Signer, addr common.Address, tx *types.Transaction) (*types.Transaction, error) { + networkID, err := c.client.NetworkID(context.Background()) + if err != nil { + return nil, fmt.Errorf("unable to fetch networkID: %v", err) + } + return c.keystore.SignTx(accounts[0], tx, networkID /* chainID */) + }, + }, nil + +} + +// dialRPC endpoint to node. +func dialRPC(endpoint string) (*rpc.Client, error) { + if endpoint == "" { + endpoint = node.DefaultIPCEndpoint(clientIdentifier) + } + return rpc.Dial(endpoint) +} diff --git a/sharding/collator.go b/sharding/collator.go new file mode 100644 index 000000000000..a4662643b498 --- /dev/null +++ b/sharding/collator.go @@ -0,0 +1,105 @@ +package sharding + +import ( + "context" + "fmt" + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" + "math/big" +) + +// SubscribeBlockHeaders checks incoming block headers and determines if +// we are an eligible proposer for collations. Then, it finds the pending tx's +// from the running geth node and sorts them by descending order of gas price, +// eliminates those that ask for too much gas, and routes them over +// to the VMC to create a collation +func subscribeBlockHeaders(c *Client) error { + headerChan := make(chan *types.Header, 16) + + _, err := c.client.SubscribeNewHead(context.Background(), headerChan) + if err != nil { + return fmt.Errorf("unable to subscribe to incoming headers. %v", err) + } + + log.Info("Listening for new headers...") + + for { + // TODO: Error handling for getting disconnected from the client + select { + case head := <-headerChan: + // Query the current state to see if we are an eligible proposer + log.Info(fmt.Sprintf("Received new header: %v", head.Number.String())) + // TODO: Only run this code on certain periods? + if err := checkShardsForProposal(c, head); err != nil { + return fmt.Errorf("unable to watch shards. %v", err) + } + } + } +} + +// checkShardsForProposal checks if we are an eligible proposer for +// collation for the available shards in the VMC. The function calls +// getEligibleProposer from the VMC and proposes a collation if +// conditions are met +func checkShardsForProposal(c *Client, head *types.Header) error { + + accounts := c.keystore.Accounts() + if len(accounts) == 0 { + return fmt.Errorf("no accounts found") + } + + if err := c.unlockAccount(accounts[0]); err != nil { + return fmt.Errorf("cannot unlock account. %v", err) + } + + log.Info("Checking if we are an eligible collation proposer for a shard...") + for s := int64(0); s < shardCount; s++ { + // Checks if we are an eligible proposer according to the VMC + period := head.Number.Div(head.Number, big.NewInt(periodLength)) + addr, err := c.vmc.VMCCaller.GetEligibleProposer(&bind.CallOpts{}, big.NewInt(s), period) + // TODO: When we are not a proposer, we get the error of being unable to + // unmarshal empty output. Open issue to deal with this. + + // If output is non-empty and the addr == coinbase + if err == nil && addr == accounts[0].Address { + log.Info(fmt.Sprintf("Selected as collator on shard: %d", s)) + err := proposeCollation(s) + if err != nil { + return fmt.Errorf("could not propose collation. %v", err) + } + } + } + + return nil +} + +// proposeCollation interacts with the VMC directly to add a collation header +func proposeCollation(shardID int64) error { + // TODO: Adds a collation header to the VMC with the following fields: + // [ + // shard_id: uint256, + // expected_period_number: uint256, + // period_start_prevhash: bytes32, + // parent_hash: bytes32, + // transactions_root: bytes32, + // coinbase: address, + // state_root: bytes32, + // receipts_root: bytes32, + // number: uint256, + // sig: bytes + // ] + // + // Before calling this, we would need to have access to the state of + // the period_start_prevhash. Refer to the comments in: + // https://github.com/ethereum/py-evm/issues/258#issuecomment-359879350 + // + // This function will call FetchCandidateHead() of the VMC to obtain + // more necessary information. + // + // This functions will fetch the transactions in the txpool and and apply + // them to finish up the collation. It will then need to broadcast the + // collation to the main chain using JSON-RPC. + log.Info("Propose collation function called") + return nil +} diff --git a/sharding/collator_test.go b/sharding/collator_test.go new file mode 100644 index 000000000000..584be3b19d29 --- /dev/null +++ b/sharding/collator_test.go @@ -0,0 +1,29 @@ +package sharding + +import ( + "context" + "fmt" + "testing" + + "github.com/ethereum/go-ethereum/core/types" +) + +type FakeClient struct { + client *FakeEthClient +} + +type FakeEthClient struct{} + +type FakeSubscription struct{} + +func (ec *FakeEthClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (FakeSubscription, error) { + return FakeSubscription{}, fmt.Errorf("error, network disconnected!") +} + +func TestSubscribeHeaders(t *testing.T) { + client := &FakeClient{client: &FakeEthClient{}} + err := subscribeBlockHeaders(client) + if err != nil { + t.Errorf("subscribe new headers should work", "no error", err) + } +} diff --git a/sharding/config.go b/sharding/config.go index 29432eeea5ae..05bd17757b85 100644 --- a/sharding/config.go +++ b/sharding/config.go @@ -8,13 +8,13 @@ import ( var ( // Number of network shards - shardCount = 100 + shardCount = int64(100) // Address of the validator management contract validatorManagerAddress = common.HexToAddress("0x0") // TODO // Gas limit for verifying signatures sigGasLimit = 40000 // Number of blocks in a period - periodLength = 5 + periodLength = int64(5) // Number of periods ahead of current period which the contract is able to return the collator of that period. lookaheadPeriods = 4 // Required deposit size in wei diff --git a/sharding/contracts/validator_manager.go b/sharding/contracts/validator_manager.go index 9d24468f43ba..71766678a448 100644 --- a/sharding/contracts/validator_manager.go +++ b/sharding/contracts/validator_manager.go @@ -13,303 +13,11 @@ import ( "github.com/ethereum/go-ethereum/core/types" ) -// RLPABI is the input ABI used to generate the binding from. -const RLPABI = "[]" - -// RLPBin is the compiled bytecode used for deploying new contracts. -const RLPBin = `0x60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a723058207370f347c211b0e9f613e9f0258468c5c9bece58db1173ee5351746458418c540029` - -// DeployRLP deploys a new Ethereum contract, binding an instance of RLP to it. -func DeployRLP(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *RLP, error) { - parsed, err := abi.JSON(strings.NewReader(RLPABI)) - if err != nil { - return common.Address{}, nil, nil, err - } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(RLPBin), backend) - if err != nil { - return common.Address{}, nil, nil, err - } - return address, tx, &RLP{RLPCaller: RLPCaller{contract: contract}, RLPTransactor: RLPTransactor{contract: contract}}, nil -} - -// RLP is an auto generated Go binding around an Ethereum contract. -type RLP struct { - RLPCaller // Read-only binding to the contract - RLPTransactor // Write-only binding to the contract -} - -// RLPCaller is an auto generated read-only Go binding around an Ethereum contract. -type RLPCaller struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// RLPTransactor is an auto generated write-only Go binding around an Ethereum contract. -type RLPTransactor struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// RLPSession is an auto generated Go binding around an Ethereum contract, -// with pre-set call and transact options. -type RLPSession struct { - Contract *RLP // Generic contract binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// RLPCallerSession is an auto generated read-only Go binding around an Ethereum contract, -// with pre-set call options. -type RLPCallerSession struct { - Contract *RLPCaller // Generic contract caller binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session -} - -// RLPTransactorSession is an auto generated write-only Go binding around an Ethereum contract, -// with pre-set transact options. -type RLPTransactorSession struct { - Contract *RLPTransactor // Generic contract transactor binding to set the session for - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// RLPRaw is an auto generated low-level Go binding around an Ethereum contract. -type RLPRaw struct { - Contract *RLP // Generic contract binding to access the raw methods on -} - -// RLPCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. -type RLPCallerRaw struct { - Contract *RLPCaller // Generic read-only contract binding to access the raw methods on -} - -// RLPTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. -type RLPTransactorRaw struct { - Contract *RLPTransactor // Generic write-only contract binding to access the raw methods on -} - -// NewRLP creates a new instance of RLP, bound to a specific deployed contract. -func NewRLP(address common.Address, backend bind.ContractBackend) (*RLP, error) { - contract, err := bindRLP(address, backend, backend) - if err != nil { - return nil, err - } - return &RLP{RLPCaller: RLPCaller{contract: contract}, RLPTransactor: RLPTransactor{contract: contract}}, nil -} - -// NewRLPCaller creates a new read-only instance of RLP, bound to a specific deployed contract. -func NewRLPCaller(address common.Address, caller bind.ContractCaller) (*RLPCaller, error) { - contract, err := bindRLP(address, caller, nil) - if err != nil { - return nil, err - } - return &RLPCaller{contract: contract}, nil -} - -// NewRLPTransactor creates a new write-only instance of RLP, bound to a specific deployed contract. -func NewRLPTransactor(address common.Address, transactor bind.ContractTransactor) (*RLPTransactor, error) { - contract, err := bindRLP(address, nil, transactor) - if err != nil { - return nil, err - } - return &RLPTransactor{contract: contract}, nil -} - -// bindRLP binds a generic wrapper to an already deployed contract. -func bindRLP(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (*bind.BoundContract, error) { - parsed, err := abi.JSON(strings.NewReader(RLPABI)) - if err != nil { - return nil, err - } - return bind.NewBoundContract(address, parsed, caller, transactor), nil -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_RLP *RLPRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _RLP.Contract.RLPCaller.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_RLP *RLPRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _RLP.Contract.RLPTransactor.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_RLP *RLPRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _RLP.Contract.RLPTransactor.contract.Transact(opts, method, params...) -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_RLP *RLPCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _RLP.Contract.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_RLP *RLPTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _RLP.Contract.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_RLP *RLPTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _RLP.Contract.contract.Transact(opts, method, params...) -} - -// SigHasherContractABI is the input ABI used to generate the binding from. -const SigHasherContractABI = "[]" - -// SigHasherContractBin is the compiled bytecode used for deploying new contracts. -const SigHasherContractBin = `0x60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a72305820d1e8d7c8f2fa07496a4b23f8a6d60871008288d5fac673be890f35954e859d0f0029` - -// DeploySigHasherContract deploys a new Ethereum contract, binding an instance of SigHasherContract to it. -func DeploySigHasherContract(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *SigHasherContract, error) { - parsed, err := abi.JSON(strings.NewReader(SigHasherContractABI)) - if err != nil { - return common.Address{}, nil, nil, err - } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(SigHasherContractBin), backend) - if err != nil { - return common.Address{}, nil, nil, err - } - return address, tx, &SigHasherContract{SigHasherContractCaller: SigHasherContractCaller{contract: contract}, SigHasherContractTransactor: SigHasherContractTransactor{contract: contract}}, nil -} - -// SigHasherContract is an auto generated Go binding around an Ethereum contract. -type SigHasherContract struct { - SigHasherContractCaller // Read-only binding to the contract - SigHasherContractTransactor // Write-only binding to the contract -} - -// SigHasherContractCaller is an auto generated read-only Go binding around an Ethereum contract. -type SigHasherContractCaller struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// SigHasherContractTransactor is an auto generated write-only Go binding around an Ethereum contract. -type SigHasherContractTransactor struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// SigHasherContractSession is an auto generated Go binding around an Ethereum contract, -// with pre-set call and transact options. -type SigHasherContractSession struct { - Contract *SigHasherContract // Generic contract binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// SigHasherContractCallerSession is an auto generated read-only Go binding around an Ethereum contract, -// with pre-set call options. -type SigHasherContractCallerSession struct { - Contract *SigHasherContractCaller // Generic contract caller binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session -} - -// SigHasherContractTransactorSession is an auto generated write-only Go binding around an Ethereum contract, -// with pre-set transact options. -type SigHasherContractTransactorSession struct { - Contract *SigHasherContractTransactor // Generic contract transactor binding to set the session for - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// SigHasherContractRaw is an auto generated low-level Go binding around an Ethereum contract. -type SigHasherContractRaw struct { - Contract *SigHasherContract // Generic contract binding to access the raw methods on -} - -// SigHasherContractCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. -type SigHasherContractCallerRaw struct { - Contract *SigHasherContractCaller // Generic read-only contract binding to access the raw methods on -} - -// SigHasherContractTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. -type SigHasherContractTransactorRaw struct { - Contract *SigHasherContractTransactor // Generic write-only contract binding to access the raw methods on -} - -// NewSigHasherContract creates a new instance of SigHasherContract, bound to a specific deployed contract. -func NewSigHasherContract(address common.Address, backend bind.ContractBackend) (*SigHasherContract, error) { - contract, err := bindSigHasherContract(address, backend, backend) - if err != nil { - return nil, err - } - return &SigHasherContract{SigHasherContractCaller: SigHasherContractCaller{contract: contract}, SigHasherContractTransactor: SigHasherContractTransactor{contract: contract}}, nil -} - -// NewSigHasherContractCaller creates a new read-only instance of SigHasherContract, bound to a specific deployed contract. -func NewSigHasherContractCaller(address common.Address, caller bind.ContractCaller) (*SigHasherContractCaller, error) { - contract, err := bindSigHasherContract(address, caller, nil) - if err != nil { - return nil, err - } - return &SigHasherContractCaller{contract: contract}, nil -} - -// NewSigHasherContractTransactor creates a new write-only instance of SigHasherContract, bound to a specific deployed contract. -func NewSigHasherContractTransactor(address common.Address, transactor bind.ContractTransactor) (*SigHasherContractTransactor, error) { - contract, err := bindSigHasherContract(address, nil, transactor) - if err != nil { - return nil, err - } - return &SigHasherContractTransactor{contract: contract}, nil -} - -// bindSigHasherContract binds a generic wrapper to an already deployed contract. -func bindSigHasherContract(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (*bind.BoundContract, error) { - parsed, err := abi.JSON(strings.NewReader(SigHasherContractABI)) - if err != nil { - return nil, err - } - return bind.NewBoundContract(address, parsed, caller, transactor), nil -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_SigHasherContract *SigHasherContractRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _SigHasherContract.Contract.SigHasherContractCaller.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_SigHasherContract *SigHasherContractRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _SigHasherContract.Contract.SigHasherContractTransactor.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_SigHasherContract *SigHasherContractRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _SigHasherContract.Contract.SigHasherContractTransactor.contract.Transact(opts, method, params...) -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_SigHasherContract *SigHasherContractCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _SigHasherContract.Contract.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_SigHasherContract *SigHasherContractTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _SigHasherContract.Contract.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_SigHasherContract *SigHasherContractTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _SigHasherContract.Contract.contract.Transact(opts, method, params...) -} - // VMCABI is the input ABI used to generate the binding from. -const VMCABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_validatorIndex\",\"type\":\"int256\"},{\"name\":\"_sig\",\"type\":\"bytes32\"}],\"name\":\"withdraw\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getValidatorsMaxIndex\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_shardId\",\"type\":\"int256\"},{\"name\":\"_txStartgas\",\"type\":\"uint256\"},{\"name\":\"_txGasprice\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes12\"}],\"name\":\"txToShard\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"name\":\"getAncestorDistance\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_valcodeAddr\",\"type\":\"address\"}],\"name\":\"getShardList\",\"outputs\":[{\"name\":\"\",\"type\":\"bool[100]\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCollationGasLimit\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_expectedPeriodNumber\",\"type\":\"uint256\"}],\"name\":\"getPeriodStartPrevhash\",\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"int256\"}],\"name\":\"sample\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_receiptId\",\"type\":\"int256\"},{\"name\":\"_txGasprice\",\"type\":\"uint256\"}],\"name\":\"updataGasPrice\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_header\",\"type\":\"bytes\"}],\"name\":\"addHeader\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_validationCodeAddr\",\"type\":\"address\"},{\"name\":\"_returnAddr\",\"type\":\"address\"}],\"name\":\"deposit\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" +const VMCABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"int256\"},{\"name\":\"_expectedPeriodNumber\",\"type\":\"uint256\"},{\"name\":\"_periodStartPrevHash\",\"type\":\"bytes32\"},{\"name\":\"_parentHash\",\"type\":\"bytes32\"},{\"name\":\"_transactionRoot\",\"type\":\"bytes32\"},{\"name\":\"_coinbase\",\"type\":\"address\"},{\"name\":\"_stateRoot\",\"type\":\"bytes32\"},{\"name\":\"_receiptRoot\",\"type\":\"bytes32\"},{\"name\":\"_number\",\"type\":\"int256\"}],\"name\":\"addHeader\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"shardCount\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_receiptId\",\"type\":\"int256\"},{\"name\":\"_txGasprice\",\"type\":\"uint256\"}],\"name\":\"updateGasPrice\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_shardId\",\"type\":\"int256\"},{\"name\":\"_txStartgas\",\"type\":\"uint256\"},{\"name\":\"_txGasprice\",\"type\":\"uint256\"},{\"name\":\"_data\",\"type\":\"bytes12\"}],\"name\":\"txToShard\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_validatorIndex\",\"type\":\"int256\"}],\"name\":\"withdraw\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"getCollationGasLimit\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[],\"name\":\"deposit\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"int256\"},{\"name\":\"_period\",\"type\":\"uint256\"}],\"name\":\"getEligibleProposer\",\"outputs\":[{\"name\":\"\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"shardId\",\"type\":\"int256\"},{\"indexed\":false,\"name\":\"receiptId\",\"type\":\"int256\"}],\"name\":\"TxToShard\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"shardId\",\"type\":\"uint256\"},{\"indexed\":false,\"name\":\"collationHeader\",\"type\":\"bytes\"},{\"indexed\":false,\"name\":\"isNewHead\",\"type\":\"bool\"},{\"indexed\":false,\"name\":\"score\",\"type\":\"uint256\"}],\"name\":\"CollationAdded\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"validator\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"index\",\"type\":\"int256\"}],\"name\":\"Deposit\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"name\":\"validatorIndex\",\"type\":\"int256\"}],\"name\":\"Withdraw\",\"type\":\"event\"}]" // VMCBin is the compiled bytecode used for deploying new contracts. -const VMCBin = `0x6060604052341561000f57600080fd5b6000600481905560075568056bc75e2d631000006008556005600981905562061a80600a55600c556064600d819055600e556040517f6164645f686561646572282900000000000000000000000000000000000000008152600c01604051908190039020600f5560108054600160a060020a03191673dffd41e18f04ad8810c83b14fd1426a82e625a7d1790556113f5806100ab6000396000f3006060604052600436106100ae5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630e3b2f0e81146100b35780632b3407f9146100e0578063372a9e2a146101055780635badac531461012f5780635e57c86c14610145578063934586ec1461019d5780639b33f907146101b0578063a8c57753146101c6578063e551e00a146101f8578063f7fecf7d14610206578063f9609f0814610257575b600080fd5b34156100be57600080fd5b6100cc600435602435610271565b604051901515815260200160405180910390f35b34156100eb57600080fd5b6100f3610414565b60405190815260200160405180910390f35b6100f3600160a060020a0360043516602435604435606435600160a060020a0319608435166104bb565b341561013a57600080fd5b6100f36004356105f7565b341561015057600080fd5b610164600160a060020a03600435166105fd565b6040518082610c8080838360005b8381101561018a578082015183820152602001610172565b5050505090500191505060405180910390f35b34156101a857600080fd5b6100f361073b565b34156101bb57600080fd5b6100f3600435610743565b34156101d157600080fd5b6101dc600435610767565b604051600160a060020a03909116815260200160405180910390f35b6100cc60043560243561087e565b341561021157600080fd5b6100cc60046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506108c395505050505050565b6100f3600160a060020a0360043581169060243516610c61565b60008060006040517f776974686472617700000000000000000000000000000000000000000000000081526008016040519081900390206000868152602081905260409081902060010154600a54929450600160a060020a031691638e19899e918790517c010000000000000000000000000000000000000000000000000000000063ffffffff85160281526004810191909152602401602060405180830381600088803b151561032157600080fd5b87f1151561032e57600080fd5b505050506040518051915050801561040c576000858152602081905260409081902060028101549054600160a060020a039091169181156108fc02919051600060405180830381858888f19350505050151561038957600080fd5b600085815260208181526040808320600181018054600160a060020a03168552600b8452918420805460ff19169055888452918390528282558054600160a060020a03199081169091556002820180549091169055600301556103eb85610de8565b60048054600019019055848260405190815260200160405180910390a18092505b505092915050565b60008060008060008060009450600093506009544381151561043257fe5b059250600754600454019150600090505b6104008112156104ac57818112610459576104ac565b600081815260208190526040902060010154600160a060020a038681169116148015906104985750600081815260208190526040902060030154839013155b156104a4576001840193505b600101610443565b60075484019550505050505090565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a0333811660808501528a1660a0840152600160a060020a0319861660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482018054600160a060020a031916600160a060020a039290921691909117905560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c0820151600690910155505060058054600181019091558086600160a060020a0389166040517f74785f746f5f73686172642829000000000000000000000000000000000000008152600d01604051809103902060405190815260200160405180910390a39695505050505050565b50600090565b6106056112fb565b61060d6112fb565b60008060008060008060006009544381151561062557fe5b05965060016009548802039550600086121561064057600095505b8540945061064c610414565b6004549094501561072a57600092505b60648360ff16101561072a5760008860ff85166064811061067957fe5b91151560209092020152600091505b60648260ff16101561071f57838560ff8086169085166040519283526020830191909152604080830191909152606090910190519081900390208115156106cb57fe5b06600081815260208190526040902060010154909150600160a060020a038b8116911614156107145760018860ff85166064811061070557fe5b9115156020909202015261071f565b816001019150610688565b82600101925061065c565b8798505b5050505050505050919050565b629896805b90565b600c546000908202600019014381901161075c57600080fd5b804091505b50919050565b6000806000806000806000600c54431015151561078357600080fd5b6009544381151561079057fe5b0595506001600954870203945060008512156107ab57600094505b600c5485409450600190438115156107bf57fe5b0643030340600190049250600d5483896001026040519182526020820152604090810190519081900390208115156107f357fe5b0691506107fe610414565b84898460405192835260208301919091526040808301919091526060909101905190819003902081151561082e57fe5b06600081815260208190526040902060030154909150869013156108555760009650610873565b600081815260208190526040902060010154600160a060020a031696505b505050505050919050565b60008281526002602052604081206004015433600160a060020a039081169116146108a857600080fd5b50600091825260026020819052604090922090910155600190565b6000806108ce611324565b6108d6611336565b6108de611357565b60009350859250838080806109026108fd88600163ffffffff610e0716565b610e6b565b95506101406040519081016040528061092261091d89610ea4565b610ee9565b815260200161093861093389610ea4565b610efa565b815260200161094961091d89610ea4565b815260200161095a61091d89610ea4565b815260200161096b61091d89610ea4565b815260200161098161097c89610ea4565b610f4b565b600160a060020a0316815260200161099b61091d89610ea4565b81526020016109ac61091d89610ea4565b81526020016109bd61091d89610ea4565b81526020016109d36109ce89610ea4565b610f95565b9052945060008551121580156109eb5750600e548551125b15156109f657600080fd5b600c54431015610a0557600080fd5b600c5443811515610a1257fe5b04856020015114610a2257600080fd5b6001600c548660200151020340604086015114610a3e57600080fd5b846040519081526020016040519081900390209350831515610a5c57fe5b60016000865181526020808201929092526040908101600090812087825290925290206001015415610a8a57fe5b846060015115610ada5784606001511580610ad25750600060018187518152602001908152602001600020600087606001518152602081019190915260400160002060010154135b1515610ada57fe5b8460200151601160008751815260200190815260200160002054121515610afd57fe5b610b078551610767565b9250600160a060020a0383161515610b22576000985061072e565b600160008651815260200190815260200160002060008660600151815260208101919091526040016000206001908101540191508161010086015114610b6457fe5b6040805190810160405280866060015181526020018390526001600087518152602080820192909252604090810160009081208882529092529020815181556020820151600190910155506020850151601160008751815260200190815260200160002081905550600160008660000151815260200190815260200160002060006003600088600001518152602001908152602001600020546000191660001916815260200190815260200160002060010154821315610c515760036000865181526020019081526020016000205490508360036000876000015181526020810191909152604001600020555b5060019998505050505050505050565b600160a060020a0382166000908152600b60205260408120548190819060ff1615610c8b57600080fd5b6008543414610c9957600080fd5b506000610ca4610fe3565b1515610cb957610cb2610fea565b9150610d6c565b600454915060095443811515610ccb57fe5b05600101905060806040519081016040908152348252600160a060020a03808816602080850191909152908716828401526060830184905260008581529081905220815181556020820151600182018054600160a060020a031916600160a060020a03929092169190911790556040820151600282018054600160a060020a031916600160a060020a03929092169190911790556060820151600390910155505b600480546001908101909155600160a060020a0386166000818152600b602052604090819020805460ff19169093179092558391517f6465706f736974282900000000000000000000000000000000000000000000008152600901604051809103902060405190815260200160405180910390a2509392505050565b6007805460009081526006602052604090209190915580546001019055565b610e0f6113b2565b610e176113b2565b6000610e2285611021565b91508315610e63578451905080610e3883611072565b1115610e4057fe5b80610e4b83516110f1565b14610e5257fe5b610e5b82611183565b1515610e6357fe5b509392505050565b610e73611336565b6000610e7e836111c5565b1515610e8957600080fd5b610e9283611072565b83519383529092016020820152919050565b610eac6113b2565b600080610eb8846111f0565b156100ae5783602001519150610ecd826110f1565b82845260208085018290528382019086015290505b5050919050565b6000610ef482610efa565b92915050565b6000806000610f0884611213565b1515610f1357600080fd5b610f1c8461123d565b9150915060208111158015610f3057508015155b1515610f3857fe5b806020036101000a825104949350505050565b6000806000610f5984611213565b1515610f6457600080fd5b610f6d8461123d565b909250905060148114610f7c57fe5b6c01000000000000000000000000825104949350505050565b610f9d611324565b600082602001519050801515610fb257610761565b80604051805910610fc05750595b818152601f19601f830116810160200160405290509150610761835183836112ba565b6007541590565b6000610ff4610fe3565b156110025750600019610740565b5060078054600019019081905560009081526006602052604090205490565b6110296113b2565b600080835191508115156110525760408051908101604052600080825260208201529250610ee2565b506020830160408051908101604052908152602081019190915292915050565b60008060008360200151151561108b5760009250610ee2565b83519050805160001a915060808210156110a85760009250610ee2565b60b88210806110c3575060c082101580156110c3575060f882105b156110d15760019250610ee2565b60c08210156110e65760b51982019250610ee2565b5060f5190192915050565b600080825160001a9050608081101561110d5760019150610761565b60b881101561112257607e1981019150610761565b60c081101561114c5760b78103806020036101000a60018501510480820160010193505050610761565b60f88110156111615760be1981019150610761565b60f78103806020036101000a6001850151048082016001019350505050919050565b600080808084519050805160001a9250805160011a91506081831480156111aa5750608082105b156111b857600093506111bd565b600193505b505050919050565b600080826020015115156111dc5760009150610761565b8251905060c0815160001a10159392505050565b60006111fa6113b2565b8251905080602001518151018360200151109392505050565b6000808260200151151561122a5760009150610761565b8251905060c0815160001a109392505050565b600080600080600061124e86611213565b151561125957600080fd5b85519150815160001a9250608083101561127957819450600193506112b2565b60b883101561129757600186602001510393508160010194506112b2565b5060b619820180600160208801510303935080820160010194505b505050915091565b60006020601f83010484602085015b8284146112e857602084028083015181830152600185019450506112c9565b6000865160200187015250505050505050565b610c806040519081016040526064815b60008152600019909101906020018161130b5790505090565b60206040519081016040526000815290565b60606040519081016040528061134a6113b2565b8152602001600081525090565b6101406040519081016040908152600080835260208301819052908201819052606082018190526080820181905260a0820181905260c0820181905260e0820181905261010082015261012081016113ad611324565b905290565b6040805190810160405260008082526020820152905600a165627a7a72305820ac752c2e2510c5d4616642d59dff6585ad73413dba273192b11758fd542c54ec0029` +const VMCBin = `0x6060604052341561000f57600080fd5b61092f8061001e6000396000f30060606040526004361061008d5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630341518d811461009257806304e9c77a146100de5780632213138914610103578063372a9e2a146101115780637e62eab81461013b578063934586ec14610153578063d0e30db014610166578063e29de3ad1461016e575b600080fd5b341561009d57600080fd5b6100ca600435602435604435606435608435600160a060020a0360a4351660c43560e435610104356101a3565b604051901515815260200160405180910390f35b34156100e957600080fd5b6100f16103f6565b60405190815260200160405180910390f35b6100ca6004356024356103fb565b6100f1600160a060020a0360043516602435604435606435600160a060020a031960843516610440565b341561014657600080fd5b610151600435610563565b005b341561015e57600080fd5b6100f1610666565b6100f161066e565b341561017957600080fd5b610187600435602435610793565b604051600160a060020a03909116815260200160405180910390f35b60006101ad6108dc565b60008b121580156101be575060648b125b15156101c957600080fd5b60054310156101d757600080fd5b600543048a146101e657600080fd5b60001960058b02014089146101fa57600080fd5b8a8a8a8a8a600160a060020a038b168a8a8a60405198895260208901979097526040808901969096526060880194909452608087019290925260a086015260c085015260e08401526101008301919091526101209091019051908190039020815260008b815260016020526040812090825181526020810191909152604001600020600101541561028757fe5b87156102af5760008b81526001602081815260408084208c855290915282200154136102af57fe5b60008b8152600960205260409020548a90126102c757fe5b6102d48b60054304610793565b600160a060020a03166040820190815251600160a060020a031615156102f957600080fd5b8060400151600160a060020a031633600160a060020a031614151561031d57600080fd5b60008b81526001602081815260408084208c855282529092208101540190820190815251831461034c57600080fd5b60408051908101604052888152602080820190830151905260008c81526001602052604081209083518152602081019190915260400160002081518155602082015160019182015560008d81526009602090815260408083208f905583825280832060038352818420548452825290912090910154915082015113156103e557805160008c815260036020526040902055600160608201525b5060019a9950505050505050505050565b606481565b60008281526002602052604081206005015433600160a060020a0390811691161461042557600080fd5b50600091825260026020819052604090922090910155600190565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a031986166080840152600160a060020a0333811660a08501528a1660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482015560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c08201516006919091018054600160a060020a031916600160a060020a039283161790556005805460018101909155925087915088167ffc322e0c42ee41e0d74b940ceeee9cd5971acdd6ace8ff8010ee7134c31d9ea58360405190815260200160405180910390a39695505050505050565b60008181526020819052604090206001015433600160a060020a0390811691161461058d57600080fd5b6000818152602081905260409081902060018101549054600160a060020a039091169181156108fc02919051600060405180830381858888f1935050505015156105d657600080fd5b600081815260208181526040808320600181018054600160a060020a0316855260088452918420805460ff19169055848452918390529190558054600160a060020a031916905561062681610821565b600480546000190190557fe13f360aa18d414ccdb598da6c447faa89d0477ffc7549dab5678fca76910b8c8160405190815260200160405180910390a150565b629896805b90565b600160a060020a033316600090815260086020526040812054819060ff161561069657600080fd5b3468056bc75e2d63100000146106ab57600080fd5b6106b3610840565b15156106c8576106c1610847565b90506106cd565b506004545b604080519081016040908152348252600160a060020a0333166020808401919091526000848152908190522081518155602082015160019182018054600160a060020a031916600160a060020a0392831617905560048054830190553390811660009081526008602052604090819020805460ff19169093179092557fd8a6d38df847dcba70dfdeb4948fb1457d61a81d132801f40dc9c00d52dfd478925090839051600160a060020a03909216825260208201526040908101905180910390a1919050565b600060048210156107a357600080fd5b436003198301600502106107b657600080fd5b600454600090136107c657600080fd5b6000806107d161087e565b600319850140600502866040519182526020820152604090810190519081900390208115156107fc57fe5b068152602081019190915260400160002060010154600160a060020a03169392505050565b6007805460009081526006602052604090209190915580546001019055565b6007541590565b6000610851610840565b1561085f575060001961066b565b5060078054600019019081905560009081526006602052604090205490565b600754600454600091829101815b6104008112156108d1578181126108a2576108d1565b600081815260208190526040902060010154600160a060020a0316156108c9576001830192505b60010161088c565b505060075401919050565b608060405190810160409081526000808352602083018190529082018190526060820152905600a165627a7a7230582080291cd26024cdcd5c217feece7715d40f91360d0ce69131b2042e64a710397a0029` // DeployVMC deploys a new Ethereum contract, binding an instance of VMC to it. func DeployVMC(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *VMC, error) { @@ -451,32 +159,6 @@ func (_VMC *VMCTransactorRaw) Transact(opts *bind.TransactOpts, method string, p return _VMC.Contract.contract.Transact(opts, method, params...) } -// GetAncestorDistance is a free data retrieval call binding the contract method 0x5badac53. -// -// Solidity: function getAncestorDistance( bytes32) constant returns(bytes32) -func (_VMC *VMCCaller) GetAncestorDistance(opts *bind.CallOpts, arg0 [32]byte) ([32]byte, error) { - var ( - ret0 = new([32]byte) - ) - out := ret0 - err := _VMC.contract.Call(opts, out, "getAncestorDistance", arg0) - return *ret0, err -} - -// GetAncestorDistance is a free data retrieval call binding the contract method 0x5badac53. -// -// Solidity: function getAncestorDistance( bytes32) constant returns(bytes32) -func (_VMC *VMCSession) GetAncestorDistance(arg0 [32]byte) ([32]byte, error) { - return _VMC.Contract.GetAncestorDistance(&_VMC.CallOpts, arg0) -} - -// GetAncestorDistance is a free data retrieval call binding the contract method 0x5badac53. -// -// Solidity: function getAncestorDistance( bytes32) constant returns(bytes32) -func (_VMC *VMCCallerSession) GetAncestorDistance(arg0 [32]byte) ([32]byte, error) { - return _VMC.Contract.GetAncestorDistance(&_VMC.CallOpts, arg0) -} - // GetCollationGasLimit is a free data retrieval call binding the contract method 0x934586ec. // // Solidity: function getCollationGasLimit() constant returns(uint256) @@ -503,150 +185,98 @@ func (_VMC *VMCCallerSession) GetCollationGasLimit() (*big.Int, error) { return _VMC.Contract.GetCollationGasLimit(&_VMC.CallOpts) } -// GetPeriodStartPrevhash is a free data retrieval call binding the contract method 0x9b33f907. -// -// Solidity: function getPeriodStartPrevhash(_expectedPeriodNumber uint256) constant returns(bytes32) -func (_VMC *VMCCaller) GetPeriodStartPrevhash(opts *bind.CallOpts, _expectedPeriodNumber *big.Int) ([32]byte, error) { - var ( - ret0 = new([32]byte) - ) - out := ret0 - err := _VMC.contract.Call(opts, out, "getPeriodStartPrevhash", _expectedPeriodNumber) - return *ret0, err -} - -// GetPeriodStartPrevhash is a free data retrieval call binding the contract method 0x9b33f907. +// GetEligibleProposer is a free data retrieval call binding the contract method 0xe29de3ad. // -// Solidity: function getPeriodStartPrevhash(_expectedPeriodNumber uint256) constant returns(bytes32) -func (_VMC *VMCSession) GetPeriodStartPrevhash(_expectedPeriodNumber *big.Int) ([32]byte, error) { - return _VMC.Contract.GetPeriodStartPrevhash(&_VMC.CallOpts, _expectedPeriodNumber) -} - -// GetPeriodStartPrevhash is a free data retrieval call binding the contract method 0x9b33f907. -// -// Solidity: function getPeriodStartPrevhash(_expectedPeriodNumber uint256) constant returns(bytes32) -func (_VMC *VMCCallerSession) GetPeriodStartPrevhash(_expectedPeriodNumber *big.Int) ([32]byte, error) { - return _VMC.Contract.GetPeriodStartPrevhash(&_VMC.CallOpts, _expectedPeriodNumber) -} - -// GetShardList is a free data retrieval call binding the contract method 0x5e57c86c. -// -// Solidity: function getShardList(_valcodeAddr address) constant returns(bool[100]) -func (_VMC *VMCCaller) GetShardList(opts *bind.CallOpts, _valcodeAddr common.Address) ([100]bool, error) { +// Solidity: function getEligibleProposer(_shardId int256, _period uint256) constant returns(address) +func (_VMC *VMCCaller) GetEligibleProposer(opts *bind.CallOpts, _shardId *big.Int, _period *big.Int) (common.Address, error) { var ( - ret0 = new([100]bool) + ret0 = new(common.Address) ) out := ret0 - err := _VMC.contract.Call(opts, out, "getShardList", _valcodeAddr) + err := _VMC.contract.Call(opts, out, "getEligibleProposer", _shardId, _period) return *ret0, err } -// GetShardList is a free data retrieval call binding the contract method 0x5e57c86c. +// GetEligibleProposer is a free data retrieval call binding the contract method 0xe29de3ad. // -// Solidity: function getShardList(_valcodeAddr address) constant returns(bool[100]) -func (_VMC *VMCSession) GetShardList(_valcodeAddr common.Address) ([100]bool, error) { - return _VMC.Contract.GetShardList(&_VMC.CallOpts, _valcodeAddr) +// Solidity: function getEligibleProposer(_shardId int256, _period uint256) constant returns(address) +func (_VMC *VMCSession) GetEligibleProposer(_shardId *big.Int, _period *big.Int) (common.Address, error) { + return _VMC.Contract.GetEligibleProposer(&_VMC.CallOpts, _shardId, _period) } -// GetShardList is a free data retrieval call binding the contract method 0x5e57c86c. +// GetEligibleProposer is a free data retrieval call binding the contract method 0xe29de3ad. // -// Solidity: function getShardList(_valcodeAddr address) constant returns(bool[100]) -func (_VMC *VMCCallerSession) GetShardList(_valcodeAddr common.Address) ([100]bool, error) { - return _VMC.Contract.GetShardList(&_VMC.CallOpts, _valcodeAddr) +// Solidity: function getEligibleProposer(_shardId int256, _period uint256) constant returns(address) +func (_VMC *VMCCallerSession) GetEligibleProposer(_shardId *big.Int, _period *big.Int) (common.Address, error) { + return _VMC.Contract.GetEligibleProposer(&_VMC.CallOpts, _shardId, _period) } -// GetValidatorsMaxIndex is a free data retrieval call binding the contract method 0x2b3407f9. +// ShardCount is a free data retrieval call binding the contract method 0x04e9c77a. // -// Solidity: function getValidatorsMaxIndex() constant returns(int256) -func (_VMC *VMCCaller) GetValidatorsMaxIndex(opts *bind.CallOpts) (*big.Int, error) { +// Solidity: function shardCount() constant returns(int256) +func (_VMC *VMCCaller) ShardCount(opts *bind.CallOpts) (*big.Int, error) { var ( ret0 = new(*big.Int) ) out := ret0 - err := _VMC.contract.Call(opts, out, "getValidatorsMaxIndex") + err := _VMC.contract.Call(opts, out, "shardCount") return *ret0, err } -// GetValidatorsMaxIndex is a free data retrieval call binding the contract method 0x2b3407f9. +// ShardCount is a free data retrieval call binding the contract method 0x04e9c77a. // -// Solidity: function getValidatorsMaxIndex() constant returns(int256) -func (_VMC *VMCSession) GetValidatorsMaxIndex() (*big.Int, error) { - return _VMC.Contract.GetValidatorsMaxIndex(&_VMC.CallOpts) +// Solidity: function shardCount() constant returns(int256) +func (_VMC *VMCSession) ShardCount() (*big.Int, error) { + return _VMC.Contract.ShardCount(&_VMC.CallOpts) } -// GetValidatorsMaxIndex is a free data retrieval call binding the contract method 0x2b3407f9. +// ShardCount is a free data retrieval call binding the contract method 0x04e9c77a. // -// Solidity: function getValidatorsMaxIndex() constant returns(int256) -func (_VMC *VMCCallerSession) GetValidatorsMaxIndex() (*big.Int, error) { - return _VMC.Contract.GetValidatorsMaxIndex(&_VMC.CallOpts) +// Solidity: function shardCount() constant returns(int256) +func (_VMC *VMCCallerSession) ShardCount() (*big.Int, error) { + return _VMC.Contract.ShardCount(&_VMC.CallOpts) } -// Sample is a free data retrieval call binding the contract method 0xa8c57753. +// AddHeader is a paid mutator transaction binding the contract method 0x0341518d. // -// Solidity: function sample(_shardId int256) constant returns(address) -func (_VMC *VMCCaller) Sample(opts *bind.CallOpts, _shardId *big.Int) (common.Address, error) { - var ( - ret0 = new(common.Address) - ) - out := ret0 - err := _VMC.contract.Call(opts, out, "sample", _shardId) - return *ret0, err -} - -// Sample is a free data retrieval call binding the contract method 0xa8c57753. -// -// Solidity: function sample(_shardId int256) constant returns(address) -func (_VMC *VMCSession) Sample(_shardId *big.Int) (common.Address, error) { - return _VMC.Contract.Sample(&_VMC.CallOpts, _shardId) +// Solidity: function addHeader(_shardId int256, _expectedPeriodNumber uint256, _periodStartPrevHash bytes32, _parentHash bytes32, _transactionRoot bytes32, _coinbase address, _stateRoot bytes32, _receiptRoot bytes32, _number int256) returns(bool) +func (_VMC *VMCTransactor) AddHeader(opts *bind.TransactOpts, _shardId *big.Int, _expectedPeriodNumber *big.Int, _periodStartPrevHash [32]byte, _parentHash [32]byte, _transactionRoot [32]byte, _coinbase common.Address, _stateRoot [32]byte, _receiptRoot [32]byte, _number *big.Int) (*types.Transaction, error) { + return _VMC.contract.Transact(opts, "addHeader", _shardId, _expectedPeriodNumber, _periodStartPrevHash, _parentHash, _transactionRoot, _coinbase, _stateRoot, _receiptRoot, _number) } -// Sample is a free data retrieval call binding the contract method 0xa8c57753. +// AddHeader is a paid mutator transaction binding the contract method 0x0341518d. // -// Solidity: function sample(_shardId int256) constant returns(address) -func (_VMC *VMCCallerSession) Sample(_shardId *big.Int) (common.Address, error) { - return _VMC.Contract.Sample(&_VMC.CallOpts, _shardId) +// Solidity: function addHeader(_shardId int256, _expectedPeriodNumber uint256, _periodStartPrevHash bytes32, _parentHash bytes32, _transactionRoot bytes32, _coinbase address, _stateRoot bytes32, _receiptRoot bytes32, _number int256) returns(bool) +func (_VMC *VMCSession) AddHeader(_shardId *big.Int, _expectedPeriodNumber *big.Int, _periodStartPrevHash [32]byte, _parentHash [32]byte, _transactionRoot [32]byte, _coinbase common.Address, _stateRoot [32]byte, _receiptRoot [32]byte, _number *big.Int) (*types.Transaction, error) { + return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _shardId, _expectedPeriodNumber, _periodStartPrevHash, _parentHash, _transactionRoot, _coinbase, _stateRoot, _receiptRoot, _number) } -// AddHeader is a paid mutator transaction binding the contract method 0xf7fecf7d. +// AddHeader is a paid mutator transaction binding the contract method 0x0341518d. // -// Solidity: function addHeader(_header bytes) returns(bool) -func (_VMC *VMCTransactor) AddHeader(opts *bind.TransactOpts, _header []byte) (*types.Transaction, error) { - return _VMC.contract.Transact(opts, "addHeader", _header) +// Solidity: function addHeader(_shardId int256, _expectedPeriodNumber uint256, _periodStartPrevHash bytes32, _parentHash bytes32, _transactionRoot bytes32, _coinbase address, _stateRoot bytes32, _receiptRoot bytes32, _number int256) returns(bool) +func (_VMC *VMCTransactorSession) AddHeader(_shardId *big.Int, _expectedPeriodNumber *big.Int, _periodStartPrevHash [32]byte, _parentHash [32]byte, _transactionRoot [32]byte, _coinbase common.Address, _stateRoot [32]byte, _receiptRoot [32]byte, _number *big.Int) (*types.Transaction, error) { + return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _shardId, _expectedPeriodNumber, _periodStartPrevHash, _parentHash, _transactionRoot, _coinbase, _stateRoot, _receiptRoot, _number) } -// AddHeader is a paid mutator transaction binding the contract method 0xf7fecf7d. +// Deposit is a paid mutator transaction binding the contract method 0xd0e30db0. // -// Solidity: function addHeader(_header bytes) returns(bool) -func (_VMC *VMCSession) AddHeader(_header []byte) (*types.Transaction, error) { - return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _header) +// Solidity: function deposit() returns(int256) +func (_VMC *VMCTransactor) Deposit(opts *bind.TransactOpts) (*types.Transaction, error) { + return _VMC.contract.Transact(opts, "deposit") } -// AddHeader is a paid mutator transaction binding the contract method 0xf7fecf7d. +// Deposit is a paid mutator transaction binding the contract method 0xd0e30db0. // -// Solidity: function addHeader(_header bytes) returns(bool) -func (_VMC *VMCTransactorSession) AddHeader(_header []byte) (*types.Transaction, error) { - return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _header) +// Solidity: function deposit() returns(int256) +func (_VMC *VMCSession) Deposit() (*types.Transaction, error) { + return _VMC.Contract.Deposit(&_VMC.TransactOpts) } -// Deposit is a paid mutator transaction binding the contract method 0xf9609f08. +// Deposit is a paid mutator transaction binding the contract method 0xd0e30db0. // -// Solidity: function deposit(_validationCodeAddr address, _returnAddr address) returns(int256) -func (_VMC *VMCTransactor) Deposit(opts *bind.TransactOpts, _validationCodeAddr common.Address, _returnAddr common.Address) (*types.Transaction, error) { - return _VMC.contract.Transact(opts, "deposit", _validationCodeAddr, _returnAddr) -} - -// Deposit is a paid mutator transaction binding the contract method 0xf9609f08. -// -// Solidity: function deposit(_validationCodeAddr address, _returnAddr address) returns(int256) -func (_VMC *VMCSession) Deposit(_validationCodeAddr common.Address, _returnAddr common.Address) (*types.Transaction, error) { - return _VMC.Contract.Deposit(&_VMC.TransactOpts, _validationCodeAddr, _returnAddr) -} - -// Deposit is a paid mutator transaction binding the contract method 0xf9609f08. -// -// Solidity: function deposit(_validationCodeAddr address, _returnAddr address) returns(int256) -func (_VMC *VMCTransactorSession) Deposit(_validationCodeAddr common.Address, _returnAddr common.Address) (*types.Transaction, error) { - return _VMC.Contract.Deposit(&_VMC.TransactOpts, _validationCodeAddr, _returnAddr) +// Solidity: function deposit() returns(int256) +func (_VMC *VMCTransactorSession) Deposit() (*types.Transaction, error) { + return _VMC.Contract.Deposit(&_VMC.TransactOpts) } // TxToShard is a paid mutator transaction binding the contract method 0x372a9e2a. @@ -670,211 +300,44 @@ func (_VMC *VMCTransactorSession) TxToShard(_to common.Address, _shardId *big.In return _VMC.Contract.TxToShard(&_VMC.TransactOpts, _to, _shardId, _txStartgas, _txGasprice, _data) } -// UpdataGasPrice is a paid mutator transaction binding the contract method 0xe551e00a. -// -// Solidity: function updataGasPrice(_receiptId int256, _txGasprice uint256) returns(bool) -func (_VMC *VMCTransactor) UpdataGasPrice(opts *bind.TransactOpts, _receiptId *big.Int, _txGasprice *big.Int) (*types.Transaction, error) { - return _VMC.contract.Transact(opts, "updataGasPrice", _receiptId, _txGasprice) -} - -// UpdataGasPrice is a paid mutator transaction binding the contract method 0xe551e00a. -// -// Solidity: function updataGasPrice(_receiptId int256, _txGasprice uint256) returns(bool) -func (_VMC *VMCSession) UpdataGasPrice(_receiptId *big.Int, _txGasprice *big.Int) (*types.Transaction, error) { - return _VMC.Contract.UpdataGasPrice(&_VMC.TransactOpts, _receiptId, _txGasprice) -} - -// UpdataGasPrice is a paid mutator transaction binding the contract method 0xe551e00a. -// -// Solidity: function updataGasPrice(_receiptId int256, _txGasprice uint256) returns(bool) -func (_VMC *VMCTransactorSession) UpdataGasPrice(_receiptId *big.Int, _txGasprice *big.Int) (*types.Transaction, error) { - return _VMC.Contract.UpdataGasPrice(&_VMC.TransactOpts, _receiptId, _txGasprice) -} - -// Withdraw is a paid mutator transaction binding the contract method 0x0e3b2f0e. +// UpdateGasPrice is a paid mutator transaction binding the contract method 0x22131389. // -// Solidity: function withdraw(_validatorIndex int256, _sig bytes32) returns(bool) -func (_VMC *VMCTransactor) Withdraw(opts *bind.TransactOpts, _validatorIndex *big.Int, _sig [32]byte) (*types.Transaction, error) { - return _VMC.contract.Transact(opts, "withdraw", _validatorIndex, _sig) +// Solidity: function updateGasPrice(_receiptId int256, _txGasprice uint256) returns(bool) +func (_VMC *VMCTransactor) UpdateGasPrice(opts *bind.TransactOpts, _receiptId *big.Int, _txGasprice *big.Int) (*types.Transaction, error) { + return _VMC.contract.Transact(opts, "updateGasPrice", _receiptId, _txGasprice) } -// Withdraw is a paid mutator transaction binding the contract method 0x0e3b2f0e. +// UpdateGasPrice is a paid mutator transaction binding the contract method 0x22131389. // -// Solidity: function withdraw(_validatorIndex int256, _sig bytes32) returns(bool) -func (_VMC *VMCSession) Withdraw(_validatorIndex *big.Int, _sig [32]byte) (*types.Transaction, error) { - return _VMC.Contract.Withdraw(&_VMC.TransactOpts, _validatorIndex, _sig) +// Solidity: function updateGasPrice(_receiptId int256, _txGasprice uint256) returns(bool) +func (_VMC *VMCSession) UpdateGasPrice(_receiptId *big.Int, _txGasprice *big.Int) (*types.Transaction, error) { + return _VMC.Contract.UpdateGasPrice(&_VMC.TransactOpts, _receiptId, _txGasprice) } -// Withdraw is a paid mutator transaction binding the contract method 0x0e3b2f0e. +// UpdateGasPrice is a paid mutator transaction binding the contract method 0x22131389. // -// Solidity: function withdraw(_validatorIndex int256, _sig bytes32) returns(bool) -func (_VMC *VMCTransactorSession) Withdraw(_validatorIndex *big.Int, _sig [32]byte) (*types.Transaction, error) { - return _VMC.Contract.Withdraw(&_VMC.TransactOpts, _validatorIndex, _sig) -} - -// ValidatorContractABI is the input ABI used to generate the binding from. -const ValidatorContractABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_sig\",\"type\":\"bytes32\"}],\"name\":\"withdraw\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" - -// ValidatorContractBin is the compiled bytecode used for deploying new contracts. -const ValidatorContractBin = `0x` - -// DeployValidatorContract deploys a new Ethereum contract, binding an instance of ValidatorContract to it. -func DeployValidatorContract(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *ValidatorContract, error) { - parsed, err := abi.JSON(strings.NewReader(ValidatorContractABI)) - if err != nil { - return common.Address{}, nil, nil, err - } - address, tx, contract, err := bind.DeployContract(auth, parsed, common.FromHex(ValidatorContractBin), backend) - if err != nil { - return common.Address{}, nil, nil, err - } - return address, tx, &ValidatorContract{ValidatorContractCaller: ValidatorContractCaller{contract: contract}, ValidatorContractTransactor: ValidatorContractTransactor{contract: contract}}, nil -} - -// ValidatorContract is an auto generated Go binding around an Ethereum contract. -type ValidatorContract struct { - ValidatorContractCaller // Read-only binding to the contract - ValidatorContractTransactor // Write-only binding to the contract -} - -// ValidatorContractCaller is an auto generated read-only Go binding around an Ethereum contract. -type ValidatorContractCaller struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// ValidatorContractTransactor is an auto generated write-only Go binding around an Ethereum contract. -type ValidatorContractTransactor struct { - contract *bind.BoundContract // Generic contract wrapper for the low level calls -} - -// ValidatorContractSession is an auto generated Go binding around an Ethereum contract, -// with pre-set call and transact options. -type ValidatorContractSession struct { - Contract *ValidatorContract // Generic contract binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// ValidatorContractCallerSession is an auto generated read-only Go binding around an Ethereum contract, -// with pre-set call options. -type ValidatorContractCallerSession struct { - Contract *ValidatorContractCaller // Generic contract caller binding to set the session for - CallOpts bind.CallOpts // Call options to use throughout this session -} - -// ValidatorContractTransactorSession is an auto generated write-only Go binding around an Ethereum contract, -// with pre-set transact options. -type ValidatorContractTransactorSession struct { - Contract *ValidatorContractTransactor // Generic contract transactor binding to set the session for - TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session -} - -// ValidatorContractRaw is an auto generated low-level Go binding around an Ethereum contract. -type ValidatorContractRaw struct { - Contract *ValidatorContract // Generic contract binding to access the raw methods on -} - -// ValidatorContractCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract. -type ValidatorContractCallerRaw struct { - Contract *ValidatorContractCaller // Generic read-only contract binding to access the raw methods on -} - -// ValidatorContractTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract. -type ValidatorContractTransactorRaw struct { - Contract *ValidatorContractTransactor // Generic write-only contract binding to access the raw methods on -} - -// NewValidatorContract creates a new instance of ValidatorContract, bound to a specific deployed contract. -func NewValidatorContract(address common.Address, backend bind.ContractBackend) (*ValidatorContract, error) { - contract, err := bindValidatorContract(address, backend, backend) - if err != nil { - return nil, err - } - return &ValidatorContract{ValidatorContractCaller: ValidatorContractCaller{contract: contract}, ValidatorContractTransactor: ValidatorContractTransactor{contract: contract}}, nil -} - -// NewValidatorContractCaller creates a new read-only instance of ValidatorContract, bound to a specific deployed contract. -func NewValidatorContractCaller(address common.Address, caller bind.ContractCaller) (*ValidatorContractCaller, error) { - contract, err := bindValidatorContract(address, caller, nil) - if err != nil { - return nil, err - } - return &ValidatorContractCaller{contract: contract}, nil -} - -// NewValidatorContractTransactor creates a new write-only instance of ValidatorContract, bound to a specific deployed contract. -func NewValidatorContractTransactor(address common.Address, transactor bind.ContractTransactor) (*ValidatorContractTransactor, error) { - contract, err := bindValidatorContract(address, nil, transactor) - if err != nil { - return nil, err - } - return &ValidatorContractTransactor{contract: contract}, nil -} - -// bindValidatorContract binds a generic wrapper to an already deployed contract. -func bindValidatorContract(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor) (*bind.BoundContract, error) { - parsed, err := abi.JSON(strings.NewReader(ValidatorContractABI)) - if err != nil { - return nil, err - } - return bind.NewBoundContract(address, parsed, caller, transactor), nil -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_ValidatorContract *ValidatorContractRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _ValidatorContract.Contract.ValidatorContractCaller.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_ValidatorContract *ValidatorContractRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _ValidatorContract.Contract.ValidatorContractTransactor.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_ValidatorContract *ValidatorContractRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _ValidatorContract.Contract.ValidatorContractTransactor.contract.Transact(opts, method, params...) -} - -// Call invokes the (constant) contract method with params as input values and -// sets the output to result. The result type might be a single field for simple -// returns, a slice of interfaces for anonymous returns and a struct for named -// returns. -func (_ValidatorContract *ValidatorContractCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error { - return _ValidatorContract.Contract.contract.Call(opts, result, method, params...) -} - -// Transfer initiates a plain transaction to move funds to the contract, calling -// its default method if one is available. -func (_ValidatorContract *ValidatorContractTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) { - return _ValidatorContract.Contract.contract.Transfer(opts) -} - -// Transact invokes the (paid) contract method with params as input values. -func (_ValidatorContract *ValidatorContractTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) { - return _ValidatorContract.Contract.contract.Transact(opts, method, params...) +// Solidity: function updateGasPrice(_receiptId int256, _txGasprice uint256) returns(bool) +func (_VMC *VMCTransactorSession) UpdateGasPrice(_receiptId *big.Int, _txGasprice *big.Int) (*types.Transaction, error) { + return _VMC.Contract.UpdateGasPrice(&_VMC.TransactOpts, _receiptId, _txGasprice) } -// Withdraw is a paid mutator transaction binding the contract method 0x8e19899e. +// Withdraw is a paid mutator transaction binding the contract method 0x7e62eab8. // -// Solidity: function withdraw(_sig bytes32) returns(bool) -func (_ValidatorContract *ValidatorContractTransactor) Withdraw(opts *bind.TransactOpts, _sig [32]byte) (*types.Transaction, error) { - return _ValidatorContract.contract.Transact(opts, "withdraw", _sig) +// Solidity: function withdraw(_validatorIndex int256) returns() +func (_VMC *VMCTransactor) Withdraw(opts *bind.TransactOpts, _validatorIndex *big.Int) (*types.Transaction, error) { + return _VMC.contract.Transact(opts, "withdraw", _validatorIndex) } -// Withdraw is a paid mutator transaction binding the contract method 0x8e19899e. +// Withdraw is a paid mutator transaction binding the contract method 0x7e62eab8. // -// Solidity: function withdraw(_sig bytes32) returns(bool) -func (_ValidatorContract *ValidatorContractSession) Withdraw(_sig [32]byte) (*types.Transaction, error) { - return _ValidatorContract.Contract.Withdraw(&_ValidatorContract.TransactOpts, _sig) +// Solidity: function withdraw(_validatorIndex int256) returns() +func (_VMC *VMCSession) Withdraw(_validatorIndex *big.Int) (*types.Transaction, error) { + return _VMC.Contract.Withdraw(&_VMC.TransactOpts, _validatorIndex) } -// Withdraw is a paid mutator transaction binding the contract method 0x8e19899e. +// Withdraw is a paid mutator transaction binding the contract method 0x7e62eab8. // -// Solidity: function withdraw(_sig bytes32) returns(bool) -func (_ValidatorContract *ValidatorContractTransactorSession) Withdraw(_sig [32]byte) (*types.Transaction, error) { - return _ValidatorContract.Contract.Withdraw(&_ValidatorContract.TransactOpts, _sig) +// Solidity: function withdraw(_validatorIndex int256) returns() +func (_VMC *VMCTransactorSession) Withdraw(_validatorIndex *big.Int) (*types.Transaction, error) { + return _VMC.Contract.Withdraw(&_VMC.TransactOpts, _validatorIndex) } diff --git a/sharding/contracts/validator_manager.sol b/sharding/contracts/validator_manager.sol index d582dc477e1a..f5879e0bf578 100644 --- a/sharding/contracts/validator_manager.sol +++ b/sharding/contracts/validator_manager.sol @@ -44,7 +44,7 @@ contract VMC { mapping (int => Receipt) receipts; // shardId => headerHash mapping (int => bytes32) shardHead; - + // Number of validators int numValidators; // Number of receipts @@ -109,19 +109,19 @@ contract VMC { index = stackPop(); else index = int(numValidators); - + validators[index] = Validator({ deposit: msg.value, addr: msg.sender }); ++numValidators; isValidatorDeposited[msg.sender] = true; - + Deposit(msg.sender, index); return index; } - // Removes the validator from the validator set and refunds the deposited ether + // Removes the validator from the validator set and refunds the deposited ether function withdraw(int _validatorIndex) public { require(msg.sender == validators[_validatorIndex].addr); // [FIXME] Should consider calling the validator's contract, might be useful @@ -193,7 +193,7 @@ contract VMC { // 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, + function txToShard(address _to, int _shardId, uint _txStartgas, uint _txGasprice, bytes12 _data) public payable returns(int) { receipts[numReceipts] = Receipt({ shardId: _shardId, @@ -206,11 +206,11 @@ contract VMC { }); var receiptId = numReceipts; ++numReceipts; - + TxToShard(_to, _shardId, receiptId); return receiptId; } - + function updateGasPrice(int _receiptId, uint _txGasprice) public payable returns(bool) { require(receipts[_receiptId].sender == msg.sender); receipts[_receiptId].txGasprice = _txGasprice; @@ -225,7 +225,7 @@ contract VMC { emptySlotsStack[emptySlotsStackTop] = index; ++emptySlotsStackTop; } - + function stackPop() internal returns(int) { if (isStackEmpty()) return -1; diff --git a/sharding/vmc.go b/sharding/vmc.go index 3e96e818aa39..c423249d616e 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -3,11 +3,9 @@ package sharding import ( "context" "fmt" + "math/big" "time" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/sharding/contracts" ) @@ -17,32 +15,18 @@ import ( func initVMC(c *Client) error { b, err := c.client.CodeAt(context.Background(), validatorManagerAddress, nil) if err != nil { - return fmt.Errorf("unable to get contract code at %s. %v", validatorManagerAddress, err) + return fmt.Errorf("unable to get contract code at %s: %v", validatorManagerAddress, err) } if len(b) == 0 { log.Info(fmt.Sprintf("No validator management contract found at %s. Deploying new contract.", validatorManagerAddress.String())) - accounts := c.keystore.Accounts() - if len(accounts) == 0 { - return fmt.Errorf("no accounts found") - } - - if err := c.unlockAccount(accounts[0]); err != nil { - return fmt.Errorf("unable to unlock account 0: %v", err) - } - ops := bind.TransactOpts{ - From: accounts[0].Address, - Signer: func(signer types.Signer, addr common.Address, tx *types.Transaction) (*types.Transaction, error) { - networkID, err := c.client.NetworkID(context.Background()) - if err != nil { - return nil, fmt.Errorf("unable to fetch networkID: %v", err) - } - return c.keystore.SignTx(accounts[0], tx, networkID /* chainID */) - }, + txOps, err := c.createTXOps(big.NewInt(0)) + if err != nil { + return fmt.Errorf("unable to intiate the transaction: %v", err) } - addr, tx, contract, err := contracts.DeployVMC(&ops, c.client) + addr, tx, contract, err := contracts.DeployVMC(&txOps, c.client) if err != nil { return fmt.Errorf("unable to deploy validator management contract: %v", err) } @@ -66,3 +50,23 @@ func initVMC(c *Client) error { return nil } + +// joinValidatorSet checks if the account is a validator in the VMC. If +// the account is not in the set, it will deposit 100ETH into contract. +func joinValidatorSet(c *Client) error { + + // TODO: Check if account is already in validator set. Fetch this From + // the VMC contract's validator set + txOps, err := c.createTXOps(depositSize) + if err != nil { + return fmt.Errorf("unable to intiate the deposit transaction: %v", err) + } + + tx, err := c.vmc.VMCTransactor.Deposit(&txOps) + if err != nil { + return fmt.Errorf("unable to deposit eth and become a validator: %v", err) + } + log.Info(fmt.Sprintf("Deposited 100ETH into contract with transaction hash: %s", tx.Hash().String())) + return nil + +}