mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
regenerate bindings with new changes
Former-commit-id: 3893bee1aeb1f4cc0b11516c93d9c9295b2b1e44 [formerly 9fa34925ad183d9319cbc9cabe1250563609dec3] Former-commit-id: 89e46099f8cbacc9ba0e2f23213b5cb3f3e49b7e
This commit is contained in:
commit
9b6eed7dae
@ -14,10 +14,10 @@ import (
|
||||
)
|
||||
|
||||
// VMCABI is the input ABI used to generate the binding from.
|
||||
const VMCABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"int256\"},{\"name\":\"_expectedPeriodNumber\",\"type\":\"uint256\"},{\"name\":\"_periodStartPrevHash\",\"type\":\"bytes32\"},{\"name\":\"_parentCollationHash\",\"type\":\"bytes32\"},{\"name\":\"_txListRoot\",\"type\":\"bytes32\"},{\"name\":\"_collationCoinbase\",\"type\":\"address\"},{\"name\":\"_postStateRoot\",\"type\":\"bytes32\"},{\"name\":\"_receiptRoot\",\"type\":\"bytes32\"},{\"name\":\"_collationNumber\",\"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\":\"_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\"},{\"constant\":false,\"inputs\":[{\"name\":\"_receiptId\",\"type\":\"int256\"},{\"name\":\"_txGasprice\",\"type\":\"uint256\"}],\"name\":\"updataGasPrice\",\"outputs\":[{\"name\":\"\",\"type\":\"bool\"}],\"payable\":true,\"stateMutability\":\"payable\",\"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\"}]"
|
||||
const VMCABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"_shardId\",\"type\":\"int256\"},{\"name\":\"_expectedPeriodNumber\",\"type\":\"uint256\"},{\"name\":\"_periodStartPrevHash\",\"type\":\"bytes32\"},{\"name\":\"_parentCollationHash\",\"type\":\"bytes32\"},{\"name\":\"_txListRoot\",\"type\":\"bytes32\"},{\"name\":\"_collationCoinbase\",\"type\":\"address\"},{\"name\":\"_postStateRoot\",\"type\":\"bytes32\"},{\"name\":\"_receiptRoot\",\"type\":\"bytes32\"},{\"name\":\"_collationNumber\",\"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 = `0x6060604052341561000f57600080fd5b6109448061001e6000396000f30060606040526004361061008d5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630341518d811461009257806304e9c77a146100de578063372a9e2a146101035780637e62eab81461012d578063934586ec14610145578063d0e30db014610158578063e29de3ad14610160578063e551e00a14610195575b600080fd5b341561009d57600080fd5b6100ca600435602435604435606435608435600160a060020a0360a4351660c43560e435610104356101a3565b604051901515815260200160405180910390f35b34156100e957600080fd5b6100f161040b565b60405190815260200160405180910390f35b6100f1600160a060020a0360043516602435604435606435600160a060020a031960843516610410565b341561013857600080fd5b610143600435610533565b005b341561015057600080fd5b6100f1610636565b6100f161063e565b341561016b57600080fd5b610179600435602435610763565b604051600160a060020a03909116815260200160405180910390f35b6100ca6004356024356107f1565b60006101ad6108f1565b60008b121580156101be575060648b125b15156101c957600080fd5b60054310156101d757600080fd5b600543048a146101e657600080fd5b60001960058b02014089146101fa57600080fd5b8a8a8a8a8a600160a060020a038b168a8a8a60405198895260208901979097526040808901969096526060880194909452608087019290925260a086015260c085015260e0840152610100830191909152610120909101905190819003902081528051151561026557fe5b60008b815260016020526040812090825181526020810191909152604001600020600101541561029157fe5b87156102c4578715806102bc575060008b81526001602081815260408084208c855290915282200154135b15156102c457fe5b60008b8152600960205260409020548a90126102dc57fe5b6102e98b60054304610763565b600160a060020a03166040820190815251600160a060020a0316151561030e57600080fd5b8060400151600160a060020a031633600160a060020a031614151561033257600080fd5b60008b81526001602081815260408084208c855282529092208101540190820190815251831461036157600080fd5b60408051908101604052888152602080820190830151905260008c81526001602052604081209083518152602081019190915260400160002081518155602082015160019182015560008d81526009602090815260408083208f905583825280832060038352818420548452825290912090910154915082015113156103fa57805160008c815260036020526040902055600160608201525b5060019a9950505050505050505050565b606481565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a031986166080840152600160a060020a0333811660a08501528a1660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482015560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c08201516006919091018054600160a060020a031916600160a060020a039283161790556005805460018101909155925087915088167ffc322e0c42ee41e0d74b940ceeee9cd5971acdd6ace8ff8010ee7134c31d9ea58360405190815260200160405180910390a39695505050505050565b60008181526020819052604090206001015433600160a060020a0390811691161461055d57600080fd5b6000818152602081905260409081902060018101549054600160a060020a039091169181156108fc02919051600060405180830381858888f1935050505015156105a657600080fd5b600081815260208181526040808320600181018054600160a060020a0316855260088452918420805460ff19169055848452918390529190558054600160a060020a03191690556105f681610836565b600480546000190190557fe13f360aa18d414ccdb598da6c447faa89d0477ffc7549dab5678fca76910b8c8160405190815260200160405180910390a150565b629896805b90565b600160a060020a033316600090815260086020526040812054819060ff161561066657600080fd5b3468056bc75e2d631000001461067b57600080fd5b610683610855565b15156106985761069161085c565b905061069d565b506004545b604080519081016040908152348252600160a060020a0333166020808401919091526000848152908190522081518155602082015160019182018054600160a060020a031916600160a060020a0392831617905560048054830190553390811660009081526008602052604090819020805460ff19169093179092557fd8a6d38df847dcba70dfdeb4948fb1457d61a81d132801f40dc9c00d52dfd478925090839051600160a060020a03909216825260208201526040908101905180910390a1919050565b6000600482101561077357600080fd5b4360031983016005021061078657600080fd5b6004546000901361079657600080fd5b6000806107a1610893565b600319850140600502866040519182526020820152604090810190519081900390208115156107cc57fe5b068152602081019190915260400160002060010154600160a060020a03169392505050565b60008281526002602052604081206005015433600160a060020a0390811691161461081b57600080fd5b50600091825260026020819052604090922090910155600190565b6007805460009081526006602052604090209190915580546001019055565b6007541590565b6000610866610855565b15610874575060001961063b565b5060078054600019019081905560009081526006602052604090205490565b600754600454600091829101815b6104008112156108e6578181126108b7576108e6565b600081815260208190526040902060010154600160a060020a0316156108de576001830192505b6001016108a1565b505060075401919050565b608060405190810160409081526000808352602083018190529082018190526060820152905600a165627a7a72305820cf6bda8a0b2efba379805dd0fa21d9896b2223809fe21406b302304d4ecb928f0029`
|
||||
const VMCBin = `0x6060604052341561000f57600080fd5b6109448061001e6000396000f30060606040526004361061008d5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630341518d811461009257806304e9c77a146100de5780632213138914610103578063372a9e2a146101115780637e62eab81461013b578063934586ec14610153578063d0e30db014610166578063e29de3ad1461016e575b600080fd5b341561009d57600080fd5b6100ca600435602435604435606435608435600160a060020a0360a4351660c43560e435610104356101a3565b604051901515815260200160405180910390f35b34156100e957600080fd5b6100f161040b565b60405190815260200160405180910390f35b6100ca600435602435610410565b6100f1600160a060020a0360043516602435604435606435600160a060020a031960843516610455565b341561014657600080fd5b610151600435610578565b005b341561015e57600080fd5b6100f161067b565b6100f1610683565b341561017957600080fd5b6101876004356024356107a8565b604051600160a060020a03909116815260200160405180910390f35b60006101ad6108f1565b60008b121580156101be575060648b125b15156101c957600080fd5b60054310156101d757600080fd5b600543048a146101e657600080fd5b60001960058b02014089146101fa57600080fd5b8a8a8a8a8a600160a060020a038b168a8a8a60405198895260208901979097526040808901969096526060880194909452608087019290925260a086015260c085015260e0840152610100830191909152610120909101905190819003902081528051151561026557fe5b60008b815260016020526040812090825181526020810191909152604001600020600101541561029157fe5b87156102c4578715806102bc575060008b81526001602081815260408084208c855290915282200154135b15156102c457fe5b60008b8152600960205260409020548a90126102dc57fe5b6102e98b600543046107a8565b600160a060020a03166040820190815251600160a060020a0316151561030e57600080fd5b8060400151600160a060020a031633600160a060020a031614151561033257600080fd5b60008b81526001602081815260408084208c855282529092208101540190820190815251831461036157600080fd5b60408051908101604052888152602080820190830151905260008c81526001602052604081209083518152602081019190915260400160002081518155602082015160019182015560008d81526009602090815260408083208f905583825280832060038352818420548452825290912090910154915082015113156103fa57805160008c815260036020526040902055600160608201525b5060019a9950505050505050505050565b606481565b60008281526002602052604081206005015433600160a060020a0390811691161461043a57600080fd5b50600091825260026020819052604090922090910155600190565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a031986166080840152600160a060020a0333811660a08501528a1660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482015560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c08201516006919091018054600160a060020a031916600160a060020a039283161790556005805460018101909155925087915088167ffc322e0c42ee41e0d74b940ceeee9cd5971acdd6ace8ff8010ee7134c31d9ea58360405190815260200160405180910390a39695505050505050565b60008181526020819052604090206001015433600160a060020a039081169116146105a257600080fd5b6000818152602081905260409081902060018101549054600160a060020a039091169181156108fc02919051600060405180830381858888f1935050505015156105eb57600080fd5b600081815260208181526040808320600181018054600160a060020a0316855260088452918420805460ff19169055848452918390529190558054600160a060020a031916905561063b81610836565b600480546000190190557fe13f360aa18d414ccdb598da6c447faa89d0477ffc7549dab5678fca76910b8c8160405190815260200160405180910390a150565b629896805b90565b600160a060020a033316600090815260086020526040812054819060ff16156106ab57600080fd5b3468056bc75e2d63100000146106c057600080fd5b6106c8610855565b15156106dd576106d661085c565b90506106e2565b506004545b604080519081016040908152348252600160a060020a0333166020808401919091526000848152908190522081518155602082015160019182018054600160a060020a031916600160a060020a0392831617905560048054830190553390811660009081526008602052604090819020805460ff19169093179092557fd8a6d38df847dcba70dfdeb4948fb1457d61a81d132801f40dc9c00d52dfd478925090839051600160a060020a03909216825260208201526040908101905180910390a1919050565b600060048210156107b857600080fd5b436003198301600502106107cb57600080fd5b600454600090136107db57600080fd5b6000806107e6610893565b6003198501406005028660405191825260208201526040908101905190819003902081151561081157fe5b068152602081019190915260400160002060010154600160a060020a03169392505050565b6007805460009081526006602052604090209190915580546001019055565b6007541590565b6000610866610855565b156108745750600019610680565b5060078054600019019081905560009081526006602052604090205490565b600754600454600091829101815b6104008112156108e6578181126108b7576108e6565b600081815260208190526040902060010154600160a060020a0316156108de576001830192505b6001016108a1565b505060075401919050565b608060405190810160409081526000808352602083018190529082018190526060820152905600a165627a7a7230582063d88aa7c9677c1be16f9f7f383603042eba112f9456d13947afb2d2d824dade0029`
|
||||
|
||||
// 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) {
|
||||
@ -300,25 +300,25 @@ 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.
|
||||
// UpdateGasPrice is a paid mutator transaction binding the contract method 0x22131389.
|
||||
//
|
||||
// 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)
|
||||
// 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)
|
||||
}
|
||||
|
||||
// UpdataGasPrice is a paid mutator transaction binding the contract method 0xe551e00a.
|
||||
// UpdateGasPrice is a paid mutator transaction binding the contract method 0x22131389.
|
||||
//
|
||||
// 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)
|
||||
// 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)
|
||||
}
|
||||
|
||||
// UpdataGasPrice is a paid mutator transaction binding the contract method 0xe551e00a.
|
||||
// UpdateGasPrice is a paid mutator transaction binding the contract method 0x22131389.
|
||||
//
|
||||
// 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)
|
||||
// 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 0x7e62eab8.
|
||||
|
@ -28,11 +28,23 @@ contract VMC {
|
||||
address to;
|
||||
}
|
||||
|
||||
mapping (int => Validator) validators;
|
||||
mapping (int => mapping (bytes32 => CollationHeader)) collationHeaders;
|
||||
mapping (int => Receipt) receipts;
|
||||
// Packed variables to be used in addHeader
|
||||
struct HeaderVars {
|
||||
bytes32 entireHeaderHash;
|
||||
int score;
|
||||
address validatorAddr;
|
||||
bool isNewHead;
|
||||
}
|
||||
|
||||
// validatorId => Validators
|
||||
mapping (int => Validator) validators;
|
||||
// shardId => (headerHash => CollationHeader)
|
||||
mapping (int => mapping (bytes32 => CollationHeader)) collationHeaders;
|
||||
// receiptId => Receipt
|
||||
mapping (int => Receipt) receipts;
|
||||
// shardId => headerHash
|
||||
mapping (int => bytes32) shardHead;
|
||||
|
||||
int numValidators;
|
||||
int numReceipts;
|
||||
// Indexs of empty slots caused by the function `withdraw`
|
||||
@ -57,32 +69,33 @@ contract VMC {
|
||||
function VMC() public {
|
||||
}
|
||||
|
||||
function isStackEmpty() internal view returns(bool) {
|
||||
return emptySlotsStackTop == 0;
|
||||
}
|
||||
function stackPush(int index) internal {
|
||||
emptySlotsStack[emptySlotsStackTop] = index;
|
||||
++emptySlotsStackTop;
|
||||
}
|
||||
function stackPop() internal returns(int) {
|
||||
if (isStackEmpty())
|
||||
return -1;
|
||||
--emptySlotsStackTop;
|
||||
return emptySlotsStack[emptySlotsStackTop];
|
||||
// Returns the gas limit that collations can currently have (by default make
|
||||
// this function always answer 10 million).
|
||||
function getCollationGasLimit() public pure returns(uint) {
|
||||
return 10000000;
|
||||
}
|
||||
|
||||
function getValidatorsMaxIndex() internal view returns(int) {
|
||||
int activateValidatorNum = 0;
|
||||
int allValidatorSlotsNum = numValidators + emptySlotsStackTop;
|
||||
|
||||
// TODO: any better way to iterate the mapping?
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
if (i >= allValidatorSlotsNum)
|
||||
break;
|
||||
if (validators[i].addr != 0x0)
|
||||
activateValidatorNum += 1;
|
||||
}
|
||||
return activateValidatorNum + emptySlotsStackTop;
|
||||
// Uses a block hash as a seed to pseudorandomly select a signer from the validator set.
|
||||
// [TODO] Chance of being selected should be proportional to the validator's deposit.
|
||||
// Should be able to return a value for the current period or any future period up to.
|
||||
function getEligibleProposer(int _shardId, uint _period) public view returns(address) {
|
||||
require(_period >= lookAheadPeriods);
|
||||
require((_period - lookAheadPeriods) * periodLength < block.number);
|
||||
require(numValidators > 0);
|
||||
// [TODO] Should check further if this safe or not
|
||||
return validators[
|
||||
int(
|
||||
uint(
|
||||
keccak256(
|
||||
uint(
|
||||
block.blockhash(_period - lookAheadPeriods)
|
||||
) * periodLength,
|
||||
_shardId
|
||||
)
|
||||
) %
|
||||
uint(getValidatorsMaxIndex())
|
||||
)
|
||||
].addr;
|
||||
}
|
||||
|
||||
function deposit() public payable returns(int) {
|
||||
@ -99,13 +112,14 @@ contract VMC {
|
||||
deposit: msg.value,
|
||||
addr: msg.sender
|
||||
});
|
||||
++numValidators;
|
||||
isValidatorDeposited[msg.sender] = true;
|
||||
++numValidators;
|
||||
isValidatorDeposited[msg.sender] = true;
|
||||
|
||||
Deposit(msg.sender, index);
|
||||
return index;
|
||||
Deposit(msg.sender, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
// 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
|
||||
@ -118,31 +132,11 @@ contract VMC {
|
||||
Withdraw(_validatorIndex);
|
||||
}
|
||||
|
||||
// Uses a block hash as a seed to pseudorandomly select a signer from the validator set.
|
||||
// [TODO] Chance of being selected should be proportional to the validator's deposit.
|
||||
// Should be able to return a value for the current period or any future period up to.
|
||||
function getEligibleProposer(int _shardId, uint _period) public view returns(address) {
|
||||
require(_period >= lookAheadPeriods);
|
||||
require((_period - lookAheadPeriods) * periodLength < block.number);
|
||||
require(numValidators > 0);
|
||||
// [TODO] Should check further if this safe or not
|
||||
return validators[
|
||||
int(
|
||||
uint(keccak256(uint(block.blockhash(_period - lookAheadPeriods)) * periodLength, _shardId))
|
||||
%
|
||||
uint(getValidatorsMaxIndex())
|
||||
)].addr;
|
||||
}
|
||||
|
||||
struct HeaderVars {
|
||||
bytes32 entireHeaderHash;
|
||||
int score;
|
||||
address validatorAddr;
|
||||
bool isNewHead;
|
||||
}
|
||||
// Attempts to process a collation header, returns true on success, reverts on failure.
|
||||
function addHeader(int _shardId, uint _expectedPeriodNumber, bytes32 _periodStartPrevHash,
|
||||
bytes32 _parentCollationHash, bytes32 _txListRoot, address _collationCoinbase,
|
||||
bytes32 _postStateRoot, bytes32 _receiptRoot, int _collationNumber) public returns(bool) {
|
||||
bytes32 _parentCollationHash, bytes32 _txListRoot,
|
||||
address _collationCoinbase, bytes32 _postStateRoot, bytes32 _receiptRoot,
|
||||
int _collationNumber) public returns(bool) {
|
||||
HeaderVars memory headerVars;
|
||||
|
||||
// Check if the header is valid
|
||||
@ -194,17 +188,12 @@ contract VMC {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns the gas limit that collations can currently have (by default make
|
||||
// this function always answer 10 million).
|
||||
function getCollationGasLimit() public pure returns(uint) {
|
||||
return 10000000;
|
||||
}
|
||||
|
||||
// Records a request to deposit msg.value ETH to address to in shard shard_id
|
||||
// during a future collation. Saves a `receipt ID` for this request,
|
||||
// also saving `msg.sender`, `msg.value`, `to`, `shard_id`, `startgas`,
|
||||
// `gasprice`, and `data`.
|
||||
function txToShard(address _to, int _shardId, uint _txStartgas, uint _txGasprice, bytes12 _data) public payable returns(int) {
|
||||
function txToShard(address _to, int _shardId, uint _txStartgas, uint _txGasprice,
|
||||
bytes12 _data) public payable returns(int) {
|
||||
receipts[numReceipts] = Receipt({
|
||||
shardId: _shardId,
|
||||
txStartgas: _txStartgas,
|
||||
@ -221,9 +210,39 @@ contract VMC {
|
||||
return receiptId;
|
||||
}
|
||||
|
||||
function updataGasPrice(int _receiptId, uint _txGasprice) public payable returns(bool) {
|
||||
function updateGasPrice(int _receiptId, uint _txGasprice) public payable returns(bool) {
|
||||
require(receipts[_receiptId].sender == msg.sender);
|
||||
receipts[_receiptId].txGasprice = _txGasprice;
|
||||
return true;
|
||||
}
|
||||
|
||||
function isStackEmpty() internal view returns(bool) {
|
||||
return emptySlotsStackTop == 0;
|
||||
}
|
||||
|
||||
function stackPush(int index) internal {
|
||||
emptySlotsStack[emptySlotsStackTop] = index;
|
||||
++emptySlotsStackTop;
|
||||
}
|
||||
|
||||
function stackPop() internal returns(int) {
|
||||
if (isStackEmpty())
|
||||
return -1;
|
||||
--emptySlotsStackTop;
|
||||
return emptySlotsStack[emptySlotsStackTop];
|
||||
}
|
||||
|
||||
function getValidatorsMaxIndex() internal view returns(int) {
|
||||
int activateValidatorNum = 0;
|
||||
int allValidatorSlotsNum = numValidators + emptySlotsStackTop;
|
||||
|
||||
// TODO: any better way to iterate the mapping?
|
||||
for (int i = 0; i < 1024; ++i) {
|
||||
if (i >= allValidatorSlotsNum)
|
||||
break;
|
||||
if (validators[i].addr != 0x0)
|
||||
activateValidatorNum += 1;
|
||||
}
|
||||
return activateValidatorNum + emptySlotsStackTop;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user