Skip to content

Commit

Permalink
Merge pull request #1 from jdkanani/geth-bor-changes
Browse files Browse the repository at this point in the history
Bor related changes on updated geth
  • Loading branch information
jdkanani authored Nov 20, 2020
2 parents 7a3036c + 6235761 commit fafb9e9
Show file tree
Hide file tree
Showing 44 changed files with 4,256 additions and 374 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ executors:
golang:
docker:
- image: circleci/golang:1.13
working_directory: /go/src/github.com/maticnetwork/bor
working_directory: /go/src/github.com/ethereum/go-ethereum

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.14.7
go-version: 1.15.5
- name: "Build binaries"
run: make all
- name: "Run tests"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linuxpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: 1.14.7
go-version: 1.15.5

- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: go
go_import_path: github.com/maticnetwork/bor
go_import_path: github.com/ethereum/go-ethereum
sudo: false
jobs:
allow_failures:
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
- mv android-ndk-r19b $ANDROID_HOME/ndk-bundle

- mkdir -p $GOPATH/src/github.com/ethereum
- ln -s `pwd` $GOPATH/src/github.com/maticnetwork/bor
- ln -s `pwd` $GOPATH/src/github.com/ethereum/go-ethereum
- go run build/ci.go aar -signer ANDROID_SIGNING_KEY -deploy https://oss.sonatype.org -upload gethstore/builds

# This builder does the OSX Azure, iOS CocoaPods and iOS Azure uploads
Expand Down
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ FROM golang:1.15-alpine as builder

RUN apk add --no-cache make gcc musl-dev linux-headers git

ADD . /go-ethereum
RUN cd /go-ethereum && make geth
ADD . /bor
RUN cd /bor && make bor

# Pull Geth into a second stage deploy alpine container
# Pull Bor into a second stage deploy alpine container
FROM alpine:latest

RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/geth /usr/local/bin/
COPY --from=builder /bor/build/bin/bor /usr/local/bin/

EXPOSE 8545 8546 30303 30303/udp
ENTRYPOINT ["geth"]
EXPOSE 8545 8546 8547 30303 30303/udp
6 changes: 3 additions & 3 deletions Dockerfile.alltools
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ FROM golang:1.15-alpine as builder

RUN apk add --no-cache make gcc musl-dev linux-headers git

ADD . /go-ethereum
RUN cd /go-ethereum && make all
ADD . /bor
RUN cd /bor && make bor-all

# Pull all binaries into a second stage deploy alpine container
FROM alpine:latest

