From d3b4c7777503ddcd769a3e2e9979a0fc78fe5f54 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 15 Jan 2018 16:53:42 -0600 Subject: [PATCH 01/25] incl blocks, transactions, and vm protocol interface overrides --- sharding/blocks.go | 6 ++++++ sharding/transactions.go | 6 ++++++ sharding/vm.go | 6 ++++++ 3 files changed, 18 insertions(+) create mode 100644 sharding/blocks.go create mode 100644 sharding/transactions.go create mode 100644 sharding/vm.go diff --git a/sharding/blocks.go b/sharding/blocks.go new file mode 100644 index 000000000000..2831175b73fc --- /dev/null +++ b/sharding/blocks.go @@ -0,0 +1,6 @@ +// 2018 Prysmatic Labs +// This file is part of the prysmaticlabs/geth-sharding library. +// +// This file overrides the default protocol blocks interface + +package sharding diff --git a/sharding/transactions.go b/sharding/transactions.go new file mode 100644 index 000000000000..8bbaa9a6da57 --- /dev/null +++ b/sharding/transactions.go @@ -0,0 +1,6 @@ +// 2018 Prysmatic Labs +// This file is part of the prysmaticlabs/geth-sharding library. +// +// This file overrides the default protocol transaction interface + +package sharding diff --git a/sharding/vm.go b/sharding/vm.go new file mode 100644 index 000000000000..bef5b0112b35 --- /dev/null +++ b/sharding/vm.go @@ -0,0 +1,6 @@ +// 2018 Prysmatic Labs +// This file is part of the prysmaticlabs/geth-sharding library. +// +// This file overrides the default protocol VM interface + +package sharding From a251652dd3aaea7bb085caa8fb8305e61889b99e Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 16 Jan 2018 10:41:00 -0600 Subject: [PATCH 02/25] sharding tx base types override --- sharding/transactions.go | 34 +++++++++++++++++++++++++++++++++- sharding/transactions_test.go | 15 +++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 sharding/transactions_test.go diff --git a/sharding/transactions.go b/sharding/transactions.go index 8bbaa9a6da57..627278c7e3ad 100644 --- a/sharding/transactions.go +++ b/sharding/transactions.go @@ -1,6 +1,38 @@ // 2018 Prysmatic Labs // This file is part of the prysmaticlabs/geth-sharding library. // -// This file overrides the default protocol transaction interface +// This file overrides the default protocol transaction interface to prep it +// for sharding package sharding + +import ( + "github.com/ethereum/go-ethereum/common" + "math/big" + "sync/atomic" + //"github.com/ethereum/go-ethereum/common/hexutil" + //"github.com/ethereum/go-ethereum/rlp" +) + +// Transaction Base Sharding Struct +type Transaction struct { + data txdata + hash atomic.Value + size atomic.Value + from atomic.Value +} + +type txdata struct { + AccountNonce uint64 `json:"nonce" gencodec:"required"` + Price *big.Int `json:"gasPrice" gencodec:"required"` + GasLimit uint64 `json:"gas" gencodec:"required"` + Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation + Amount *big.Int `json:"value" gencodec:"required"` + // Code Payload + Payload []byte `json:"input" gencodec:"required"` + // TODO: + // add accesslist, chainid, shardid, + + // This is only used when marshaling to JSON. + Hash *common.Hash `json:"hash" rlp:"-"` +} diff --git a/sharding/transactions_test.go b/sharding/transactions_test.go new file mode 100644 index 000000000000..dc7b4559455b --- /dev/null +++ b/sharding/transactions_test.go @@ -0,0 +1,15 @@ +package sharding + +import ( + //"flag" + //"fmt" + //"math/rand" + //"os" + "testing" +) + +func TestCreation(t *testing.T) { + if 1 != 2 { + t.Fatalf("Values are not equal") + } +} From ddff62c5583645a8cabd0e88de252b5d6c3260e4 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 16 Jan 2018 11:16:46 -0600 Subject: [PATCH 03/25] creates a new sharding transaction --- sharding/transactions.go | 53 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/sharding/transactions.go b/sharding/transactions.go index 627278c7e3ad..2159ac837b1d 100644 --- a/sharding/transactions.go +++ b/sharding/transactions.go @@ -8,14 +8,14 @@ package sharding import ( "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "math/big" "sync/atomic" - //"github.com/ethereum/go-ethereum/common/hexutil" //"github.com/ethereum/go-ethereum/rlp" ) -// Transaction Base Sharding Struct -type Transaction struct { +// ShardingTransaction Base Struct +type ShardingTransaction struct { data txdata hash atomic.Value size atomic.Value @@ -30,9 +30,52 @@ type txdata struct { Amount *big.Int `json:"value" gencodec:"required"` // Code Payload Payload []byte `json:"input" gencodec:"required"` - // TODO: - // add accesslist, chainid, shardid, + // Sharding specific fields + AccessList []*common.Address `json:"accessList" gencodec:"required"` + ChainID uint64 `json:"chainId" gencodec:"required"` + ShardID uint64 `json:"shardId" gencodec:"required"` // This is only used when marshaling to JSON. Hash *common.Hash `json:"hash" rlp:"-"` } + +type txdataMarshaling struct { + AccountNonce hexutil.Uint64 + Price *hexutil.Big + GasLimit hexutil.Uint64 + Amount *hexutil.Big + Payload hexutil.Bytes + ChainID hexutil.Uint64 + ShardID hexutil.Uint64 +} + +func NewShardingTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { + return newShardingTransaction(nonce, &to, amount, gasLimit, gasPrice, data, accessList) +} + +func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { + return newShardingTransaction(nonce, nil, amount, gasLimit, gasPrice, data, accessList) +} + +func newShardingTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { + if len(data) > 0 { + data = common.CopyBytes(data) + } + d := txdata{ + AccountNonce: nonce, + Recipient: to, + Payload: data, + Amount: new(big.Int), + GasLimit: gasLimit, + Price: new(big.Int), + AccessList: accessList, + } + if amount != nil { + d.Amount.Set(amount) + } + if gasPrice != nil { + d.Price.Set(gasPrice) + } + + return &ShardingTransaction{data: d} +} From 8b75ccb7609426fd36ce2ac4da54c18fc75bcdab Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 16 Jan 2018 11:21:28 -0600 Subject: [PATCH 04/25] new sharding tx creation --- sharding/transactions.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sharding/transactions.go b/sharding/transactions.go index 2159ac837b1d..77a1c0191aee 100644 --- a/sharding/transactions.go +++ b/sharding/transactions.go @@ -32,9 +32,9 @@ type txdata struct { Payload []byte `json:"input" gencodec:"required"` // Sharding specific fields + // TODO: Figure out exact format of accesslist. array of arrays of addr + prefixes? AccessList []*common.Address `json:"accessList" gencodec:"required"` - ChainID uint64 `json:"chainId" gencodec:"required"` - ShardID uint64 `json:"shardId" gencodec:"required"` + // This is only used when marshaling to JSON. Hash *common.Hash `json:"hash" rlp:"-"` } @@ -79,3 +79,14 @@ func newShardingTransaction(nonce uint64, to *common.Address, amount *big.Int, g return &ShardingTransaction{data: d} } + +// ChainID determines the chain the tx will go into (this is 1 on the mainnet) +func (tx *ShardingTransaction) ChainID() *big.Int { + return big.NewInt(1) +} + +// ShardID determines the shard a transaction belongs to +func (tx *ShardingTransaction) ShardID() *big.Int { + // TODO: figure out how to determine ShardID. 1 for now + return big.NewInt(1) +} From 48f5c828fd2a0e8f59764b2c757a89d2343a4ecd Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 16 Jan 2018 11:56:21 -0600 Subject: [PATCH 05/25] sharding transaction tests --- sharding/transactions.go | 8 ++++---- sharding/transactions_test.go | 26 ++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/sharding/transactions.go b/sharding/transactions.go index 77a1c0191aee..14e8731eb361 100644 --- a/sharding/transactions.go +++ b/sharding/transactions.go @@ -33,7 +33,7 @@ type txdata struct { // Sharding specific fields // TODO: Figure out exact format of accesslist. array of arrays of addr + prefixes? - AccessList []*common.Address `json:"accessList" gencodec:"required"` + AccessList []common.Address `json:"accessList" gencodec:"required"` // This is only used when marshaling to JSON. Hash *common.Hash `json:"hash" rlp:"-"` @@ -49,15 +49,15 @@ type txdataMarshaling struct { ShardID hexutil.Uint64 } -func NewShardingTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { +func NewShardingTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { return newShardingTransaction(nonce, &to, amount, gasLimit, gasPrice, data, accessList) } -func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { +func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { return newShardingTransaction(nonce, nil, amount, gasLimit, gasPrice, data, accessList) } -func newShardingTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []*common.Address) *ShardingTransaction { +func newShardingTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { if len(data) > 0 { data = common.CopyBytes(data) } diff --git a/sharding/transactions_test.go b/sharding/transactions_test.go index dc7b4559455b..3c53d94765bf 100644 --- a/sharding/transactions_test.go +++ b/sharding/transactions_test.go @@ -5,11 +5,33 @@ import ( //"fmt" //"math/rand" //"os" + "github.com/ethereum/go-ethereum/common" + "math/big" "testing" ) +var ( + txSimple = NewShardingTransaction( + 0, + common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), + // amount + big.NewInt(10), + // gasLimit + 1000000, + // gasPrice + big.NewInt(1), + // data + common.FromHex("hello world this is the data"), + // access list + []common.Address{common.HexToAddress("032e7baea6a6c7c4c2dfe98392932326af552d87"), common.HexToAddress("083e7baea6a6c7c4c2dfeb97710293843f552d87")}, + ) +) + func TestCreation(t *testing.T) { - if 1 != 2 { - t.Fatalf("Values are not equal") + if txSimple.ChainID().Cmp(big.NewInt(1)) != 0 { + t.Fatalf("ChainID invalid") + } + if txSimple.ShardID().Cmp(big.NewInt(1)) != 0 { + t.Fatalf("ShardID invalid") } } From 13d9bf4fc974d02db9824f21723a48d92b5614d9 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 21 Jan 2018 22:47:58 -0600 Subject: [PATCH 06/25] fix up genesis to reflect 12345 chainid and higher gas limit for testing purposes --- sharding/genesis.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding/genesis.json b/sharding/genesis.json index f807a7a42e65..aa5d95858636 100644 --- a/sharding/genesis.json +++ b/sharding/genesis.json @@ -1,12 +1,12 @@ { "config": { - "chainId": 1000, + "chainId": 12345, "homesteadBlock": 0, "eip155Block": 0, "eip158Block": 0 }, "difficulty": "200", - "gasLimit": "2100000", + "gasLimit": "210000000000", "alloc": { "826f3F66dB0416ea82033aE917A611bfBF4D98b6": { "balance": "300000" }, "Dd0cbc3AE49DD62915877ebFa6050cad362B83Ad": { "balance": "400000" } From 4aecc7ed255c89a288d57522844333b10a547ce1 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 15:10:26 -0600 Subject: [PATCH 07/25] modifying the sharding client to listen for incoming tx's in the pool --- sharding/blocks.go | 6 --- sharding/client.go | 2 +- sharding/transactions.go | 91 ----------------------------------- sharding/transactions_test.go | 37 -------------- 4 files changed, 1 insertion(+), 135 deletions(-) delete mode 100644 sharding/blocks.go delete mode 100644 sharding/transactions.go delete mode 100644 sharding/transactions_test.go diff --git a/sharding/blocks.go b/sharding/blocks.go deleted file mode 100644 index 2831175b73fc..000000000000 --- a/sharding/blocks.go +++ /dev/null @@ -1,6 +0,0 @@ -// 2018 Prysmatic Labs -// This file is part of the prysmaticlabs/geth-sharding library. -// -// This file overrides the default protocol blocks interface - -package sharding diff --git a/sharding/client.go b/sharding/client.go index 740aa3b4db44..f71a5f71162f 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -72,7 +72,7 @@ func (c *Client) Start() error { return err } - // TODO: Wait to be selected as collator in goroutine? + // Listens to incoming transactions from the geth node's txpool return nil } diff --git a/sharding/transactions.go b/sharding/transactions.go deleted file mode 100644 index b21ce69b143b..000000000000 --- a/sharding/transactions.go +++ /dev/null @@ -1,91 +0,0 @@ -// 2018 Prysmatic Labs -// This file is part of the prysmaticlabs/geth-sharding library. -// -// This file overrides the default protocol transaction interface to prep it -// for sharding - -package sharding - -import ( - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "math/big" - "sync/atomic" - //"github.com/ethereum/go-ethereum/rlp" -) - -// ShardingTransaction Base Struct -type ShardingTransaction struct { - data txdata - hash atomic.Value - size atomic.Value - from atomic.Value -} - -type txdata struct { - AccountNonce uint64 `json:"nonce" gencodec:"required"` - Price *big.Int `json:"gasPrice" gencodec:"required"` - GasLimit uint64 `json:"gas" gencodec:"required"` - Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation - Amount *big.Int `json:"value" gencodec:"required"` - // Code Payload - Payload []byte `json:"input" gencodec:"required"` - - // Sharding specific fields - // TODO: Figure out exact format of accesslist. array of arrays of addr + prefixes? - AccessList []common.Address `json:"accessList" gencodec:"required"` - - // This is only used when marshaling to JSON. - Hash *common.Hash `json:"hash" rlp:"-"` -} - -type txdataMarshaling struct { - AccountNonce hexutil.Uint64 - Price *hexutil.Big - GasLimit hexutil.Uint64 - Amount *hexutil.Big - Payload hexutil.Bytes - ChainID hexutil.Uint64 - ShardID hexutil.Uint64 -} - -func NewShardingTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { - return newShardingTransaction(nonce, &to, amount, gasLimit, gasPrice, data, accessList) -} - -func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { - return newShardingTransaction(nonce, nil, amount, gasLimit, gasPrice, data, accessList) -} - -func newShardingTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, accessList []common.Address) *ShardingTransaction { - if len(data) > 0 { - data = common.CopyBytes(data) - } - d := txdata{ - AccountNonce: nonce, - Recipient: to, - Payload: data, - Amount: new(big.Int), - GasLimit: gasLimit, - Price: new(big.Int), - AccessList: accessList, - } - if amount != nil { - d.Amount.Set(amount) - } - if gasPrice != nil { - d.Price.Set(gasPrice) - } - - return &ShardingTransaction{data: d} -} - -// ChainID determines the chain the tx will go into (this is 1 on the mainnet) -func (tx *ShardingTransaction) ChainID() *big.Int { - return big.NewInt(1) -} - -// ShardID determines the shard a transaction belongs to -func (tx *ShardingTransaction) ShardID() *big.Int { - return big.NewInt(1) -} diff --git a/sharding/transactions_test.go b/sharding/transactions_test.go deleted file mode 100644 index 3c53d94765bf..000000000000 --- a/sharding/transactions_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package sharding - -import ( - //"flag" - //"fmt" - //"math/rand" - //"os" - "github.com/ethereum/go-ethereum/common" - "math/big" - "testing" -) - -var ( - txSimple = NewShardingTransaction( - 0, - common.HexToAddress("095e7baea6a6c7c4c2dfeb977efac326af552d87"), - // amount - big.NewInt(10), - // gasLimit - 1000000, - // gasPrice - big.NewInt(1), - // data - common.FromHex("hello world this is the data"), - // access list - []common.Address{common.HexToAddress("032e7baea6a6c7c4c2dfe98392932326af552d87"), common.HexToAddress("083e7baea6a6c7c4c2dfeb97710293843f552d87")}, - ) -) - -func TestCreation(t *testing.T) { - if txSimple.ChainID().Cmp(big.NewInt(1)) != 0 { - t.Fatalf("ChainID invalid") - } - if txSimple.ShardID().Cmp(big.NewInt(1)) != 0 { - t.Fatalf("ShardID invalid") - } -} From 24bdf86dcc293f9ec28d785490fd75c181587e3d Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 15:30:32 -0600 Subject: [PATCH 08/25] added txpool func --- sharding/client.go | 8 +++++++- sharding/txpool.go | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 sharding/txpool.go diff --git a/sharding/client.go b/sharding/client.go index f71a5f71162f..a80637a75a95 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -72,8 +72,14 @@ func (c *Client) Start() error { return err } - // Listens to incoming transactions from the geth node's txpool + // TODO: Wait to be selected as a collator, then start listening to the + // geth node's txpool. + // Listens to incoming transactions from the geth node's txpool and directs + // them into the VMC if node is a collator + if err := listenTXPool(c); err != nil { + return err + } return nil } diff --git a/sharding/txpool.go b/sharding/txpool.go new file mode 100644 index 000000000000..14cf6817fc3d --- /dev/null +++ b/sharding/txpool.go @@ -0,0 +1,13 @@ +package sharding + +import ( + "fmt" +) + +// listenTXPool 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 if the current +// node is a collator +func listenTXPool(c *Client) error { + return fmt.Errorf("Not Implemented") +} From b2e501e3f445d7961ec2dbc68bac8b457a5f99b9 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 15:57:20 -0600 Subject: [PATCH 09/25] subscribe to new block headers for eligible proposer --- password.txt | 1 + sharding/client.go | 9 +++------ sharding/listener.go | 32 ++++++++++++++++++++++++++++++++ sharding/txpool.go | 13 ------------- 4 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 password.txt create mode 100644 sharding/listener.go delete mode 100644 sharding/txpool.go diff --git a/password.txt b/password.txt new file mode 100644 index 000000000000..9f358a4addef --- /dev/null +++ b/password.txt @@ -0,0 +1 @@ +123456 diff --git a/sharding/client.go b/sharding/client.go index a80637a75a95..5e6359314327 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -72,12 +72,9 @@ func (c *Client) Start() error { return err } - // TODO: Wait to be selected as a collator, then start listening to the - // geth node's txpool. - - // Listens to incoming transactions from the geth node's txpool and directs - // them into the VMC if node is a collator - if err := listenTXPool(c); err != nil { + // 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 diff --git a/sharding/listener.go b/sharding/listener.go new file mode 100644 index 000000000000..8d3a85e5ce8b --- /dev/null +++ b/sharding/listener.go @@ -0,0 +1,32 @@ +package sharding + +import ( + "context" + "fmt" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" +) + +// 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 err + } + + log.Info("listening for new headers...") + + for { + 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())) + } + } +} diff --git a/sharding/txpool.go b/sharding/txpool.go deleted file mode 100644 index 14cf6817fc3d..000000000000 --- a/sharding/txpool.go +++ /dev/null @@ -1,13 +0,0 @@ -package sharding - -import ( - "fmt" -) - -// listenTXPool 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 if the current -// node is a collator -func listenTXPool(c *Client) error { - return fmt.Errorf("Not Implemented") -} From 57af73bf9d50e6230bc2a1f4ae9476b78e87324c Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 16:21:46 -0600 Subject: [PATCH 10/25] init vmc validator --- sharding/client.go | 7 +++++++ sharding/vmc.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/sharding/client.go b/sharding/client.go index 5e6359314327..4e01bf74c411 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -72,6 +72,13 @@ func (c *Client) Start() error { return err } + // TODO: 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 + if err := initVMCValidator(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 { diff --git a/sharding/vmc.go b/sharding/vmc.go index 3e96e818aa39..7d18247b0301 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -66,3 +66,11 @@ func initVMC(c *Client) error { return nil } + +// initVMCValidator 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 initVMCValidator(c *Client) error { + + // TODO: Implement + +} From d4b42c2797754b733b0e0424586bf2904adbc0f2 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 16:22:09 -0600 Subject: [PATCH 11/25] comments --- sharding/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sharding/client.go b/sharding/client.go index 4e01bf74c411..316ba0a65363 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -72,8 +72,8 @@ func (c *Client) Start() error { return err } - // TODO: 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) + // 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 if err := initVMCValidator(c); err != nil { return err From 1daf350be9f15bccd5a99f4fe618f496d5bc2ffd Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 23:35:15 -0600 Subject: [PATCH 12/25] deposit into vmc using transact ops --- sharding/vmc.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/sharding/vmc.go b/sharding/vmc.go index 7d18247b0301..0fff49974bf3 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -71,6 +71,29 @@ func initVMC(c *Client) error { // the account is not in the set, it will deposit 100ETH into contract. func initVMCValidator(c *Client) error { - // TODO: Implement + // TODO: Check if account is already in validator set + + 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 */) + }, + } + + // Deposits 100ETH into the VMC from the current account + c.vmc.VMCTransactor.Deposit(&ops) + return nil } From 8ff844dbf93afa429a4502268e64df214be28326 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 23:41:40 -0600 Subject: [PATCH 13/25] deposit eth into vmc --- sharding/vmc.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sharding/vmc.go b/sharding/vmc.go index 0fff49974bf3..f276319fc10b 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -81,8 +81,11 @@ func initVMCValidator(c *Client) error { if err := c.unlockAccount(accounts[0]); err != nil { return fmt.Errorf("unable to unlock account 0: %v", err) } + + // Deposits 100ETH into the VMC from the current account ops := bind.TransactOpts{ - From: accounts[0].Address, + From: accounts[0].Address, + Value: depositSize, Signer: func(signer types.Signer, addr common.Address, tx *types.Transaction) (*types.Transaction, error) { networkID, err := c.client.NetworkID(context.Background()) if err != nil { @@ -92,8 +95,10 @@ func initVMCValidator(c *Client) error { }, } - // Deposits 100ETH into the VMC from the current account - c.vmc.VMCTransactor.Deposit(&ops) + tx, err := c.vmc.VMCTransactor.Deposit(&ops, /* validatorcodeaddr */, accounts[0].Address) + if err != nil { + return fmt.Errorf("unable to deposit eth and become a validator: %v", err) + } return nil } From 3a95e010de45e25bfc89bc5e626bd4e1e59fc8c8 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Sun, 28 Jan 2018 23:54:10 -0600 Subject: [PATCH 14/25] add question --- sharding/vmc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sharding/vmc.go b/sharding/vmc.go index f276319fc10b..b380c63621e6 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -71,7 +71,8 @@ func initVMC(c *Client) error { // the account is not in the set, it will deposit 100ETH into contract. func initVMCValidator(c *Client) error { - // TODO: Check if account is already in validator set + // TODO: Check if account is already in validator set. Do we need to implement + // a func in solidity to do this? accounts := c.keystore.Accounts() if len(accounts) == 0 { From f230a2273ba2df53840dbcbc05b2a1648d8450eb Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 31 Jan 2018 22:33:38 -0600 Subject: [PATCH 15/25] rename to collator.go and implement the watchShards func --- sharding/{listener.go => collator.go} | 9 +++++++++ sharding/vmc.go | 8 +++++--- 2 files changed, 14 insertions(+), 3 deletions(-) rename sharding/{listener.go => collator.go} (73%) diff --git a/sharding/listener.go b/sharding/collator.go similarity index 73% rename from sharding/listener.go rename to sharding/collator.go index 8d3a85e5ce8b..addd46f468bb 100644 --- a/sharding/listener.go +++ b/sharding/collator.go @@ -27,6 +27,15 @@ func subscribeBlockHeaders(c *Client) error { 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? + watchShards(head) } } } + +// watchShards 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 watchShards(head types.Header) { + +} diff --git a/sharding/vmc.go b/sharding/vmc.go index b380c63621e6..22007056f2af 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -71,9 +71,10 @@ func initVMC(c *Client) error { // the account is not in the set, it will deposit 100ETH into contract. func initVMCValidator(c *Client) error { - // TODO: Check if account is already in validator set. Do we need to implement - // a func in solidity to do this? + // TODO: Check if account is already in validator set. Fetch this From + // the VMC contract's validator set. + // Unlocks the current account from the keystore accounts := c.keystore.Accounts() if len(accounts) == 0 { return fmt.Errorf("no accounts found") @@ -96,10 +97,11 @@ func initVMCValidator(c *Client) error { }, } - tx, err := c.vmc.VMCTransactor.Deposit(&ops, /* validatorcodeaddr */, accounts[0].Address) + _, err := c.vmc.VMCTransactor.Deposit(&ops, accounts[0].Address) if err != nil { return fmt.Errorf("unable to deposit eth and become a validator: %v", err) } + log.Info(fmt.Sprintf("deposited 100ETH into contract")) return nil } From 255aa011b0fbdf0e67a229ce8be66133a208e5ed Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 31 Jan 2018 22:41:11 -0600 Subject: [PATCH 16/25] get shard list programmatically --- sharding/collator.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/sharding/collator.go b/sharding/collator.go index addd46f468bb..c2b693ffc7ff 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -28,7 +28,7 @@ func subscribeBlockHeaders(c *Client) error { // 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? - watchShards(head) + watchShards(c, head) } } } @@ -36,6 +36,22 @@ func subscribeBlockHeaders(c *Client) error { // watchShards 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 watchShards(head types.Header) { +func watchShards(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("unable to unlock account 0: %v", err) + } + + shards, err := c.vmc.VMCCaller.GetShardList(accounts[0].Address) + if err != nil { + return fmt.Errorf("shard list could not be fetched") + } + log.info(fmt.Sprintf("%s", shards)) + + return nil } From e362985d38c1464a617aeaec87e69c02f2c2dee8 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 1 Feb 2018 13:30:24 -0600 Subject: [PATCH 17/25] loops over shards and checks if eligible proposer --- sharding/client.go | 6 ++--- sharding/collator.go | 21 ++++++++++++---- sharding/contracts/validator_manager.go | 32 +++++++++++++++++++++--- sharding/contracts/validator_manager.sol | 18 ++++++------- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/sharding/client.go b/sharding/client.go index 316ba0a65363..7fb1c376e6cc 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -75,9 +75,9 @@ func (c *Client) Start() error { // 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 - if err := initVMCValidator(c); err != nil { - return err - } + // if err := initVMCValidator(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 diff --git a/sharding/collator.go b/sharding/collator.go index c2b693ffc7ff..0f14e8fca29f 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -3,6 +3,7 @@ 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" ) @@ -28,7 +29,10 @@ func subscribeBlockHeaders(c *Client) error { // 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? - watchShards(c, head) + err := watchShards(c, head) + if err != nil { + return err + } } } } @@ -44,14 +48,21 @@ func watchShards(c *Client, head *types.Header) error { } if err := c.unlockAccount(accounts[0]); err != nil { - return fmt.Errorf("unable to unlock account 0: %v", err) + return err } - shards, err := c.vmc.VMCCaller.GetShardList(accounts[0].Address) + ops := bind.CallOpts{} + count, err := c.vmc.VMCCaller.ShardCount(&ops) if err != nil { - return fmt.Errorf("shard list could not be fetched") + return err + } + + s := 0 + for s < int(count.Int64()) { + // Checks if we are an eligible proposer according to the VMC + log.Info(fmt.Sprintf("shard %d", s)) + s++ } - log.info(fmt.Sprintf("%s", shards)) return nil } diff --git a/sharding/contracts/validator_manager.go b/sharding/contracts/validator_manager.go index b5d9fb296697..1a99d3c92273 100644 --- a/sharding/contracts/validator_manager.go +++ b/sharding/contracts/validator_manager.go @@ -163,7 +163,7 @@ func (_RLP *RLPTransactorRaw) Transact(opts *bind.TransactOpts, method string, p const SigHasherContractABI = "[]" // SigHasherContractBin is the compiled bytecode used for deploying new contracts. -const SigHasherContractBin = `0x60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a72305820c5e12cfe03e1e876e69b3e7102c7e127c4297a29e99b2f672d5d071d1f25699f0029` +const SigHasherContractBin = `0x60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a72305820dd94c909af80cc14b692c0ae3ce550a5f230d5b96835c38888dea73913db29930029` // 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) { @@ -306,10 +306,10 @@ func (_SigHasherContract *SigHasherContractTransactorRaw) Transact(opts *bind.Tr } // VMCABI is the input ABI used to generate the binding from. -const VMCABI = "[{\"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\":\"_validatorAddr\",\"type\":\"address\"}],\"name\":\"getShardList\",\"outputs\":[{\"name\":\"\",\"type\":\"bool[100]\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":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\":\"_returnAddr\",\"type\":\"address\"}],\"name\":\"deposit\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"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\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" +const VMCABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"shardCount\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":\"_validatorAddr\",\"type\":\"address\"}],\"name\":\"getShardList\",\"outputs\":[{\"name\":\"\",\"type\":\"bool[100]\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":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\":\"_returnAddr\",\"type\":\"address\"}],\"name\":\"deposit\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"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\"},{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"}]" // VMCBin is the compiled bytecode used for deploying new contracts. -const VMCBin = `0x6060604052341561000f57600080fd5b6000600481905560075568056bc75e2d631000006008556005600981905562061a80600a55600c556064600d819055600e556040517f6164645f686561646572282900000000000000000000000000000000000000008152600c01604051908190039020600f5560108054600160a060020a03191673dffd41e18f04ad8810c83b14fd1426a82e625a7d179055611340806100ab6000396000f3006060604052600436106100ae5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632b3407f981146100b3578063372a9e2a146100d85780635badac53146101025780635e57c86c146101185780637e62eab814610170578063934586ec146101885780639b33f9071461019b578063a8c57753146101b1578063e551e00a146101e3578063f340fa0114610205578063f7fecf7d14610219575b600080fd5b34156100be57600080fd5b6100c661026a565b60405190815260200160405180910390f35b6100c6600160a060020a0360043516602435604435606435600160a060020a0319608435166102df565b341561010d57600080fd5b6100c660043561041b565b341561012357600080fd5b610137600160a060020a0360043516610421565b6040518082610c8080838360005b8381101561015d578082015183820152602001610145565b5050505090500191505060405180910390f35b341561017b57600080fd5b61018660043561055c565b005b341561019357600080fd5b6100c6610689565b34156101a657600080fd5b6100c6600435610691565b34156101bc57600080fd5b6101c76004356106b5565b604051600160a060020a03909116815260200160405180910390f35b6101f16004356024356107cc565b604051901515815260200160405180910390f35b6100c6600160a060020a0360043516610811565b341561022457600080fd5b6101f160046024813581810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284375094965061099b95505050505050565b60008060008060008093506009544381151561028257fe5b059250600754600454019150600090505b6104008112156102d1578181126102a9576102d1565b6000818152602081905260409020600301548390136102c9576001840193505b600101610293565b600754840194505050505090565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a0333811660808501528a1660a0840152600160a060020a0319861660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482018054600160a060020a031916600160a060020a039290921691909117905560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c0820151600690910155505060058054600181019091558086600160a060020a0389166040517f74785f746f5f73686172642829000000000000000000000000000000000000008152600d01604051809103902060405190815260200160405180910390a39695505050505050565b50600090565b610429611246565b610431611246565b60008060008060008060006009544381151561044957fe5b05965060016009548802039550600086121561046457600095505b8540945061047061026a565b6004549094501561054e57600092505b60648360ff16101561054e5760008860ff85166064811061049d57fe5b91151560209092020152600091505b60648260ff16101561054357838560ff8086169085166040519283526020830191909152604080830191909152606090910190519081900390208115156104ef57fe5b06600081815260208190526040902060010154909150600160a060020a038b8116911614156105385760018860ff85166064811061052957fe5b91151560209092020152610543565b8160010191506104ac565b826001019250610480565b509598975050505050505050565b60006040517f7769746864726177000000000000000000000000000000000000000000000000815260080160405190819003902060008381526020819052604090206001015490915033600160a060020a039081169116146105bd57600080fd5b6000828152602081905260409081902060028101549054600160a060020a039091169181156108fc02919051600060405180830381858888f19350505050151561060657600080fd5b600082815260208181526040808320600181018054600160a060020a03168552600b8452918420805460ff19169055858452918390528282558054600160a060020a031990811690915560028201805490911690556003015561066882610d36565b60048054600019019055818160405190815260200160405180910390a15050565b629896805b90565b600c54600090820260001901438190116106aa57600080fd5b804091505b50919050565b6000806000806000806000600c5443101515156106d157600080fd5b600954438115156106de57fe5b0595506001600954870203945060008512156106f957600094505b600c54854094506001904381151561070d57fe5b0643030340600190049250600d54838960010260405191825260208201526040908101905190819003902081151561074157fe5b06915061074c61026a565b84898460405192835260208301919091526040808301919091526060909101905190819003902081151561077c57fe5b06600081815260208190526040902060030154909150869013156107a357600096506107c1565b600081815260208190526040902060010154600160a060020a031696505b505050505050919050565b60008281526002602052604081206004015433600160a060020a039081169116146107f657600080fd5b50600091825260026020819052604090922090910155600190565b600160a060020a0333166000908152600b60205260408120548190819060ff161561083b57600080fd5b600854341461084957600080fd5b506000610854610d55565b151561086957610862610d5c565b915061091c565b60045491506009544381151561087b57fe5b05600101905060806040519081016040908152348252600160a060020a03338116602080850191909152908716828401526060830184905260008581529081905220815181556020820151600182018054600160a060020a031916600160a060020a03929092169190911790556040820151600282018054600160a060020a031916600160a060020a03929092169190911790556060820151600390910155505b600480546001908101909155600160a060020a0333166000818152600b602052604090819020805460ff19169093179092558391517f6465706f736974282900000000000000000000000000000000000000000000008152600901604051809103902060405190815260200160405180910390a28192505b5050919050565b60006109a561126f565b6109ad611281565b6109b56112a2565b84925060008080806109d66109d188600163ffffffff610d9316565b610df7565b9550610140604051908101604052806109f66109f189610e30565b610e72565b8152602001610a0c610a0789610e30565b610e83565b8152602001610a1d6109f189610e30565b8152602001610a2e6109f189610e30565b8152602001610a3f6109f189610e30565b8152602001610a55610a5089610e30565b610ed4565b600160a060020a03168152602001610a6f6109f189610e30565b8152602001610a806109f189610e30565b8152602001610a916109f189610e30565b8152602001610aa7610aa289610e30565b610f1e565b905294506000855112158015610abf5750600e548551125b1515610aca57600080fd5b600c54431015610ad957600080fd5b600c5443811515610ae657fe5b04856020015114610af657600080fd5b6001600c548660200151020340604086015114610b1257600080fd5b846040519081526020016040519081900390209350831515610b3057fe5b60016000865181526020808201929092526040908101600090812087825290925290206001015415610b5e57fe5b846060015115610bae5784606001511580610ba65750600060018187518152602001908152602001600020600087606001518152602081019190915260400160002060010154135b1515610bae57fe5b8460200151601160008751815260200190815260200160002054121515610bd157fe5b610bdb85516106b5565b9250600160a060020a0383161515610bf65760009750610d2a565b600160008651815260200190815260200160002060008660600151815260208101919091526040016000206001908101540191508161010086015114610c3857fe5b6040805190810160405280866060015181526020018390526001600087518152602080820192909252604090810160009081208882529092529020815181556020820151600190910155506020850151601160008751815260200190815260200160002081905550600160008660000151815260200190815260200160002060006003600088600001518152602001908152602001600020546000191660001916815260200190815260200160002060010154821315610d255760036000865181526020019081526020016000205490508360036000876000015181526020810191909152604001600020555b600197505b50505050505050919050565b6007805460009081526006602052604090209190915580546001019055565b6007541590565b6000610d66610d55565b15610d74575060001961068e565b5060078054600019019081905560009081526006602052604090205490565b610d9b6112fd565b610da36112fd565b6000610dae85610f6c565b91508315610def578451905080610dc483610fbd565b1115610dcc57fe5b80610dd7835161103c565b14610dde57fe5b610de7826110ce565b1515610def57fe5b509392505050565b610dff611281565b6000610e0a83611110565b1515610e1557600080fd5b610e1e83610fbd565b83519383529092016020820152919050565b610e386112fd565b600080610e448461113b565b156100ae5783602001519150610e598261103c565b8284526020808501829052838201908601529050610994565b6000610e7d82610e83565b92915050565b6000806000610e918461115e565b1515610e9c57600080fd5b610ea584611188565b9150915060208111158015610eb957508015155b1515610ec157fe5b806020036101000a825104949350505050565b6000806000610ee28461115e565b1515610eed57600080fd5b610ef684611188565b909250905060148114610f0557fe5b6c01000000000000000000000000825104949350505050565b610f2661126f565b600082602001519050801515610f3b576106af565b80604051805910610f495750595b818152601f19601f8301168101602001604052905091506106af83518383611205565b610f746112fd565b60008083519150811515610f9d5760408051908101604052600080825260208201529250610994565b506020830160408051908101604052908152602081019190915292915050565b600080600083602001511515610fd65760009250610994565b83519050805160001a91506080821015610ff35760009250610994565b60b882108061100e575060c0821015801561100e575060f882105b1561101c5760019250610994565b60c08210156110315760b51982019250610994565b5060f5190192915050565b600080825160001a9050608081101561105857600191506106af565b60b881101561106d57607e19810191506106af565b60c08110156110975760b78103806020036101000a600185015104808201600101935050506106af565b60f88110156110ac5760be19810191506106af565b60f78103806020036101000a6001850151048082016001019350505050919050565b600080808084519050805160001a9250805160011a91506081831480156110f55750608082105b156111035760009350611108565b600193505b505050919050565b6000808260200151151561112757600091506106af565b8251905060c0815160001a10159392505050565b60006111456112fd565b8251905080602001518151018360200151109392505050565b6000808260200151151561117557600091506106af565b8251905060c0815160001a109392505050565b60008060008060006111998661115e565b15156111a457600080fd5b85519150815160001a925060808310156111c457819450600193506111fd565b60b88310156111e257600186602001510393508160010194506111fd565b5060b619820180600160208801510303935080820160010194505b505050915091565b60006020601f83010484602085015b8284146112335760208402808301518183015260018501945050611214565b6000865160200187015250505050505050565b610c806040519081016040526064815b6000815260001990910190602001816112565790505090565b60206040519081016040526000815290565b6060604051908101604052806112956112fd565b8152602001600081525090565b6101406040519081016040908152600080835260208301819052908201819052606082018190526080820181905260a0820181905260c0820181905260e0820181905261010082015261012081016112f861126f565b905290565b6040805190810160405260008082526020820152905600a165627a7a723058201e5dfd4590fe444b86534a5417adf73abd6edb65742c9c70d8223afa491d76730029` +const VMCBin = `0x6060604052341561000f57600080fd5b6000600481905560075568056bc75e2d631000006008556005600981905562061a80600a55600c556064600d819055600e556040517f6164645f686561646572282900000000000000000000000000000000000000008152600c01604051908190039020600f5560108054600160a060020a03191673dffd41e18f04ad8810c83b14fd1426a82e625a7d179055611364806100ab6000396000f3006060604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166304e9c77a81146100be5780632b3407f9146100e3578063372a9e2a146100f65780635badac53146101205780635e57c86c146101365780637e62eab81461018e578063934586ec146101a65780639b33f907146101b9578063a8c57753146101cf578063e551e00a14610201578063f340fa0114610223578063f7fecf7d14610237575b600080fd5b34156100c957600080fd5b6100d1610288565b60405190815260200160405180910390f35b34156100ee57600080fd5b6100d161028e565b6100d1600160a060020a0360043516602435604435606435600160a060020a031960843516610303565b341561012b57600080fd5b6100d160043561043f565b341561014157600080fd5b610155600160a060020a0360043516610445565b6040518082610c8080838360005b8381101561017b578082015183820152602001610163565b5050505090500191505060405180910390f35b341561019957600080fd5b6101a4600435610580565b005b34156101b157600080fd5b6100d16106ad565b34156101c457600080fd5b6100d16004356106b5565b34156101da57600080fd5b6101e56004356106d9565b604051600160a060020a03909116815260200160405180910390f35b61020f6004356024356107f0565b604051901515815260200160405180910390f35b6100d1600160a060020a0360043516610835565b341561024257600080fd5b61020f60046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506109bf95505050505050565b600e5481565b6000806000806000809350600954438115156102a657fe5b059250600754600454019150600090505b6104008112156102f5578181126102cd576102f5565b6000818152602081905260409020600301548390136102ed576001840193505b6001016102b7565b600754840194505050505090565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a0333811660808501528a1660a0840152600160a060020a0319861660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482018054600160a060020a031916600160a060020a039290921691909117905560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c0820151600690910155505060058054600181019091558086600160a060020a0389166040517f74785f746f5f73686172642829000000000000000000000000000000000000008152600d01604051809103902060405190815260200160405180910390a39695505050505050565b50600090565b61044d61126a565b61045561126a565b60008060008060008060006009544381151561046d57fe5b05965060016009548802039550600086121561048857600095505b8540945061049461028e565b6004549094501561057257600092505b60648360ff1610156105725760008860ff8516606481106104c157fe5b91151560209092020152600091505b60648260ff16101561056757838560ff80861690851660405192835260208301919091526040808301919091526060909101905190819003902081151561051357fe5b06600081815260208190526040902060010154909150600160a060020a038b81169116141561055c5760018860ff85166064811061054d57fe5b91151560209092020152610567565b8160010191506104d0565b8260010192506104a4565b509598975050505050505050565b60006040517f7769746864726177000000000000000000000000000000000000000000000000815260080160405190819003902060008381526020819052604090206001015490915033600160a060020a039081169116146105e157600080fd5b6000828152602081905260409081902060028101549054600160a060020a039091169181156108fc02919051600060405180830381858888f19350505050151561062a57600080fd5b600082815260208181526040808320600181018054600160a060020a03168552600b8452918420805460ff19169055858452918390528282558054600160a060020a031990811690915560028201805490911690556003015561068c82610d5a565b60048054600019019055818160405190815260200160405180910390a15050565b629896805b90565b600c54600090820260001901438190116106ce57600080fd5b804091505b50919050565b6000806000806000806000600c5443101515156106f557600080fd5b6009544381151561070257fe5b05955060016009548702039450600085121561071d57600094505b600c54854094506001904381151561073157fe5b0643030340600190049250600d54838960010260405191825260208201526040908101905190819003902081151561076557fe5b06915061077061028e565b8489846040519283526020830191909152604080830191909152606090910190519081900390208115156107a057fe5b06600081815260208190526040902060030154909150869013156107c757600096506107e5565b600081815260208190526040902060010154600160a060020a031696505b505050505050919050565b60008281526002602052604081206004015433600160a060020a0390811691161461081a57600080fd5b50600091825260026020819052604090922090910155600190565b600160a060020a0333166000908152600b60205260408120548190819060ff161561085f57600080fd5b600854341461086d57600080fd5b506000610878610d79565b151561088d57610886610d80565b9150610940565b60045491506009544381151561089f57fe5b05600101905060806040519081016040908152348252600160a060020a03338116602080850191909152908716828401526060830184905260008581529081905220815181556020820151600182018054600160a060020a031916600160a060020a03929092169190911790556040820151600282018054600160a060020a031916600160a060020a03929092169190911790556060820151600390910155505b600480546001908101909155600160a060020a0333166000818152600b602052604090819020805460ff19169093179092558391517f6465706f736974282900000000000000000000000000000000000000000000008152600901604051809103902060405190815260200160405180910390a28192505b5050919050565b60006109c9611293565b6109d16112a5565b6109d96112c6565b84925060008080806109fa6109f588600163ffffffff610db716565b610e1b565b955061014060405190810160405280610a1a610a1589610e54565b610e96565b8152602001610a30610a2b89610e54565b610ea7565b8152602001610a41610a1589610e54565b8152602001610a52610a1589610e54565b8152602001610a63610a1589610e54565b8152602001610a79610a7489610e54565b610ef8565b600160a060020a03168152602001610a93610a1589610e54565b8152602001610aa4610a1589610e54565b8152602001610ab5610a1589610e54565b8152602001610acb610ac689610e54565b610f42565b905294506000855112158015610ae35750600e548551125b1515610aee57600080fd5b600c54431015610afd57600080fd5b600c5443811515610b0a57fe5b04856020015114610b1a57600080fd5b6001600c548660200151020340604086015114610b3657600080fd5b846040519081526020016040519081900390209350831515610b5457fe5b60016000865181526020808201929092526040908101600090812087825290925290206001015415610b8257fe5b846060015115610bd25784606001511580610bca5750600060018187518152602001908152602001600020600087606001518152602081019190915260400160002060010154135b1515610bd257fe5b8460200151601160008751815260200190815260200160002054121515610bf557fe5b610bff85516106d9565b9250600160a060020a0383161515610c1a5760009750610d4e565b600160008651815260200190815260200160002060008660600151815260208101919091526040016000206001908101540191508161010086015114610c5c57fe5b6040805190810160405280866060015181526020018390526001600087518152602080820192909252604090810160009081208882529092529020815181556020820151600190910155506020850151601160008751815260200190815260200160002081905550600160008660000151815260200190815260200160002060006003600088600001518152602001908152602001600020546000191660001916815260200190815260200160002060010154821315610d495760036000865181526020019081526020016000205490508360036000876000015181526020810191909152604001600020555b600197505b50505050505050919050565b6007805460009081526006602052604090209190915580546001019055565b6007541590565b6000610d8a610d79565b15610d9857506000196106b2565b5060078054600019019081905560009081526006602052604090205490565b610dbf611321565b610dc7611321565b6000610dd285610f90565b91508315610e13578451905080610de883610fe1565b1115610df057fe5b80610dfb8351611060565b14610e0257fe5b610e0b826110f2565b1515610e1357fe5b509392505050565b610e236112a5565b6000610e2e83611134565b1515610e3957600080fd5b610e4283610fe1565b83519383529092016020820152919050565b610e5c611321565b600080610e688461115f565b156100b95783602001519150610e7d82611060565b82845260208085018290528382019086015290506109b8565b6000610ea182610ea7565b92915050565b6000806000610eb584611182565b1515610ec057600080fd5b610ec9846111ac565b9150915060208111158015610edd57508015155b1515610ee557fe5b806020036101000a825104949350505050565b6000806000610f0684611182565b1515610f1157600080fd5b610f1a846111ac565b909250905060148114610f2957fe5b6c01000000000000000000000000825104949350505050565b610f4a611293565b600082602001519050801515610f5f576106d3565b80604051805910610f6d5750595b818152601f19601f8301168101602001604052905091506106d383518383611229565b610f98611321565b60008083519150811515610fc157604080519081016040526000808252602082015292506109b8565b506020830160408051908101604052908152602081019190915292915050565b600080600083602001511515610ffa57600092506109b8565b83519050805160001a9150608082101561101757600092506109b8565b60b8821080611032575060c08210158015611032575060f882105b1561104057600192506109b8565b60c08210156110555760b519820192506109b8565b5060f5190192915050565b600080825160001a9050608081101561107c57600191506106d3565b60b881101561109157607e19810191506106d3565b60c08110156110bb5760b78103806020036101000a600185015104808201600101935050506106d3565b60f88110156110d05760be19810191506106d3565b60f78103806020036101000a6001850151048082016001019350505050919050565b600080808084519050805160001a9250805160011a91506081831480156111195750608082105b15611127576000935061112c565b600193505b505050919050565b6000808260200151151561114b57600091506106d3565b8251905060c0815160001a10159392505050565b6000611169611321565b8251905080602001518151018360200151109392505050565b6000808260200151151561119957600091506106d3565b8251905060c0815160001a109392505050565b60008060008060006111bd86611182565b15156111c857600080fd5b85519150815160001a925060808310156111e85781945060019350611221565b60b88310156112065760018660200151039350816001019450611221565b5060b619820180600160208801510303935080820160010194505b505050915091565b60006020601f83010484602085015b8284146112575760208402808301518183015260018501945050611238565b6000865160200187015250505050505050565b610c806040519081016040526064815b60008152600019909101906020018161127a5790505090565b60206040519081016040526000815290565b6060604051908101604052806112b9611321565b8152602001600081525090565b6101406040519081016040908152600080835260208301819052908201819052606082018190526080820181905260a0820181905260c0820181905260e08201819052610100820152610120810161131c611293565b905290565b6040805190810160405260008082526020820152905600a165627a7a7230582050bbfe7f79d1b6bf46d368599f08e975a149719bdaa908ea220213b77af1fc5d0029` // 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) { @@ -607,6 +607,32 @@ func (_VMC *VMCCallerSession) Sample(_shardId *big.Int) (common.Address, error) return _VMC.Contract.Sample(&_VMC.CallOpts, _shardId) } +// ShardCount is a free data retrieval call binding the contract method 0x04e9c77a. +// +// 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, "shardCount") + return *ret0, err +} + +// ShardCount is a free data retrieval call binding the contract method 0x04e9c77a. +// +// Solidity: function shardCount() constant returns(int256) +func (_VMC *VMCSession) ShardCount() (*big.Int, error) { + return _VMC.Contract.ShardCount(&_VMC.CallOpts) +} + +// ShardCount is a free data retrieval call binding the contract method 0x04e9c77a. +// +// Solidity: function shardCount() constant returns(int256) +func (_VMC *VMCCallerSession) ShardCount() (*big.Int, error) { + return _VMC.Contract.ShardCount(&_VMC.CallOpts) +} + // AddHeader is a paid mutator transaction binding the contract method 0xf7fecf7d. // // Solidity: function addHeader(_header bytes) returns(bool) diff --git a/sharding/contracts/validator_manager.sol b/sharding/contracts/validator_manager.sol index 5aa53302af7b..1b7d9cb1d0bd 100644 --- a/sharding/contracts/validator_manager.sol +++ b/sharding/contracts/validator_manager.sol @@ -10,7 +10,7 @@ contract VMC { using RLP for RLP.RLPItem; using RLP for RLP.Iterator; using RLP for bytes; - + struct Validator { // Amount of wei the validator holds uint deposit; @@ -59,7 +59,7 @@ contract VMC { mapping (address => bool) isValcodeDeposited; uint periodLength; int numValidatorsPerCycle; - int shardCount; + int public shardCount; bytes32 addHeaderLogTopic; SigHasherContract sighasher; // Log the latest period number of the shard @@ -127,7 +127,7 @@ contract VMC { } ++numValidators; isValcodeDeposited[msg.sender] = true; - + log2(keccak256("deposit()"), bytes32(msg.sender), bytes32(index)); return index; } @@ -156,7 +156,7 @@ contract VMC { uint indexInSubset = uint(keccak256(seed, bytes32(_shardId))) % uint(numValidatorsPerCycle); uint validatorIndex = uint(keccak256(cycleSeed, bytes32(_shardId), bytes32(indexInSubset))) % uint(getValidatorsMaxIndex()); - + if (validators[int(validatorIndex)].cycle > cycle) return 0x0; else @@ -178,7 +178,7 @@ contract VMC { for (uint8 shardId = 0; shardId < 100; ++shardId) { shardList[shardId] = false; for (uint8 possibleIndexInSubset = 0; possibleIndexInSubset < 100; ++possibleIndexInSubset) { - uint validatorIndex = uint(keccak256(cycleSeed, bytes32(shardId), bytes32(possibleIndexInSubset))) + uint validatorIndex = uint(keccak256(cycleSeed, bytes32(shardId), bytes32(possibleIndexInSubset))) % uint(validatorsMaxIndex); if (_validatorAddr == validators[int(validatorIndex)].addr) { shardList[shardId] = true; @@ -259,7 +259,7 @@ contract VMC { var collatorValcodeAddr = sample(header.shardId); if (collatorValcodeAddr == 0x0) return false; - + // assembly { // TODO next block // } @@ -291,7 +291,7 @@ contract VMC { // Emit log // TODO LOG // log1(addHeaderLogTopic, _header); - + return true; } @@ -332,11 +332,11 @@ contract VMC { }); var receiptId = numReceipts; ++numReceipts; - + log3(keccak256("tx_to_shard()"), bytes32(_to), bytes32(_shardId), bytes32(receiptId)); return receiptId; } - + function updataGasPrice(int _receiptId, uint _txGasprice) public payable returns(bool) { require(receipts[_receiptId].sender == msg.sender); receipts[_receiptId].txGasprice = _txGasprice; From 93b962ec03d945b2a9e1c72b03180b274a270e43 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 1 Feb 2018 18:01:21 -0600 Subject: [PATCH 18/25] propose collation called if addr from sample is coinbase --- sharding/collator.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sharding/collator.go b/sharding/collator.go index 0f14e8fca29f..20824866112f 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -60,9 +60,21 @@ func watchShards(c *Client, head *types.Header) error { s := 0 for s < int(count.Int64()) { // Checks if we are an eligible proposer according to the VMC - log.Info(fmt.Sprintf("shard %d", s)) + addr, err := c.vmc.VMCCaller.Sample(&ops, big.NewInt(s)) + if err != nil { + return err + } + // if the address is the coinbase addr (current node running the sharding + // clint, then we propose a new collation) + if addr == accounts[0].Address { + proposeCollation() + } s++ } return nil } + +func proposeCollation() { + return nil +} From 75cfe333509a53447a31ebc89b14e20c8a99a297 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 5 Feb 2018 11:54:33 -0600 Subject: [PATCH 19/25] incl shardcount and geteligibleproposer --- sharding/collator.go | 2 +- sharding/contracts/validator_manager.go | 472 ++--------------------- sharding/contracts/validator_manager.sol | 2 +- 3 files changed, 40 insertions(+), 436 deletions(-) diff --git a/sharding/collator.go b/sharding/collator.go index 20824866112f..b67fe7d7afe2 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -60,7 +60,7 @@ func watchShards(c *Client, head *types.Header) error { s := 0 for s < int(count.Int64()) { // Checks if we are an eligible proposer according to the VMC - addr, err := c.vmc.VMCCaller.Sample(&ops, big.NewInt(s)) + addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(s)) if err != nil { return err } diff --git a/sharding/contracts/validator_manager.go b/sharding/contracts/validator_manager.go index 1a99d3c92273..a27e847a0c4c 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 = `0x60606040523415600e57600080fd5b603580601b6000396000f3006060604052600080fd00a165627a7a72305820dd94c909af80cc14b692c0ae3ce550a5f230d5b96835c38888dea73913db29930029` - -// 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\":true,\"inputs\":[],\"name\":\"shardCount\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":\"_validatorAddr\",\"type\":\"address\"}],\"name\":\"getShardList\",\"outputs\":[{\"name\":\"\",\"type\":\"bool[100]\"}],\"payable\":false,\"stateMutability\":\"view\",\"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\":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\":\"_returnAddr\",\"type\":\"address\"}],\"name\":\"deposit\",\"outputs\":[{\"name\":\"\",\"type\":\"int256\"}],\"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\"},{\"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\":\"_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\"}]" // VMCBin is the compiled bytecode used for deploying new contracts. -const VMCBin = `0x6060604052341561000f57600080fd5b6000600481905560075568056bc75e2d631000006008556005600981905562061a80600a55600c556064600d819055600e556040517f6164645f686561646572282900000000000000000000000000000000000000008152600c01604051908190039020600f5560108054600160a060020a03191673dffd41e18f04ad8810c83b14fd1426a82e625a7d179055611364806100ab6000396000f3006060604052600436106100b95763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166304e9c77a81146100be5780632b3407f9146100e3578063372a9e2a146100f65780635badac53146101205780635e57c86c146101365780637e62eab81461018e578063934586ec146101a65780639b33f907146101b9578063a8c57753146101cf578063e551e00a14610201578063f340fa0114610223578063f7fecf7d14610237575b600080fd5b34156100c957600080fd5b6100d1610288565b60405190815260200160405180910390f35b34156100ee57600080fd5b6100d161028e565b6100d1600160a060020a0360043516602435604435606435600160a060020a031960843516610303565b341561012b57600080fd5b6100d160043561043f565b341561014157600080fd5b610155600160a060020a0360043516610445565b6040518082610c8080838360005b8381101561017b578082015183820152602001610163565b5050505090500191505060405180910390f35b341561019957600080fd5b6101a4600435610580565b005b34156101b157600080fd5b6100d16106ad565b34156101c457600080fd5b6100d16004356106b5565b34156101da57600080fd5b6101e56004356106d9565b604051600160a060020a03909116815260200160405180910390f35b61020f6004356024356107f0565b604051901515815260200160405180910390f35b6100d1600160a060020a0360043516610835565b341561024257600080fd5b61020f60046024813581810190830135806020601f820181900481020160405190810160405281815292919060208401838380828437509496506109bf95505050505050565b600e5481565b6000806000806000809350600954438115156102a657fe5b059250600754600454019150600090505b6104008112156102f5578181126102cd576102f5565b6000818152602081905260409020600301548390136102ed576001840193505b6001016102b7565b600754840194505050505090565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a0333811660808501528a1660a0840152600160a060020a0319861660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482018054600160a060020a031916600160a060020a039290921691909117905560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c0820151600690910155505060058054600181019091558086600160a060020a0389166040517f74785f746f5f73686172642829000000000000000000000000000000000000008152600d01604051809103902060405190815260200160405180910390a39695505050505050565b50600090565b61044d61126a565b61045561126a565b60008060008060008060006009544381151561046d57fe5b05965060016009548802039550600086121561048857600095505b8540945061049461028e565b6004549094501561057257600092505b60648360ff1610156105725760008860ff8516606481106104c157fe5b91151560209092020152600091505b60648260ff16101561056757838560ff80861690851660405192835260208301919091526040808301919091526060909101905190819003902081151561051357fe5b06600081815260208190526040902060010154909150600160a060020a038b81169116141561055c5760018860ff85166064811061054d57fe5b91151560209092020152610567565b8160010191506104d0565b8260010192506104a4565b509598975050505050505050565b60006040517f7769746864726177000000000000000000000000000000000000000000000000815260080160405190819003902060008381526020819052604090206001015490915033600160a060020a039081169116146105e157600080fd5b6000828152602081905260409081902060028101549054600160a060020a039091169181156108fc02919051600060405180830381858888f19350505050151561062a57600080fd5b600082815260208181526040808320600181018054600160a060020a03168552600b8452918420805460ff19169055858452918390528282558054600160a060020a031990811690915560028201805490911690556003015561068c82610d5a565b60048054600019019055818160405190815260200160405180910390a15050565b629896805b90565b600c54600090820260001901438190116106ce57600080fd5b804091505b50919050565b6000806000806000806000600c5443101515156106f557600080fd5b6009544381151561070257fe5b05955060016009548702039450600085121561071d57600094505b600c54854094506001904381151561073157fe5b0643030340600190049250600d54838960010260405191825260208201526040908101905190819003902081151561076557fe5b06915061077061028e565b8489846040519283526020830191909152604080830191909152606090910190519081900390208115156107a057fe5b06600081815260208190526040902060030154909150869013156107c757600096506107e5565b600081815260208190526040902060010154600160a060020a031696505b505050505050919050565b60008281526002602052604081206004015433600160a060020a0390811691161461081a57600080fd5b50600091825260026020819052604090922090910155600190565b600160a060020a0333166000908152600b60205260408120548190819060ff161561085f57600080fd5b600854341461086d57600080fd5b506000610878610d79565b151561088d57610886610d80565b9150610940565b60045491506009544381151561089f57fe5b05600101905060806040519081016040908152348252600160a060020a03338116602080850191909152908716828401526060830184905260008581529081905220815181556020820151600182018054600160a060020a031916600160a060020a03929092169190911790556040820151600282018054600160a060020a031916600160a060020a03929092169190911790556060820151600390910155505b600480546001908101909155600160a060020a0333166000818152600b602052604090819020805460ff19169093179092558391517f6465706f736974282900000000000000000000000000000000000000000000008152600901604051809103902060405190815260200160405180910390a28192505b5050919050565b60006109c9611293565b6109d16112a5565b6109d96112c6565b84925060008080806109fa6109f588600163ffffffff610db716565b610e1b565b955061014060405190810160405280610a1a610a1589610e54565b610e96565b8152602001610a30610a2b89610e54565b610ea7565b8152602001610a41610a1589610e54565b8152602001610a52610a1589610e54565b8152602001610a63610a1589610e54565b8152602001610a79610a7489610e54565b610ef8565b600160a060020a03168152602001610a93610a1589610e54565b8152602001610aa4610a1589610e54565b8152602001610ab5610a1589610e54565b8152602001610acb610ac689610e54565b610f42565b905294506000855112158015610ae35750600e548551125b1515610aee57600080fd5b600c54431015610afd57600080fd5b600c5443811515610b0a57fe5b04856020015114610b1a57600080fd5b6001600c548660200151020340604086015114610b3657600080fd5b846040519081526020016040519081900390209350831515610b5457fe5b60016000865181526020808201929092526040908101600090812087825290925290206001015415610b8257fe5b846060015115610bd25784606001511580610bca5750600060018187518152602001908152602001600020600087606001518152602081019190915260400160002060010154135b1515610bd257fe5b8460200151601160008751815260200190815260200160002054121515610bf557fe5b610bff85516106d9565b9250600160a060020a0383161515610c1a5760009750610d4e565b600160008651815260200190815260200160002060008660600151815260208101919091526040016000206001908101540191508161010086015114610c5c57fe5b6040805190810160405280866060015181526020018390526001600087518152602080820192909252604090810160009081208882529092529020815181556020820151600190910155506020850151601160008751815260200190815260200160002081905550600160008660000151815260200190815260200160002060006003600088600001518152602001908152602001600020546000191660001916815260200190815260200160002060010154821315610d495760036000865181526020019081526020016000205490508360036000876000015181526020810191909152604001600020555b600197505b50505050505050919050565b6007805460009081526006602052604090209190915580546001019055565b6007541590565b6000610d8a610d79565b15610d9857506000196106b2565b5060078054600019019081905560009081526006602052604090205490565b610dbf611321565b610dc7611321565b6000610dd285610f90565b91508315610e13578451905080610de883610fe1565b1115610df057fe5b80610dfb8351611060565b14610e0257fe5b610e0b826110f2565b1515610e1357fe5b509392505050565b610e236112a5565b6000610e2e83611134565b1515610e3957600080fd5b610e4283610fe1565b83519383529092016020820152919050565b610e5c611321565b600080610e688461115f565b156100b95783602001519150610e7d82611060565b82845260208085018290528382019086015290506109b8565b6000610ea182610ea7565b92915050565b6000806000610eb584611182565b1515610ec057600080fd5b610ec9846111ac565b9150915060208111158015610edd57508015155b1515610ee557fe5b806020036101000a825104949350505050565b6000806000610f0684611182565b1515610f1157600080fd5b610f1a846111ac565b909250905060148114610f2957fe5b6c01000000000000000000000000825104949350505050565b610f4a611293565b600082602001519050801515610f5f576106d3565b80604051805910610f6d5750595b818152601f19601f8301168101602001604052905091506106d383518383611229565b610f98611321565b60008083519150811515610fc157604080519081016040526000808252602082015292506109b8565b506020830160408051908101604052908152602081019190915292915050565b600080600083602001511515610ffa57600092506109b8565b83519050805160001a9150608082101561101757600092506109b8565b60b8821080611032575060c08210158015611032575060f882105b1561104057600192506109b8565b60c08210156110555760b519820192506109b8565b5060f5190192915050565b600080825160001a9050608081101561107c57600191506106d3565b60b881101561109157607e19810191506106d3565b60c08110156110bb5760b78103806020036101000a600185015104808201600101935050506106d3565b60f88110156110d05760be19810191506106d3565b60f78103806020036101000a6001850151048082016001019350505050919050565b600080808084519050805160001a9250805160011a91506081831480156111195750608082105b15611127576000935061112c565b600193505b505050919050565b6000808260200151151561114b57600091506106d3565b8251905060c0815160001a10159392505050565b6000611169611321565b8251905080602001518151018360200151109392505050565b6000808260200151151561119957600091506106d3565b8251905060c0815160001a109392505050565b60008060008060006111bd86611182565b15156111c857600080fd5b85519150815160001a925060808310156111e85781945060019350611221565b60b88310156112065760018660200151039350816001019450611221565b5060b619820180600160208801510303935080820160010194505b505050915091565b60006020601f83010484602085015b8284146112575760208402808301518183015260018501945050611238565b6000865160200187015250505050505050565b610c806040519081016040526064815b60008152600019909101906020018161127a5790505090565b60206040519081016040526000815290565b6060604051908101604052806112b9611321565b8152602001600081525090565b6101406040519081016040908152600080835260208301819052908201819052606082018190526080820181905260a0820181905260c0820181905260e08201819052610100820152610120810161131c611293565b905290565b6040805190810160405260008082526020820152905600a165627a7a7230582050bbfe7f79d1b6bf46d368599f08e975a149719bdaa908ea220213b77af1fc5d0029` +const VMCBin = `0x6060604052341561000f57600080fd5b6109448061001e6000396000f30060606040526004361061008d5763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630341518d811461009257806304e9c77a146100de578063372a9e2a146101035780637e62eab81461012d578063934586ec14610145578063d0e30db014610158578063e29de3ad14610160578063e551e00a14610195575b600080fd5b341561009d57600080fd5b6100ca600435602435604435606435608435600160a060020a0360a4351660c43560e435610104356101a3565b604051901515815260200160405180910390f35b34156100e957600080fd5b6100f161040b565b60405190815260200160405180910390f35b6100f1600160a060020a0360043516602435604435606435600160a060020a031960843516610410565b341561013857600080fd5b610143600435610533565b005b341561015057600080fd5b6100f1610636565b6100f161063e565b341561016b57600080fd5b610179600435602435610763565b604051600160a060020a03909116815260200160405180910390f35b6100ca6004356024356107f1565b60006101ad6108f1565b60008b121580156101be575060648b125b15156101c957600080fd5b60054310156101d757600080fd5b600543048a146101e657600080fd5b60001960058b02014089146101fa57600080fd5b8a8a8a8a8a600160a060020a038b168a8a8a60405198895260208901979097526040808901969096526060880194909452608087019290925260a086015260c085015260e0840152610100830191909152610120909101905190819003902081528051151561026557fe5b60008b815260016020526040812090825181526020810191909152604001600020600101541561029157fe5b87156102c4578715806102bc575060008b81526001602081815260408084208c855290915282200154135b15156102c457fe5b60008b8152600960205260409020548a90126102dc57fe5b6102e98b60054304610763565b600160a060020a03166040820190815251600160a060020a0316151561030e57600080fd5b8060400151600160a060020a031633600160a060020a031614151561033257600080fd5b60008b81526001602081815260408084208c855282529092208101540190820190815251831461036157600080fd5b60408051908101604052888152602080820190830151905260008c81526001602052604081209083518152602081019190915260400160002081518155602082015160019182015560008d81526009602090815260408083208f905583825280832060038352818420548452825290912090910154915082015113156103fa57805160008c815260036020526040902055600160608201525b5060019a9950505050505050505050565b606481565b60008060e060405190810160409081528782526020808301889052818301879052346060840152600160a060020a031986166080840152600160a060020a0333811660a08501528a1660c08401526005546000908152600290915220815181556020820151816001015560408201518160020155606082015181600301556080820151600482015560a0820151600582018054600160a060020a031916600160a060020a039290921691909117905560c08201516006919091018054600160a060020a031916600160a060020a039283161790556005805460018101909155925087915088167ffc322e0c42ee41e0d74b940ceeee9cd5971acdd6ace8ff8010ee7134c31d9ea58360405190815260200160405180910390a39695505050505050565b60008181526020819052604090206001015433600160a060020a0390811691161461055d57600080fd5b6000818152602081905260409081902060018101549054600160a060020a039091169181156108fc02919051600060405180830381858888f1935050505015156105a657600080fd5b600081815260208181526040808320600181018054600160a060020a0316855260088452918420805460ff19169055848452918390529190558054600160a060020a03191690556105f681610836565b600480546000190190557fe13f360aa18d414ccdb598da6c447faa89d0477ffc7549dab5678fca76910b8c8160405190815260200160405180910390a150565b629896805b90565b600160a060020a033316600090815260086020526040812054819060ff161561066657600080fd5b3468056bc75e2d631000001461067b57600080fd5b610683610855565b15156106985761069161085c565b905061069d565b506004545b604080519081016040908152348252600160a060020a0333166020808401919091526000848152908190522081518155602082015160019182018054600160a060020a031916600160a060020a0392831617905560048054830190553390811660009081526008602052604090819020805460ff19169093179092557fd8a6d38df847dcba70dfdeb4948fb1457d61a81d132801f40dc9c00d52dfd478925090839051600160a060020a03909216825260208201526040908101905180910390a1919050565b6000600482101561077357600080fd5b4360031983016005021061078657600080fd5b6004546000901361079657600080fd5b6000806107a1610893565b600319850140600502866040519182526020820152604090810190519081900390208115156107cc57fe5b068152602081019190915260400160002060010154600160a060020a03169392505050565b60008281526002602052604081206005015433600160a060020a0390811691161461081b57600080fd5b50600091825260026020819052604090922090910155600190565b6007805460009081526006602052604090209190915580546001019055565b6007541590565b6000610866610855565b15610874575060001961063b565b5060078054600019019081905560009081526006602052604090205490565b600754600454600091829101815b6104008112156108e6578181126108b7576108e6565b600081815260208190526040902060010154600160a060020a0316156108de576001830192505b6001016108a1565b505060075401919050565b608060405190810160409081526000808352602083018190529082018190526060820152905600a165627a7a72305820cf6bda8a0b2efba379805dd0fa21d9896b2223809fe21406b302304d4ecb928f0029` // 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,108 +185,30 @@ 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. -// -// 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(_validatorAddr address) constant returns(bool[100]) -func (_VMC *VMCCaller) GetShardList(opts *bind.CallOpts, _validatorAddr common.Address) ([100]bool, error) { - var ( - ret0 = new([100]bool) - ) - out := ret0 - err := _VMC.contract.Call(opts, out, "getShardList", _validatorAddr) - return *ret0, err -} - -// GetShardList is a free data retrieval call binding the contract method 0x5e57c86c. -// -// Solidity: function getShardList(_validatorAddr address) constant returns(bool[100]) -func (_VMC *VMCSession) GetShardList(_validatorAddr common.Address) ([100]bool, error) { - return _VMC.Contract.GetShardList(&_VMC.CallOpts, _validatorAddr) -} - -// GetShardList is a free data retrieval call binding the contract method 0x5e57c86c. -// -// Solidity: function getShardList(_validatorAddr address) constant returns(bool[100]) -func (_VMC *VMCCallerSession) GetShardList(_validatorAddr common.Address) ([100]bool, error) { - return _VMC.Contract.GetShardList(&_VMC.CallOpts, _validatorAddr) -} - -// GetValidatorsMaxIndex is a free data retrieval call binding the contract method 0x2b3407f9. -// -// Solidity: function getValidatorsMaxIndex() constant returns(int256) -func (_VMC *VMCCaller) GetValidatorsMaxIndex(opts *bind.CallOpts) (*big.Int, error) { - var ( - ret0 = new(*big.Int) - ) - out := ret0 - err := _VMC.contract.Call(opts, out, "getValidatorsMaxIndex") - return *ret0, err -} - -// GetValidatorsMaxIndex is a free data retrieval call binding the contract method 0x2b3407f9. -// -// Solidity: function getValidatorsMaxIndex() constant returns(int256) -func (_VMC *VMCSession) GetValidatorsMaxIndex() (*big.Int, error) { - return _VMC.Contract.GetValidatorsMaxIndex(&_VMC.CallOpts) -} - -// GetValidatorsMaxIndex is a free data retrieval call binding the contract method 0x2b3407f9. -// -// Solidity: function getValidatorsMaxIndex() constant returns(int256) -func (_VMC *VMCCallerSession) GetValidatorsMaxIndex() (*big.Int, error) { - return _VMC.Contract.GetValidatorsMaxIndex(&_VMC.CallOpts) -} - -// Sample is a free data retrieval call binding the contract method 0xa8c57753. +// GetEligibleProposer is a free data retrieval call binding the contract method 0xe29de3ad. // -// Solidity: function sample(_shardId int256) constant returns(address) -func (_VMC *VMCCaller) Sample(opts *bind.CallOpts, _shardId *big.Int) (common.Address, 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(common.Address) ) out := ret0 - err := _VMC.contract.Call(opts, out, "sample", _shardId) + err := _VMC.contract.Call(opts, out, "getEligibleProposer", _shardId, _period) return *ret0, err } -// Sample is a free data retrieval call binding the contract method 0xa8c57753. +// GetEligibleProposer is a free data retrieval call binding the contract method 0xe29de3ad. // -// 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 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) } -// Sample is a free data retrieval call binding the contract method 0xa8c57753. +// GetEligibleProposer is a free data retrieval call binding the contract method 0xe29de3ad. // -// 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 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) } // ShardCount is a free data retrieval call binding the contract method 0x04e9c77a. @@ -633,46 +237,46 @@ func (_VMC *VMCCallerSession) ShardCount() (*big.Int, error) { return _VMC.Contract.ShardCount(&_VMC.CallOpts) } -// 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, _parentCollationHash bytes32, _txListRoot bytes32, _collationCoinbase address, _postStateRoot bytes32, _receiptRoot bytes32, _collationNumber int256) returns(bool) +func (_VMC *VMCTransactor) AddHeader(opts *bind.TransactOpts, _shardId *big.Int, _expectedPeriodNumber *big.Int, _periodStartPrevHash [32]byte, _parentCollationHash [32]byte, _txListRoot [32]byte, _collationCoinbase common.Address, _postStateRoot [32]byte, _receiptRoot [32]byte, _collationNumber *big.Int) (*types.Transaction, error) { + return _VMC.contract.Transact(opts, "addHeader", _shardId, _expectedPeriodNumber, _periodStartPrevHash, _parentCollationHash, _txListRoot, _collationCoinbase, _postStateRoot, _receiptRoot, _collationNumber) } -// 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 *VMCSession) AddHeader(_header []byte) (*types.Transaction, error) { - return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _header) +// Solidity: function addHeader(_shardId int256, _expectedPeriodNumber uint256, _periodStartPrevHash bytes32, _parentCollationHash bytes32, _txListRoot bytes32, _collationCoinbase address, _postStateRoot bytes32, _receiptRoot bytes32, _collationNumber int256) returns(bool) +func (_VMC *VMCSession) AddHeader(_shardId *big.Int, _expectedPeriodNumber *big.Int, _periodStartPrevHash [32]byte, _parentCollationHash [32]byte, _txListRoot [32]byte, _collationCoinbase common.Address, _postStateRoot [32]byte, _receiptRoot [32]byte, _collationNumber *big.Int) (*types.Transaction, error) { + return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _shardId, _expectedPeriodNumber, _periodStartPrevHash, _parentCollationHash, _txListRoot, _collationCoinbase, _postStateRoot, _receiptRoot, _collationNumber) } -// 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 *VMCTransactorSession) AddHeader(_header []byte) (*types.Transaction, error) { - return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _header) +// Solidity: function addHeader(_shardId int256, _expectedPeriodNumber uint256, _periodStartPrevHash bytes32, _parentCollationHash bytes32, _txListRoot bytes32, _collationCoinbase address, _postStateRoot bytes32, _receiptRoot bytes32, _collationNumber int256) returns(bool) +func (_VMC *VMCTransactorSession) AddHeader(_shardId *big.Int, _expectedPeriodNumber *big.Int, _periodStartPrevHash [32]byte, _parentCollationHash [32]byte, _txListRoot [32]byte, _collationCoinbase common.Address, _postStateRoot [32]byte, _receiptRoot [32]byte, _collationNumber *big.Int) (*types.Transaction, error) { + return _VMC.Contract.AddHeader(&_VMC.TransactOpts, _shardId, _expectedPeriodNumber, _periodStartPrevHash, _parentCollationHash, _txListRoot, _collationCoinbase, _postStateRoot, _receiptRoot, _collationNumber) } -// Deposit is a paid mutator transaction binding the contract method 0xf340fa01. +// Deposit is a paid mutator transaction binding the contract method 0xd0e30db0. // -// Solidity: function deposit(_returnAddr address) returns(int256) -func (_VMC *VMCTransactor) Deposit(opts *bind.TransactOpts, _returnAddr common.Address) (*types.Transaction, error) { - return _VMC.contract.Transact(opts, "deposit", _returnAddr) +// Solidity: function deposit() returns(int256) +func (_VMC *VMCTransactor) Deposit(opts *bind.TransactOpts) (*types.Transaction, error) { + return _VMC.contract.Transact(opts, "deposit") } -// Deposit is a paid mutator transaction binding the contract method 0xf340fa01. +// Deposit is a paid mutator transaction binding the contract method 0xd0e30db0. // -// Solidity: function deposit(_returnAddr address) returns(int256) -func (_VMC *VMCSession) Deposit(_returnAddr common.Address) (*types.Transaction, error) { - return _VMC.Contract.Deposit(&_VMC.TransactOpts, _returnAddr) +// 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 0xf340fa01. +// Deposit is a paid mutator transaction binding the contract method 0xd0e30db0. // -// Solidity: function deposit(_returnAddr address) returns(int256) -func (_VMC *VMCTransactorSession) Deposit(_returnAddr common.Address) (*types.Transaction, error) { - return _VMC.Contract.Deposit(&_VMC.TransactOpts, _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. diff --git a/sharding/contracts/validator_manager.sol b/sharding/contracts/validator_manager.sol index af4925dde5d7..cc4053dfdeb7 100644 --- a/sharding/contracts/validator_manager.sol +++ b/sharding/contracts/validator_manager.sol @@ -44,7 +44,7 @@ contract VMC { // Constant values uint constant periodLength = 5; - int constant shardCount = 100; + int constant public shardCount = 100; // The exact deposit size which you have to deposit to become a validator uint constant depositSize = 100 ether; // Number of periods ahead of current period, which the contract From 7f9d88051dd0791ebf0e6417be7ef4e0aef7fadd Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 5 Feb 2018 12:00:29 -0600 Subject: [PATCH 20/25] proper error handling in collator.go --- sharding/client.go | 6 +++--- sharding/collator.go | 17 ++++++++++------- sharding/collator_test.go | 0 sharding/vmc.go | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 sharding/collator_test.go diff --git a/sharding/client.go b/sharding/client.go index 7fb1c376e6cc..316ba0a65363 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -75,9 +75,9 @@ func (c *Client) Start() error { // 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 - // if err := initVMCValidator(c); err != nil { - // return err - // } + if err := initVMCValidator(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 diff --git a/sharding/collator.go b/sharding/collator.go index b67fe7d7afe2..faa5e4306bd3 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -18,7 +18,7 @@ func subscribeBlockHeaders(c *Client) error { _, err := c.client.SubscribeNewHead(context.Background(), headerChan) if err != nil { - return err + return fmt.Errorf("unable to subscribe to incoming headers. %v", err) } log.Info("listening for new headers...") @@ -31,7 +31,7 @@ func subscribeBlockHeaders(c *Client) error { // TODO: Only run this code on certain periods? err := watchShards(c, head) if err != nil { - return err + return fmt.Errorf("unable to watch shards. %v", err) } } } @@ -48,13 +48,13 @@ func watchShards(c *Client, head *types.Header) error { } if err := c.unlockAccount(accounts[0]); err != nil { - return err + return fmt.Errorf("cannot unlock account. %v", err) } ops := bind.CallOpts{} count, err := c.vmc.VMCCaller.ShardCount(&ops) if err != nil { - return err + return fmt.Errorf("unable to fetch shard count. %v", err) } s := 0 @@ -62,12 +62,15 @@ func watchShards(c *Client, head *types.Header) error { // Checks if we are an eligible proposer according to the VMC addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(s)) if err != nil { - return err + return fmt.Errorf("cannot fetch eligible collation proposer. %v", err) } // if the address is the coinbase addr (current node running the sharding // clint, then we propose a new collation) if addr == accounts[0].Address { - proposeCollation() + err := proposeCollation() + if err != nil { + return fmt.Errorf("could not propose collation. %v", err) + } } s++ } @@ -75,6 +78,6 @@ func watchShards(c *Client, head *types.Header) error { return nil } -func proposeCollation() { +func proposeCollation() error { return nil } diff --git a/sharding/collator_test.go b/sharding/collator_test.go new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sharding/vmc.go b/sharding/vmc.go index 22007056f2af..594e767b6983 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -72,7 +72,7 @@ func initVMC(c *Client) error { func initVMCValidator(c *Client) error { // TODO: Check if account is already in validator set. Fetch this From - // the VMC contract's validator set. + // the VMC contract's validator set // Unlocks the current account from the keystore accounts := c.keystore.Accounts() From e754f7c3cf03a28e8b5b0ae7c258278ada4a2ba4 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Mon, 5 Feb 2018 22:41:40 -0600 Subject: [PATCH 21/25] propose collation called on geteligibleproposer --- sharding/collator.go | 29 +++++++++++++---------------- sharding/collator_test.go | 16 ++++++++++++---- sharding/vmc.go | 2 +- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/sharding/collator.go b/sharding/collator.go index 77aa121dfeaa..7d6f41f8d148 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -6,6 +6,7 @@ import ( "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 @@ -51,27 +52,23 @@ func watchShards(c *Client, head *types.Header) error { return fmt.Errorf("cannot unlock account. %v", err) } - ops := bind.CallOpts{} - count, err := c.vmc.VMCCaller.ShardCount(&ops) - if err != nil { - return fmt.Errorf("unable to fetch shard count. %v", err) - } - + log.Info(fmt.Sprint("watching shards...")) s := 0 - for s < int(count.Int64()) { + for s < shardCount { // Checks if we are an eligible proposer according to the VMC - addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(s)) - if err != nil { - return fmt.Errorf("cannot fetch eligible collation proposer. %v", err) - } - // if the address is the coinbase addr (current node running the sharding - // clint, then we propose a new collation) - if addr == accounts[0].Address { - err := proposeCollation() + ops := bind.CallOpts{} + period := head.Number.Div(head.Number, big.NewInt(int64(periodLength))) + addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(int64(s)), period) + + // 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) } } + s++ } @@ -104,6 +101,6 @@ func proposeCollation(shardID int) error { // 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(fmt.Sprint("propose collation called")) return nil } diff --git a/sharding/collator_test.go b/sharding/collator_test.go index 29ca48f1ec04..274ebc2d4d85 100644 --- a/sharding/collator_test.go +++ b/sharding/collator_test.go @@ -1,11 +1,19 @@ package sharding import ( + "github.com/ethereum/go-ethereum/common/hexutil" + "sync" "testing" ) -func TestDeposit(t *testing.T) { - if 0 != 0 { - t.Errorf("test incorrect") - } +// FakeEthService based on implementation of internal/ethapi.Client +type FakeEthService struct { + mu sync.Mutex + + getCodeResp hexutil.Bytes + getCodeErr error +} + +func TestSubscribeHeaders(t *testing.T) { + } diff --git a/sharding/vmc.go b/sharding/vmc.go index 594e767b6983..5184ff8e45da 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -97,7 +97,7 @@ func initVMCValidator(c *Client) error { }, } - _, err := c.vmc.VMCTransactor.Deposit(&ops, accounts[0].Address) + _, err := c.vmc.VMCTransactor.Deposit(&ops) if err != nil { return fmt.Errorf("unable to deposit eth and become a validator: %v", err) } From df7ee2943bc3147424cd2dc2f91997ba4dd458b3 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 6 Feb 2018 14:04:45 -0600 Subject: [PATCH 22/25] adjust code to reviews, abstract funcs, clean up files --- password.txt | 1 - sharding/client.go | 38 ++++++++++++++++++++++++---- sharding/collator.go | 37 +++++++++++++-------------- sharding/config.go | 4 +-- sharding/vmc.go | 60 +++++++++----------------------------------- 5 files changed, 65 insertions(+), 75 deletions(-) delete mode 100644 password.txt diff --git a/password.txt b/password.txt deleted file mode 100644 index 9f358a4addef..000000000000 --- a/password.txt +++ /dev/null @@ -1 +0,0 @@ -123456 diff --git a/sharding/client.go b/sharding/client.go index d89c78fe5585..976288972aee 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -1,13 +1,17 @@ package sharding import ( + "context" "fmt" "io/ioutil" "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" @@ -78,7 +82,7 @@ func (c *Client) Start() error { // // TODO: this function should store the validator's VMC index as a property // in the client's struct - if err := initVMCValidator(c); err != nil { + if err := joinValidatorSet(c); err != nil { return err } @@ -95,6 +99,13 @@ func (c *Client) Wait() { // TODO: Blocking lock. } +// 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() { + +} + // dialRPC endpoint to node. func dialRPC(endpoint string) (*rpc.Client, error) { if endpoint == "" { @@ -119,9 +130,26 @@ func (c *Client) unlockAccount(account accounts.Account) error { return c.keystore.Unlock(account, pass) } -// TODO: Watch logs for add_header func calls and update the head collation -// of the client. We can probably store this as a property of the client -// struct -func (c *Client) watchHeaders() { +func (c *Client) createTXOps() (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) + } + + 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 } diff --git a/sharding/collator.go b/sharding/collator.go index 7d6f41f8d148..3b0d7cf58096 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -22,26 +22,27 @@ func subscribeBlockHeaders(c *Client) error { return fmt.Errorf("unable to subscribe to incoming headers. %v", err) } - log.Info("listening for new headers...") + 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())) + log.Info(fmt.Sprintf("Received new header: %v", head.Number.String())) // TODO: Only run this code on certain periods? - err := watchShards(c, head) - if err != nil { + if err := checkShardsForProposal(c, head); err != nil { return fmt.Errorf("unable to watch shards. %v", err) } } } } -// watchShards 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 watchShards(c *Client, head *types.Header) error { +// 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 { @@ -52,31 +53,29 @@ func watchShards(c *Client, head *types.Header) error { return fmt.Errorf("cannot unlock account. %v", err) } - log.Info(fmt.Sprint("watching shards...")) - s := 0 - for s < shardCount { + log.Info("Watching shards...") + for s := int64(0); s < shardCount; s++ { // Checks if we are an eligible proposer according to the VMC - ops := bind.CallOpts{} - period := head.Number.Div(head.Number, big.NewInt(int64(periodLength))) - addr, err := c.vmc.VMCCaller.GetEligibleProposer(&ops, big.NewInt(int64(s)), period) + 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)) + 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) } } - - s++ } return nil } // proposeCollation interacts with the VMC directly to add a collation header -func proposeCollation(shardID int) error { +func proposeCollation(shardID int64) error { // TODO: Adds a collation header to the VMC with the following fields: // [ // shard_id: uint256, @@ -101,6 +100,6 @@ func proposeCollation(shardID int) error { // 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(fmt.Sprint("propose collation called")) + log.Info("Propose collation function called") return nil } 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/vmc.go b/sharding/vmc.go index 5184ff8e45da..fee6daf48dd0 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -5,9 +5,6 @@ import ( "fmt" "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 +14,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() + 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) } @@ -67,41 +50,22 @@ func initVMC(c *Client) error { return nil } -// initVMCValidator checks if the account is a validator in the VMC. If +// 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 initVMCValidator(c *Client) error { +func joinValidatorSet(c *Client) error { // TODO: Check if account is already in validator set. Fetch this From // the VMC contract's validator set - - // Unlocks the current account from the keystore - 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) - } - - // Deposits 100ETH into the VMC from the current account - ops := bind.TransactOpts{ - From: accounts[0].Address, - Value: depositSize, - 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() + if err != nil { + return fmt.Errorf("unable to intiate the deposit transaction: %v", err) } - _, err := c.vmc.VMCTransactor.Deposit(&ops) + 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")) + log.Info(fmt.Sprintf("Deposited 100ETH into contract with transaction hash: %v", tx.Hash())) return nil } From 49e40024c310a1e8fd5c6f3a42229ae60907db34 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 6 Feb 2018 14:08:28 -0600 Subject: [PATCH 23/25] wait func --- cmd/geth/shardingcmd.go | 2 +- sharding/client.go | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) 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 976288972aee..334feb337be5 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -96,7 +96,7 @@ func (c *Client) Start() error { // Wait until sharding client is shutdown. func (c *Client) Wait() { - // TODO: Blocking lock. + log.Info("Sharding client has been shutdown...") } // WatchCollationHeaders checks the logs for add_header func calls @@ -106,14 +106,6 @@ func (c *Client) WatchCollationHeaders() { } -// dialRPC endpoint to node. -func dialRPC(endpoint string) (*rpc.Client, error) { - if endpoint == "" { - endpoint = node.DefaultIPCEndpoint(clientIdentifier) - } - return rpc.Dial(endpoint) -} - // UnlockAccount will unlock the specified account using utils.PasswordFileFlag or empty string if unset. func (c *Client) unlockAccount(account accounts.Account) error { pass := "" @@ -153,3 +145,11 @@ func (c *Client) createTXOps() (bind.TransactOpts, error) { }, nil } + +// dialRPC endpoint to node. +func dialRPC(endpoint string) (*rpc.Client, error) { + if endpoint == "" { + endpoint = node.DefaultIPCEndpoint(clientIdentifier) + } + return rpc.Dial(endpoint) +} From 56f35f0dd7b334f973612e53ad82f6e76a7ff2ea Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 6 Feb 2018 14:22:19 -0600 Subject: [PATCH 24/25] include latest changes with txops and everything running smoothly --- sharding/client.go | 19 +++++++++++++++++-- sharding/collator.go | 2 +- sharding/vmc.go | 7 ++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/sharding/client.go b/sharding/client.go index 334feb337be5..80d85cfaa826 100644 --- a/sharding/client.go +++ b/sharding/client.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io/ioutil" + "math/big" "strings" "github.com/ethereum/go-ethereum/accounts" @@ -122,7 +123,7 @@ func (c *Client) unlockAccount(account accounts.Account) error { return c.keystore.Unlock(account, pass) } -func (c *Client) createTXOps() (bind.TransactOpts, error) { +func (c *Client) createTXOps(value *big.Int) (bind.TransactOpts, error) { accounts := c.keystore.Accounts() if len(accounts) == 0 { @@ -133,8 +134,22 @@ func (c *Client) createTXOps() (bind.TransactOpts, error) { 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, + 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 { diff --git a/sharding/collator.go b/sharding/collator.go index 3b0d7cf58096..42db582f763e 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -53,7 +53,7 @@ func checkShardsForProposal(c *Client, head *types.Header) error { return fmt.Errorf("cannot unlock account. %v", err) } - log.Info("Watching shards...") + 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)) diff --git a/sharding/vmc.go b/sharding/vmc.go index fee6daf48dd0..c423249d616e 100644 --- a/sharding/vmc.go +++ b/sharding/vmc.go @@ -3,6 +3,7 @@ package sharding import ( "context" "fmt" + "math/big" "time" "github.com/ethereum/go-ethereum/log" @@ -20,7 +21,7 @@ func initVMC(c *Client) error { if len(b) == 0 { log.Info(fmt.Sprintf("No validator management contract found at %s. Deploying new contract.", validatorManagerAddress.String())) - txOps, err := c.createTXOps() + txOps, err := c.createTXOps(big.NewInt(0)) if err != nil { return fmt.Errorf("unable to intiate the transaction: %v", err) } @@ -56,7 +57,7 @@ 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() + txOps, err := c.createTXOps(depositSize) if err != nil { return fmt.Errorf("unable to intiate the deposit transaction: %v", err) } @@ -65,7 +66,7 @@ func joinValidatorSet(c *Client) error { 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: %v", tx.Hash())) + log.Info(fmt.Sprintf("Deposited 100ETH into contract with transaction hash: %s", tx.Hash().String())) return nil } From 9f11c3654dc20a11ecbae29b6756ab0ed1971bc8 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 6 Feb 2018 17:06:47 -0800 Subject: [PATCH 25/25] adjust all for review, create test files --- sharding/collator.go | 2 +- sharding/collator_test.go | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/sharding/collator.go b/sharding/collator.go index 42db582f763e..a4662643b498 100644 --- a/sharding/collator.go +++ b/sharding/collator.go @@ -9,7 +9,7 @@ import ( "math/big" ) -// subscribeBlockHeaders checks incoming block headers and determines if +// 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 diff --git a/sharding/collator_test.go b/sharding/collator_test.go index 274ebc2d4d85..584be3b19d29 100644 --- a/sharding/collator_test.go +++ b/sharding/collator_test.go @@ -1,19 +1,29 @@ package sharding import ( - "github.com/ethereum/go-ethereum/common/hexutil" - "sync" + "context" + "fmt" "testing" + + "github.com/ethereum/go-ethereum/core/types" ) -// FakeEthService based on implementation of internal/ethapi.Client -type FakeEthService struct { - mu sync.Mutex +type FakeClient struct { + client *FakeEthClient +} + +type FakeEthClient struct{} - getCodeResp hexutil.Bytes - getCodeErr error +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) + } }