sharding: Completely Remove Geth, Create a Single Sharding Entry Point That Builds (#238)

Former-commit-id: b853fd1c3ea2284d30d7f3032cf83287c7198c10 [formerly c012daacceec9cb3497f1d066ee3ca2d20aa5b14]
Former-commit-id: 0a5a60c296f878c7057b25fc759dec2487363d30
This commit is contained in:
Raul Jordan
2018-07-08 21:40:34 -05:00
committed by GitHub
parent aae781531a
commit 2624cd2b3c
53 changed files with 315 additions and 592 deletions

5
.gitignore vendored
View File

@@ -1,2 +1,5 @@
# Ignore bazel directories
bazel-*
bazel-*
build
.DS_Store
.gitattributes

View File

@@ -36,11 +36,10 @@ go_repository(
commit = "eb95493d32b6e1eb1cad63518637e1a958632389",
)
# TODO: Update this to use github.com/urfave/cli.
go_repository(
name = "in_gopkg_urfave_cli_v1",
importpath = "gopkg.in/urfave/cli.v1",
commit = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1",
name = "com_github_urfave_cli",
importpath = "github.com/urfave/cli",
commit = "8e01ec4cd3e2d84ab2fe90d8210528ffbb06d8ff",
)
go_repository(
@@ -48,3 +47,15 @@ go_repository(
importpath = "github.com/fjl/memsize",
commit = "ca190fb6ffbc076ff49197b7168a760f30182d2e",
)
go_repository(
name = "com_github_mattn_go_colorable",
importpath = "github.com/mattn/go-colorable",
commit = "efa589957cd060542a26d2dd7832fd6a6c6c3ade",
)
go_repository(
name = "com_github_mattn_go_isatty",
importpath = "github.com/mattn/go-isatty",
commit = "6ca4dbf54d38eea1a992b3c722a76a5d1c4cb25c",
)

View File

@@ -1,24 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "go_default_library",
srcs = [
"main.go",
"shardingcmd.go",
"usage.go",
],
importpath = "github.com/prysmaticlabs/geth-sharding/cmd/geth",
visibility = ["//visibility:private"],
deps = [
"//cmd/utils:go_default_library",
"//internal/debug:go_default_library",
"//sharding/node:go_default_library",
"@in_gopkg_urfave_cli_v1//:go_default_library",
],
)
go_binary(
name = "geth",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)

View File

@@ -1,76 +0,0 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// geth is the official command-line client for Ethereum.
package main
import (
"fmt"
"os"
"runtime"
"sort"
"github.com/prysmaticlabs/geth-sharding/cmd/utils"
"github.com/prysmaticlabs/geth-sharding/internal/debug"
cli "gopkg.in/urfave/cli.v1"
)
var (
// Git SHA1 commit hash of the release (set via linker flags)
gitCommit = ""
// The app that holds all commands and flags.
app = utils.NewApp(gitCommit, "the go-ethereum command line interface")
// flags that configure the node
nodeFlags = []cli.Flag{
utils.DataDirFlag,
utils.PasswordFileFlag,
utils.NetworkIdFlag,
utils.DepositFlag,
utils.ActorFlag,
utils.ShardIDFlag,
}
)
func init() {
// Initialize the CLI app and start Geth
app.HideVersion = true // we have a command to print the version
app.Commands = []cli.Command{
// See shardingcmd.go:
shardingCommand,
}
sort.Sort(cli.CommandsByName(app.Commands))
app.Flags = append(app.Flags, nodeFlags...)
app.Flags = append(app.Flags, debug.Flags...)
app.Before = func(ctx *cli.Context) error {
runtime.GOMAXPROCS(runtime.NumCPU())
return debug.Setup(ctx)
}
app.After = func(ctx *cli.Context) error {
debug.Exit()
return nil
}
}
func main() {
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

View File

@@ -1,44 +0,0 @@
package main
import (
"fmt"
"github.com/prysmaticlabs/geth-sharding/cmd/utils"
"github.com/prysmaticlabs/geth-sharding/internal/debug"
node "github.com/prysmaticlabs/geth-sharding/sharding/node"
cli "gopkg.in/urfave/cli.v1"
)
var (
flags = []cli.Flag{utils.ActorFlag, utils.DataDirFlag, utils.PasswordFileFlag, utils.NetworkIdFlag, utils.IPCPathFlag, utils.DepositFlag, utils.ShardIDFlag}
shardingCommand = cli.Command{
Action: utils.MigrateFlags(shardingCmd),
Name: "sharding",
Usage: "Start a sharding-enabled node",
ArgsUsage: "[endpoint]",
Flags: append(flags, debug.Flags...),
Category: "SHARDING COMMANDS",
Description: `
Launches a sharding node that manages services related to submitting collations to a Sharding Manager Contract, notary and proposer services, and shardp2p connections. This feature is a work in progress.
`,
}
)
// shardingCmd is the main cmd line entry point for starting a sharding-enabled node.
// A sharding node launches a suite of services including notary services,
// proposer services, and a shardp2p protocol.
func shardingCmd(ctx *cli.Context) error {
if err := debug.Setup(ctx); err != nil {
return err
}
// configures a sharding-enabled node using the cli's context.
shardingNode, err := node.New(ctx)
if err != nil {
return fmt.Errorf("could not initialize sharding node instance: %v", err)
}
// starts a connection to a geth node and kicks off every registered service.
shardingNode.Start()
return nil
}

View File

@@ -1,173 +0,0 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// Contains the geth command usage template and generator.
package main
import (
"io"
"sort"
"strings"
"github.com/prysmaticlabs/geth-sharding/cmd/utils"
cli "gopkg.in/urfave/cli.v1"
)
// AppHelpTemplate is the test template for the default, global app help topic.
var AppHelpTemplate = `NAME:
{{.App.Name}} - {{.App.Usage}}
Copyright 2013-2018 The go-ethereum Authors
USAGE:
{{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}}
{{if .App.Version}}
VERSION:
{{.App.Version}}
{{end}}{{if len .App.Authors}}
AUTHOR(S):
{{range .App.Authors}}{{ . }}{{end}}
{{end}}{{if .App.Commands}}
COMMANDS:
{{range .App.Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}{{end}}{{if .FlagGroups}}
{{range .FlagGroups}}{{.Name}} OPTIONS:
{{range .Flags}}{{.}}
{{end}}
{{end}}{{end}}{{if .App.Copyright }}
COPYRIGHT:
{{.App.Copyright}}
{{end}}
`
// flagGroup is a collection of flags belonging to a single topic.
type flagGroup struct {
Name string
Flags []cli.Flag
}
// AppHelpFlagGroups is the application flags, grouped by functionality.
var AppHelpFlagGroups = []flagGroup{
{
Name: "SHARDING",
Flags: []cli.Flag{
utils.ActorFlag,
utils.DepositFlag,
},
},
}
// byCategory sorts an array of flagGroup by Name in the order
// defined in AppHelpFlagGroups.
type byCategory []flagGroup
func (a byCategory) Len() int { return len(a) }
func (a byCategory) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a byCategory) Less(i, j int) bool {
iCat, jCat := a[i].Name, a[j].Name
iIdx, jIdx := len(AppHelpFlagGroups), len(AppHelpFlagGroups) // ensure non categorized flags come last
for i, group := range AppHelpFlagGroups {
if iCat == group.Name {
iIdx = i
}
if jCat == group.Name {
jIdx = i
}
}
return iIdx < jIdx
}
func flagCategory(flag cli.Flag) string {
for _, category := range AppHelpFlagGroups {
for _, flg := range category.Flags {
if flg.GetName() == flag.GetName() {
return category.Name
}
}
}
return "MISC"
}
func init() {
// Override the default app help template
cli.AppHelpTemplate = AppHelpTemplate
// Define a one shot struct to pass to the usage template
type helpData struct {
App interface{}
FlagGroups []flagGroup
}
// Override the default app help printer, but only for the global app help
originalHelpPrinter := cli.HelpPrinter
cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
if tmpl == AppHelpTemplate {
// Iterate over all the flags and add any uncategorized ones
categorized := make(map[string]struct{})
for _, group := range AppHelpFlagGroups {
for _, flag := range group.Flags {
categorized[flag.String()] = struct{}{}
}
}
uncategorized := []cli.Flag{}
for _, flag := range data.(*cli.App).Flags {
if _, ok := categorized[flag.String()]; !ok {
if strings.HasPrefix(flag.GetName(), "dashboard") {
continue
}
uncategorized = append(uncategorized, flag)
}
}
if len(uncategorized) > 0 {
// Append all ungategorized options to the misc group
miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags)
AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...)
// Make sure they are removed afterwards
defer func() {
AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs]
}()
}
// Render out custom usage screen
originalHelpPrinter(w, tmpl, helpData{data, AppHelpFlagGroups})
} else if tmpl == utils.CommandHelpTemplate {
// Iterate over all command specific flags and categorize them
categorized := make(map[string][]cli.Flag)
for _, flag := range data.(cli.Command).Flags {
if _, ok := categorized[flag.String()]; !ok {
categorized[flagCategory(flag)] = append(categorized[flagCategory(flag)], flag)
}
}
// sort to get a stable ordering
sorted := make([]flagGroup, 0, len(categorized))
for cat, flgs := range categorized {
sorted = append(sorted, flagGroup{cat, flgs})
}
sort.Sort(byCategory(sorted))
// add sorted array to data and render with default printer
originalHelpPrinter(w, tmpl, map[string]interface{}{
"cmd": data,
"categorizedFlags": sorted,
})
} else {
originalHelpPrinter(w, tmpl, data)
}
}
}

