Skip to content

Commit

Permalink
create turbo/services pkg (erigontech#4269)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored May 26, 2022
1 parent 619beb7 commit fc1a37e
Show file tree
Hide file tree
Showing 44 changed files with 171 additions and 337 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,5 @@ git-submodules:
@[ -d ".git" ] || (echo "Not a git repository" && exit 1)
@echo "Updating git submodules"
@# Dockerhub using ./hooks/post-checkout to set submodules, so this line will fail on Dockerhub
@git submodule sync --recursive
@git submodule sync --quiet --recursive
@git submodule update --quiet --init --recursive --force || true
6 changes: 3 additions & 3 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ledgerwatch/erigon-lib/common/cmp"
"github.com/ledgerwatch/erigon-lib/etl"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/interfaces"
"github.com/ledgerwatch/erigon/cmd/sentry/sentry"
"github.com/ledgerwatch/erigon/consensus"
"github.com/ledgerwatch/erigon/consensus/ethash"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/ledgerwatch/erigon/migrations"
"github.com/ledgerwatch/erigon/p2p"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snap"
stages2 "github.com/ledgerwatch/erigon/turbo/stages"
Expand Down Expand Up @@ -1104,9 +1104,9 @@ func allSnapshots(cc *params.ChainConfig) *snapshotsync.RoSnapshots {
}

var openBlockReaderOnce sync.Once
var _blockReaderSingleton interfaces.FullBlockReader
var _blockReaderSingleton services.FullBlockReader

func getBlockReader(cc *params.ChainConfig) (blockReader interfaces.FullBlockReader) {
func getBlockReader(cc *params.ChainConfig) (blockReader services.FullBlockReader) {
openBlockReaderOnce.Do(func() {
_blockReaderSingleton = snapshotsync.NewBlockReader()
if sn := allSnapshots(cc); sn != nil {
Expand Down
32 changes: 16 additions & 16 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/remotedb"
"github.com/ledgerwatch/erigon-lib/kv/remotedbserver"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli/httpcfg"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/health"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/interfaces"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices/rpcinterfaces"
"github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/hexutil"
Expand All @@ -39,6 +38,7 @@ import (
"github.com/ledgerwatch/erigon/node"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/services"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snap"
"github.com/ledgerwatch/log/v3"
Expand Down Expand Up @@ -210,10 +210,10 @@ func checkDbCompatibility(ctx context.Context, db kv.RoDB) error {
return nil
}

func EmbeddedServices(ctx context.Context, erigonDB kv.RoDB, stateCacheCfg kvcache.CoherentConfig, blockReader interfaces.BlockAndTxnReader, ethBackendServer remote.ETHBACKENDServer,
func EmbeddedServices(ctx context.Context, erigonDB kv.RoDB, stateCacheCfg kvcache.CoherentConfig, blockReader services.BlockAndTxnReader, ethBackendServer remote.ETHBACKENDServer,
txPoolServer txpool.TxpoolServer, miningServer txpool.MiningServer,
) (
eth services.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient, starknet *services.StarknetService, stateCache kvcache.Cache, ff *filters.Filters, err error,
eth rpcinterfaces.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient, starknet *rpcservices.StarknetService, stateCache kvcache.Cache, ff *rpcservices.Filters, err error,
) {
if stateCacheCfg.KeysLimit > 0 {
stateCache = kvcache.New(stateCacheCfg)
Expand All @@ -227,21 +227,21 @@ func EmbeddedServices(ctx context.Context, erigonDB kv.RoDB, stateCacheCfg kvcac

directClient := direct.NewEthBackendClientDirect(ethBackendServer)

eth = services.NewRemoteBackend(directClient, erigonDB, blockReader)
eth = rpcservices.NewRemoteBackend(directClient, erigonDB, blockReader)
txPool = direct.NewTxPoolClient(txPoolServer)
mining = direct.NewMiningClient(miningServer)
ff = filters.New(ctx, eth, txPool, mining, func() {})
ff = rpcservices.New(ctx, eth, txPool, mining, func() {})
return
}

// RemoteServices - use when RPCDaemon run as independent process. Still it can use --datadir flag to enable
// `cfg.WithDatadir` (mode when it on 1 machine with Erigon)
func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger, rootCancel context.CancelFunc) (
db kv.RoDB, borDb kv.RoDB,
eth services.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient,
starknet *services.StarknetService,
stateCache kvcache.Cache, blockReader interfaces.BlockAndTxnReader,
ff *filters.Filters, err error) {
eth rpcinterfaces.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient,
starknet *rpcservices.StarknetService,
stateCache kvcache.Cache, blockReader services.BlockAndTxnReader,
ff *rpcservices.Filters, err error) {
if !cfg.WithDatadir && cfg.PrivateApiAddr == "" {
return nil, nil, nil, nil, nil, nil, nil, nil, ff, fmt.Errorf("either remote db or local db must be specified")
}
Expand Down Expand Up @@ -385,7 +385,7 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
if !cfg.WithDatadir {
blockReader = snapshotsync.NewRemoteBlockReader(remote.NewETHBACKENDClient(conn))
}
remoteEth := services.NewRemoteBackend(remote.NewETHBACKENDClient(conn), db, blockReader)
remoteEth := rpcservices.NewRemoteBackend(remote.NewETHBACKENDClient(conn), db, blockReader)
blockReader = remoteEth

txpoolConn := conn
Expand All @@ -397,9 +397,9 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
}

mining = txpool.NewMiningClient(txpoolConn)
miningService := services.NewMiningService(mining)
miningService := rpcservices.NewMiningService(mining)
txPool = txpool.NewTxpoolClient(txpoolConn)
txPoolService := services.NewTxPoolService(txPool)
txPoolService := rpcservices.NewTxPoolService(txPool)
if db == nil {
db = remoteKv
}
Expand All @@ -424,10 +424,10 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, ff, fmt.Errorf("could not connect to starknet api: %w", err)
}
starknet = services.NewStarknetService(starknetConn)
starknet = rpcservices.NewStarknetService(starknetConn)
}

ff = filters.New(ctx, eth, txPool, mining, onNewSnapshot)
ff = rpcservices.New(ctx, eth, txPool, mining, onNewSnapshot)

return db, borDb, eth, txPool, mining, starknet, stateCache, blockReader, ff, err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/admin_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices/rpcinterfaces"
"github.com/ledgerwatch/erigon/p2p"
)

Expand All @@ -21,11 +21,11 @@ type AdminAPI interface {

// AdminAPIImpl data structure to store things needed for admin_* commands.
type AdminAPIImpl struct {
ethBackend services.ApiBackend
ethBackend rpcinterfaces.ApiBackend
}

// NewAdminAPI returns AdminAPIImpl instance.
func NewAdminAPI(eth services.ApiBackend) *AdminAPIImpl {
func NewAdminAPI(eth rpcinterfaces.ApiBackend) *AdminAPIImpl {
return &AdminAPIImpl{
ethBackend: eth,
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/rpcdaemon/commands/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli/httpcfg"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/interfaces"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices/rpcinterfaces"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/services"
)

// APIList describes the list of available RPC apis
func APIList(db kv.RoDB, borDb kv.RoDB, eth services.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient,
starknet starknet.CAIROVMClient, filters *filters.Filters, stateCache kvcache.Cache,
blockReader interfaces.BlockAndTxnReader, cfg httpcfg.HttpCfg) (list []rpc.API) {
func APIList(db kv.RoDB, borDb kv.RoDB, eth rpcinterfaces.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient,
starknet starknet.CAIROVMClient, filters *rpcservices.Filters, stateCache kvcache.Cache,
blockReader services.BlockAndTxnReader, cfg httpcfg.HttpCfg) (list []rpc.API) {

base := NewBaseApi(filters, stateCache, blockReader, cfg.WithDatadir)
if cfg.TevmEnabled {
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
types2 "github.com/ledgerwatch/erigon-lib/gointerfaces/types"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices/rpcinterfaces"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/core/types"
Expand Down Expand Up @@ -69,7 +69,7 @@ type EngineAPI interface {
type EngineImpl struct {
*BaseAPI
db kv.RoDB
api services.ApiBackend
api rpcinterfaces.ApiBackend
}

func convertPayloadStatus(x *remote.EnginePayloadStatus) map[string]interface{} {
Expand Down Expand Up @@ -253,7 +253,7 @@ func (e *EngineImpl) ExchangeTransitionConfigurationV1(ctx context.Context, beac
}

// NewEngineAPI returns EngineImpl instance
func NewEngineAPI(base *BaseAPI, db kv.RoDB, api services.ApiBackend) *EngineImpl {
func NewEngineAPI(base *BaseAPI, db kv.RoDB, api rpcinterfaces.ApiBackend) *EngineImpl {
return &EngineImpl{
BaseAPI: base,
db: db,
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/erigon_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices/rpcinterfaces"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/p2p"
Expand Down Expand Up @@ -39,11 +39,11 @@ type ErigonAPI interface {
type ErigonImpl struct {
*BaseAPI
db kv.RoDB
ethBackend services.ApiBackend
ethBackend rpcinterfaces.ApiBackend
}

// NewErigonAPI returns ErigonImpl instance
func NewErigonAPI(base *BaseAPI, db kv.RoDB, eth services.ApiBackend) *ErigonImpl {
func NewErigonAPI(base *BaseAPI, db kv.RoDB, eth rpcinterfaces.ApiBackend) *ErigonImpl {
return &ErigonImpl{
BaseAPI: base,
db: db,
Expand Down
18 changes: 9 additions & 9 deletions cmd/rpcdaemon/commands/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/interfaces"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices/rpcinterfaces"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/common/math"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/ledgerwatch/erigon/internal/ethapi"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rpc"
"github.com/ledgerwatch/erigon/turbo/services"
)

// EthAPI is a collection of functions that are exposed in the
Expand Down Expand Up @@ -96,17 +96,17 @@ type EthAPI interface {
type BaseAPI struct {
stateCache kvcache.Cache // thread-safe
blocksLRU *lru.Cache // thread-safe
filters *filters.Filters
filters *rpcservices.Filters
_chainConfig *params.ChainConfig
_genesis *types.Block
_genesisLock sync.RWMutex

_blockReader interfaces.BlockReader
_txnReader interfaces.TxnReader
_blockReader services.BlockReader
_txnReader services.TxnReader
TevmEnabled bool // experiment
}

func NewBaseApi(f *filters.Filters, stateCache kvcache.Cache, blockReader interfaces.BlockAndTxnReader, singleNodeMode bool) *BaseAPI {
func NewBaseApi(f *rpcservices.Filters, stateCache kvcache.Cache, blockReader services.BlockAndTxnReader, singleNodeMode bool) *BaseAPI {
blocksLRUSize := 128 // ~32Mb
if !singleNodeMode {
blocksLRUSize = 512
Expand Down Expand Up @@ -230,15 +230,15 @@ func (api *BaseAPI) blockByRPCNumber(number rpc.BlockNumber, tx kv.Tx) (*types.B
// APIImpl is implementation of the EthAPI interface based on remote Db access
type APIImpl struct {
*BaseAPI
ethBackend services.ApiBackend
ethBackend rpcinterfaces.ApiBackend
txPool txpool.TxpoolClient
mining txpool.MiningClient
db kv.RoDB
GasCap uint64
}

// NewEthAPI returns APIImpl instance
func NewEthAPI(base *BaseAPI, db kv.RoDB, eth services.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient, gascap uint64) *APIImpl {
func NewEthAPI(base *BaseAPI, db kv.RoDB, eth rpcinterfaces.ApiBackend, txPool txpool.TxpoolClient, mining txpool.MiningClient, gascap uint64) *APIImpl {
if gascap == 0 {
gascap = uint64(math.MaxUint64 / 2)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/rpcdaemon/commands/eth_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

filters2 "github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
filters2 "github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices"

"github.com/ledgerwatch/erigon/common"

Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/eth_ming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/erigon/turbo/snapshotsync"
Expand All @@ -19,7 +19,7 @@ import (
func TestPendingBlock(t *testing.T) {
ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, stages.Mock(t))
mining := txpool.NewMiningClient(conn)
ff := filters.New(ctx, nil, nil, mining, func() {})
ff := rpcservices.New(ctx, nil, nil, mining, func() {})
stateCache := kvcache.New(kvcache.DefaultCoherentConfig)
api := NewEthAPI(NewBaseApi(ff, stateCache, snapshotsync.NewBlockReader(), false), nil, nil, nil, mining, 5000000)
expect := uint64(12345)
Expand All @@ -44,7 +44,7 @@ func TestPendingBlock(t *testing.T) {
func TestPendingLogs(t *testing.T) {
ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, stages.Mock(t))
mining := txpool.NewMiningClient(conn)
ff := filters.New(ctx, nil, nil, mining, func() {})
ff := rpcservices.New(ctx, nil, nil, mining, func() {})
expect := []byte{211}

ch := make(chan types.Logs, 1)
Expand Down
7 changes: 3 additions & 4 deletions cmd/rpcdaemon/commands/eth_subscribe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (

"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
"github.com/ledgerwatch/erigon-lib/gointerfaces/sentry"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/types"
Expand Down Expand Up @@ -38,8 +37,8 @@ func TestEthSubscribe(t *testing.T) {
m.ReceiveWg.Wait() // Wait for all messages to be processed before we proceeed

ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, m)
backend := services.NewRemoteBackend(remote.NewETHBACKENDClient(conn), m.DB, snapshotsync.NewBlockReader())
ff := filters.New(ctx, backend, nil, nil, func() {})
backend := rpcservices.NewRemoteBackend(remote.NewETHBACKENDClient(conn), m.DB, snapshotsync.NewBlockReader())
ff := rpcservices.New(ctx, backend, nil, nil, func() {})

newHeads := make(chan *types.Header)
defer close(newHeads)
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpcdaemon/commands/net_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strconv"

"github.com/ledgerwatch/erigon/cmd/rpcdaemon/services"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices/rpcinterfaces"
"github.com/ledgerwatch/erigon/common/hexutil"
)

Expand All @@ -18,11 +18,11 @@ type NetAPI interface {

// NetAPIImpl data structure to store things needed for net_ commands
type NetAPIImpl struct {
ethBackend services.ApiBackend
ethBackend rpcinterfaces.ApiBackend
}

// NewNetAPIImpl returns NetAPIImplImpl instance
func NewNetAPIImpl(eth services.ApiBackend) *NetAPIImpl {
func NewNetAPIImpl(eth rpcinterfaces.ApiBackend) *NetAPIImpl {
return &NetAPIImpl{
ethBackend: eth,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/rpcdaemon/commands/send_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
"github.com/ledgerwatch/erigon-lib/kv/kvcache"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/commands"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/filters"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcdaemontest"
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/rpcservices"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/u256"
"github.com/ledgerwatch/erigon/core"
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestSendRawTransaction(t *testing.T) {

ctx, conn := rpcdaemontest.CreateTestGrpcConn(t, m)
txPool := txpool.NewTxpoolClient(conn)
ff := filters.New(ctx, nil, txPool, txpool.NewMiningClient(conn), func() {})
ff := rpcservices.New(ctx, nil, txPool, txpool.NewMiningClient(conn), func() {})
stateCache := kvcache.New(kvcache.DefaultCoherentConfig)
api := commands.NewEthAPI(commands.NewBaseApi(ff, stateCache, snapshotsync.NewBlockReader(), false), m.DB, nil, txPool, nil, 5000000)

Expand Down
Loading

0 comments on commit fc1a37e

Please sign in to comment.