From 79d6617cfa53ee6138e33d7b92528711713893b6 Mon Sep 17 00:00:00 2001 From: Shoham Chakraborty Date: Sat, 7 Sep 2024 11:44:45 +0800 Subject: [PATCH] polygon/bridge: Support Astrid bridge on standalone and privateapi server (#11693) Fixes #11485 --- cmd/rpcdaemon/cli/config.go | 68 ++++++++++++---------- cmd/rpcdaemon/main.go | 7 ++- cmd/rpcdaemon/rpcdaemontest/test_util.go | 2 +- erigon-lib/chain/chain_config.go | 1 + eth/backend.go | 2 +- ethdb/privateapi/ethbackend.go | 49 ++++++++++++++-- polygon/bor/borcfg/bor_config.go | 4 ++ polygon/bridge/bridge.go | 2 +- polygon/bridge/reader.go | 74 ++++++++++++++++++++++-- polygon/heimdall/service_store.go | 2 +- polygon/polygoncommon/database.go | 15 +++-- turbo/jsonrpc/eth_subscribe_test.go | 2 +- 12 files changed, 178 insertions(+), 50 deletions(-) diff --git a/cmd/rpcdaemon/cli/config.go b/cmd/rpcdaemon/cli/config.go index 3e897ece2ef..2dfffdcc2e0 100644 --- a/cmd/rpcdaemon/cli/config.go +++ b/cmd/rpcdaemon/cli/config.go @@ -55,6 +55,7 @@ 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" @@ -94,6 +95,7 @@ var rootCmd = &cobra.Command{ var ( stateCacheStr string + polygonSync bool ) func RootCommand() (*cobra.Command, *httpcfg.HttpCfg) { @@ -105,6 +107,7 @@ func RootCommand() (*cobra.Command, *httpcfg.HttpCfg) { rootCmd.PersistentFlags().BoolVar(&cfg.GraphQLEnabled, "graphql", false, "enables graphql endpoint (disabled by default)") rootCmd.PersistentFlags().Uint64Var(&cfg.Gascap, "rpc.gascap", 50_000_000, "Sets a cap on gas that can be used in eth_call/estimateGas") rootCmd.PersistentFlags().Uint64Var(&cfg.MaxTraces, "trace.maxtraces", 200, "Sets a limit on traces that can be returned in trace_filter") + rootCmd.PersistentFlags().BoolVar(&polygonSync, "polygon.sync", false, "Enable if Erigon has been synced using the new polygon sync component") rootCmd.PersistentFlags().StringVar(&cfg.RpcAllowListFilePath, utils.RpcAccessListFlag.Name, "", "Specify granular (method-by-method) API allowlist") rootCmd.PersistentFlags().UintVar(&cfg.RpcBatchConcurrency, utils.RpcBatchConcurrencyFlag.Name, 2, utils.RpcBatchConcurrencyFlag.Usage) @@ -320,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, err error) { + ff *rpchelper.Filters, bridgeReader bridge.ReaderService, err error) { if !cfg.WithDatadir && cfg.PrivateApiAddr == "" { - return nil, nil, nil, nil, nil, nil, nil, ff, errors.New("either remote db or local db must be specified") + return nil, nil, nil, nil, nil, nil, nil, ff, 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, fmt.Errorf("open tls cert: %w", err) + return nil, nil, nil, nil, nil, nil, nil, ff, 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, fmt.Errorf("could not connect to execution service privateApi: %w", err) + return nil, nil, nil, nil, nil, nil, nil, ff, 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, fmt.Errorf("could not connect to remoteKv: %w", err) + return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("could not connect to remoteKv: %w", err) } // Configure DB first @@ -362,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, err + return nil, nil, nil, nil, nil, nil, nil, ff, nil, err } if compatErr := checkDbCompatibility(ctx, rwKv); compatErr != nil { - return nil, nil, nil, nil, nil, nil, nil, ff, compatErr + return nil, nil, nil, nil, nil, nil, nil, ff, nil, compatErr } db = rwKv @@ -380,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, err + return nil, nil, nil, nil, nil, nil, nil, ff, nil, err } if cc == nil { - return nil, nil, nil, nil, nil, nil, nil, ff, 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, errors.New("chain config not found in db. Need start erigon at least once on this db") } // Configure sapshots @@ -401,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, fmt.Errorf("create aggregator: %w", err) + return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("create aggregator: %w", err) } _ = agg.OpenFolder() //TODO: must use analog of `OptimisticReopenWithDB` @@ -452,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, err + return nil, nil, nil, nil, nil, nil, nil, nil, nil, err } stateCache = kvcache.NewDummy() } @@ -476,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, fmt.Errorf("could not connect to txpool api: %w", err) + return nil, nil, nil, nil, nil, nil, nil, ff, nil, fmt.Errorf("could not connect to txpool api: %w", err) } } @@ -496,29 +499,36 @@ func RemoteServices(ctx context.Context, cfg *httpcfg.HttpCfg, logger log.Logger var remoteCE *remoteConsensusEngine if cfg.WithDatadir { - switch { - case cc != nil: - switch { - case cc.Bor != nil: - var borKv kv.RoDB - - // bor (consensus) specific db - borDbPath := filepath.Join(cfg.DataDir, "bor") - logger.Warn("[rpc] Opening Bor db", "path", borDbPath) - borKv, err = kv2.NewMDBX(logger).Path(borDbPath).Label(kv.ConsensusDB).Accede().Open(ctx) + if cc != nil && cc.Bor != nil { + if polygonSync { + 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, err + return nil, nil, nil, nil, nil, nil, nil, ff, nil, err } - // Skip the compatibility check, until we have a schema in erigon-lib - engine = bor.NewRo(cc, borKv, blockReader, logger) - default: - engine = ethash.NewFaker() } - default: + // NOTE: bor_* RPCs are not fully supported when using polygon.sync (https://github.com/erigontech/erigon/issues/11171) + var borKv kv.RoDB + + // bor (consensus) specific db + borDbPath := filepath.Join(cfg.DataDir, "bor") + 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 + } + // Skip the compatibility check, until we have a schema in erigon-lib + engine = bor.NewRo(cc, borKv, blockReader, logger) + } else { engine = ethash.NewFaker() } } else { + if cc != nil && cc.Bor != nil && polygonSync { + stateReceiverContractAddress := cc.Bor.GetStateReceiverContract() + bridgeReader = bridge.NewRemoteReader(remoteBackendClient, stateReceiverContractAddress) + } + remoteCE = &remoteConsensusEngine{} engine = remoteCE } @@ -544,7 +554,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, err + return db, eth, txPool, mining, stateCache, blockReader, engine, ff, bridgeReader, err } func StartRpcServer(ctx context.Context, cfg *httpcfg.HttpCfg, rpcAPI []rpc.API, logger log.Logger) error { diff --git a/cmd/rpcdaemon/main.go b/cmd/rpcdaemon/main.go index 665327679c9..102d5fd346b 100644 --- a/cmd/rpcdaemon/main.go +++ b/cmd/rpcdaemon/main.go @@ -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, err := cli.RemoteServices(ctx, cfg, logger, rootCancel) + db, backend, txPool, mining, stateCache, blockReader, engine, ff, bridgeReader, 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) @@ -49,8 +49,11 @@ func main() { } defer db.Close() defer engine.Close() + if bridgeReader != nil { + defer bridgeReader.Close() + } - apiList := jsonrpc.APIList(db, backend, txPool, mining, ff, stateCache, blockReader, cfg, engine, logger, nil) + apiList := jsonrpc.APIList(db, backend, txPool, mining, ff, stateCache, blockReader, cfg, engine, logger, bridgeReader) rpc.PreAllocateRPCMetricLabels(apiList) if err := cli.StartRpcServer(ctx, cfg, apiList, logger); err != nil { logger.Error(err.Error()) diff --git a/cmd/rpcdaemon/rpcdaemontest/test_util.go b/cmd/rpcdaemon/rpcdaemontest/test_util.go index c48c5c32f1c..becf04724bc 100644 --- a/cmd/rpcdaemon/rpcdaemontest/test_util.go +++ b/cmd/rpcdaemon/rpcdaemontest/test_util.go @@ -312,7 +312,7 @@ func CreateTestGrpcConn(t *testing.T, m *mock.MockSentry) (context.Context, *grp server := grpc.NewServer() remote.RegisterETHBACKENDServer(server, privateapi.NewEthBackendServer(ctx, nil, m.DB, m.Notifications.Events, - m.BlockReader, log.New(), builder.NewLatestBlockBuiltStore())) + m.BlockReader, log.New(), builder.NewLatestBlockBuiltStore(), nil)) txpool.RegisterTxpoolServer(server, m.TxPoolGrpcServer) txpool.RegisterMiningServer(server, privateapi.NewMiningServer(ctx, &IsMiningMock{}, ethashApi, m.Log)) listener := bufconn.Listen(1024 * 1024) diff --git a/erigon-lib/chain/chain_config.go b/erigon-lib/chain/chain_config.go index 3230b7897eb..fa0df5d6f48 100644 --- a/erigon-lib/chain/chain_config.go +++ b/erigon-lib/chain/chain_config.go @@ -98,6 +98,7 @@ type BorConfig interface { IsNapoli(num uint64) bool GetNapoliBlock() *big.Int IsAhmedabad(number uint64) bool + GetStateReceiverContract() string } func (c *Config) String() string { diff --git a/eth/backend.go b/eth/backend.go index e52358bff4f..37d968df51c 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -748,7 +748,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger } // Initialize ethbackend - ethBackendRPC := privateapi.NewEthBackendServer(ctx, backend, backend.chainDB, backend.notifications.Events, blockReader, logger, latestBlockBuiltStore) + ethBackendRPC := privateapi.NewEthBackendServer(ctx, backend, backend.chainDB, backend.notifications.Events, blockReader, logger, latestBlockBuiltStore, polygonBridge) // initialize engine backend blockSnapBuildSema := semaphore.NewWeighted(int64(dbg.BuildSnapshotAllowance)) diff --git a/ethdb/privateapi/ethbackend.go b/ethdb/privateapi/ethbackend.go index 8b8a0e5ab67..c9cde0b89e3 100644 --- a/ethdb/privateapi/ethbackend.go +++ b/ethdb/privateapi/ethbackend.go @@ -24,6 +24,7 @@ import ( "google.golang.org/protobuf/types/known/emptypb" "github.com/erigontech/erigon-lib/log/v3" + "github.com/erigontech/erigon/core/types" libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/direct" @@ -40,6 +41,11 @@ import ( "github.com/erigontech/erigon/turbo/shards" ) +type bridgeReader interface { + Events(ctx context.Context, blockNum uint64) ([]*types.Message, error) + EventTxnLookup(ctx context.Context, borTxHash libcommon.Hash) (uint64, bool, error) +} + // EthBackendAPIVersion // 2.0.0 - move all mining-related methods to 'txpool/mining' server // 2.1.0 - add NetPeerCount function @@ -58,6 +64,7 @@ type EthBackendServer struct { events *shards.Events db kv.RoDB blockReader services.FullBlockReader + bridgeReader bridgeReader latestBlockBuiltStore *builder.LatestBlockBuiltStore logsFilter *LogsFilterAggregator @@ -74,9 +81,15 @@ type EthBackend interface { } func NewEthBackendServer(ctx context.Context, eth EthBackend, db kv.RwDB, events *shards.Events, blockReader services.FullBlockReader, - logger log.Logger, latestBlockBuiltStore *builder.LatestBlockBuiltStore, + logger log.Logger, latestBlockBuiltStore *builder.LatestBlockBuiltStore, bridgeReader bridgeReader, ) *EthBackendServer { - s := &EthBackendServer{ctx: ctx, eth: eth, events: events, db: db, blockReader: blockReader, + s := &EthBackendServer{ + ctx: ctx, + eth: eth, + events: events, + db: db, + blockReader: blockReader, + bridgeReader: bridgeReader, logsFilter: NewLogsFilterAggregator(events), logger: logger, latestBlockBuiltStore: latestBlockBuiltStore, @@ -329,6 +342,18 @@ func (s *EthBackendServer) SubscribeLogs(server remote.ETHBACKEND_SubscribeLogsS } func (s *EthBackendServer) BorTxnLookup(ctx context.Context, req *remote.BorTxnLookupRequest) (*remote.BorTxnLookupReply, error) { + if s.bridgeReader != nil { + blockNum, ok, err := s.bridgeReader.EventTxnLookup(ctx, gointerfaces.ConvertH256ToHash(req.BorTxHash)) + if err != nil { + return nil, err + } + + return &remote.BorTxnLookupReply{ + Present: ok, + BlockNumber: blockNum, + }, nil + } + tx, err := s.db.BeginRo(ctx) if err != nil { return nil, err @@ -346,6 +371,22 @@ func (s *EthBackendServer) BorTxnLookup(ctx context.Context, req *remote.BorTxnL } func (s *EthBackendServer) BorEvents(ctx context.Context, req *remote.BorEventsRequest) (*remote.BorEventsReply, error) { + if s.bridgeReader != nil { + events, err := s.bridgeReader.Events(ctx, req.BlockNum) + if err != nil { + return nil, err + } + + eventsRaw := make([][]byte, len(events)) + for i, event := range events { + eventsRaw[i] = event.Data() + } + + return &remote.BorEventsReply{ + EventRlps: eventsRaw, + }, nil + } + tx, err := s.db.BeginRo(ctx) if err != nil { return nil, err @@ -358,8 +399,8 @@ func (s *EthBackendServer) BorEvents(ctx context.Context, req *remote.BorEventsR } eventsRaw := make([][]byte, len(events)) - for i, e := range events { - eventsRaw[i] = e + for i, event := range events { + eventsRaw[i] = event } return &remote.BorEventsReply{ diff --git a/polygon/bor/borcfg/bor_config.go b/polygon/bor/borcfg/bor_config.go index 248d2fbedaf..0509e6a0b4c 100644 --- a/polygon/bor/borcfg/bor_config.go +++ b/polygon/bor/borcfg/bor_config.go @@ -167,6 +167,10 @@ func (c *BorConfig) CalculateStateSyncDelay(number uint64) uint64 { return borKeyValueConfigHelper(c.StateSyncConfirmationDelay, number) } +func (c *BorConfig) GetStateReceiverContract() string { + return c.StateReceiverContract +} + func borKeyValueConfigHelper[T uint64 | common.Address](field map[string]T, number uint64) T { fieldUint := make(map[uint64]T) for k, v := range field { diff --git a/polygon/bridge/bridge.go b/polygon/bridge/bridge.go index 6f38f651bf1..34cd63ec62b 100644 --- a/polygon/bridge/bridge.go +++ b/polygon/bridge/bridge.go @@ -41,7 +41,7 @@ type eventFetcher interface { } func Assemble(dataDir string, logger log.Logger, borConfig *borcfg.BorConfig, eventFetcher eventFetcher) *Bridge { - bridgeDB := polygoncommon.NewDatabase(dataDir, kv.PolygonBridgeDB, databaseTablesCfg, logger) + bridgeDB := polygoncommon.NewDatabase(dataDir, kv.PolygonBridgeDB, databaseTablesCfg, logger, false /* accede */) bridgeStore := NewStore(bridgeDB) reader := NewReader(bridgeStore, logger, borConfig.StateReceiverContract) return NewBridge(bridgeStore, logger, borConfig, eventFetcher, reader) diff --git a/polygon/bridge/reader.go b/polygon/bridge/reader.go index c89265bd04e..5740ab75ae3 100644 --- a/polygon/bridge/reader.go +++ b/polygon/bridge/reader.go @@ -6,14 +6,14 @@ import ( "fmt" libcommon "github.com/erigontech/erigon-lib/common" + "github.com/erigontech/erigon-lib/gointerfaces" + remote "github.com/erigontech/erigon-lib/gointerfaces/remoteproto" + "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon-lib/log/v3" "github.com/erigontech/erigon/common/u256" "github.com/erigontech/erigon/core" "github.com/erigontech/erigon/core/state" "github.com/erigontech/erigon/core/types" - "github.com/erigontech/erigon/polygon/bor/borcfg" - - "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon/polygon/polygoncommon" ) @@ -23,8 +23,8 @@ type Reader struct { stateClientAddress libcommon.Address } -func AssembleReader(ctx context.Context, dataDir string, logger log.Logger, borConfig *borcfg.BorConfig) (*Reader, error) { - bridgeDB := polygoncommon.NewDatabase(dataDir, kv.PolygonBridgeDB, databaseTablesCfg, logger) +func AssembleReader(ctx context.Context, dataDir string, logger log.Logger, stateReceiverContractAddress string) (*Reader, error) { + bridgeDB := polygoncommon.NewDatabase(dataDir, kv.PolygonBridgeDB, databaseTablesCfg, logger, true /* accede */) bridgeStore := NewStore(bridgeDB) err := bridgeStore.Prepare(ctx) @@ -32,7 +32,7 @@ func AssembleReader(ctx context.Context, dataDir string, logger log.Logger, borC return nil, err } - return NewReader(bridgeStore, logger, borConfig.StateReceiverContract), nil + return NewReader(bridgeStore, logger, stateReceiverContractAddress), nil } func NewReader(store Store, logger log.Logger, stateReceiverContractAddress string) *Reader { @@ -91,3 +91,65 @@ func (r *Reader) EventTxnLookup(ctx context.Context, borTxHash libcommon.Hash) ( func (r *Reader) Close() { r.store.Close() } + +type RemoteReader struct { + client remote.ETHBACKENDClient + stateReceiverContractAddress libcommon.Address +} + +func NewRemoteReader(client remote.ETHBACKENDClient, stateReceiverContractAddress string) *RemoteReader { + return &RemoteReader{ + client: client, + stateReceiverContractAddress: libcommon.HexToAddress(stateReceiverContractAddress), + } +} + +func (r *RemoteReader) Events(ctx context.Context, blockNum uint64) ([]*types.Message, error) { + reply, err := r.client.BorEvents(ctx, &remote.BorEventsRequest{BlockNum: blockNum}) + if err != nil { + return nil, err + } + if reply == nil { + return nil, nil + } + + result := make([]*types.Message, len(reply.EventRlps)) + for i, event := range reply.EventRlps { + result[i] = messageFromData(r.stateReceiverContractAddress, event) + } + + return result, nil +} + +func (r *RemoteReader) EventTxnLookup(ctx context.Context, borTxHash libcommon.Hash) (uint64, bool, error) { + reply, err := r.client.BorTxnLookup(ctx, &remote.BorTxnLookupRequest{BorTxHash: gointerfaces.ConvertHashToH256(borTxHash)}) + if err != nil { + return 0, false, err + } + if reply == nil { + return 0, false, nil + } + + return reply.BlockNumber, reply.Present, nil +} + +// Close implements bridge.ReaderService. It's a noop as there is no attached store. +func (r *RemoteReader) Close() { + return +} + +func messageFromData(to libcommon.Address, data []byte) *types.Message { + msg := types.NewMessage( + state.SystemAddress, + &to, + 0, u256.Num0, + core.SysCallGasLimit, + u256.Num0, + nil, nil, + data, nil, false, + true, + nil, + ) + + return &msg +} diff --git a/polygon/heimdall/service_store.go b/polygon/heimdall/service_store.go index f7e10962275..c6f0945a6b8 100644 --- a/polygon/heimdall/service_store.go +++ b/polygon/heimdall/service_store.go @@ -37,7 +37,7 @@ type ServiceStore interface { } func NewMdbxServiceStore(logger log.Logger, dataDir string, tmpDir string) *MdbxServiceStore { - db := polygoncommon.NewDatabase(dataDir, kv.HeimdallDB, databaseTablesCfg, logger) + db := polygoncommon.NewDatabase(dataDir, kv.HeimdallDB, databaseTablesCfg, logger, false /* accede */) blockNumToIdIndexFactory := func(ctx context.Context) (*RangeIndex, error) { return NewRangeIndex(ctx, tmpDir, logger) } diff --git a/polygon/polygoncommon/database.go b/polygon/polygoncommon/database.go index 151e433d9ef..b77b5afc8b6 100644 --- a/polygon/polygoncommon/database.go +++ b/polygon/polygoncommon/database.go @@ -35,14 +35,16 @@ type Database struct { tableCfg kv.TableCfg openOnce sync.Once logger log.Logger + accede bool } -func NewDatabase(dataDir string, label kv.Label, tableCfg kv.TableCfg, logger log.Logger) *Database { +func NewDatabase(dataDir string, label kv.Label, tableCfg kv.TableCfg, logger log.Logger, accede bool) *Database { return &Database{ dataDir: dataDir, label: label, tableCfg: tableCfg, logger: logger, + accede: accede, } } @@ -51,13 +53,18 @@ func (db *Database) open(ctx context.Context) error { db.logger.Info("Opening Database", "label", db.label.String(), "path", dbPath) var err error - db.db, err = mdbx.NewMDBX(db.logger). + opts := mdbx.NewMDBX(db.logger). Label(db.label). Path(dbPath). WithTableCfg(func(_ kv.TableCfg) kv.TableCfg { return db.tableCfg }). MapSize(16 * datasize.GB). - GrowthStep(16 * datasize.MB). - Open(ctx) + GrowthStep(16 * datasize.MB) + + if db.accede { + opts = opts.Accede() + } + + db.db, err = opts.Open(ctx) return err } diff --git a/turbo/jsonrpc/eth_subscribe_test.go b/turbo/jsonrpc/eth_subscribe_test.go index c4024683453..40cb4e58199 100644 --- a/turbo/jsonrpc/eth_subscribe_test.go +++ b/turbo/jsonrpc/eth_subscribe_test.go @@ -62,7 +62,7 @@ func TestEthSubscribe(t *testing.T) { ctx := context.Background() logger := log.New() - backendServer := privateapi.NewEthBackendServer(ctx, nil, m.DB, m.Notifications.Events, m.BlockReader, logger, builder.NewLatestBlockBuiltStore()) + backendServer := privateapi.NewEthBackendServer(ctx, nil, m.DB, m.Notifications.Events, m.BlockReader, logger, builder.NewLatestBlockBuiltStore(), nil) backendClient := direct.NewEthBackendClientDirect(backendServer) backend := rpcservices.NewRemoteBackend(backendClient, m.DB, m.BlockReader) ff := rpchelper.New(ctx, rpchelper.DefaultFiltersConfig, backend, nil, nil, func() {}, m.Log)