modifying the sharding client to listen for incoming tx's in the pool

Former-commit-id: 2baeab1f2d2ca80fd7c93f73a094a1b9754c9ea4 [formerly 4783c52f7f1998b97f97734b8e77e97fed0295d9]
Former-commit-id: 1bd46ad5776d2ffcf2bf5c04cbc8d7a221405871
This commit is contained in:
Raul Jordan
2018-01-28 15:10:26 -06:00
parent 8406d59f3d
commit 7569bce70f
4 changed files with 1 additions and 135 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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")
}
}