Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into call-many-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JkLondon committed Sep 10, 2024
2 parents 8192713 + f3f1e67 commit 5e4be1d
Show file tree
Hide file tree
Showing 21 changed files with 251 additions and 117 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-cd-main-branch-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ run-name: "Commit id ${{ github.sha }}: CI-CD build and deploy docker images bas

env:
APPLICATION: "erigon"
BUILDER_IMAGE: "golang:1.22.6-alpine3.20"
TARGET_BASE_IMAGE: "alpine:3.20.2"
BUILDER_IMAGE: "golang:1.22.7-alpine3.20"
TARGET_BASE_IMAGE: "alpine:3.20.3"
APP_REPO: "erigontech/erigon"
CHECKOUT_REF: "main"
DOCKERHUB_REPOSITORY: "erigontech/erigon"
Expand Down
29 changes: 14 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.1
skip-build-cache: true
args: --help

- name: Lint
Expand Down Expand Up @@ -114,23 +113,23 @@ jobs:
- name: Test erigon-lib
run: cd erigon-lib && make test-no-fuzz

docker-build-check:
# don't run this on main - the PR must have run it to be merged and it misleads that this pushes the docker image
if: (${{ github.event_name == 'push' || !github.event.pull_request.draft }}) && ${{ github.ref != 'refs/heads/main' }}
runs-on: ubuntu-22.04

steps:
- uses: AutoModality/action-clean@v1
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch git tags for "git describe"
# docker-build-check:
# # don't run this on main - the PR must have run it to be merged and it misleads that this pushes the docker image
# if: (${{ github.event_name == 'push' || !github.event.pull_request.draft }}) && ${{ github.ref != 'refs/heads/main' }}
# runs-on: ubuntu-22.04
#
# steps:
# - uses: AutoModality/action-clean@v1
# - uses: actions/checkout@v4
# with:
# fetch-depth: 0 # fetch git tags for "git describe"

- name: make docker (see dockerhub for image builds)
run: DOCKER_TAG=thorax/erigon:ci-$GITHUB_SHA DOCKER_UID=$(id -u) DOCKER_GID=$(id -g) make docker
# - name: make docker (see dockerhub for image builds)
# run: DOCKER_TAG=thorax/erigon:ci-$GITHUB_SHA DOCKER_UID=$(id -u) DOCKER_GID=$(id -g) make docker

# check with root permissions, should be cached from previous build
- name: sudo make docker
run: sudo DOCKER_TAG=thorax/erigon:ci-$GITHUB_SHA DOCKER_UID=$(id -u) DOCKER_GID=$(id -g) make docker
# - name: sudo make docker
# run: sudo DOCKER_TAG=thorax/erigon:ci-$GITHUB_SHA DOCKER_UID=$(id -u) DOCKER_GID=$(id -g) make docker

# automated-tests:
# runs-on:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Release

env:
APPLICATION: "erigon"
BUILDER_IMAGE: "ghcr.io/goreleaser/goreleaser-cross:v1.21.13"
DOCKER_BASE_IMAGE: "alpine:3.20.2"
BUILDER_IMAGE: "ghcr.io/goreleaser/goreleaser-cross:v1.22.7"
DOCKER_BASE_IMAGE: "alpine:3.20.3"
APP_REPO: "erigontech/erigon"
PACKAGE: "github.com/erigontech/erigon"
DOCKERHUB_REPOSITORY: "erigontech/erigon"
Expand Down
39 changes: 22 additions & 17 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import (
"github.com/erigontech/erigon-lib/kv/temporal"
"github.com/erigontech/erigon-lib/log/v3"
libstate "github.com/erigontech/erigon-lib/state"
"github.com/erigontech/erigon/polygon/bridge"

"github.com/erigontech/erigon/cmd/rpcdaemon/cli/httpcfg"
"github.com/erigontech/erigon/cmd/rpcdaemon/graphql"
"github.com/erigontech/erigon/cmd/rpcdaemon/health"
Expand All @@ -75,6 +73,8 @@ import (
"github.com/erigontech/erigon/node"
"github.com/erigontech/erigon/node/nodecfg"
"github.com/erigontech/erigon/polygon/bor"
"github.com/erigontech/erigon/polygon/bridge"
"github.com/erigontech/erigon/polygon/heimdall"
"github.com/erigontech/erigon/rpc"
"github.com/erigontech/erigon/rpc/rpccfg"
"github.com/erigontech/erigon/turbo/debug"
Expand Down Expand Up @@ -323,24 +323,24 @@ func EmbeddedServices(ctx context.Context,
func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger, rootCancel context.CancelFunc) (
db kv.RoDB, eth rpchelper.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient,
stateCache kvcache.Cache, blockReader services.FullBlockReader, engine consensus.EngineReader,
ff *rpchelper.Filters, bridgeReader bridge.ReaderService, err error) {
ff *rpchelper.Filters, bridgeReader bridge.ReaderService, heimdallReader *heimdall.Reader, err error) {
if !cfg.WithDatadir && cfg.PrivateApiAddr == "" {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, errors.New("either remote db or local db must be specified")
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, errors.New("either remote db or local db must be specified")
}
creds, err := grpcutil.TLS(cfg.TLSCACert, cfg.TLSCertfile, cfg.TLSKeyFile)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("open tls cert: %w", err)
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, fmt.Errorf("open tls cert: %w", err)
}
conn, err := grpcutil.Connect(creds, cfg.PrivateApiAddr)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("could not connect to execution service privateApi: %w", err)
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, fmt.Errorf("could not connect to execution service privateApi: %w", err)
}

remoteBackendClient := remote.NewETHBACKENDClient(conn)
remoteKvClient := remote.NewKVClient(conn)
remoteKv, err := remotedb.NewRemote(gointerfaces.VersionFromProto(remotedbserver.KvServiceAPIVersion), logger, remoteKvClient).Open()
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("could not connect to remoteKv: %w", err)
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, fmt.Errorf("could not connect to remoteKv: %w", err)
}

