mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
Mdbx v0.11.0 (#123)
This commit is contained in:
parent
66c9c6f3f7
commit
ec0155d4ed
32
common/dbg/log_panic.go
Normal file
32
common/dbg/log_panic.go
Normal file
@ -0,0 +1,32 @@
|
||||
package dbg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
stack2 "github.com/go-stack/stack"
|
||||
)
|
||||
|
||||
func StackInLogsFormat() string {
|
||||
return stack2.Trace().TrimBelow(stack2.Caller(1)).String()
|
||||
}
|
||||
|
||||
// Recover - does save panic to datadir/crashreports, bud doesn't log to logger and doesn't stop the process
|
||||
// it returns recovered panic as error in format friendly for our logger
|
||||
// common pattern of use - assign to named output param:
|
||||
// func A() (err error) {
|
||||
// defer func() { err = debug.Recover(err) }() // avoid crash because Erigon's core does many things
|
||||
// }
|
||||
func Recover(err error) error {
|
||||
panicResult := recover()
|
||||
if panicResult == nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch typed := panicResult.(type) {
|
||||
case error:
|
||||
err = fmt.Errorf("%w, trace: %s", typed, StackInLogsFormat())
|
||||
default:
|
||||
err = fmt.Errorf("%+v, trace: %s", typed, StackInLogsFormat())
|
||||
}
|
||||
return err
|
||||
}
|
2
go.mod
2
go.mod
@ -16,7 +16,7 @@ require (
|
||||
github.com/matryer/moq v0.2.3
|
||||
github.com/spaolacci/murmur3 v1.1.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/torquem-ch/mdbx-go v0.21.1
|
||||
github.com/torquem-ch/mdbx-go v0.22.0
|
||||
github.com/ugorji/go/codec v1.1.13
|
||||
go.uber.org/atomic v1.9.0
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
|
||||
|
4
go.sum
4
go.sum
@ -94,8 +94,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/torquem-ch/mdbx-go v0.21.1 h1:E6ZiTsZxXMUceaRm2TbGxSi5q9xTfU/+3flFfHftXCQ=
|
||||
github.com/torquem-ch/mdbx-go v0.21.1/go.mod h1:T2fsoJDVppxfAPTLd1svUgH1kpPmeXdPESmroSHcL1E=
|
||||
github.com/torquem-ch/mdbx-go v0.22.0 h1:d0YMSLQ+Wy4gidxV0SZUgPALRG1lhpEA87Y9m02G/tE=
|
||||
github.com/torquem-ch/mdbx-go v0.22.0/go.mod h1:T2fsoJDVppxfAPTLd1svUgH1kpPmeXdPESmroSHcL1E=
|
||||
github.com/ugorji/go v1.1.13 h1:nB3O5kBSQGjEQAcfe1aLUYuxmXdFKmYgBZhY32rQb6Q=
|
||||
github.com/ugorji/go v1.1.13/go.mod h1:jxau1n+/wyTGLQoCkjok9r5zFa/FxT6eI5HiHKQszjc=
|
||||
github.com/ugorji/go/codec v1.1.13 h1:013LbFhocBoIqgHeIHKlV4JWYhqogATYWZhIcH0WHn4=
|
||||
|
@ -29,13 +29,12 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/c2h5oh/datasize"
|
||||
stack2 "github.com/go-stack/stack"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/torquem-ch/mdbx-go/mdbx"
|
||||
)
|
||||
|
||||
const expectMdbxVersionMajor = 0
|
||||
const expectMdbxVersionMinor = 10
|
||||
const pageSize = 4 * 1024
|
||||
|
||||
const NonExistingDBI kv.DBI = 999_999_999
|
||||
@ -129,10 +128,6 @@ func (opts MdbxOpts) WithTablessCfg(f TableCfgFunc) MdbxOpts {
|
||||
}
|
||||
|
||||
func (opts MdbxOpts) Open() (kv.RwDB, error) {
|
||||
if expectMdbxVersionMajor != mdbx.Major || expectMdbxVersionMinor != mdbx.Minor {
|
||||
return nil, fmt.Errorf("unexpected mdbx version: %d.%d, expected %d %d. Please run 'make mdbx'", int(mdbx.Major), int(mdbx.Minor), expectMdbxVersionMajor, expectMdbxVersionMinor)
|
||||
}
|
||||
|
||||
var err error
|
||||
if opts.inMem {
|
||||
opts.path = testKVPath()
|
||||
@ -219,7 +214,7 @@ func (opts MdbxOpts) Open() (kv.RwDB, error) {
|
||||
|
||||
err = env.Open(opts.path, opts.flags, 0664)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w, label: %s, trace: %s", err, opts.label.String(), callers(10))
|
||||
return nil, fmt.Errorf("%w, label: %s, trace: %s", err, opts.label.String(), stack2.Trace().String())
|
||||
}
|
||||
|
||||
db := &MdbxKV{
|
||||
@ -368,7 +363,7 @@ func (db *MdbxKV) BeginRo(ctx context.Context) (txn kv.Tx, err error) {
|
||||
|
||||
tx, err := db.env.BeginTxn(nil, mdbx.Readonly)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%w, label: %s, trace: %s", err, db.opts.label.String(), callers(10))
|
||||
return nil, fmt.Errorf("%w, label: %s, trace: %s", err, db.opts.label.String(), stack2.Trace().String())
|
||||
}
|
||||
tx.RawRead = true
|
||||
return &MdbxTx{
|
||||
@ -392,7 +387,7 @@ func (db *MdbxKV) BeginRw(_ context.Context) (txn kv.RwTx, err error) {
|
||||
tx, err := db.env.BeginTxn(nil, 0)
|
||||
if err != nil {
|
||||
runtime.UnlockOSThread() // unlock only in case of error. normal flow is "defer .Rollback()"
|
||||
return nil, fmt.Errorf("%w, lable: %s, trace: %s", err, db.opts.label.String(), callers(10))
|
||||
return nil, fmt.Errorf("%w, lable: %s, trace: %s", err, db.opts.label.String(), stack2.Trace().String())
|
||||
}
|
||||
tx.RawRead = true
|
||||
return &MdbxTx{
|
||||
@ -1593,23 +1588,3 @@ func bucketSlice(b kv.TableCfg) []string {
|
||||
})
|
||||
return buckets
|
||||
}
|
||||
|
||||
// Callers returns given number of callers with packages
|
||||
func callers(show int) []string {
|
||||
fpcs := make([]uintptr, show)
|
||||
n := runtime.Callers(2, fpcs)
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
callers := make([]string, 0, len(fpcs))
|
||||
for _, p := range fpcs {
|
||||
caller := runtime.FuncForPC(p - 1)
|
||||
if caller == nil {
|
||||
continue
|
||||
}
|
||||
callers = append(callers, caller.Name())
|
||||
}
|
||||
|
||||
return callers
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
"github.com/ledgerwatch/erigon-lib/common/dbg"
|
||||
"github.com/ledgerwatch/erigon-lib/direct"
|
||||
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
|
||||
"github.com/ledgerwatch/erigon-lib/gointerfaces/sentry"
|
||||
@ -195,7 +196,7 @@ func (f *Fetch) receiveMessage(ctx context.Context, sentryClient sentry.SentryCl
|
||||
if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) {
|
||||
continue
|
||||
}
|
||||
log.Warn("[txpool.fetch] Handling incoming message", "msg", req.Id.String(), "err", err, "rlp", fmt.Sprintf("%x", req.Data))
|
||||
log.Warn("[txpool.fetch] Handling incoming message", "msg", req.Id.String(), "err", err)
|
||||
}
|
||||
if f.wg != nil {
|
||||
f.wg.Done()
|
||||
@ -203,7 +204,13 @@ func (f *Fetch) receiveMessage(ctx context.Context, sentryClient sentry.SentryCl
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Fetch) handleInboundMessage(ctx context.Context, req *sentry.InboundMessage, sentryClient sentry.SentryClient) error {
|
||||
func (f *Fetch) handleInboundMessage(ctx context.Context, req *sentry.InboundMessage, sentryClient sentry.SentryClient) (err error) {
|
||||
defer func() {
|
||||
if rec := recover(); rec != nil {
|
||||
err = fmt.Errorf("%+v, trace: %s", rec, dbg.StackInLogsFormat())
|
||||
}
|
||||
}()
|
||||
|
||||
if !f.pool.Started() {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user