Skip to content

Commit

Permalink
Merge branch 'develop' into feature/benchmark-sequencer
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nedkov <[email protected]>
  • Loading branch information
Psykepro committed Dec 16, 2022
2 parents 46edc7f + 58334d4 commit 5b95e6e
Show file tree
Hide file tree
Showing 32 changed files with 334 additions and 155 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ RUN cd /src && make build

# CONTAINER FOR RUNNING BINARY
FROM alpine:3.16.0
ARG BUILD_COMMIT
ENV COMMIT_HASH $BUILD_COMMIT
COPY --from=build /src/dist/zkevm-node /app/zkevm-node
COPY --from=build /src/config/environments/local/local.node.config.toml /app/example.config.toml
EXPOSE 8123
CMD ["/bin/sh", "-c", "/app/zkevm-node run"]
CMD ["/bin/sh", "-c", "/app/zkevm-node run"]
19 changes: 10 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
VERSION := $(shell git describe --tags --always)
COMMIT := $(shell git rev-parse --short HEAD)
DATE := $(shell date +%Y-%m-%dT%H:%M:%S%z)
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
include version.mk

ARCH := $(shell arch)

ifeq ($(ARCH),x86_64)
Expand All @@ -11,25 +9,28 @@ else
ARCH = arm64
endif
endif

GOBASE := $(shell pwd)
GOBIN := $(GOBASE)/dist
GOENVVARS := GOBIN=$(GOBIN) CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH)
GOBINARY := zkevm-node
GOCMD := $(GOBASE)/cmd
$(eval BUILD_COMMIT:=$(shell git rev-parse --short HEAD))

LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-node.Version=$(VERSION)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-node.GitRev=$(GITREV)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-node.GitBranch=$(GITBRANCH)'
LDFLAGS += -X 'github.com/0xPolygonHermez/zkevm-node.BuildDate=$(DATE)'

.PHONY: build
build: ## Builds the binary locally into ./dist
$(GOENVVARS) go build $(LDFLAGS) -o $(GOBIN)/$(GOBINARY) $(GOCMD)
$(GOENVVARS) go build -ldflags "all=$(LDFLAGS)" -o $(GOBIN)/$(GOBINARY) $(GOCMD)

.PHONY: build-docker
build-docker: ## Builds a docker image with the node binary
docker build -t zkevm-node --build-arg BUILD_COMMIT="$(BUILD_COMMIT)" -f ./Dockerfile .
docker build -t zkevm-node -f ./Dockerfile .

.PHONY: build-docker-nc
build-docker-nc: ## Builds a docker image with the node binary - but without build cache
docker build --no-cache=true -t zkevm-node --build-arg BUILD_COMMIT="$(BUILD_COMMIT)" -f ./Dockerfile .
docker build --no-cache=true -t zkevm-node -f ./Dockerfile .

.PHONY: run-rpc
run-rpc: ## Runs all the services need to run a local zkEMV RPC node
Expand Down
21 changes: 3 additions & 18 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ import (
"fmt"
"os"

"github.com/0xPolygonHermez/zkevm-node"
"github.com/0xPolygonHermez/zkevm-node/config"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/test/testutils"
"github.com/urfave/cli/v2"
)

const (
// App name
appName = "zkevm-node"
// version represents the program based on the git tag
version = "v0.1.0"
// date represents the date of application was built
date = ""
)
const appName = "zkevm-node"