// Configure DB first
Expand All @@ -365,10 +365,10 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
limiter := semaphore.NewWeighted(int64(cfg.DBReadConcurrency))
rwKv, err = kv2.NewMDBX(logger).RoTxsLimiter(limiter).Path(cfg.Dirs.Chaindata).Accede().Open(ctx)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, err
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, err
}
if compatErr := checkDbCompatibility(ctx, rwKv); compatErr != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, compatErr
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, compatErr
}
db = rwKv

Expand All @@ -383,10 +383,10 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
}
return nil
}); err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, err
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, err
}
if cc == nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, errors.New("chain config not found in db. Need start erigon at least once on this db")
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, errors.New("chain config not found in db. Need start erigon at least once on this db")
}

// Configure sapshots
Expand All @@ -404,7 +404,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
cr := rawdb.NewCanonicalReader(txNumsReader)
agg, err := libstate.NewAggregator(ctx, cfg.Dirs, config3.HistoryV3AggregationStep, db, cr, logger)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("create aggregator: %w", err)
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, fmt.Errorf("create aggregator: %w", err)
}
_ = agg.OpenFolder() //TODO: must use analog of `OptimisticReopenWithDB`

Expand Down Expand Up @@ -455,7 +455,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger

db, err = temporal.New(rwKv, agg)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, err
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err
}
stateCache = kvcache.NewDummy()
}
Expand All @@ -479,7 +479,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
if cfg.TxPoolApiAddr != cfg.PrivateApiAddr {
txpoolConn, err = grpcutil.Connect(creds, cfg.TxPoolApiAddr)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("could not connect to txpool api: %w", err)
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, fmt.Errorf("could not connect to txpool api: %w", err)
}
}

Expand All @@ -504,7 +504,12 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
stateReceiverContractAddress := cc.Bor.GetStateReceiverContract()
bridgeReader, err = bridge.AssembleReader(ctx, cfg.DataDir, logger, stateReceiverContractAddress)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, err
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, err
}

heimdallReader, err = heimdall.AssembleReader(ctx, cc.Bor.CalculateSprintNumber, cfg.DataDir, cfg.Dirs.Tmp, logger)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, err
}
}

Expand All @@ -516,7 +521,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
logger.Warn("[rpc] Opening Bor db", "path", borDbPath)
borKv, err = kv2.NewMDBX(logger).Path(borDbPath).Label(kv.ConsensusDB).Accede().Open(ctx)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, ff, nil, err
return nil, nil, nil, nil, nil, nil, nil, ff, nil, nil, err
}
// Skip the compatibility check, until we have a schema in erigon-lib
engine = bor.NewRo(cc, borKv, blockReader, logger)
Expand Down Expand Up @@ -554,7 +559,7 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger
}()

ff = rpchelper.New(ctx, cfg.RpcFiltersConfig, eth, txPool, mining, onNewSnapshot, logger)
return db, eth, txPool, mining, stateCache, blockReader, engine, ff, bridgeReader, err
return db, eth, txPool, mining, stateCache, blockReader, engine, ff, bridgeReader, heimdallReader, err
}

