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

Upstream changes - 30/06/2022 #2

Merged
merged 136 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
109e8ab
StageSenders: wrong canonical array size at initial sync with snapsho…
AskAlexSharov Jun 6, 2022
f3575ce
Fix MarkAllVerified (#4380)
yperbasis Jun 6, 2022
b2f9b25
For for overwritten anchor (#4379)
AlexeyAkhunov Jun 6, 2022
3d3b190
Copy deletion key to prevent deleting more blocks (#4384)
AlexeyAkhunov Jun 6, 2022
f6c9d2b
downloader torrent_hashes --verify: 1 error line per file #4386
AskAlexSharov Jun 7, 2022
a53642b
datadir.Dirs configuration object to group dir config (#4387)
AskAlexSharov Jun 7, 2022
7c79d6d
Cfg dirs (#4388)
AskAlexSharov Jun 7, 2022
e146b66
more usage of dirs object #4390
AskAlexSharov Jun 7, 2022
974b1d8
more use of dirs config #4391
AskAlexSharov Jun 7, 2022
2211088
don't open snapshots at startup #4392
AskAlexSharov Jun 7, 2022
d655854
Snapshots: optimisticaly open at app startup (#4393)
AskAlexSharov Jun 7, 2022
454c7aa
torrent: allow del db #4394
AskAlexSharov Jun 7, 2022
e90bc39
Another anchor fix (#4395)
AlexeyAkhunov Jun 7, 2022
a1f4472
added back PR 3806 (#4382)
enriavil1 Jun 7, 2022
a4a466b
Fixed Last in the mining mutation (#4397)
Giulio2002 Jun 7, 2022
07df1eb
Fix mining PoS for Deleting of state entries (#4399)
Giulio2002 Jun 7, 2022
d7d698f
db migration to reset blocks (#4389)
AskAlexSharov Jun 7, 2022
feabb96
Snapshots: allow delete .seg files #4403
AskAlexSharov Jun 8, 2022
cbe2566
Fix --help for --http; embedded rpcdaemon is off by default (#4402)
wmitsuda Jun 8, 2022
c970641
Open reset blocks migration: to delete .torrent files also #4404 (#4…
AskAlexSharov Jun 8, 2022
46d026d
Start txpool in AddLocalTxs (#4406)
yperbasis Jun 8, 2022
2305d09
Print blocks to TTD (#4405)
AlexeyAkhunov Jun 8, 2022
644d25d
MergeForkBlock -> MergeNetsplitBlock (#4407)
yperbasis Jun 8, 2022
bd96c69
Fix operation order during tracing suicide op code (#4409)
iFA88 Jun 8, 2022
f31abfe
Fixes for RPC notification log (#4410)
AlexeyAkhunov Jun 9, 2022
935975b
methods to configure db (#4412)
AskAlexSharov Jun 9, 2022
77e2934
if no latest valid hash default to empty hash (#4411)
enriavil1 Jun 9, 2022
27d652b
WriteForkchoiceHead for no-op FCUs (#4415)
yperbasis Jun 9, 2022
ace482b
revert #4411 (#4418)
enriavil1 Jun 9, 2022
0e142e3
Reclaimable space in logs (#4417)
AskAlexSharov Jun 9, 2022
b8e5cbf
fixed timeout (#4419)
Giulio2002 Jun 9, 2022
367a417
core/types: remove unused field 'td' in Block (#25010) (#4416)
yperbasis Jun 9, 2022
f830401
Update skip_analysis.go (#4420)
AlexeyAkhunov Jun 9, 2022
36eacd2
eth_blockNumber should be equal to latest in eth_getBlockByNumber (#4…
yperbasis Jun 9, 2022
4b4218d
added licensing (#4422)
Giulio2002 Jun 9, 2022
f9024fe
Removed annoying log (#4424)
Giulio2002 Jun 9, 2022
e2a04f7
fix (#4425)
Giulio2002 Jun 10, 2022
b004589
up mmap-go version to solve Win problem #4426
AskAlexSharov Jun 10, 2022
059e5d1
roaring: up version #4427
AskAlexSharov Jun 10, 2022
1e3c90b
Bor devnet option (#4428)
0xKrishna Jun 10, 2022
43f5f0a
Close peerInfo tasks channel (#4429)
AlexeyAkhunov Jun 10, 2022
8e3ac8a
Erigon2 upgrade 2 prototype (#4341)
AlexeyAkhunov Jun 10, 2022
1cc5b92
Another fix for stuck header download (#4433)
AlexeyAkhunov Jun 11, 2022
3f1e994
Update skip_analysis.go (#4435)
AlexeyAkhunov Jun 11, 2022
41c0a47
Add REVERT result to trace (#4434)
iFA88 Jun 11, 2022
fd8addd
trace_filter implementation based on erigon 2 update 2 data (#4431)
AlexeyAkhunov Jun 12, 2022
eb49737
Interruptible PoS block building (#4438)
yperbasis Jun 13, 2022
1f36d76
Added Flush function to memory mutation (#4439)
Giulio2002 Jun 13, 2022
e47dd15
[erigon2.2] Prototype of eth_getLogs (#4437)
AlexeyAkhunov Jun 13, 2022
f376d0a
Remove debug output (#4442)
laughship Jun 14, 2022
a5cb53d
safe and finalized blocks from eth_getBlockByNumber (#4436)
enriavil1 Jun 14, 2022
92b1f06
Gray Glacier bomb delay (#4443)
yperbasis Jun 14, 2022
34d823c
txid patch to try to reduce GC work during commit (#4441)
AlexeyAkhunov Jun 14, 2022
352e5b3
Clean up (#4445)
enriavil1 Jun 14, 2022
21e3ebd
Update skip analysis, add more BSC snapshot hashes (#4448)
AlexeyAkhunov Jun 14, 2022
7f81e0d
in transaction execution, subtract from account balance only after en…
sudeepdino008 Jun 14, 2022
cad32ee
added deletion support (#4451)
Giulio2002 Jun 14, 2022
ff5cbcb
Made in memory mutation compatible with all buckets (#4454)
Giulio2002 Jun 14, 2022
2e4e7bd
[erigon2.2] Log stats tool (#4453)
AlexeyAkhunov Jun 15, 2022
663ccfd
better flush (#4459)
Giulio2002 Jun 15, 2022
631d485
Renamed mutations types to be exported (#4463)
Giulio2002 Jun 15, 2022
bca563f
Fix genesis storage collision state tests (#4462)
yperbasis Jun 15, 2022
df3eea6
Not send sentry task to closed tasks channel (#4467)
AlexeyAkhunov Jun 16, 2022
963fb7a
BSC main net Euler fork (#4461)
enriavil1 Jun 16, 2022
2e60031
Used memory batches from Erigon (#4469)
Giulio2002 Jun 16, 2022
a738a0d
makefile: Add DOCKER_{UID,GID,TAG} make params (#4457)
3nprob Jun 16, 2022
b1572a1
No reorgs when fork choice head points to a canonical header (#4466)
AlexeyAkhunov Jun 16, 2022
45b374a
Enable --http by default (#4470)
yperbasis Jun 16, 2022
70b41f5
Small readjustment of FCU logs (#4473)
yperbasis Jun 17, 2022
93151f0
[erigon2.2] Reduce allocations when replaying historical txs (#4460)
AlexeyAkhunov Jun 17, 2022
027faa1
Update state_processor.go (#4475)
AlexeyAkhunov Jun 17, 2022
ecf528d
Prevent clogging up pending subpool with transactions that were alrea…
AlexeyAkhunov Jun 17, 2022
e44d62d
Fix trace block (#4480)
AlexeyAkhunov Jun 17, 2022
d1aab4e
Bring a corner case in line with the Engine API spec (#4477)
yperbasis Jun 17, 2022
50873a5
[erigon2.2] Fix for code merge (#4478)
AlexeyAkhunov Jun 17, 2022
c2518ad
Removes StorageBlock type (#4483)
Zachinquarantine Jun 18, 2022
dfae218
fix typo (#4486)
uwe Jun 18, 2022
dc8a3fc
fix docs(#4491)
AskAlexSharov Jun 19, 2022
ef749e3
Roaring version up (#4492)
AskAlexSharov Jun 19, 2022
f88fa89
Fix in skip_analysis (#4493)
AlexeyAkhunov Jun 19, 2022
2e3a75f
[erigon2.2] Add skip analysis to trace_filter (#4487)
AlexeyAkhunov Jun 19, 2022
64067a2
Debugging Engine API (#4488)
AlexeyAkhunov Jun 19, 2022
29760d1
Getting rid of unnecessary cache (#4494)
enriavil1 Jun 19, 2022
7a2b575
Added memory execution (#4446)
Giulio2002 Jun 19, 2022
811eef5
add_abigen_error_handle (#4498)
fenghaojiang Jun 20, 2022
8200147
[BSC] fix for the Euler fork (#4500)
AlexeyAkhunov Jun 20, 2022
79830ad
[erigon2.2] collecting read indices (#4499)
AlexeyAkhunov Jun 20, 2022
6612cf4
"torrent_hashes --verify" to detect "snapshots/tmp" dir (#4501)
AskAlexSharov Jun 20, 2022
acd69a6
"-tags debug" to allow pprof show profiling from C code (#4502)
AskAlexSharov Jun 20, 2022
834f0f4
add eulerBlock in chapel.json (#4503)
j75689 Jun 20, 2022
f38ab48
Update chainConfig in the database (#4505)
AlexeyAkhunov Jun 20, 2022
daa8492
Commit transaction before responding on Engine API (#4506)
yperbasis Jun 20, 2022
a11dadd
fixed typo in db_faq.md (#4509)
LMonty-1 Jun 21, 2022
18e5bf3
Rework PR 4505 (#4511)
yperbasis Jun 21, 2022
0a527fe
Send Engine API response after tx.Commit() even when useExternalTx (#…
yperbasis Jun 22, 2022
1c4584b
Include admin methods in README (#4519)
MysticRyuujin Jun 23, 2022
70bd93c
Only apply overrides to stored config of a private chain (#4521)
yperbasis Jun 23, 2022
7896fc6
fixed notifications (#4520)
Giulio2002 Jun 23, 2022
8de7c5e
JSON parsing of safe & finalized (#4524)
yperbasis Jun 23, 2022
5e2f6bb
Fix/new eth filters (#4504)
primalcs Jun 24, 2022
389af4f
check if block is nil (#4528)
enriavil1 Jun 24, 2022
9b8888d
Delete bad blocks on unwind (#4529)
yperbasis Jun 24, 2022
0982edd
Wmake.ps1 changes (#4532)
AndreaLanfranchi Jun 25, 2022
0d29c3d
Compress: reduce etl buffers to save RAM (#4536)
AskAlexSharov Jun 25, 2022
1f4f850
pass context around hased state stage (#4537)
AskAlexSharov Jun 25, 2022
529682a
New goerli snapshot (#4544)
AskAlexSharov Jun 26, 2022
afd07e5
--no-downloader flag support (#4545)
AskAlexSharov Jun 26, 2022
b9cb6d9
Fix nil td (#4546)
AskAlexSharov Jun 26, 2022
f0fde26
document rpc filter methods (#4548)
AskAlexSharov Jun 27, 2022
4897f03
Update Readme re http=false (#4550)
ValValu Jun 27, 2022
588c2d4
Implemented side forks support (up to depth of 128). (#4514)
Giulio2002 Jun 27, 2022
b96a3e7
ttd sepolia (#4552)
Giulio2002 Jun 27, 2022
5b42a6e
Pass context to engines that perform async operations (#4531)
tsutsu Jun 28, 2022
359ae88
don't crush on p2p message handling panic (#4557)
AskAlexSharov Jun 28, 2022
538b4fe
Snapshots: don't panic after too far reset (#4558)
AskAlexSharov Jun 28, 2022
b315394
eth_estimateGas to use snapshots and blocksLRU (#4556)
AskAlexSharov Jun 28, 2022
16e57aa
Switch from eth/66 to eth/67 (#4549)
yperbasis Jun 28, 2022
dc5d3ff
Revert "Switch from eth/66 to eth/67 (#4549)" (#4562)
yperbasis Jun 28, 2022
aa79853
LVH support to memory overlay (#4555)
Giulio2002 Jun 28, 2022
6878ddb
More user-friendly warning about non-existing module of rpc #4568
AskAlexSharov Jun 29, 2022
ed69bac
Fixed in-memory execution hive tests (#4565)
Giulio2002 Jun 29, 2022
64697a9
torrent verbosity now uses int (#4551)
enriavil1 Jun 29, 2022
f613fca
torrent verbosity allow debug #4569 Open
AskAlexSharov Jun 29, 2022
95b4149
Advise remove --snap.stop when no indices (#4570)
AskAlexSharov Jun 29, 2022
880a339
gen less blocks in test (#4571)
AskAlexSharov Jun 29, 2022
8f86c5d
Remove getNodeData experimental feature (#4559)
yperbasis Jun 29, 2022
4155ec1
Fix txpool.accountslots flag (#4573)
yperbasis Jun 29, 2022
4799124
Introduce `eth_callMany` and `debug_traceCallMany` (#4567)
hrthaowang Jun 29, 2022
cfa8b54
downloader: fix tmp dir detection check #4575
AskAlexSharov Jun 29, 2022
d72fba3
eth_estimateGas: read header instead of whole block (#4561)
enriavil1 Jun 29, 2022
b947374
don't recommend --snap.stop flag #4577 Open
AskAlexSharov Jun 29, 2022
6add6ec
Snapshots: new bsc hash #4578
AskAlexSharov Jun 29, 2022
7cd1951
More robust quitting of PoW mining (#4574)
yperbasis Jun 29, 2022
687295f
fixed stall (#4576)
Giulio2002 Jun 29, 2022
7d8c67e
Exempt local transactions from spam protection (#4580)
yperbasis Jun 29, 2022
8558778
fixed engine unit tests (#4581)
Giulio2002 Jun 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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