View File

@@ -1,23 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"customflags.go",
"flags.go",
],
importpath = "github.com/prysmaticlabs/geth-sharding/cmd/utils",
visibility = ["//visibility:public"],
deps = [
"//sharding/params:go_default_library",
"@com_github_ethereum_go_ethereum//node:go_default_library",
"@com_github_ethereum_go_ethereum//params:go_default_library",
"@in_gopkg_urfave_cli_v1//:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["customflags_test.go"],
embed = [":go_default_library"],
)

View File

@@ -18,6 +18,7 @@ go_library(
"@com_github_ethereum_go_ethereum//metrics:go_default_library",
"@com_github_ethereum_go_ethereum//metrics/exp:go_default_library",
"@com_github_fjl_memsize//memsizeui:go_default_library",
"@in_gopkg_urfave_cli_v1//:go_default_library",
"@com_github_mattn_go_colorable//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
)

View File

@@ -29,7 +29,8 @@ import (
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/metrics/exp"
"github.com/fjl/memsize/memsizeui"
"gopkg.in/urfave/cli.v1"
colorable "github.com/mattn/go-colorable"
"github.com/urfave/cli"
)
var Memsize memsizeui.Handler
@@ -99,6 +100,9 @@ var glogger *log.GlogHandler
func init() {
usecolor := term.IsTty(os.Stderr.Fd()) && os.Getenv("TERM") != "dumb"
output := io.Writer(os.Stderr)
if usecolor {
output = colorable.NewColorableStderr()
}
glogger = log.NewGlogHandler(log.StreamHandler(output, log.TerminalFormat(usecolor)))
}

View File

@@ -1,38 +1,20 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "go_default_library",
srcs = [
"collation.go",
"interfaces.go",
"shard.go",
],
srcs = ["main.go"],
importpath = "github.com/prysmaticlabs/geth-sharding/sharding",
visibility = ["//visibility:public"],
deps = [
"//internal/debug:go_default_library",
"//sharding/node:go_default_library",
"//sharding/utils:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_ethereum_go_ethereum//crypto/sha3:go_default_library",
"@com_github_ethereum_go_ethereum//ethdb:go_default_library",
"@com_github_ethereum_go_ethereum//rlp:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = [
"collation_test.go",
"shard_test.go",
],
go_binary(
name = "sharding",
embed = [":go_default_library"],
deps = [
"//sharding/database:go_default_library",
"//sharding/utils:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_ethereum_go_ethereum//crypto/sha3:go_default_library",
"@com_github_ethereum_go_ethereum//ethdb:go_default_library",
"@com_github_ethereum_go_ethereum//rlp:go_default_library",
],
visibility = ["//visibility:public"],
)

View File

@@ -23,8 +23,8 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//sharding:go_default_library",
"//sharding/internal:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//ethdb:go_default_library",
"@com_github_ethereum_go_ethereum//log:go_default_library",
],

View File

@@ -5,12 +5,12 @@ import (
"testing"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
internal "github.com/prysmaticlabs/geth-sharding/sharding/internal"
)
// Verifies that ShardDB implements the sharding Service inteface.
var _ = sharding.Service(&ShardDB{})
var _ = types.Service(&ShardDB{})
var testDB *ShardDB

View File