func StartRpcServer(ctx context.Context, cfg *httpcfg.HttpCfg, rpcAPI []rpc.API, logger log.Logger) error {
Expand Down
7 changes: 5 additions & 2 deletions cmd/rpcdaemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
cmd.RunE = func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
logger := debug.SetupCobra(cmd, "sentry")
db, backend, txPool, mining, stateCache, blockReader, engine, ff, bridgeReader, err := cli.RemoteServices(ctx, cfg, logger, rootCancel)
db, backend, txPool, mining, stateCache, blockReader, engine, ff, bridgeReader, heimdallReader, err := cli.RemoteServices(ctx, cfg, logger, rootCancel)
if err != nil {
if !errors.Is(err, context.Canceled) {
logger.Error("Could not connect to DB", "err", err)
Expand All @@ -52,8 +52,11 @@ func main() {
if bridgeReader != nil {
defer bridgeReader.Close()
}
if heimdallReader != nil {
defer heimdallReader.Close()
}

apiList := jsonrpc.APIList(db, backend, txPool, mining, ff, stateCache, blockReader, cfg, engine, logger, bridgeReader)
apiList := jsonrpc.APIList(db, backend, txPool, mining, ff, stateCache, blockReader, cfg, engine, logger, bridgeReader, heimdallReader)
rpc.PreAllocateRPCMetricLabels(apiList)
if err := cli.StartRpcServer(ctx, cfg, apiList, logger); err != nil {
logger.Error(err.Error())
Expand Down
1 change: 1 addition & 0 deletions erigon-lib/chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type BorConfig interface {
GetNapoliBlock() *big.Int
IsAhmedabad(number uint64) bool
GetStateReceiverContract() string
CalculateSprintNumber(number uint64) uint64
}

func (c *Config) String() string {
Expand Down
16 changes: 9 additions & 7 deletions erigon-lib/kv/rawdbv3/txnum.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ func (TxNumsReader) Last(tx kv.Tx) (blockNum, txNum uint64, err error) {
}
defer c.Close()

lastK, lastV, err := c.Last()
k, v, err := c.Last()
if err != nil {
return 0, 0, err
}
if lastK == nil || lastV == nil {
if k == nil || v == nil {
return 0, 0, nil
}
return binary.BigEndian.Uint64(lastK), binary.BigEndian.Uint64(lastV), nil
return binary.BigEndian.Uint64(k), binary.BigEndian.Uint64(v), nil
}
func (TxNumsReader) First(tx kv.Tx) (blockNum, txNum uint64, err error) {
c, err := tx.Cursor(kv.MaxTxNum)
Expand All @@ -253,14 +253,14 @@ func (TxNumsReader) First(tx kv.Tx) (blockNum, txNum uint64, err error) {
}
defer c.Close()

lastK, lastV, err := c.First()
k, v, err := c.First()
if err != nil {
return 0, 0, err
}
if lastK == nil || lastV == nil {
if k == nil || v == nil {
return 0, 0, nil
}
return binary.BigEndian.Uint64(lastK), binary.BigEndian.Uint64(lastV), nil
return binary.BigEndian.Uint64(k), binary.BigEndian.Uint64(v), nil
}

// LastKey
Expand Down Expand Up @@ -355,7 +355,9 @@ func (i *MapTxNum2BlockNumIter) Next() (txNum, blockNum uint64, txIndex int, isF
return
}
if !ok {
return txNum, i.blockNum, txIndex, isFinalTxn, blockNumChanged, fmt.Errorf("can't find blockNumber by txnID=%d", txNum)
_lb, _lt, _ := i.txNumsReader.Last(i.tx)
_fb, _ft, _ := i.txNumsReader.First(i.tx)
return txNum, i.blockNum, txIndex, isFinalTxn, blockNumChanged, fmt.Errorf("can't find blockNumber by txnID=%d; last in db: (%d-%d, %d-%d)", txNum, _fb, _lb, _ft, _lt)
}
}
blockNum = i.blockNum
Expand Down
3 changes: 0 additions & 3 deletions erigon-lib/kv/stream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ func (it *ArrStream[V]) NextBatch() ([]V, error) {
}

func Range[T constraints.Integer](from, to T) *RangeIter[T] {
if from == to {
to++
}
return &RangeIter[T]{i: from, to: to}
}

Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/kv/stream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestRange(t *testing.T) {
s1 := stream.Range[uint64](1, 1)
res, err := stream.ToArray[uint64](s1)
require.NoError(t, err)
require.Equal(t, []uint64{1}, res)
require.Empty(t, res)
})
}

Expand Down
9 changes: 6 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ type Ethereum struct {

polygonSyncService polygonsync.Service
polygonBridge bridge.PolygonBridge
heimdallService heimdall.Service
stopNode func() error
}

Expand Down Expand Up @@ -550,10 +551,12 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
}

if config.PolygonSync {
polygonBridge = bridge.Assemble(config.Dirs.DataDir, logger, consensusConfig.(*borcfg.BorConfig), heimdallClient)
heimdallService = heimdall.AssembleService(consensusConfig.(*borcfg.BorConfig), config.HeimdallURL, dirs.DataDir, tmpdir, logger)
borConfig := consensusConfig.(*borcfg.BorConfig)
polygonBridge = bridge.Assemble(config.Dirs.DataDir, logger, borConfig, heimdallClient)
heimdallService = heimdall.AssembleService(borConfig.CalculateSprintNumber, config.HeimdallURL, dirs.DataDir, tmpdir, logger)

backend.polygonBridge = polygonBridge
backend.heimdallService = heimdallService
}

flags.Milestone = config.WithHeimdallMilestones
Expand Down Expand Up @@ -1020,7 +1023,7 @@ func (s *Ethereum) Init(stack *node.Node, config *ethconfig.Config, chainConfig
}
}

s.apiList = jsonrpc.APIList(chainKv, ethRpcClient, txPoolRpcClient, miningRpcClient, ff, stateCache, blockReader, &httpRpcCfg, s.engine, s.logger, s.polygonBridge)
s.apiList = jsonrpc.APIList(chainKv, ethRpcClient, txPoolRpcClient, miningRpcClient, ff, stateCache, blockReader, &httpRpcCfg, s.engine, s.logger, s.polygonBridge, s.heimdallService)

if config.SilkwormRpcDaemon && httpRpcCfg.Enabled {
interface_log_settings := silkworm.RpcInterfaceLogSettings{
Expand Down
3 changes: 2 additions & 1 deletion eth/stagedsync/stage_polygon_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ func NewPolygonSyncStageCfg(
txActionStream: txActionStream,
}
borConfig := chainConfig.Bor.(*borcfg.BorConfig)
heimdallService := heimdall.NewService(borConfig, heimdallClient, heimdallStore, logger)
heimdallReader := heimdall.NewReader(borConfig.CalculateSprintNumber, heimdallStore, logger)
heimdallService := heimdall.NewService(borConfig.CalculateSprintNumber, heimdallClient, heimdallStore, logger, heimdallReader)
bridgeService := bridge.NewBridge(bridgeStore, logger, borConfig, heimdallClient, nil)
p2pService := p2p.NewService(maxPeers, logger, sentry, statusDataProvider.GetStatusData)
checkpointVerifier := polygonsync.VerifyCheckpointHeaders
Expand Down
57 changes: 57 additions & 0 deletions polygon/heimdall/reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package heimdall

import (
"context"

libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon/polygon/bor/valset"
)

type Reader struct {
logger log.Logger
store ServiceStore
spanBlockProducersTracker *spanBlockProducersTracker
}

// AssembleReader creates and opens the MDBX store. For use cases where the store is only being read from. Must call Close.
func AssembleReader(ctx context.Context, calculateSprintNumber CalculateSprintNumberFunc, dataDir string, tmpDir string, logger log.Logger) (*Reader, error) {
store := NewMdbxServiceStore(logger, dataDir, tmpDir)

err := store.Prepare(ctx)
if err != nil {
return nil, err
}

return NewReader(calculateSprintNumber, store, logger), nil
}

func NewReader(calculateSprintNumber CalculateSprintNumberFunc, store ServiceStore, logger log.Logger) *Reader {
return &Reader{
logger: logger,
store: store,
spanBlockProducersTracker: newSpanBlockProducersTracker(logger, calculateSprintNumber, store.SpanBlockProducerSelections()),
}
}

func (r *Reader) Span(ctx context.Context, id uint64) (*Span, bool, error) {
return r.store.Spans().Entity(ctx, id)
}

func (r *Reader) CheckpointsFromBlock(ctx context.Context, startBlock uint64) (Waypoints, error) {
entities, err := r.store.Checkpoints().RangeFromBlockNum(ctx, startBlock)
return libcommon.SliceMap(entities, castEntityToWaypoint[*Checkpoint]), err
}

func (r *Reader) MilestonesFromBlock(ctx context.Context, startBlock uint64) (Waypoints, error) {
entities, err := r.store.Milestones().RangeFromBlockNum(ctx, startBlock)
return libcommon.SliceMap(entities, castEntityToWaypoint[*Milestone]), err
}

func (r *Reader) Producers(ctx context.Context, blockNum uint64) (*valset.ValidatorSet, error) {
return r.spanBlockProducersTracker.Producers(ctx, blockNum)
}

func (r *Reader) Close() {
r.store.Close()
}
Loading

0 comments on commit 5e4be1d

Please sign in to comment.