const (
// AGGREGATOR is the aggregator component identifier.
Expand All @@ -33,14 +26,7 @@ const (
BROADCAST = "broadcast-trusted-state"
)

const (
//envCommitHash environment variable name for COMMIT_HASH
envCommitHash = "COMMIT_HASH"
)

var (
// commit represents the program based on the git commit
commit = testutils.GetEnv(envCommitHash, "dev")
configFileFlag = cli.StringFlag{
Name: config.FlagCfg,
Aliases: []string{"c"},
Expand Down Expand Up @@ -78,14 +64,13 @@ var (
func main() {
app := cli.NewApp()
app.Name = appName
app.Version = version
app.Version = zkevm.Version
flags := []cli.Flag{
&configFileFlag,
&yesFlag,
&componentsFlag,
&httpAPIFlag,
}
log.Infof("Starting application [Commit Hash: %s, Version: %s] ...", commit, version)
app.Commands = []*cli.Command{
{
Name: "version",
Expand Down
3 changes: 3 additions & 0 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/signal"
"path/filepath"

"github.com/0xPolygonHermez/zkevm-node"
"github.com/0xPolygonHermez/zkevm-node/aggregator"
"github.com/0xPolygonHermez/zkevm-node/config"
"github.com/0xPolygonHermez/zkevm-node/db"
Expand Down Expand Up @@ -40,6 +41,8 @@ import (
)

func start(cliCtx *cli.Context) error {
zkevm.PrintVersion(os.Stdout)

c, err := config.Load(cliCtx)
if err != nil {
return err
Expand Down
7 changes: 3 additions & 4 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package main

import (
"fmt"
"os"

"github.com/0xPolygonHermez/zkevm-node"
"github.com/urfave/cli/v2"
)

func versionCmd(*cli.Context) error {
fmt.Printf("Version = \"%v\"\n", version)
fmt.Printf("Build = \"%v\"\n", commit)
fmt.Printf("Date = \"%v\"\n", date)
zkevm.PrintVersion(os.Stdout)
return nil
}
15 changes: 12 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ type Config struct {
Metrics metrics.Config
}

// Load loads the configuration
func Load(ctx *cli.Context) (*Config, error) {
// Default parses the default configuration values.
func Default() (*Config, error) {
var cfg Config
viper.SetConfigType("toml")

Expand All @@ -75,6 +75,15 @@ func Load(ctx *cli.Context) (*Config, error) {
if err != nil {
return nil, err
}
return &cfg, nil
}

// Load loads the configuration
func Load(ctx *cli.Context) (*Config, error) {
cfg, err := Default()
if err != nil {
return nil, err
}
configFilePath := ctx.String(FlagCfg)
if configFilePath != "" {
dirName, fileName := filepath.Split(configFilePath)
Expand Down Expand Up @@ -114,5 +123,5 @@ func Load(ctx *cli.Context) (*Config, error) {
}
log.Debugf("Configuration loaded: \n%s\n", string(cfgJSON))
*/
return &cfg, nil
return cfg, nil
}
15 changes: 14 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/0xPolygonHermez/zkevm-node/config"
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/pricegetter"
"github.com/0xPolygonHermez/zkevm-node/sequencer"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -23,6 +24,18 @@ func Test_Defaults(t *testing.T) {
path string
expectedValue interface{}
}{
{
path: "Log.Environment",
expectedValue: log.LogEnvironment("development"),
},
{
path: "Log.Level",
expectedValue: "debug",
},
{
path: "Log.Outputs",
expectedValue: []string{"stderr"},
},
{
path: "Synchronizer.SyncChunkSize",
expectedValue: uint64(100),
Expand Down Expand Up @@ -57,7 +70,7 @@ func Test_Defaults(t *testing.T) {
},
{
path: "Sequencer.MaxBatchBytesSize",
expectedValue: 30000,
expectedValue: 150000,
},
{
path: "Sequencer.MaxTimeForBatchToBeOpen",
Expand Down
5 changes: 3 additions & 2 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ const DefaultValues = `
IsTrustedSequencer = false
[Log]
Environment = "development" # "production" or "development"
Level = "debug"
Outputs = ["stdout"]
Outputs = ["stderr"]
[StateDB]
User = "state_user"
Expand Down Expand Up @@ -82,7 +83,7 @@ MaxTimeForBatchToBeOpen = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
MaxTxsPerBatch = 150
MaxBatchBytesSize = 30000
MaxBatchBytesSize = 150000
MaxCumulativeGasUsed = 30000000
MaxKeccakHashes = 468
MaxPoseidonHashes = 279620
Expand Down
5 changes: 3 additions & 2 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
IsTrustedSequencer = false

[Log]
Environment = "development" # "production" or "development"
Level = "debug"
Outputs = ["stdout"]
Outputs = ["stderr"]

[StateDB]
User = "state_user"
Expand Down Expand Up @@ -80,7 +81,7 @@ MaxTimeForBatchToBeOpen = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
MaxTxsPerBatch = 150
MaxBatchBytesSize = 30000
MaxBatchBytesSize = 150000
MaxCumulativeGasUsed = 30000000
MaxKeccakHashes = 468
MaxPoseidonHashes = 279620
Expand Down
5 changes: 3 additions & 2 deletions config/environments/public/public.node.config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[Log]
Level = "debug"
Outputs = ["stdout"]
Environment = "development" # "production" or "development"
Level = "info"
Outputs = ["stderr"]

[StateDB]
User = "state_user"
Expand Down
3 changes: 0 additions & 3 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ func (etherMan *Client) forcedBatchEvent(ctx context.Context, vLog types.Log, bl
}
msg, err := tx.AsMessage(types.NewLondonSigner(tx.ChainId()), big.NewInt(0))
if err != nil {
log.Error(err)
return err
}
if fb.Sequencer == msg.From() {
Expand Down Expand Up @@ -526,7 +525,6 @@ func (etherMan *Client) sequencedBatchesEvent(ctx context.Context, vLog types.Lo
}
msg, err := tx.AsMessage(types.NewLondonSigner(tx.ChainId()), big.NewInt(0))
if err != nil {
log.Error(err)
return err
}
sequences, err := decodeSequences(tx.Data(), sb.NumBatch, msg.From(), vLog.TxHash, msg.Nonce())
Expand Down Expand Up @@ -651,7 +649,6 @@ func (etherMan *Client) forceSequencedBatchesEvent(ctx context.Context, vLog typ
}
msg, err := tx.AsMessage(types.NewLondonSigner(tx.ChainId()), big.NewInt(0))
if err != nil {
log.Error(err)
return err
}
fullBlock, err := etherMan.EtherClient.BlockByHash(ctx, vLog.BlockHash)
Expand Down
2 changes: 1 addition & 1 deletion etherman/etherman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func init() {
log.Init(log.Config{
Level: "debug",
Outputs: []string{"stdout"},
Outputs: []string{"stderr"},
})
}

Expand Down
2 changes: 1 addition & 1 deletion etherman/etherscan/etherscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func init() {
log.Init(log.Config{
Level: "debug",
Outputs: []string{"stdout"},
Outputs: []string{"stderr"},
})
}

Expand Down
2 changes: 1 addition & 1 deletion etherman/ethgasstation/ethgasstation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func init() {
log.Init(log.Config{
Level: "debug",
Outputs: []string{"stdout"},
Outputs: []string{"stderr"},
})
}

Expand Down
1 change: 1 addition & 0 deletions etherman/types/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// processed.
type Sequence struct {
GlobalExitRoot, StateRoot, LocalExitRoot common.Hash
AccInputHash common.Hash
Timestamp int64
Txs []types.Transaction
IsSequenceTooBig bool
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/umbracle/ethgo v0.1.3
github.com/urfave/cli/v2 v2.23.6
github.com/urfave/cli/v2 v2.23.7
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,8 @@ github.com/umbracle/ethgo v0.1.3/go.mod h1:g9zclCLixH8liBI27Py82klDkW7Oo33AxUOr+
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722 h1:10Nbw6cACsnQm7r34zlpJky+IzxVLRk6MKTS2d3Vp0E=
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722/go.mod h1:c8J0h9aULj2i3umrfyestM6jCq0LK0U6ly6bWy96nd4=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/cli/v2 v2.23.6 h1:iWmtKD+prGo1nKUtLO0Wg4z9esfBM4rAV4QRLQiEmJ4=
github.com/urfave/cli/v2 v2.23.6/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY=
github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.4.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s=
github.com/valyala/fastjson v1.4.1 h1:hrltpHpIpkaxll8QltMU8c3QZ5+qIiCL8yKqPFJI/yE=
Expand Down
5 changes: 3 additions & 2 deletions jsonrpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var connectionCounterMutex sync.Mutex
// Handle is the function that knows which and how a function should
// be executed when a JSON RPC request is received
func (d *Handler) Handle(req Request) Response {
log := log.WithFields("method", req.Method, "requestId", req.ID)
connectionCounterMutex.Lock()
connectionCounter++
connectionCounterMutex.Unlock()
Expand All @@ -59,7 +60,7 @@ func (d *Handler) Handle(req Request) Response {
log.Debugf("Current open connections %d", connectionCounter)
}()
log.Debugf("Current open connections %d", connectionCounter)
log.Debugf("request method %s id %v params %v", req.Method, req.ID, string(req.Params))
log.Debugf("request params %v", string(req.Params))

service, fd, err := d.getFnHandler(req)
if err != nil {
Expand Down Expand Up @@ -90,7 +91,7 @@ func (d *Handler) Handle(req Request) Response {

output := fd.fv.Call(inArgs)
if err := getError(output[1]); err != nil {
log.Infof("failed to call method %s: [%v]%v. Params: %v", req.Method, err.ErrorCode(), err.Error(), string(req.Params))
log.Infof("failed call: [%v]%v. Params: %v", err.ErrorCode(), err.Error(), string(req.Params))
return NewResponse(req, nil, err)
}

Expand Down
2 changes: 2 additions & 0 deletions log/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package log

// Config for log
type Config struct {
// Environment defining the log format ("production" or "development").
Environment LogEnvironment `mapstructure:"Environment"`
// Level of log, e.g. INFO, WARN, ...
Level string `mapstructure:"Level"`
// Outputs
Expand Down
Loading

0 comments on commit 5b95e6e

Please sign in to comment.