RUN apk add --no-cache ca-certificates
COPY --from=builder /go-ethereum/build/bin/* /usr/local/bin/
COPY --from=builder /bor/build/bin/* /usr/local/bin/

EXPOSE 8545 8546 30303 30303/udp
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
GOBIN = ./build/bin
GO ?= latest
GORUN = env GO111MODULE=on go run
GOPATH = $(shell go env GOPATH)

bor:
$(GORUN) build/ci.go install ./cmd/geth
mkdir -p $(GOPATH)/bin/
cp $(GOBIN)/geth $(GOBIN)/bor
cp $(GOBIN)/* $(GOPATH)/bin/

bor-all:
$(GORUN) build/ci.go install
mkdir -p $(GOPATH)/bin/
cp $(GOBIN)/geth $(GOBIN)/bor
cp $(GOBIN)/* $(GOPATH)/bin/

geth:
$(GORUN) build/ci.go install ./cmd/geth
Expand Down
341 changes: 5 additions & 336 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const (
MimetypeDataWithValidator = "data/validator"
MimetypeTypedData = "data/typed"
MimetypeClique = "application/x-clique-header"
MimetypeBor = "application/x-bor-header"
MimetypeTextPlain = "text/plain"
)

Expand Down
13 changes: 9 additions & 4 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
Action: utils.MigrateFlags(importChain),
Name: "import",
Usage: "Import a blockchain file",
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
ArgsUsage: "<filename> (<filename 2> ... <filename N>) <genesisPath>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.CacheFlag,
Expand All @@ -94,6 +94,10 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
utils.MetricsInfluxDBPasswordFlag,
utils.MetricsInfluxDBTagsFlag,
utils.TxLookupLimitFlag,

// bor related flags
utils.HeimdallURLFlag,
utils.WithoutHeimdallFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
Expand Down Expand Up @@ -270,7 +274,7 @@ func dumpGenesis(ctx *cli.Context) error {
}

func importChain(ctx *cli.Context) error {
if len(ctx.Args()) < 1 {
if len(ctx.Args()) < 2 {
utils.Fatalf("This command requires an argument.")
}
// Start metrics export if enabled
Expand Down Expand Up @@ -304,13 +308,14 @@ func importChain(ctx *cli.Context) error {

var importErr error

if len(ctx.Args()) == 1 {
// ArgsUsage: "<filename> (<filename 2> ... <filename N>) <genesisPath>",
if len(ctx.Args()) == 2 {
if err := utils.ImportChain(chain, ctx.Args().First()); err != nil {
importErr = err
log.Error("Import error", "err", err)
}
} else {
for _, arg := range ctx.Args() {
for _, arg := range ctx.Args()[:len(ctx.Args())-1] {
if err := utils.ImportChain(chain, arg); err != nil {
importErr = err
log.Error("Import error", "file", arg, "err", err)
Expand Down
5 changes: 4 additions & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func defaultNodeConfig() node.Config {
cfg.Version = params.VersionWithCommit(gitCommit, gitDate)
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
cfg.WSModules = append(cfg.WSModules, "eth")
cfg.IPCPath = "geth.ipc"
cfg.IPCPath = clientIdentifier + ".ipc"
return cfg
}

Expand Down Expand Up @@ -146,6 +146,9 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
}
utils.SetShhConfig(ctx, stack)

// Set Bor config flags
utils.SetBorConfig(ctx, &cfg.Eth)

return stack, cfg
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,16 @@ import (
)

const (
clientIdentifier = "geth" // Client identifier to advertise over the network
clientIdentifier = "bor" // Client identifier to advertise over the network
repositoryIdentifier = "go-bor"
)

var (
// Git SHA1 commit hash of the release (set via linker flags)
gitCommit = ""
gitDate = ""
// The app that holds all commands and flags.
app = flags.NewApp(gitCommit, gitDate, "the go-ethereum command line interface")
app = flags.NewApp(gitCommit, gitDate, fmt.Sprintf("the %s command line interface", repositoryIdentifier))
// flags that configure the node
nodeFlags = []cli.Flag{
utils.IdentityFlag,
Expand Down Expand Up @@ -259,6 +260,9 @@ func init() {
app.Flags = append(app.Flags, whisperFlags...)
app.Flags = append(app.Flags, metricsFlags...)

// add bor flags
app.Flags = append(app.Flags, utils.BorFlags...)

app.Before = func(ctx *cli.Context) error {
return debug.Setup(ctx)
}
Expand Down
88 changes: 88 additions & 0 deletions cmd/utils/bor_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package utils

import (
"encoding/json"
"io/ioutil"
"os"

"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"gopkg.in/urfave/cli.v1"
)

var (
//
// Bor Specific flags
//

// HeimdallURLFlag flag for heimdall url
HeimdallURLFlag = cli.StringFlag{
Name: "bor.heimdall",
Usage: "URL of Heimdall service",
Value: "http://localhost:1317",
}

// WithoutHeimdallFlag no heimdall (for testing purpose)
WithoutHeimdallFlag = cli.BoolFlag{
Name: "bor.withoutheimdall",
Usage: "Run without Heimdall service (for testing purpose)",
}

// BorFlags all bor related flags
BorFlags = []cli.Flag{
HeimdallURLFlag,
WithoutHeimdallFlag,
}
)

func getGenesis(genesisPath string) (*core.Genesis, error) {
log.Info("Reading genesis at ", "file", genesisPath)
file, err := os.Open(genesisPath)
if err != nil {
return nil, err
}
defer file.Close()

genesis := new(core.Genesis)
if err := json.NewDecoder(file).Decode(genesis); err != nil {
return nil, err
}
return genesis, nil
}

// SetBorConfig sets bor config
func SetBorConfig(ctx *cli.Context, cfg *eth.Config) {
cfg.HeimdallURL = ctx.GlobalString(HeimdallURLFlag.Name)
cfg.WithoutHeimdall = ctx.GlobalBool(WithoutHeimdallFlag.Name)
}

// CreateBorEthereum Creates bor ethereum object from eth.Config
func CreateBorEthereum(cfg *eth.Config) *eth.Ethereum {
workspace, err := ioutil.TempDir("", "bor-command-node-")
if err != nil {
Fatalf("Failed to create temporary keystore: %v", err)
}

// Create a networkless protocol stack and start an Ethereum service within
stack, err := node.New(&node.Config{DataDir: workspace, UseLightweightKDF: true, Name: "bor-command-node"})
if err != nil {
Fatalf("Failed to create node: %v", err)
}
ethereum, err := eth.New(stack, cfg)
if err != nil {
Fatalf("Failed to register Ethereum protocol: %v", err)
}

// Start the node and assemble the JavaScript console around it
if err = stack.Start(); err != nil {
Fatalf("Failed to start stack: %v", err)
}
_, err = stack.Attach()
if err != nil {
Fatalf("Failed to attach to node: %v", err)
}

return ethereum
}
20 changes: 18 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1801,15 +1801,28 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {

// MakeChain creates a chain manager from set command line flags.
func MakeChain(ctx *cli.Context, stack *node.Node, readOnly bool) (chain *core.BlockChain, chainDb ethdb.Database) {
var err error
// expecting the last argument to be the genesis file
genesis, err := getGenesis(ctx.Args().Get(len(ctx.Args()) - 1))
if err != nil {
Fatalf("Valid genesis file is required as argument: {}", err)
}

chainDb = MakeChainDatabase(ctx, stack)
config, _, err := core.SetupGenesisBlock(chainDb, MakeGenesis(ctx))
config, _, err := core.SetupGenesisBlock(chainDb, genesis)
if err != nil {
Fatalf("%v", err)
}
var engine consensus.Engine
var ethereum *eth.Ethereum
if config.Clique != nil {
engine = clique.New(config.Clique, chainDb)
} else if config.Bor != nil {
ethereum = CreateBorEthereum(&eth.Config{
Genesis: genesis,
HeimdallURL: ctx.GlobalString(HeimdallURLFlag.Name),
WithoutHeimdall: ctx.GlobalBool(WithoutHeimdallFlag.Name),
})
engine = ethereum.Engine()
} else {
engine = ethash.NewFaker()
if !ctx.GlobalBool(FakePoWFlag.Name) {
Expand Down Expand Up @@ -1855,6 +1868,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readOnly bool) (chain *core.B
if err != nil {
Fatalf("Can't create BlockChain: %v", err)
}
if ethereum != nil {
ethereum.SetBlockchain(chain)
}
return chain, chainDb
}

Expand Down
Loading

0 comments on commit fafb9e9

Please sign in to comment.