@@ -12,7 +12,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/prysmaticlabs/geth-sharding/sharding/contracts"
shardparams "github.com/prysmaticlabs/geth-sharding/sharding/params"
@@ -59,7 +59,7 @@ func (m *MockClient) WaitForTransaction(ctx context.Context, hash common.Hash, d
return nil
}
func (m *MockClient) TransactionReceipt(hash common.Hash) (*types.Receipt, error) {
func (m *MockClient) TransactionReceipt(hash common.Hash) (*gethTypes.Receipt, error) {
return m.Backend.TransactionReceipt(context.Background(), hash)
}
@@ -96,12 +96,12 @@ func (m *MockClient) FastForward(p int) {
}
}
func (m *MockClient) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) {
func (m *MockClient) SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error) {
return nil, nil
}
func (m *MockClient) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
return types.NewBlockWithHeader(&types.Header{Number: big.NewInt(m.BlockNumber)}), nil
func (m *MockClient) BlockByNumber(ctx context.Context, number *big.Int) (*gethTypes.Block, error) {
return gethTypes.NewBlockWithHeader(&gethTypes.Header{Number: big.NewInt(m.BlockNumber)}), nil
}
func TransactOpts() *bind.TransactOpts {

72
sharding/main.go Normal file
View File

@@ -0,0 +1,72 @@
package main
import (
"fmt"
"os"
"runtime"
"github.com/prysmaticlabs/geth-sharding/internal/debug"
"github.com/prysmaticlabs/geth-sharding/sharding/node"
"github.com/prysmaticlabs/geth-sharding/sharding/utils"
"github.com/urfave/cli"
)
func startNode(ctx *cli.Context) error {
if err := debug.Setup(ctx); err != nil {
return err
}
shardingNode, err := node.New(ctx)
if err != nil {
return err
}
// starts a connection to a beacon node and kicks off every registered service.
shardingNode.Start()
return nil
}
func main() {
cli.AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}
{{if len .Authors}}
AUTHOR:
{{range .Authors}}{{ . }}{{end}}
{{end}}{{if .Commands}}
GLOBAL OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}{{if .Copyright }}
COPYRIGHT:
{{.Copyright}}
{{end}}{{if .Version}}
VERSION:
{{.Version}}
{{end}}
`
app := cli.NewApp()
app.Name = "sharding"
app.Usage = `launches a sharding client that interacts with a beacon chain, starts proposer services, shardp2p connections, and more
`
app.Action = startNode
app.Flags = []cli.Flag{utils.ActorFlag, utils.DataDirFlag, utils.PasswordFileFlag, utils.NetworkIdFlag, utils.IPCPathFlag, utils.DepositFlag, utils.ShardIDFlag}
app.Flags = append(app.Flags, debug.Flags...)
app.Before = func(ctx *cli.Context) error {
runtime.GOMAXPROCS(runtime.NumCPU())
return debug.Setup(ctx)
}
app.After = func(ctx *cli.Context) error {
debug.Exit()
return nil
}
if err := app.Run(os.Args); err != nil {
if _, err := fmt.Fprintln(os.Stderr, err); err != nil {
panic(err)
}
os.Exit(1)
}
}

View File

@@ -30,8 +30,8 @@ go_test(
srcs = ["smc_client_test.go"],
embed = [":go_default_library"],
deps = [
"//sharding:go_default_library",
"//sharding/contracts:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind/backends:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core:go_default_library",

View File

@@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/prysmaticlabs/geth-sharding/sharding/contracts"
)
@@ -45,15 +45,15 @@ type ContractTransactor interface {
type EthClient interface {
Account() *accounts.Account
WaitForTransaction(ctx context.Context, hash common.Hash, durationInSeconds time.Duration) error
TransactionReceipt(hash common.Hash) (*types.Receipt, error)
TransactionReceipt(hash common.Hash) (*gethTypes.Receipt, error)
DepositFlag() bool
}
// Reader defines an interface for a struct that can read mainchain information
// such as blocks, transactions, receipts, and more. Useful for testing.
type Reader interface {
BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)
SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error)
BlockByNumber(ctx context.Context, number *big.Int) (*gethTypes.Block, error)
SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error)
}
// RecordFetcher serves as an interface for a struct that can fetch collation information

View File

@@ -18,7 +18,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "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"
@@ -115,7 +115,7 @@ func (s *SMCClient) CreateTXOpts(value *big.Int) (*bind.TransactOpts, error) {
return &bind.TransactOpts{
From: account.Address,
Value: value,
Signer: func(signer types.Signer, addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
Signer: func(signer gethTypes.Signer, addr common.Address, tx *gethTypes.Transaction) (*gethTypes.Transaction, error) {
networkID, err := s.client.NetworkID(context.Background())
if err != nil {
return nil, fmt.Errorf("unable to fetch networkID: %v", err)
@@ -184,7 +184,7 @@ func (s *SMCClient) WaitForTransaction(ctx context.Context, hash common.Hash, du
// TransactionReceipt allows an SMCClient to retrieve transaction receipts on
// the mainchain by hash.
func (s *SMCClient) TransactionReceipt(hash common.Hash) (*types.Receipt, error) {
func (s *SMCClient) TransactionReceipt(hash common.Hash) (*gethTypes.Receipt, error) {
receipt, err := s.client.TransactionReceipt(context.Background(), hash)
if err != nil {

View File

@@ -11,12 +11,12 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/contracts"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
)
var (
@@ -26,7 +26,7 @@ var (
)
// Verifies that SMCCLient implements the sharding Service inteface.
var _ = sharding.Service(&SMCClient{})
var _ = types.Service(&SMCClient{})
// mockClient is struct to implement the smcClient methods for testing.
type mockClient struct {
@@ -41,7 +41,7 @@ type mockClient struct {
// it is replaced by the simulated backend.
func (m *mockClient) WaitForTransaction(ctx context.Context, hash common.Hash, durationInSeconds time.Duration) error {
var receipt *types.Receipt
var receipt *gethTypes.Receipt
ctxTimeout, cancel := context.WithTimeout(ctx, durationInSeconds*time.Second)
@@ -64,9 +64,9 @@ func (m *mockClient) WaitForTransaction(ctx context.Context, hash common.Hash, d
// Creates and send Fake Transactions to the backend to be mined, takes in the context and
// the current blocknumber as an argument and returns the signed transaction after it has been sent.
func (m *mockClient) CreateAndSendFakeTx(ctx context.Context) (*types.Transaction, error) {
tx := types.NewTransaction(m.blockNumber.Uint64(), common.HexToAddress("0x"), nil, 50000, nil, nil)
signedtx, err := types.SignTx(tx, types.MakeSigner(&params.ChainConfig{}, m.blockNumber), key)
func (m *mockClient) CreateAndSendFakeTx(ctx context.Context) (*gethTypes.Transaction, error) {
tx := gethTypes.NewTransaction(m.blockNumber.Uint64(), common.HexToAddress("0x"), nil, 50000, nil, nil)
signedtx, err := gethTypes.SignTx(tx, gethTypes.MakeSigner(&params.ChainConfig{}, m.blockNumber), key)
if err != nil {
return nil, err
}

View File

@@ -6,9 +6,6 @@ go_library(
importpath = "github.com/prysmaticlabs/geth-sharding/sharding/node",
visibility = ["//visibility:public"],
deps = [
"//cmd/utils:go_default_library",
"//internal/debug:go_default_library",
"//sharding:go_default_library",
"//sharding/database:go_default_library",
"//sharding/mainchain:go_default_library",
"//sharding/notary:go_default_library",
@@ -19,10 +16,12 @@ go_library(
"//sharding/simulator:go_default_library",
"//sharding/syncer:go_default_library",
"//sharding/txpool:go_default_library",
"//sharding/types:go_default_library",
"//sharding/utils:go_default_library",
"@com_github_ethereum_go_ethereum//event:go_default_library",
"@com_github_ethereum_go_ethereum//log:go_default_library",
"@com_github_ethereum_go_ethereum//node:go_default_library",
"@in_gopkg_urfave_cli_v1//:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
)
@@ -31,7 +30,7 @@ go_test(
srcs = ["backend_test.go"],
embed = [":go_default_library"],
deps = [
"//sharding:go_default_library",
"@in_gopkg_urfave_cli_v1//:go_default_library",
"//sharding/types:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
)

View File

@@ -13,13 +13,9 @@ import (
"syscall"
"time"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/prysmaticlabs/geth-sharding/internal/debug"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/cmd/utils"
"github.com/prysmaticlabs/geth-sharding/sharding/database"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
"github.com/prysmaticlabs/geth-sharding/sharding/notary"
@@ -30,7 +26,9 @@ import (
"github.com/prysmaticlabs/geth-sharding/sharding/simulator"
"github.com/prysmaticlabs/geth-sharding/sharding/syncer"
"github.com/prysmaticlabs/geth-sharding/sharding/txpool"
"gopkg.in/urfave/cli.v1"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
"github.com/prysmaticlabs/geth-sharding/sharding/utils"
"github.com/urfave/cli"
)
const shardChainDBName = "shardchaindata"
@@ -41,12 +39,12 @@ const shardChainDBName = "shardchaindata"
type ShardEthereum struct {
shardConfig *params.Config // Holds necessary information to configure shards.
txPool *txpool.TXPool // Defines the sharding-specific txpool. To be designed.
actor sharding.Actor // Either notary, proposer, or observer.
actor types.Actor // Either notary, proposer, or observer.
eventFeed *event.Feed // Used to enable P2P related interactions via different sharding actors.
// Lifecycle and service stores.
services map[reflect.Type]sharding.Service // Service registry.
serviceTypes []reflect.Type // Keeps an ordered slice of registered service types.
services map[reflect.Type]types.Service // Service registry.
serviceTypes []reflect.Type // Keeps an ordered slice of registered service types.
lock sync.RWMutex
stop chan struct{} // Channel to wait for termination notifications
}
@@ -55,7 +53,7 @@ type ShardEthereum struct {
// geth sharding entrypoint.
func New(ctx *cli.Context) (*ShardEthereum, error) {
shardEthereum := &ShardEthereum{
services: make(map[reflect.Type]sharding.Service),
services: make(map[reflect.Type]types.Service),
stop: make(chan struct{}),
}
@@ -123,8 +121,7 @@ func (s *ShardEthereum) Start() {
}
}
// ensure trace and CPU profile data is flushed.
debug.Exit()
debug.LoudPanic("boom")
panic("Panic closing the sharding node")
}()
// Wait for stop channel to be closed
@@ -149,7 +146,7 @@ func (s *ShardEthereum) Close() {
// registerService appends a service constructor function to the service registry of the
// sharding node.
func (s *ShardEthereum) registerService(service sharding.Service) error {
func (s *ShardEthereum) registerService(service types.Service) error {
kind := reflect.TypeOf(service)
if _, exists := s.services[kind]; exists {
return fmt.Errorf("service already exists: %v", kind)

View File

@@ -4,13 +4,13 @@ import (
"flag"
"testing"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
cli "gopkg.in/urfave/cli.v1"
"github.com/urfave/cli"
)
// Verifies that ShardEthereum implements the Node interface.
var _ = sharding.Node(&ShardEthereum{})
var _ = types.Node(&ShardEthereum{})
// Test that the sharding node can build with default flag values.
func TestNode_Builds(t *testing.T) {

View File

@@ -9,12 +9,12 @@ go_library(
importpath = "github.com/prysmaticlabs/geth-sharding/sharding/notary",
visibility = ["//visibility:public"],
deps = [
"//sharding:go_default_library",
"//sharding/contracts:go_default_library",
"//sharding/database:go_default_library",
"//sharding/mainchain:go_default_library",
"//sharding/p2p:go_default_library",
"//sharding/params:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//accounts:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
@@ -29,9 +29,9 @@ go_test(
srcs = ["service_test.go"],
embed = [":go_default_library"],
deps = [
"//sharding:go_default_library",
"//sharding/internal:go_default_library",
"//sharding/params:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//crypto:go_default_library",
],

View File

@@ -11,13 +11,13 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/contracts"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
shardparams "github.com/prysmaticlabs/geth-sharding/sharding/params"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
)
// subscribeBlockHeaders checks incoming block headers and determines if
@@ -26,7 +26,7 @@ import (
// eliminates those that ask for too much gas, and routes them over
// to the SMC to create a collation.
func subscribeBlockHeaders(reader mainchain.Reader, caller mainchain.ContractCaller, account *accounts.Account) error {
headerChan := make(chan *types.Header, 16)
headerChan := make(chan *gethTypes.Header, 16)
_, err := reader.SubscribeNewHead(context.Background(), headerChan)
if err != nil {
@@ -59,7 +59,7 @@ func subscribeBlockHeaders(reader mainchain.Reader, caller mainchain.ContractCal
// collation for the available shards in the SMC. The function calls
// getEligibleNotary from the SMC and notary a collation if
// conditions are met.
func checkSMCForNotary(caller mainchain.ContractCaller, account *accounts.Account, head *types.Header) error {
func checkSMCForNotary(caller mainchain.ContractCaller, account *accounts.Account, head *gethTypes.Header) error {
log.Info("Checking if we are an eligible collation notary for a shard...")
shardCount, err := caller.GetShardCount()
if err != nil {
@@ -143,7 +143,7 @@ func isLockUpOver(caller mainchain.ContractCaller, reader mainchain.Reader, acco
}
func transactionWaiting(client mainchain.EthClient, tx *types.Transaction, duration time.Duration) error {
func transactionWaiting(client mainchain.EthClient, tx *gethTypes.Transaction, duration time.Duration) error {
err := client.WaitForTransaction(context.Background(), tx.Hash(), duration)
if err != nil {
@@ -155,14 +155,14 @@ func transactionWaiting(client mainchain.EthClient, tx *types.Transaction, durat
return err
}
if receipt.Status == types.ReceiptStatusFailed {
if receipt.Status == gethTypes.ReceiptStatusFailed {
return errors.New("transaction was not successful, unable to release Notary")
}
return nil
}
func settingCanonicalShardChain(shard sharding.Shard, manager mainchain.ContractManager, period *big.Int, headerHash *common.Hash) error {
func settingCanonicalShardChain(shard types.Shard, manager mainchain.ContractManager, period *big.Int, headerHash *common.Hash) error {
shardID := shard.ShardID()
collationRecords, err := manager.SMCCaller().CollationRecords(&bind.CallOpts{}, shardID, period)
@@ -193,7 +193,7 @@ func settingCanonicalShardChain(shard sharding.Shard, manager mainchain.Contract
}
func getCurrentNetworkState(manager mainchain.ContractManager, shard sharding.Shard, reader mainchain.Reader) (int64, *big.Int, *types.Block, error) {
func getCurrentNetworkState(manager mainchain.ContractManager, shard types.Shard, reader mainchain.Reader) (int64, *big.Int, *gethTypes.Block, error) {
shardcount, err := manager.GetShardCount()
if err != nil {
@@ -215,7 +215,7 @@ func getCurrentNetworkState(manager mainchain.ContractManager, shard sharding.Sh
}
func checkCollationPeriod(manager mainchain.ContractManager, block *types.Block, shardID *big.Int) (*big.Int, *big.Int, error) {
func checkCollationPeriod(manager mainchain.ContractManager, block *gethTypes.Block, shardID *big.Int) (*big.Int, *big.Int, error) {
period := big.NewInt(0).Div(block.Number(), big.NewInt(shardparams.DefaultConfig.PeriodLength))
collPeriod, err := manager.SMCCaller().LastSubmittedCollation(&bind.CallOpts{}, shardID)
@@ -297,7 +297,7 @@ func joinNotaryPool(manager mainchain.ContractManager, client mainchain.EthClien
if err != nil {
return err
}
if receipt.Status == types.ReceiptStatusFailed {
if receipt.Status == gethTypes.ReceiptStatusFailed {
return errors.New("transaction was not successful, unable to deposit ETH and become a notary")
}
@@ -344,7 +344,7 @@ func leaveNotaryPool(manager mainchain.ContractManager, client mainchain.EthClie
return err
}
if receipt.Status == types.ReceiptStatusFailed {
if receipt.Status == gethTypes.ReceiptStatusFailed {
return errors.New("transaction was not successful, unable to deregister notary")
}
@@ -410,7 +410,7 @@ func releaseNotary(manager mainchain.ContractManager, client mainchain.EthClient
// submitVote votes for a collation on the shard
// by taking in the shard and the hash of the collation header
func submitVote(shard sharding.Shard, manager mainchain.ContractManager, client mainchain.EthClient, reader mainchain.Reader, headerHash *common.Hash) error {
func submitVote(shard types.Shard, manager mainchain.ContractManager, client mainchain.EthClient, reader mainchain.Reader, headerHash *common.Hash) error {
_, shardID, block, err := getCurrentNetworkState(manager, shard, reader)
if err != nil {

View File

@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
"github.com/prysmaticlabs/geth-sharding/sharding/internal"
shardparams "github.com/prysmaticlabs/geth-sharding/sharding/params"
)
@@ -18,7 +18,7 @@ var (
)
// Verifies that Notary implements the Actor interface.
var _ = sharding.Actor(&Notary{})
var _ = types.Actor(&Notary{})
func TestHasAccountBeenDeregistered(t *testing.T) {
backend, smc := internal.SetupMockClient(t)

View File

@@ -6,11 +6,11 @@ go_library(
importpath = "github.com/prysmaticlabs/geth-sharding/sharding/observer",
visibility = ["//visibility:public"],
deps = [
"//sharding:go_default_library",
"//sharding/database:go_default_library",
"//sharding/mainchain:go_default_library",
"//sharding/p2p:go_default_library",
"//sharding/syncer:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//log:go_default_library",
],
)
@@ -20,13 +20,13 @@ go_test(
srcs = ["service_test.go"],
embed = [":go_default_library"],
deps = [
"//sharding:go_default_library",
"//sharding/database:go_default_library",
"//sharding/internal:go_default_library",
"//sharding/mainchain:go_default_library",
"//sharding/p2p:go_default_library",
"//sharding/params:go_default_library",
"//sharding/syncer:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//log:go_default_library",
],
)

View File

@@ -8,7 +8,7 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
"github.com/prysmaticlabs/geth-sharding/sharding/database"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
@@ -22,7 +22,7 @@ type Observer struct {
p2p *p2p.Server
dbService *database.ShardDB
shardID int
shard *sharding.Shard
shard *types.Shard
ctx context.Context
cancel context.CancelFunc
sync *syncer.Syncer
@@ -39,7 +39,7 @@ func NewObserver(p2p *p2p.Server, dbService *database.ShardDB, shardID int, sync
// Start the main loop for observer service.
func (o *Observer) Start() {
log.Info(fmt.Sprintf("Starting observer service"))
o.shard = sharding.NewShard(big.NewInt(int64(o.shardID)), o.dbService.DB())
o.shard = types.NewShard(big.NewInt(int64(o.shardID)), o.dbService.DB())
go o.sync.HandleCollationBodyRequests(o.shard)
}

View File

@@ -4,7 +4,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
"github.com/prysmaticlabs/geth-sharding/sharding/database"
"github.com/prysmaticlabs/geth-sharding/sharding/internal"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
@@ -14,7 +14,7 @@ import (
)
// Verifies that Observer implements the Actor interface.
var _ = sharding.Actor(&Observer{})
var _ = types.Actor(&Observer{})
func TestStartStop(t *testing.T) {
h := internal.NewLogHandler(t)

View File

@@ -24,5 +24,5 @@ go_test(
"service_test.go",
],
embed = [":go_default_library"],
deps = ["//sharding:go_default_library"],
deps = ["//sharding/types:go_default_library"],
)

View File

@@ -1,8 +1,6 @@
package p2p
import (
"github.com/prysmaticlabs/geth-sharding/sharding"
)
import "github.com/prysmaticlabs/geth-sharding/sharding/types"
// Ensure that server implements service.
var _ = sharding.Service(&Server{})
var _ = types.Service(&Server{})

View File

@@ -9,13 +9,13 @@ go_library(
importpath = "github.com/prysmaticlabs/geth-sharding/sharding/proposer",
visibility = ["//visibility:public"],
deps = [
"//sharding:go_default_library",
"//sharding/database:go_default_library",
"//sharding/mainchain:go_default_library",
"//sharding/p2p:go_default_library",
"//sharding/params:go_default_library",
"//sharding/syncer:go_default_library",
"//sharding/txpool:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//accounts:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",

View File

@@ -7,17 +7,17 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
)
// AddHeader adds the collation header to the main chain by sending
// an addHeader transaction to the sharding manager contract.
// There can only exist one header per period per shard, it is the proposer's
// responsibility to check if a header has been added.
func AddHeader(client mainchain.EthClient, transactor mainchain.ContractTransactor, collation *sharding.Collation) error {
func AddHeader(client mainchain.EthClient, transactor mainchain.ContractTransactor, collation *types.Collation) error {
log.Info("Adding header to SMC")
txOps, err := transactor.CreateTXOpts(big.NewInt(0))
@@ -40,7 +40,7 @@ func AddHeader(client mainchain.EthClient, transactor mainchain.ContractTransact
if err != nil {
return err
}
if receipt.Status != types.ReceiptStatusSuccessful {
if receipt.Status != gethTypes.ReceiptStatusSuccessful {
return fmt.Errorf("add header transaction failed with receipt status %v", receipt.Status)
}
@@ -52,7 +52,7 @@ func AddHeader(client mainchain.EthClient, transactor mainchain.ContractTransact
// and body. Header consists of shardID, ChunkRoot, period,
// proposer addr and signatures. Body contains serialized blob
// of a collations transactions.
func createCollation(caller mainchain.ContractCaller, account *accounts.Account, signer mainchain.Signer, shardID *big.Int, period *big.Int, txs []*types.Transaction) (*sharding.Collation, error) {
func createCollation(caller mainchain.ContractCaller, account *accounts.Account, signer mainchain.Signer, shardID *big.Int, period *big.Int, txs []*gethTypes.Transaction) (*types.Collation, error) {
// shardId has to be within range
shardCount, err := caller.GetShardCount()
if err != nil {
@@ -68,17 +68,17 @@ func createCollation(caller mainchain.ContractCaller, account *accounts.Account,
}
// serialized tx to blob for collation body.
blobs, err := sharding.SerializeTxToBlob(txs)
blobs, err := types.SerializeTxToBlob(txs)
if err != nil {
return nil, fmt.Errorf("can't create collation, serialization to blob failed: %v", err)
}
// construct the header, leave chunkRoot and signature fields empty, to be filled later.
addr := account.Address
header := sharding.NewCollationHeader(shardID, nil, period, &addr, [32]byte{})
header := types.NewCollationHeader(shardID, nil, period, &addr, [32]byte{})
// construct the body with header, blobs(serialized txs) and txs.
collation := sharding.NewCollation(header, blobs, txs)
collation := types.NewCollation(header, blobs, txs)
collation.CalculateChunkRoot()
sig, err := signer.Sign(collation.Header().Hash())
if err != nil {

View File

@@ -7,16 +7,16 @@ import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/database"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
"github.com/prysmaticlabs/geth-sharding/sharding/params"
"github.com/prysmaticlabs/geth-sharding/sharding/syncer"
"github.com/prysmaticlabs/geth-sharding/sharding/txpool"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
)
// Proposer holds functionality required to run a collation proposer
@@ -30,7 +30,7 @@ type Proposer struct {
txpoolSub event.Subscription
dbService *database.ShardDB
shardID int
shard *sharding.Shard
shard *types.Shard
ctx context.Context
cancel context.CancelFunc
sync *syncer.Syncer
@@ -58,7 +58,7 @@ func NewProposer(config *params.Config, client *mainchain.SMCClient, p2p *p2p.Se
// Start the main loop for proposing collations.
func (p *Proposer) Start() {
log.Info("Starting proposer service")
shard := sharding.NewShard(big.NewInt(int64(p.shardID)), p.dbService.DB())
shard := types.NewShard(big.NewInt(int64(p.shardID)), p.dbService.DB())
p.shard = shard
go p.proposeCollations()
go p.sync.HandleCollationBodyRequests(p.shard)
@@ -74,14 +74,14 @@ func (p *Proposer) Stop() error {
// proposeCollations listens to the transaction feed and submits collations over an interval.
func (p *Proposer) proposeCollations() {
requests := make(chan *types.Transaction)
requests := make(chan *gethTypes.Transaction)
p.txpoolSub = p.txpool.TransactionsFeed().Subscribe(requests)
defer close(requests)
for {
select {
case tx := <-requests:
log.Info(fmt.Sprintf("Received transaction: %x", tx.Hash()))
if err := p.createCollation(p.ctx, []*types.Transaction{tx}); err != nil {
if err := p.createCollation(p.ctx, []*gethTypes.Transaction{tx}); err != nil {
log.Error(fmt.Sprintf("Create collation failed: %v", err))
}
case <-p.ctx.Done():
@@ -94,7 +94,7 @@ func (p *Proposer) proposeCollations() {
}
}
func (p *Proposer) createCollation(ctx context.Context, txs []*types.Transaction) error {
func (p *Proposer) createCollation(ctx context.Context, txs []*gethTypes.Transaction) error {
// Get current block number.
blockNumber, err := p.client.ChainReader().BlockByNumber(ctx, nil)
if err != nil {

View File

@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/prysmaticlabs/geth-sharding/sharding/internal"
"github.com/prysmaticlabs/geth-sharding/sharding/params"
@@ -21,11 +21,11 @@ var (
func TestCreateCollation(t *testing.T) {
backend, smc := internal.SetupMockClient(t)
node := &internal.MockClient{SMC: smc, T: t, Backend: backend}
var txs []*types.Transaction
var txs []*gethTypes.Transaction
for i := 0; i < 10; i++ {
data := make([]byte, 1024)
rand.Read(data)
txs = append(txs, types.NewTransaction(0, common.HexToAddress("0x0"),
txs = append(txs, gethTypes.NewTransaction(0, common.HexToAddress("0x0"),
nil, 0, nil, data))
}
@@ -45,11 +45,11 @@ func TestCreateCollation(t *testing.T) {
t.Errorf("Create collation should have failed with invalid shard number")
}
// negative test case #2, create collation with blob size > collationBodySizeLimit.
var badTxs []*types.Transaction
var badTxs []*gethTypes.Transaction
for i := 0; i <= 1024; i++ {
data := make([]byte, 1024)
rand.Read(data)
badTxs = append(badTxs, types.NewTransaction(0, common.HexToAddress("0x0"),
badTxs = append(badTxs, gethTypes.NewTransaction(0, common.HexToAddress("0x0"),
nil, 0, nil, data))
}
collation, err = createCollation(node, node.Account(), node, big.NewInt(0), big.NewInt(2), badTxs)
@@ -79,11 +79,11 @@ func TestCreateCollation(t *testing.T) {
func TestAddCollation(t *testing.T) {
backend, smc := internal.SetupMockClient(t)
node := &internal.MockClient{SMC: smc, T: t, Backend: backend}
var txs []*types.Transaction
var txs []*gethTypes.Transaction
for i := 0; i < 10; i++ {
data := make([]byte, 1024)
rand.Read(data)
txs = append(txs, types.NewTransaction(0, common.HexToAddress("0x0"),
txs = append(txs, gethTypes.NewTransaction(0, common.HexToAddress("0x0"),
nil, 0, nil, data))
}
@@ -127,11 +127,11 @@ func TestAddCollation(t *testing.T) {
func TestCheckCollation(t *testing.T) {
backend, smc := internal.SetupMockClient(t)
node := &internal.MockClient{SMC: smc, T: t, Backend: backend}
var txs []*types.Transaction
var txs []*gethTypes.Transaction
for i := 0; i < 10; i++ {
data := make([]byte, 1024)
rand.Read(data)
txs = append(txs, types.NewTransaction(0, common.HexToAddress("0x0"),
txs = append(txs, gethTypes.NewTransaction(0, common.HexToAddress("0x0"),
nil, 0, nil, data))
}

View File

@@ -11,7 +11,6 @@ go_library(
"//sharding/p2p/messages:go_default_library",
"//sharding/params:go_default_library",
"//sharding/syncer:go_default_library",
"//sharding/utils:go_default_library",
"@com_github_ethereum_go_ethereum//event:go_default_library",
"@com_github_ethereum_go_ethereum//log:go_default_library",
],
@@ -22,12 +21,12 @@ go_test(
srcs = ["service_test.go"],
embed = [":go_default_library"],
deps = [
"//sharding:go_default_library",
"//sharding/internal:go_default_library",
"//sharding/mainchain:go_default_library",
"//sharding/p2p:go_default_library",
"//sharding/p2p/messages:go_default_library",
"//sharding/params:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",

View File

@@ -13,17 +13,17 @@ import (
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p/messages"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
internal "github.com/prysmaticlabs/geth-sharding/sharding/internal"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
"github.com/prysmaticlabs/geth-sharding/sharding/params"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
)
var _ = sharding.Service(&Simulator{})
var _ = types.Service(&Simulator{})
type faultyReader struct{}
type goodReader struct{}
@@ -59,25 +59,25 @@ func (g *goodSMCCaller) CollationRecords(opts *bind.CallOpts, arg0 *big.Int, arg
Signature [32]byte
})
body := []byte{1, 2, 3, 4, 5}
res.ChunkRoot = [32]byte(types.DeriveSha(sharding.Chunks(body)))
res.ChunkRoot = [32]byte(gethTypes.DeriveSha(types.Chunks(body)))
res.Proposer = common.BytesToAddress([]byte{})
res.IsElected = false
return *res, nil
}
func (f *faultyReader) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
func (f *faultyReader) BlockByNumber(ctx context.Context, number *big.Int) (*gethTypes.Block, error) {
return nil, fmt.Errorf("cannot fetch block by number")
}
func (f *faultyReader) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) {
func (f *faultyReader) SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error) {
return nil, nil
}
func (g *goodReader) BlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error) {
return types.NewBlock(&types.Header{Number: big.NewInt(0)}, nil, nil, nil), nil
func (g *goodReader) BlockByNumber(ctx context.Context, number *big.Int) (*gethTypes.Block, error) {
return gethTypes.NewBlock(&gethTypes.Header{Number: big.NewInt(0)}, nil, nil, nil), nil
}
func (g *goodReader) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header) (ethereum.Subscription, error) {
func (g *goodReader) SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error) {
return nil, nil
}

View File

@@ -9,12 +9,12 @@ go_library(
importpath = "github.com/prysmaticlabs/geth-sharding/sharding/syncer",
visibility = ["//visibility:public"],
deps = [
"//sharding:go_default_library",
"//sharding/database:go_default_library",
"//sharding/mainchain:go_default_library",
"//sharding/p2p:go_default_library",
"//sharding/p2p/messages:go_default_library",
"//sharding/params:go_default_library",
"//sharding/types:go_default_library",
"//sharding/utils:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
@@ -31,7 +31,6 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//sharding:go_default_library",
"//sharding/contracts:go_default_library",
"//sharding/database:go_default_library",
"//sharding/internal:go_default_library",
@@ -39,6 +38,7 @@ go_test(
"//sharding/p2p:go_default_library",
"//sharding/p2p/messages:go_default_library",
"//sharding/params:go_default_library",
"//sharding/types:go_default_library",
"@com_github_ethereum_go_ethereum//accounts:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library",
"@com_github_ethereum_go_ethereum//accounts/abi/bind/backends:go_default_library",

View File

@@ -6,7 +6,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p/messages"
@@ -16,14 +16,14 @@ import (
// for a collation body given a (shardID, chunkRoot, period, proposerAddress) tuple.
// The proposer will fetch the corresponding data from persistent storage (shardDB) by
// constructing a collation header from the input and calculating its hash.
func RespondCollationBody(req p2p.Message, collationFetcher sharding.CollationFetcher) (*messages.CollationBodyResponse, error) {
func RespondCollationBody(req p2p.Message, collationFetcher types.CollationFetcher) (*messages.CollationBodyResponse, error) {
// Type assertion helps us catch incorrect data requests.
msg, ok := req.Data.(messages.CollationBodyRequest)
if !ok {
return nil, fmt.Errorf("received incorrect data request type: %v", msg)
}
header := sharding.NewCollationHeader(msg.ShardID, msg.ChunkRoot, msg.Period, msg.Proposer, msg.Signature)
header := types.NewCollationHeader(msg.ShardID, msg.ChunkRoot, msg.Period, msg.Proposer, msg.Signature)
// Fetch the collation by its header hash from the shardChainDB.
headerHash := header.Hash()

View File

@@ -15,11 +15,11 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/contracts"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p/messages"
shardparams "github.com/prysmaticlabs/geth-sharding/sharding/params"
shardingTypes "github.com/prysmaticlabs/geth-sharding/sharding/types"
)
var (
@@ -119,17 +119,17 @@ func (m *mockSigner) Sign(hash common.Hash) ([]byte, error) {
return []byte{}, nil
}
func (m *mockCollationFetcher) CollationByHeaderHash(headerHash *common.Hash) (*sharding.Collation, error) {
func (m *mockCollationFetcher) CollationByHeaderHash(headerHash *common.Hash) (*shardingTypes.Collation, error) {
shardID := big.NewInt(1)
chunkRoot := common.BytesToHash([]byte{})
period := big.NewInt(1)
proposerAddress := common.BytesToAddress([]byte{})
header := sharding.NewCollationHeader(shardID, &chunkRoot, period, &proposerAddress, [32]byte{})
return sharding.NewCollation(header, []byte{}, []*types.Transaction{}), nil
header := shardingTypes.NewCollationHeader(shardID, &chunkRoot, period, &proposerAddress, [32]byte{})
return shardingTypes.NewCollation(header, []byte{}, []*types.Transaction{}), nil
}
func (f *faultyCollationFetcher) CollationByHeaderHash(headerHash *common.Hash) (*sharding.Collation, error) {
func (f *faultyCollationFetcher) CollationByHeaderHash(headerHash *common.Hash) (*shardingTypes.Collation, error) {
return nil, errors.New("could not fetch collation")
}
@@ -181,7 +181,7 @@ func TestCollationBodyResponse(t *testing.T) {
t.Error("Faulty collatiom fetcher should cause function to throw error. no error thrown.")
}
header := sharding.NewCollationHeader(goodReq.ShardID, goodReq.ChunkRoot, goodReq.Period, goodReq.Proposer, [32]byte{})
header := shardingTypes.NewCollationHeader(goodReq.ShardID, goodReq.ChunkRoot, goodReq.Period, goodReq.Proposer, [32]byte{})
body := []byte{}
response, err := RespondCollationBody(goodMsg, fetcher)
if err != nil {

View File

@@ -8,12 +8,12 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/database"
"github.com/prysmaticlabs/geth-sharding/sharding/mainchain"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p/messages"
"github.com/prysmaticlabs/geth-sharding/sharding/params"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
"github.com/prysmaticlabs/geth-sharding/sharding/utils"
)
@@ -47,7 +47,7 @@ func NewSyncer(config *params.Config, client *mainchain.SMCClient, p2p *p2p.Serv
func (s *Syncer) Start() {
log.Info("Starting sync service")
shard := sharding.NewShard(big.NewInt(int64(s.shardID)), s.shardChainDB.DB())
shard := types.NewShard(big.NewInt(int64(s.shardID)), s.shardChainDB.DB())
s.msgChan = make(chan p2p.Message, 100)
s.bodyRequests = s.p2p.Feed(messages.CollationBodyRequest{}).Subscribe(s.msgChan)
@@ -70,7 +70,7 @@ func (s *Syncer) Stop() error {
// HandleCollationBodyRequests subscribes to messages from the shardp2p
// network and responds to a specific peer that requested the body using
// the Send method exposed by the p2p server's API (implementing the p2p.Sender interface).
func (s *Syncer) HandleCollationBodyRequests(collationFetcher sharding.CollationFetcher) {
func (s *Syncer) HandleCollationBodyRequests(collationFetcher types.CollationFetcher) {
for {
select {
// Makes sure to close this goroutine when the service stops.

View File

@@ -10,19 +10,19 @@ import (
"github.com/prysmaticlabs/geth-sharding/sharding/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p/messages"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding"
"github.com/prysmaticlabs/geth-sharding/sharding/database"
internal "github.com/prysmaticlabs/geth-sharding/sharding/internal"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
"github.com/prysmaticlabs/geth-sharding/sharding/types"
)
var _ = sharding.Service(&Syncer{})
var _ = types.Service(&Syncer{})
func TestStop(t *testing.T) {
h := internal.NewLogHandler(t)
@@ -83,7 +83,7 @@ func TestHandleCollationBodyRequests_FaultySigner(t *testing.T) {
}
feed := server.Feed(messages.CollationBodyRequest{})
shard := sharding.NewShard(big.NewInt(int64(shardID)), shardChainDB.DB())
shard := types.NewShard(big.NewInt(int64(shardID)), shardChainDB.DB())
syncer.msgChan = make(chan p2p.Message)
syncer.errChan = make(chan error)
@@ -128,16 +128,16 @@ func TestHandleCollationBodyRequests(t *testing.T) {
body := []byte{1, 2, 3, 4, 5}
shardID := big.NewInt(0)
chunkRoot := types.DeriveSha(sharding.Chunks(body))
chunkRoot := gethTypes.DeriveSha(types.Chunks(body))
period := big.NewInt(0)
proposerAddress := common.BytesToAddress([]byte{})
header := sharding.NewCollationHeader(shardID, &chunkRoot, period, &proposerAddress, [32]byte{})
header := types.NewCollationHeader(shardID, &chunkRoot, period, &proposerAddress, [32]byte{})
// Stores the collation into the inmemory kv store shardChainDB.
collation := sharding.NewCollation(header, body, nil)
collation := types.NewCollation(header, body, nil)
shard := sharding.NewShard(shardID, shardChainDB.DB())
shard := types.NewShard(shardID, shardChainDB.DB())
if err := shard.SaveCollation(collation); err != nil {
t.Fatalf("Could not store collation in shardChainDB: %v", err)

View File

@@ -18,5 +18,5 @@ go_test(
name = "go_default_test",
srcs = ["service_test.go"],
embed = [":go_default_library"],
deps = ["//sharding:go_default_library"],
deps = ["//sharding/types:go_default_library"],
)

View File

@@ -7,7 +7,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/prysmaticlabs/geth-sharding/sharding/p2p"
@@ -54,8 +54,8 @@ func (p *TXPool) sendTestTransaction() {
}
}
func createTestTransaction() *types.Transaction {
func createTestTransaction() *gethTypes.Transaction {
data := make([]byte, 1024)
rand.Read(data)
return types.NewTransaction(0, common.HexToAddress("0x0"), nil, 0, nil, data)
return gethTypes.NewTransaction(0, common.HexToAddress("0x0"), nil, 0, nil, data)
}

View File

@@ -1,6 +1,6 @@
package txpool
import "github.com/prysmaticlabs/geth-sharding/sharding"
import "github.com/prysmaticlabs/geth-sharding/sharding/types"
// Verifies that TXPool implements the Service interface.
var _ = sharding.Service(&TXPool{})
var _ = types.Service(&TXPool{})

View File

@@ -0,0 +1,38 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"collation.go",
"interfaces.go",
"shard.go",
],
importpath = "github.com/prysmaticlabs/geth-sharding/sharding/types",
visibility = ["//visibility:public"],
deps = [
"//sharding/utils:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_ethereum_go_ethereum//crypto/sha3:go_default_library",
"@com_github_ethereum_go_ethereum//ethdb:go_default_library",
"@com_github_ethereum_go_ethereum//rlp:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = [
"collation_test.go",
"shard_test.go",
],
embed = [":go_default_library"],
deps = [
"//sharding/database:go_default_library",
"//sharding/utils:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_ethereum_go_ethereum//crypto/sha3:go_default_library",
"@com_github_ethereum_go_ethereum//ethdb:go_default_library",
"@com_github_ethereum_go_ethereum//rlp:go_default_library",
],
)

View File

@@ -1,4 +1,4 @@
package sharding
package types
import (
"fmt"
@@ -6,7 +6,7 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/rlp"
"github.com/prysmaticlabs/geth-sharding/sharding/utils"
@@ -23,7 +23,7 @@ type Collation struct {
// collation's body. Every time this transactions slice is updated, the serialized
// body would need to be recalculated. This will be a useful property for proposers
// in our system.
transactions []*types.Transaction
transactions []*gethTypes.Transaction
}
// CollationHeader base struct.
@@ -46,7 +46,7 @@ var collationSizelimit = int64(math.Pow(float64(2), float64(20)))
// NewCollation initializes a collation and leaves it up to clients to serialize, deserialize
// and provide the body and transactions upon creation.
func NewCollation(header *CollationHeader, body []byte, transactions []*types.Transaction) *Collation {
func NewCollation(header *CollationHeader, body []byte, transactions []*gethTypes.Transaction) *Collation {
return &Collation{header, body, transactions}
}
@@ -104,7 +104,7 @@ func (c *Collation) Header() *CollationHeader { return c.header }
func (c *Collation) Body() []byte { return c.body }
// Transactions returns an array of tx's in the collation.
func (c *Collation) Transactions() []*types.Transaction { return c.transactions }
func (c *Collation) Transactions() []*gethTypes.Transaction { return c.transactions }
// ProposerAddress is the coinbase addr of the creator for the collation.
func (c *Collation) ProposerAddress() *common.Address {
@@ -113,8 +113,8 @@ func (c *Collation) ProposerAddress() *common.Address {
// CalculateChunkRoot updates the collation header's chunk root based on the body.
func (c *Collation) CalculateChunkRoot() {
chunks := BytesToChunks(c.body) // wrapper allowing us to merklizing the chunks.
chunkRoot := types.DeriveSha(chunks) // merklize the serialized blobs.
chunks := BytesToChunks(c.body) // wrapper allowing us to merklizing the chunks.
chunkRoot := gethTypes.DeriveSha(chunks) // merklize the serialized blobs.
c.header.data.ChunkRoot = &chunkRoot
}
@@ -131,8 +131,8 @@ func (c *Collation) CalculatePOC(salt []byte) common.Hash {
if len(c.body) == 0 {
body = salt
}
chunks := BytesToChunks(body) // wrapper allowing us to merklizing the chunks.
return types.DeriveSha(chunks) // merklize the serialized blobs.
chunks := BytesToChunks(body) // wrapper allowing us to merklizing the chunks.
return gethTypes.DeriveSha(chunks) // merklize the serialized blobs.
}
// BytesToChunks takes the collation body bytes and wraps it into type Chunks,
@@ -142,7 +142,7 @@ func BytesToChunks(body []byte) Chunks {
}
// convertTxToRawBlob transactions into RawBlobs. This step encodes transactions uses RLP encoding
func convertTxToRawBlob(txs []*types.Transaction) ([]*utils.RawBlob, error) {
func convertTxToRawBlob(txs []*gethTypes.Transaction) ([]*utils.RawBlob, error) {
blobs := make([]*utils.RawBlob, len(txs))
for i := 0; i < len(txs); i++ {
err := error(nil)
@@ -155,7 +155,7 @@ func convertTxToRawBlob(txs []*types.Transaction) ([]*utils.RawBlob, error) {
}
// SerializeTxToBlob converts transactions using two steps. First performs RLP encoding, and then blob encoding.
func SerializeTxToBlob(txs []*types.Transaction) ([]byte, error) {
func SerializeTxToBlob(txs []*gethTypes.Transaction) ([]byte, error) {
blobs, err := convertTxToRawBlob(txs)
if err != nil {
return nil, err
@@ -174,11 +174,11 @@ func SerializeTxToBlob(txs []*types.Transaction) ([]byte, error) {
}
// convertRawBlobToTx converts raw blobs back to their original transactions.
func convertRawBlobToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error) {
blobs := make([]*types.Transaction, len(rawBlobs))
func convertRawBlobToTx(rawBlobs []utils.RawBlob) ([]*gethTypes.Transaction, error) {
blobs := make([]*gethTypes.Transaction, len(rawBlobs))
for i := 0; i < len(rawBlobs); i++ {
blobs[i] = types.NewTransaction(0, common.HexToAddress("0x"), nil, 0, nil, nil)
blobs[i] = gethTypes.NewTransaction(0, common.HexToAddress("0x"), nil, 0, nil, nil)
err := utils.ConvertFromRawBlob(&rawBlobs[i], blobs[i])
if err != nil {
@@ -190,7 +190,7 @@ func convertRawBlobToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error)
// DeserializeBlobToTx takes byte array blob and converts it back
// to original txs and returns the txs in tx array.
func DeserializeBlobToTx(serialisedBlob []byte) (*[]*types.Transaction, error) {
func DeserializeBlobToTx(serialisedBlob []byte) (*[]*gethTypes.Transaction, error) {
deserializedBlobs, err := utils.Deserialize(serialisedBlob)
if err != nil {
return nil, err

View File

@@ -1,4 +1,4 @@
package sharding
package types
import (
"bytes"
@@ -8,7 +8,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/prysmaticlabs/geth-sharding/sharding/utils"
)
@@ -24,7 +24,7 @@ func fieldAccess(i interface{}, fields []string) reflect.Value {
func TestCollation_Transactions(t *testing.T) {
header := NewCollationHeader(big.NewInt(1), nil, big.NewInt(1), nil, [32]byte{})
body := []byte{}
transactions := []*types.Transaction{
transactions := []*gethTypes.Transaction{
makeTxWithGasLimit(0),
makeTxWithGasLimit(1),
makeTxWithGasLimit(2),
@@ -40,14 +40,14 @@ func TestCollation_Transactions(t *testing.T) {
}
}
//TODO: Add test for converting *types.Transaction into raw blobs
//TODO: Add test for converting *gethTypes.Transaction into raw blobs
//Tests that Transactions can be serialised
func TestSerialize_Deserialize(t *testing.T) {
header := NewCollationHeader(big.NewInt(1), nil, big.NewInt(1), nil, [32]byte{})
body := []byte{}
transactions := []*types.Transaction{
transactions := []*gethTypes.Transaction{
makeTxWithGasLimit(0),
makeTxWithGasLimit(5),
makeTxWithGasLimit(20),
@@ -125,14 +125,14 @@ func TestSerialize_Deserialize(t *testing.T) {
}
func makeTxWithGasLimit(gl uint64) *types.Transaction {
return types.NewTransaction(0 /*nonce*/, common.HexToAddress("0x0") /*to*/, nil /*amount*/, gl, nil /*gasPrice*/, nil /*data*/)
func makeTxWithGasLimit(gl uint64) *gethTypes.Transaction {
return gethTypes.NewTransaction(0 /*nonce*/, common.HexToAddress("0x0") /*to*/, nil /*amount*/, gl, nil /*gasPrice*/, nil /*data*/)
}
func Test_CalculatePOC(t *testing.T) {
header := NewCollationHeader(big.NewInt(1), nil, big.NewInt(1), nil, [32]byte{})
body := []byte{0x56, 0xff}
transactions := []*types.Transaction{
transactions := []*gethTypes.Transaction{
makeTxWithGasLimit(0),
makeTxWithGasLimit(5),
makeTxWithGasLimit(20),
@@ -151,14 +151,14 @@ func Test_CalculatePOC(t *testing.T) {
// BENCHMARK TESTS
// Helper function to generate test that completes round trip serialization tests for a specific number of transactions.
func makeRandomTransactions(numTransactions int) []*types.Transaction {
var txs []*types.Transaction
func makeRandomTransactions(numTransactions int) []*gethTypes.Transaction {
var txs []*gethTypes.Transaction
for i := 0; i < numTransactions; i++ {
// 150 is the current average tx size, based on recent blocks (i.e. tx size = block size / # txs)
// for example: https://etherscan.io/block/5722271
data := make([]byte, 150)
rand.Read(data)
txs = append(txs, types.NewTransaction(0 /*nonce*/, common.HexToAddress("0x0") /*to*/, nil /*amount*/, 0 /*gasLimit*/, nil /*gasPrice*/, data))
txs = append(txs, gethTypes.NewTransaction(0 /*nonce*/, common.HexToAddress("0x0") /*to*/, nil /*amount*/, 0 /*gasLimit*/, nil /*gasPrice*/, data))
}
return txs

View File

@@ -1,4 +1,4 @@
package sharding
package types
import (
"github.com/ethereum/go-ethereum/common"

View File

@@ -1,4 +1,4 @@
package sharding
package types
import (
"bytes"
@@ -7,7 +7,7 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -185,8 +185,8 @@ func (s *Shard) SaveBody(body []byte) error {
if len(body) == 0 {
return errors.New("body is empty")
}
chunks := Chunks(body) // wrapper allowing us to merklizing the chunks.
chunkRoot := types.DeriveSha(chunks) // merklize the serialized blobs.
chunks := Chunks(body) // wrapper allowing us to merklizing the chunks.
chunkRoot := gethTypes.DeriveSha(chunks) // merklize the serialized blobs.
s.SetAvailability(&chunkRoot, true)
return s.shardDB.Put(chunkRoot.Bytes(), body)
}

View File

@@ -1,4 +1,4 @@
package sharding
package types
import (
"bytes"
@@ -7,7 +7,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
@@ -318,8 +318,8 @@ func TestShard_BodyByChunkRoot(t *testing.T) {
t.Fatalf("cannot save body: %v", err)
}
chunks := Chunks(body) // wrapper allowing us to merklizing the chunks.
chunkRoot := types.DeriveSha(chunks) // merklize the serialized blobs.
chunks := Chunks(body) // wrapper allowing us to merklizing the chunks.
chunkRoot := gethTypes.DeriveSha(chunks) // merklize the serialized blobs.
dbBody, err := shard.BodyByChunkRoot(&chunkRoot)
if err != nil {

View File

@@ -3,20 +3,26 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"customflags.go",
"flags.go",
"marshal.go",
"service.go",
],
importpath = "github.com/prysmaticlabs/geth-sharding/sharding/utils",
visibility = ["//visibility:public"],
deps = [
"//sharding/params:go_default_library",
"@com_github_ethereum_go_ethereum//log:go_default_library",
"@com_github_ethereum_go_ethereum//node:go_default_library",
"@com_github_ethereum_go_ethereum//rlp:go_default_library",
"@com_github_urfave_cli//:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = [
"customflags_test.go",
"marshal_test.go",
"service_test.go",
],

View File

@@ -19,65 +19,18 @@ package utils
import (
"math/big"
"os"
"path/filepath"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
shardparams "github.com/prysmaticlabs/geth-sharding/sharding/params"
"gopkg.in/urfave/cli.v1"
"github.com/urfave/cli"
)
var (
CommandHelpTemplate = `{{.cmd.Name}}{{if .cmd.Subcommands}} command{{end}}{{if .cmd.Flags}} [command options]{{end}} [arguments...]
{{if .cmd.Description}}{{.cmd.Description}}
{{end}}{{if .cmd.Subcommands}}
SUBCOMMANDS:
{{range .cmd.Subcommands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{end}}{{if .categorizedFlags}}
{{range $idx, $categorized := .categorizedFlags}}{{$categorized.Name}} OPTIONS:
{{range $categorized.Flags}}{{"\t"}}{{.}}
{{end}}
{{end}}{{end}}`
)
func init() {
cli.AppHelpTemplate = `{{.Name}} {{if .Flags}}[global options] {{end}}command{{if .Flags}} [command options]{{end}} [arguments...]
VERSION:
{{.Version}}
COMMANDS:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
GLOBAL OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
cli.CommandHelpTemplate = CommandHelpTemplate
}
// NewApp creates an app with sane defaults.
func NewApp(gitCommit, usage string) *cli.App {
app := cli.NewApp()
app.Name = filepath.Base(os.Args[0])
app.Author = ""
//app.Authors = nil
app.Email = ""
app.Version = params.Version
if len(gitCommit) >= 8 {
app.Version += "-" + gitCommit[:8]
}
app.Usage = usage
return app
}
// These are all the command line flags we support.
// If you add to this list, please remember to include the
// flag in the appropriate command definition.
//
// The flags are defined here so their names and help texts
// are the same for all commands.
var (
// General settings
IPCPathFlag = DirectoryFlag{