good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit abf4fa58 authored by Igor Mandrigin's avatar Igor Mandrigin Committed by GitHub
Browse files

Don't require MDBX if you don't specify it (#1313)

* fix compilation

* add mdbx flag to the tg binary

* fix makefile

* fixups

* fix makefile

* fix readme

* fix linters

* fix tests
parent a139f31d
No related branches found
No related tags found
No related merge requests found
GOBIN = $(CURDIR)/build/bin
GOBUILD = env GO111MODULE=on go build -trimpath
GOTEST = go test ./... -p 1
GOTEST = go test ./... -p 1 --tags 'mdbx'
LATEST_COMMIT ?= $(shell git log -n 1 origin/master --pretty=format:"%H")
ifeq ($(LATEST_COMMIT),)
......@@ -31,19 +31,19 @@ docker-compose:
docker-compose up
geth:
$(GOBUILD) -o $(GOBIN)/tg -ldflags "-X main.gitCommit=${GIT_COMMIT}" ./cmd/tg
$(GOBUILD) -o $(GOBIN)/tg -tags "mdbx" -ldflags "-X main.gitCommit=${GIT_COMMIT}" ./cmd/tg
@echo "Done building."
@echo "Run \"$(GOBIN)/tg\" to launch turbo-geth."
tg:
@echo "Building mdbx"
cd ethdb/mdbx/dist/ && make clean && make libmdbx.a && cat config.h
$(GOBUILD) -o $(GOBIN)/tg -ldflags "-X main.gitCommit=${GIT_COMMIT}" ./cmd/tg
$(GOBUILD) -o $(GOBIN)/tg -tags "mdbx" -ldflags "-X main.gitCommit=${GIT_COMMIT}" ./cmd/tg
@echo "Done building."
@echo "Run \"$(GOBIN)/tg\" to launch turbo-geth."
hack:
$(GOBUILD) -o $(GOBIN)/hack ./cmd/hack
$(GOBUILD) -o $(GOBIN)/hack -tags "mdbx" ./cmd/hack
@echo "Done building."
@echo "Run \"$(GOBIN)/hack\" to launch hack."
......@@ -102,8 +102,8 @@ headers:
@echo "Run \"$(GOBIN)/integration\" to run headers download PoC."
db-tools:
$(GOBUILD) -o $(GOBIN)/lmdb_stat github.com/ledgerwatch/lmdb-go/cmd/lmdb_stat
$(GOBUILD) -o $(GOBIN)/lmdb_copy github.com/ledgerwatch/lmdb-go/cmd/lmdb_copy
$(GOBUILD) -o $(GOBIN)/lmdb_stat -tags "mdbx" github.com/ledgerwatch/lmdb-go/cmd/lmdb_stat
$(GOBUILD) -o $(GOBIN)/lmdb_copy -tags "mdbx" github.com/ledgerwatch/lmdb-go/cmd/lmdb_copy
cd ethdb/mdbx/dist/ && make tools
cp ethdb/mdbx/dist/mdbx_stat $(GOBIN)
......@@ -125,7 +125,7 @@ test-lmdb: semantics/z3/build/libz3.a
TEST_DB=lmdb $(GOTEST)
test-mdbx: semantics/z3/build/libz3.a ethdb/mdbx/dist/libmdbx.a
TEST_DB=mdbx $(GOTEST)
TEST_DB=mdbx $(GOTEST_MDBX)
lint: lintci
......@@ -133,19 +133,23 @@ lintci: semantics/z3/build/libz3.a ethdb/mdbx/dist/libmdbx.a
@echo "--> Running linter for code diff versus commit $(LATEST_COMMIT)"
@./build/bin/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--build-tags="mdbx" \
--config ./.golangci/step1.yml \
--exclude "which can be annoying to use"
@./build/bin/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--build-tags="mdbx" \
--config ./.golangci/step2.yml
@./build/bin/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--build-tags="mdbx" \
--config ./.golangci/step3.yml
@./build/bin/golangci-lint run \
--new-from-rev=$(LATEST_COMMIT) \
--build-tags="mdbx" \
--config ./.golangci/step4.yml
lintci-deps:
......
......@@ -251,42 +251,3 @@ it impacts performance - one of main TG optimisations: "reduce Disk random acces
"Blocks Execution stage" still does much random reads - this is reason why it's slowest stage.
We do not recommend run multiple genesis syncs on same Disk.
If genesis sync passed, then it's fine to run multiple TG on same Disk.
## 2. `go run` doesn't work `no such file or directory: <>./ethdb/mdbx/dist/libmdbx.a`
If you are trying to run our binaries with `go run` you might end up with an issue like that
```
> go run ./cmd/integration print_stages --chaindata /Volumes/OWC1/ddd-dev/tg/chaindata
go: downloading github.com/spf13/cobra v1.1.1
# github.com/ethereum/evmc/v7/bindings/go/evmc
host.c:33:20: warning: unused function 'go_exported_functions_type_checks' [-Wunused-function]
# github.com/ledgerwatch/turbo-geth/ethdb/mdbx
clang: error: no such file or directory: '<..>/turbo-geth/ethdb/mdbx/dist/libmdbx.a'
```
To fix that, do `make all` and after that `go run` should work successfully.
```
> make all
<...>
> go run ./cmd/integration print_stages --chaindata /Volumes/OWC_DISK_3/ddd-dev/tg/chaindata
# github.com/ethereum/evmc/v7/bindings/go/evmc
host.c:33:20: warning: unused function 'go_exported_functions_type_checks' [-Wunused-function]
Headers 11104855
BlockHashes 11104855
Bodies 11098821
Senders 11098816
Execution 11098816
IntermediateHashes 11098816
HashState 11098816
AccountHistoryIndex 11098816
StorageHistoryIndex 11098816
LogIndex 11098816
CallTraces 0
TxLookup 11098816
TxPool 11098816
Finish 11098816
INFO [10-28|09:29:17.907] database closed (LMDB) lmdb=chaindata
```
......@@ -18,6 +18,8 @@ import (
"github.com/prometheus/tsdb/fileutil"
)
var _ DbCopier = &LmdbKV{}
const (
NonExistingDBI dbutils.DBI = 999_999_999
)
......@@ -276,6 +278,10 @@ type LmdbKV struct {
func NewLMDB() LmdbOpts {
return LmdbOpts{bucketsCfg: DefaultBucketConfigs}
}
func (db *LmdbKV) NewDbWithTheSameParameters() *ObjectDatabase {
opts := db.opts
return NewObjectDatabase(NewLMDB().Set(opts).MustOpen())
}
// Close closes db
// All transactions must be closed before closing the database.
......
//+build mdbx
package ethdb
import (
......@@ -17,6 +19,8 @@ import (
"github.com/ledgerwatch/turbo-geth/log"
)
var _ DbCopier = &MdbxKV{}
type MdbxOpts struct {
inMem bool
exclusive bool
......@@ -261,6 +265,11 @@ func (db *MdbxKV) Close() {
}
func (db *MdbxKV) NewDbWithTheSameParameters() *ObjectDatabase {
opts := db.opts
return NewObjectDatabase(NewMDBX().Set(opts).MustOpen())
}
func (db *MdbxKV) DiskSize(_ context.Context) (uint64, error) {
stats, err := db.env.Stat()
if err != nil {
......
// +build mdbx
/*
Package lmdb provides bindings to the lmdb C API. The package bindings are
fairly low level and are designed to provide a minimal interface that prevents
......
......@@ -39,6 +39,10 @@ var (
dbPutTimer = metrics.NewRegisteredTimer("db/put", nil)
)
type DbCopier interface {
NewDbWithTheSameParameters() *ObjectDatabase
}
// ObjectDatabase - is an object-style interface of DB accessing
type ObjectDatabase struct {
kv KV
......@@ -321,13 +325,11 @@ func (db *ObjectDatabase) SetKV(kv KV) {
func (db *ObjectDatabase) MemCopy() *ObjectDatabase {
var mem *ObjectDatabase
// Open the db and recover any potential corruptions
switch db.kv.(type) {
case *LmdbKV:
opts := db.kv.(*LmdbKV).opts
mem = NewObjectDatabase(NewLMDB().Set(opts).MustOpen())
case *MdbxKV:
opts := db.kv.(*MdbxKV).opts
mem = NewObjectDatabase(NewMDBX().Set(opts).MustOpen())
switch t := db.kv.(type) {
case DbCopier:
mem = t.NewDbWithTheSameParameters()
default:
panic(fmt.Sprintf("MemCopy is not implemented for type %T", t))
}
if err := db.kv.View(context.Background(), func(readTx Tx) error {
......
//+build !mdbx
package ethdb
func NewMDBX() LmdbOpts {
panic("to use MDBX, compile with -tags 'mdbx'")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment