Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/devel' into devel+classic
Browse files Browse the repository at this point in the history
  • Loading branch information
meowsbits committed Oct 6, 2023
2 parents 57f1717 + 0eed8e3 commit 0a9009d
Show file tree
Hide file tree
Showing 103 changed files with 1,236 additions and 734 deletions.
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (b *SimulatedBackend) Commit() {
Headers: []*types.Header{b.pendingHeader},
Blocks: []*types.Block{b.pendingBlock},
TopBlock: b.pendingBlock,
}, nil); err != nil {
}); err != nil {
panic(err)
}
//nolint:prealloc
Expand Down
1 change: 0 additions & 1 deletion cl/beacon/handler/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (a *ApiHandler) getBlock(r *http.Request) (data any, finalized *bool, versi

blockId, err = blockIdFromRequest(r)
if err != nil {
fmt.Println("A")
httpStatus = http.StatusBadRequest
return
}
Expand Down
28 changes: 19 additions & 9 deletions cmd/downloader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,21 @@ import (
"strings"
"time"

"github.com/ledgerwatch/erigon-lib/common/dir"
"github.com/ledgerwatch/erigon-lib/downloader/snaptype"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
"github.com/ledgerwatch/erigon/cmd/hack/tool"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snapcfg"
"github.com/pelletier/go-toml/v2"

"github.com/c2h5oh/datasize"
mdbx2 "github.com/erigontech/mdbx-go/mdbx"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/common/dir"
"github.com/ledgerwatch/erigon-lib/downloader"
downloadercfg2 "github.com/ledgerwatch/erigon-lib/downloader/downloadercfg"
"github.com/ledgerwatch/erigon-lib/downloader/snaptype"
proto_downloader "github.com/ledgerwatch/erigon-lib/gointerfaces/downloader"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
"github.com/ledgerwatch/log/v3"
"github.com/pelletier/go-toml/v2"
"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand All @@ -37,12 +35,14 @@ import (
"google.golang.org/grpc/reflection"

"github.com/ledgerwatch/erigon/cmd/downloader/downloadernat"
"github.com/ledgerwatch/erigon/cmd/hack/tool"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/common/paths"
"github.com/ledgerwatch/erigon/p2p/nat"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/debug"
"github.com/ledgerwatch/erigon/turbo/logging"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snapcfg"
)

func main() {
Expand Down Expand Up @@ -146,6 +146,9 @@ var rootCmd = &cobra.Command{

func Downloader(ctx context.Context, logger log.Logger) error {
dirs := datadir.New(datadirCli)
if err := datadir.ApplyMigrations(dirs); err != nil {
return err
}
if err := checkChainName(dirs, chain); err != nil {
return err
}
Expand Down Expand Up @@ -243,6 +246,10 @@ var printTorrentHashes = &cobra.Command{

func doPrintTorrentHashes(ctx context.Context, logger log.Logger) error {
dirs := datadir.New(datadirCli)
if err := datadir.ApplyMigrations(dirs); err != nil {
return err
}

if forceRebuild { // remove and create .torrent files (will re-read all snapshots)
//removePieceCompletionStorage(snapDir)
files, err := downloader.AllTorrentPaths(dirs)
Expand Down Expand Up @@ -371,7 +378,10 @@ func checkChainName(dirs datadir.Dirs, chainName string) error {
if !dir.FileExist(filepath.Join(dirs.Chaindata, "mdbx.dat")) {
return nil
}
db := mdbx.NewMDBX(log.New()).Path(dirs.Chaindata).Label(kv.ChainDB).MustOpen()
db := mdbx.NewMDBX(log.New()).
Path(dirs.Chaindata).Label(kv.ChainDB).
Flags(func(flags uint) uint { return flags | mdbx2.Accede }).
MustOpen()
defer db.Close()
if err := db.View(context.Background(), func(tx kv.Tx) error {
cc := tool.ChainConfig(tx)
Expand Down
5 changes: 5 additions & 0 deletions cmd/erigon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"strings"

"github.com/ledgerwatch/erigon-lib/common/datadir"
"github.com/ledgerwatch/erigon-lib/common/dbg"
"github.com/ledgerwatch/erigon/diagnostics"
"github.com/ledgerwatch/erigon/metrics"
Expand Down Expand Up @@ -70,6 +71,10 @@ func runErigon(cliCtx *cli.Context) error {
erigonInfoGauge.Set(1)

nodeCfg := node.NewNodConfigUrfave(cliCtx, logger)
if err := datadir.ApplyMigrations(nodeCfg.Dirs); err != nil {
return err
}

ethCfg := node.NewEthConfigUrfave(cliCtx, nodeCfg, logger)

ethNode, err := node.New(cliCtx.Context, nodeCfg, ethCfg, logger)
Expand Down
13 changes: 11 additions & 2 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,11 @@ func stageSnapshots(db kv.RwDB, ctx context.Context, logger log.Logger) error {
}

func stageHeaders(db kv.RwDB, ctx context.Context, logger log.Logger) error {
dirs := datadir.New(datadirCli)
if err := datadir.ApplyMigrations(dirs); err != nil {
return err
}

sn, borSn, agg := allSnapshots(ctx, db, logger)
defer sn.Close()
defer borSn.Close()
Expand Down Expand Up @@ -852,6 +857,10 @@ func stageSenders(db kv.RwDB, ctx context.Context, logger log.Logger) error {

func stageExec(db kv.RwDB, ctx context.Context, logger log.Logger) error {
dirs := datadir.New(datadirCli)
if err := datadir.ApplyMigrations(dirs); err != nil {
return err
}

engine, vmConfig, sync, _, _ := newSync(ctx, db, nil /* miningConfig */, logger)
must(sync.SetCurrentStage(stages.Execution))
sn, borSn, agg := allSnapshots(ctx, db, logger)
Expand Down Expand Up @@ -894,7 +903,7 @@ func stageExec(db kv.RwDB, ctx context.Context, logger log.Logger) error {
br, _ := blocksIO(db, logger)
cfg := stagedsync.StageExecuteBlocksCfg(db, pm, batchSize, nil, chainConfig, engine, vmConfig, nil,
/*stateStream=*/ false,
/*badBlockHalt=*/ false, historyV3, dirs, br, nil, genesis, syncCfg, agg)
/*badBlockHalt=*/ false, historyV3, dirs, br, nil, genesis, syncCfg, agg, nil)

var tx kv.RwTx //nil - means lower-level code (each stage) will manage transactions
if noCommit {
Expand Down Expand Up @@ -1531,7 +1540,7 @@ func newSync(ctx context.Context, db kv.RwDB, miningConfig *params.MiningConfig,
notifications := &shards.Notifications{}
blockRetire := freezeblocks.NewBlockRetire(1, dirs, blockReader, blockWriter, db, notifications.Events, logger)

stages := stages2.NewDefaultStages(context.Background(), db, p2p.Config{}, &cfg, sentryControlServer, notifications, nil, blockReader, blockRetire, agg, nil, heimdallClient, logger)
stages := stages2.NewDefaultStages(context.Background(), db, p2p.Config{}, &cfg, sentryControlServer, notifications, nil, blockReader, blockRetire, agg, nil, nil, heimdallClient, logger)
sync := stagedsync.New(stages, stagedsync.DefaultUnwindOrder, stagedsync.DefaultPruneOrder, logger)

miner := stagedsync.NewMiningState(&cfg.Miner)
Expand Down
8 changes: 6 additions & 2 deletions cmd/integration/commands/state_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ func init() {

func syncBySmallSteps(db kv.RwDB, miningConfig params.MiningConfig, ctx context.Context, logger1 log.Logger) error {
dirs := datadir.New(datadirCli)
if err := datadir.ApplyMigrations(dirs); err != nil {
return err
}

sn, borSn, agg := allSnapshots(ctx, db, logger1)
defer sn.Close()
defer borSn.Close()
Expand Down Expand Up @@ -218,7 +222,7 @@ func syncBySmallSteps(db kv.RwDB, miningConfig params.MiningConfig, ctx context.

br, _ := blocksIO(db, logger1)
execCfg := stagedsync.StageExecuteBlocksCfg(db, pm, batchSize, changeSetHook, chainConfig, engine, vmConfig, changesAcc, false, false, historyV3, dirs,
br, nil, genesis, syncCfg, agg)
br, nil, genesis, syncCfg, agg, nil)

execUntilFunc := func(execToBlock uint64) func(firstCycle bool, badBlockUnwind bool, stageState *stagedsync.StageState, unwinder stagedsync.Unwinder, tx kv.RwTx, logger log.Logger) error {
return func(firstCycle bool, badBlockUnwind bool, s *stagedsync.StageState, unwinder stagedsync.Unwinder, tx kv.RwTx, logger log.Logger) error {
Expand Down Expand Up @@ -556,7 +560,7 @@ func loopExec(db kv.RwDB, ctx context.Context, unwind uint64, logger log.Logger)
br, _ := blocksIO(db, logger)
cfg := stagedsync.StageExecuteBlocksCfg(db, pm, batchSize, nil, chainConfig, engine, vmConfig, nil,
/*stateStream=*/ false,
/*badBlockHalt=*/ false, historyV3, dirs, br, nil, genesis, syncCfg, agg)
/*badBlockHalt=*/ false, historyV3, dirs, br, nil, genesis, syncCfg, agg, nil)

// set block limit of execute stage
sync.MockExecFunc(stages.Execution, func(firstCycle bool, badBlockUnwind bool, stageState *stagedsync.StageState, unwinder stagedsync.Unwinder, tx kv.RwTx, logger log.Logger) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/pics/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,13 @@ func initialState1() error {
// BLOCKS

for i := 0; i < chain.Length(); i++ {
if err = m2.InsertChain(chain.Slice(i, i+1), nil); err != nil {
if err = m2.InsertChain(chain.Slice(i, i+1)); err != nil {
return err
}
if err = stateDatabaseComparison(m.DB, m2.DB, i+1); err != nil {
return err
}
if err = m.InsertChain(chain.Slice(i, i+1), nil); err != nil {
if err = m.InsertChain(chain.Slice(i, i+1)); err != nil {
return err
}
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/rpcdaemon/rpcdaemontest/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ func CreateTestSentry(t *testing.T) (*mock.MockSentry, *core.ChainPack, []*core.
t.Fatal(err)
}

if err = m.InsertChain(orphanedChain, nil); err != nil {
if err = m.InsertChain(orphanedChain); err != nil {
t.Fatal(err)
}
if err = m.InsertChain(chain, nil); err != nil {
if err = m.InsertChain(chain); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -428,7 +428,7 @@ func CreateTestSentryForTraces(t *testing.T) *mock.MockSentry {
t.Fatalf("generate blocks: %v", err)
}

if err := m.InsertChain(chain, nil); err != nil {
if err := m.InsertChain(chain); err != nil {
t.Fatalf("failed to insert into chain: %v", err)
}
return m
Expand Down Expand Up @@ -534,7 +534,7 @@ func CreateTestSentryForTracesCollision(t *testing.T) *mock.MockSentry {
t.Fatalf("generate blocks: %v", err)
}
// Import the canonical chain
if err := m.InsertChain(chain, nil); err != nil {
if err := m.InsertChain(chain); err != nil {
t.Fatalf("failed to insert into chain: %v", err)
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/state/commands/opcode_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ type opcodeTracer struct {
saveBblocks bool
blockNumber uint64
depth int
env vm.VMInterface
env *vm.EVM
}

func NewOpcodeTracer(blockNum uint64, saveOpcodes bool, saveBblocks bool) *opcodeTracer {
Expand Down Expand Up @@ -195,7 +195,7 @@ func (ot *opcodeTracer) captureStartOrEnter(from, to libcommon.Address, create b
ot.stack = append(ot.stack, &newTx)
}

func (ot *opcodeTracer) CaptureStart(env vm.VMInterface, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) {
func (ot *opcodeTracer) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) {
ot.env = env
ot.depth = 0
ot.captureStartOrEnter(from, to, create, input)
Expand Down
2 changes: 1 addition & 1 deletion cmd/state/exec3/calltracer_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (ct *CallTracer) Tos() map[libcommon.Address]struct{} { return ct.tos }

func (ct *CallTracer) CaptureTxStart(gasLimit uint64) {}
func (ct *CallTracer) CaptureTxEnd(restGas uint64) {}
func (ct *CallTracer) CaptureStart(env vm.VMInterface, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) {
func (ct *CallTracer) CaptureStart(env *vm.EVM, from libcommon.Address, to libcommon.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) {
if ct.froms == nil {
ct.froms = map[libcommon.Address]struct{}{}
ct.tos = map[libcommon.Address]struct{}{}
Expand Down
18 changes: 16 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ var (
WithHeimdallMilestones = cli.BoolFlag{
Name: "bor.milestone",
Usage: "Enabling bor milestone processing",
Value: false,
Value: true,
}

// HeimdallgRPCAddressFlag flag for heimdall gRPC address
Expand Down Expand Up @@ -828,6 +828,12 @@ var (
Name: "diagnostics.ids",
Usage: "Comma separated list of support session ids to connect to",
}

SilkwormPathFlag = cli.StringFlag{
Name: "silkworm.path",
Usage: "Path to the silkworm_api library (enables embedded Silkworm execution)",
Value: "",
}
)

var MetricFlags = []cli.Flag{&MetricsEnabledFlag, &MetricsHTTPFlag, &MetricsPortFlag}
Expand Down Expand Up @@ -1450,6 +1456,13 @@ func setWhitelist(ctx *cli.Context, cfg *ethconfig.Config) {
}
}

func setSilkworm(ctx *cli.Context, cfg *ethconfig.Config) {
cfg.SilkwormEnabled = ctx.IsSet(SilkwormPathFlag.Name)
if cfg.SilkwormEnabled {
cfg.SilkwormPath = ctx.String(SilkwormPathFlag.Name)
}
}

// CheckExclusive verifies that only a single instance of the provided flags was
// set by the user. Each flag might optionally be followed by a string type to
// specialize it further.
Expand Down Expand Up @@ -1552,6 +1565,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
setMiner(ctx, &cfg.Miner)
setWhitelist(ctx, cfg)
setBorConfig(ctx, cfg)
setSilkworm(ctx, cfg)

cfg.Ethstats = ctx.String(EthStatsURLFlag.Name)
cfg.P2PEnabled = len(nodeConfig.P2P.SentryAddr) == 0
Expand Down Expand Up @@ -1636,7 +1650,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
cfg.TxPool.OverrideCancunTime = cfg.OverrideCancunTime
}

if ctx.IsSet(InternalConsensusFlag.Name) && clparams.EmbeddedEnabledByDefault(cfg.NetworkID) {
if ctx.IsSet(InternalConsensusFlag.Name) && clparams.EmbeddedSupported(cfg.NetworkID) {
cfg.InternalCL = ctx.Bool(InternalConsensusFlag.Name)
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/aura/aura_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestEmptyBlock(t *testing.T) {
blocks[0] = block

chain := &core.ChainPack{Headers: headers, Blocks: blocks, Receipts: receipts, TopBlock: block}
err = m.InsertChain(chain, nil)
err = m.InsertChain(chain)
require.NoError(err)
}

Expand Down
22 changes: 2 additions & 20 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -36,7 +35,6 @@ import (
"github.com/ledgerwatch/erigon/consensus/misc"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/systemcontracts"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/types/accounts"
"github.com/ledgerwatch/erigon/crypto"
Expand Down Expand Up @@ -415,7 +413,7 @@ func New(

// make sure we can decode all the GenesisAlloc in the BorConfig.
for key, genesisAlloc := range c.config.BlockAlloc {
if _, err := decodeGenesisAlloc(genesisAlloc); err != nil {
if _, err := types.DecodeGenesisAlloc(genesisAlloc); err != nil {
panic(fmt.Sprintf("BUG: Block alloc '%s' in genesis is not correct: %v", key, err))
}
}
Expand Down Expand Up @@ -1041,25 +1039,10 @@ func (c *Bor) Finalize(config *chain.Config, header *types.Header, state *state.
return nil, types.Receipts{}, nil
}

func decodeGenesisAlloc(i interface{}) (types.GenesisAlloc, error) {
var alloc types.GenesisAlloc

b, err := json.Marshal(i)
if err != nil {
return nil, err
}

if err := json.Unmarshal(b, &alloc); err != nil {
return nil, err
}

return alloc, nil
}

func (c *Bor) changeContractCodeIfNeeded(headerNumber uint64, state *state.IntraBlockState) error {
for blockNumber, genesisAlloc := range c.config.BlockAlloc {
if blockNumber == strconv.FormatUint(headerNumber, 10) {
allocs, err := decodeGenesisAlloc(genesisAlloc)
allocs, err := types.DecodeGenesisAlloc(genesisAlloc)
if err != nil {
return fmt.Errorf("failed to decode genesis alloc: %v", err)
}
Expand Down Expand Up @@ -1128,7 +1111,6 @@ func (c *Bor) GenerateSeal(chain consensus.ChainHeaderReader, currnt, parent *ty

func (c *Bor) Initialize(config *chain.Config, chain consensus.ChainHeaderReader, header *types.Header,
state *state.IntraBlockState, syscall consensus.SysCallCustom, logger log.Logger) {
systemcontracts.UpgradeBuildInSystemContract(config, header.Number, state, logger)
}

// Authorize injects a private key into the consensus engine to mint new blocks
Expand Down
4 changes: 2 additions & 2 deletions consensus/clique/clique_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestReimportMirroredState(t *testing.T) {
}

// Insert the first two blocks and make sure the chain is valid
if err := m.InsertChain(chain.Slice(0, 2), nil); err != nil {
if err := m.InsertChain(chain.Slice(0, 2)); err != nil {
t.Fatalf("failed to insert initial blocks: %v", err)
}
if err := m.DB.View(m.Ctx, func(tx kv.Tx) error {
Expand All @@ -123,7 +123,7 @@ func TestReimportMirroredState(t *testing.T) {
// Simulate a crash by creating a new chain on top of the database, without
// flushing the dirty states out. Insert the last block, triggering a sidechain
// reimport.
if err := m.InsertChain(chain.Slice(2, chain.Length()), nil); err != nil {
if err := m.InsertChain(chain.Slice(2, chain.Length())); err != nil {
t.Fatalf("failed to insert final block: %v", err)
}
if err := m.DB.View(m.Ctx, func(tx kv.Tx) error {
Expand Down
Loading

0 comments on commit 0a9009d

Please sign in to comment.