Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'ledgerwatch:devel' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
0xKrishna authored Jun 30, 2022
2 parents b513a03 + 8558778 commit 6b1971b
Show file tree
Hide file tree
Showing 281 changed files with 31,312 additions and 8,256 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ FROM docker.io/library/alpine:3.15
RUN apk add --no-cache ca-certificates libstdc++ tzdata
COPY --from=builder /app/build/bin/* /usr/local/bin/

RUN adduser -H -u 1000 -g 1000 -D erigon
ARG PUID=1000
ARG PGID=1000
RUN adduser -H -u ${PUID} -g ${PGID} -D erigon
RUN mkdir -p /home/erigon
RUN mkdir -p /home/erigon/.local/share/erigon
RUN chown -R erigon:erigon /home/erigon
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ GOBIN = $(CURDIR)/build/bin
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
GIT_TAG ?= $(shell git describe --tags '--match=v*' --dirty)
DOCKER_UID ?= 1000
DOCKER_PID ?= 1000
DOCKER_TAG ?= thorax/erigon:latest

CGO_CFLAGS := $(shell $(GO) env CGO_CFLAGS) # don't loose default
CGO_CFLAGS += -DMDBX_FORCE_ASSERTIONS=1 # Enable MDBX's asserts by default in 'devel' branch and disable in 'stable'
Expand All @@ -30,10 +33,12 @@ go-version:
fi

docker: git-submodules
DOCKER_BUILDKIT=1 docker build -t thorax/erigon:latest \
DOCKER_BUILDKIT=1 docker build -t ${DOCKER_TAG} \
--build-arg "BUILD_DATE=$(shell date -Iseconds)" \
--build-arg VCS_REF=${GIT_COMMIT} \
--build-arg VERSION=${GIT_TAG} \
--build-arg PUID=${DOCKER_UID} \
--build-arg PGID=${DOCKER_PID} \
${DOCKER_FLAGS} \
.

Expand Down Expand Up @@ -68,6 +73,7 @@ COMMANDS += integration
COMMANDS += observer
COMMANDS += pics
COMMANDS += rpcdaemon
COMMANDS += rpcdaemon22
COMMANDS += rpctest
COMMANDS += sentry
COMMANDS += state
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ socket connection to pass data between them. To use this mode, run Erigon in one

```sh
make erigon
./build/bin/erigon --private.api.addr=localhost:9090
./build/bin/erigon --private.api.addr=localhost:9090 --http=false
make rpcdaemon
./build/bin/rpcdaemon --private.api.addr=localhost:9090 --http.api=eth,erigon,web3,net,debug,trace,txpool
```
Expand Down
4 changes: 4 additions & 0 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ABI struct {
Constructor Method
Methods map[string]Method
Events map[string]Event
Errors map[string]Error

// Additional "special" functions introduced in solidity v0.6.0.
// It's separated from the original default fallback. Each contract
Expand Down Expand Up @@ -158,6 +159,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
}
abi.Methods = make(map[string]Method)
abi.Events = make(map[string]Event)
abi.Errors = make(map[string]Error)
for _, field := range fields {
switch field.Type {
case "constructor":
Expand Down Expand Up @@ -185,6 +187,8 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
case "event":
name := abi.overloadedEventName(field.Name)
abi.Events[name] = NewEvent(name, field.Name, field.Anonymous, field.Inputs)
case "error":
abi.Errors[field.Name] = NewError(field.Name, field.Inputs)
default:
return fmt.Errorf("abi: could not recognize type %v of field %v", field.Type, field.Name)
}
Expand Down
14 changes: 14 additions & 0 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,3 +1144,17 @@ func TestUnpackRevert(t *testing.T) {
})
}
}

func TestCustomErrors(t *testing.T) {
json := `[{ "inputs": [ { "internalType": "uint256", "name": "", "type": "uint256" } ],"name": "MyError", "type": "error"} ]`
abi, err := JSON(strings.NewReader(json))
if err != nil {
t.Fatal(err)
}
check := func(name string, expect string) {
if abi.Errors[name].Sig != expect {
t.Fatalf("The signature of overloaded method mismatch, want %s, have %s", expect, abi.Methods[name].Sig)
}
}
check("MyError", "MyError(uint256)")
}
67 changes: 67 additions & 0 deletions accounts/abi/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,78 @@
package abi

import (
"bytes"
"errors"
"fmt"
"reflect"
"strings"

"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/crypto"
)

type Error struct {
Name string
Inputs Arguments
str string
// Sig contains the string signature according to the ABI spec.
// e.g. event foo(uint32 a, int b) = "foo(uint32,int256)"
// Please note that "int" is substitute for its canonical representation "int256"
Sig string
// ID returns the canonical representation of the event's signature used by the
// abi definition to identify event names and types.
ID common.Hash
}

func NewError(name string, inputs Arguments) Error {
names := make([]string, len(inputs))
types := make([]string, len(inputs))
for i, input := range inputs {
if input.Name == "" {
inputs[i] = Argument{
Name: fmt.Sprintf("arg%d", i),
Indexed: input.Indexed,
Type: input.Type,
}
} else {
inputs[i] = input
}
// string representation
names[i] = fmt.Sprintf("%v %v", input.Type, inputs[i].Name)
if input.Indexed {
names[i] = fmt.Sprintf("%v indexed %v", input.Type, inputs[i].Name)
}
// sig representation
types[i] = input.Type.String()
}

str := fmt.Sprintf("error %v(%v)", name, strings.Join(names, ", "))
sig := fmt.Sprintf("%v(%v)", name, strings.Join(types, ","))
id := common.BytesToHash(crypto.Keccak256([]byte(sig)))

return Error{
Name: name,
Inputs: inputs,
str: str,
Sig: sig,
ID: id,
}
}

func (e *Error) String() string {
return e.str
}

func (e *Error) Unpack(data []byte) (interface{}, error) {
if len(data) < 4 {
return "", errors.New("invalid data for unpacking")
}
if !bytes.Equal(data[:4], e.ID[:4]) {
return "", errors.New("invalid data for unpacking")
}
return e.Inputs.Unpack(data[4:])
}

var (
errBadBool = errors.New("abi: improperly encoded boolean value")
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/cons/commands/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func cliqueEngine(ctx context.Context, logger log.Logger) error {
return err
}
}
server.db = openDB(filepath.Join(datadir, "clique", "db"), logger)
server.db = openDB(filepath.Join(datadirCli, "clique", "db"), logger)
server.c = clique.New(server.chainConfig, params.CliqueSnapshot, server.db)
<-ctx.Done()
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/cons/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var (
consensusAddr string // Address of the consensus engine <host>:<port>
datadir string // Path to the working dir
datadirCli string // Path to the working dir
config string // `file:<path>`` to specify config file in file system, `embed:<path>`` to use embedded file, `test` to register test interface and receive config from test driver
)

Expand Down Expand Up @@ -52,7 +52,7 @@ func must(err error) {
}

func withDataDir(cmd *cobra.Command) {
cmd.Flags().StringVar(&datadir, "datadir", paths.DefaultDataDir(), "directory where databases and temporary files are kept")
cmd.Flags().StringVar(&datadirCli, "datadir", paths.DefaultDataDir(), "directory where databases and temporary files are kept")
must(cmd.MarkFlagDirname("datadir"))
}

Expand Down
26 changes: 21 additions & 5 deletions cmd/downloader/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
common2 "github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
"github.com/ledgerwatch/erigon/cmd/downloader/downloader/torrentcfg"
"github.com/ledgerwatch/erigon/cmd/downloader/downloader/downloadercfg"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/log/v3"
mdbx2 "github.com/torquem-ch/mdbx-go/mdbx"
Expand All @@ -29,7 +29,7 @@ type Downloader struct {
torrentClient *torrent.Client
clientLock *sync.RWMutex

cfg *torrentcfg.Cfg
cfg *downloadercfg.Cfg

statsLock *sync.RWMutex
stats AggStats
Expand All @@ -51,7 +51,7 @@ type AggStats struct {
UploadRate, DownloadRate uint64
}

func New(cfg *torrentcfg.Cfg) (*Downloader, error) {
func New(cfg *downloadercfg.Cfg) (*Downloader, error) {
if err := portMustBeTCPAndUDPOpen(cfg.ListenPort); err != nil {
return nil, err
}
Expand All @@ -63,7 +63,7 @@ func New(cfg *torrentcfg.Cfg) (*Downloader, error) {
if common.FileExist(cfg.DataDir + "_tmp") { // migration from prev versions
_ = os.Rename(cfg.DataDir+"_tmp", filepath.Join(cfg.DataDir, "tmp")) // ignore error, because maybe they are on different drive, or target folder already created manually, all is fine
}
if !common.FileExist(filepath.Join(cfg.DataDir, "db")) {
if !common.FileExist(filepath.Join(cfg.DataDir, "db")) && !HasSegFile(cfg.DataDir) { // it's ok to remove "datadir/snapshots/db" dir or add .seg files manually
cfg.DataDir = filepath.Join(cfg.DataDir, "tmp")
} else {
if err := copyFromTmp(cfg.DataDir); err != nil {
Expand Down Expand Up @@ -205,7 +205,7 @@ func (d *Downloader) onComplete() {
panic(err)
}
d.cfg.DataDir = snapDir
fmt.Printf("alex1: %s\n", d.cfg.DataDir)
// fmt.Printf("alex1: %s\n", d.cfg.DataDir)

db, c, m, torrentClient, err := openClient(d.cfg.ClientConfig)
if err != nil {
Expand Down Expand Up @@ -367,3 +367,19 @@ func MainLoop(ctx context.Context, d *Downloader, silent bool) {
}
}
}

func HasSegFile(dir string) bool {
files, err := os.ReadDir(dir)
if err != nil {
return false
}
for _, f := range files {
if f.IsDir() {
continue
}
if filepath.Ext(f.Name()) == ".seg" {
return true
}
}
return false
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package torrentcfg
package downloadercfg

import (
"fmt"
Expand Down Expand Up @@ -54,7 +54,7 @@ func Default() *torrent.ClientConfig {
return torrentConfig
}

func New(snapDir string, verbosity lg.Level, natif nat.Interface, downloadRate, uploadRate datasize.ByteSize, port, connsPerFile int, downloadSlots int) (*Cfg, error) {
func New(snapDir string, verbosity lg.Level, dbg bool, natif nat.Interface, downloadRate, uploadRate datasize.ByteSize, port, connsPerFile, downloadSlots int) (*Cfg, error) {
torrentConfig := Default()
// We would-like to reduce amount of goroutines in Erigon, so reducing next params
torrentConfig.EstablishedConnsPerTorrent = connsPerFile // default: 50
Expand Down Expand Up @@ -114,9 +114,9 @@ func New(snapDir string, verbosity lg.Level, natif nat.Interface, downloadRate,
}

// debug
//if lg.Debug == verbosity {
// torrentConfig.Debug = true
//}
if dbg {
torrentConfig.Debug = true
}
torrentConfig.Logger = lg.Default.FilterLevel(verbosity)
torrentConfig.Logger.Handlers = []lg.Handler{adapterHandler{}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package torrentcfg
package downloadercfg

import (
"fmt"
"strings"

utp "github.com/anacrolix/go-libutp"
Expand All @@ -13,12 +14,25 @@ func init() {
utp.Logger.Handlers = []lg.Handler{noopHandler{}}
}

func Str2LogLevel(in string) (lg.Level, error) {
lvl := lg.Level{}
if err := lvl.UnmarshalText([]byte(in)); err != nil {
return lvl, err
func Int2LogLevel(level int) (lvl lg.Level, dbg bool, err error) {
switch level {
case 0:
lvl = lg.Critical
case 1:
lvl = lg.Error
case 2:
lvl = lg.Warning
case 3:
lvl = lg.Info
case 4:
lvl = lg.Debug
case 5:
lvl = lg.Debug
dbg = true
default:
return lvl, dbg, fmt.Errorf("invalid level set, expected a number between 0-5 but got: %d", level)
}
return lvl, nil
return lvl, dbg, nil
}

type noopHandler struct{}
Expand Down
Loading

0 comments on commit 6b1971b

Please sign in to comment.