diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 50f2e736ae379daccc15f03d465e0eaa52d7e042..96e1dec448466624823f771ab1b700add4b0c0ba 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -58,6 +58,7 @@ var ( app = flags.NewApp(gitCommit, gitDate, fmt.Sprintf("the %s command line interface", repositoryIdentifier)) // flags that configure the node nodeFlags = []cli.Flag{ + utils.BorLogsFlag, utils.IdentityFlag, utils.UnlockedAccountFlag, utils.PasswordFileFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5e009793f0e0f1185e651d96e5fd6e00ce39bbf9..34d7c72b072bf6839484be0e3207a0af5e8eb422 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -370,6 +370,10 @@ var ( Value: ethconfig.Defaults.TxPool.Lifetime, } // Performance tuning settings + BorLogsFlag = cli.BoolFlag{ + Name: "bor.logs", + Usage: "Enable bor logs retrieval", + } CacheFlag = cli.IntFlag{ Name: "cache", Usage: "Megabytes of memory allocated to internal caching (default = 4096 mainnet full node, 128 light mode)", @@ -1468,6 +1472,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { setWhitelist(ctx, cfg) setLes(ctx, cfg) + if ctx.GlobalIsSet(BorLogsFlag.Name) { + cfg.BorLogs = ctx.GlobalBool(BorLogsFlag.Name) + } + if ctx.GlobalIsSet(SyncModeFlag.Name) { cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode) } diff --git a/eth/backend.go b/eth/backend.go index e9700121fbc7005946fab800f607086755080029..16e8104a12b4592f059babda11a37c786b496753 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -299,7 +299,7 @@ func (s *Ethereum) APIs() []rpc.API { // BOR change starts // set genesis to public filter api - publicFilterAPI := filters.NewPublicFilterAPI(s.APIBackend, false, 5*time.Minute) + publicFilterAPI := filters.NewPublicFilterAPI(s.APIBackend, false, 5*time.Minute, s.config.BorLogs) // avoiding constructor changed by introducing new method to set genesis publicFilterAPI.SetChainConfig(s.blockchain.Config()) // BOR change ends diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 064cc5bd34c9c5a61547b73af7faa1322ed966c7..e018bef420d5fd20f9cbb4ef5049dcd0741aaf43 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -209,6 +209,9 @@ type Config struct { // Berlin block override (TODO: remove after the fork) OverrideBerlin *big.Int `toml:",omitempty"` + + // Bor logs flag + BorLogs bool } // CreateConsensusEngine creates a consensus engine for the given chain configuration. diff --git a/eth/filters/api.go b/eth/filters/api.go index 6de872f079e00eb0c21d55ae1aaf42c800fbbbd7..050d27d235319b95ecec0901692c62f8d4df913d 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -57,18 +57,20 @@ type PublicFilterAPI struct { filtersMu sync.Mutex filters map[rpc.ID]*filter timeout time.Duration + borLogs bool chainConfig *params.ChainConfig } // NewPublicFilterAPI returns a new PublicFilterAPI instance. -func NewPublicFilterAPI(backend Backend, lightMode bool, timeout time.Duration) *PublicFilterAPI { +func NewPublicFilterAPI(backend Backend, lightMode bool, timeout time.Duration, borLogs bool) *PublicFilterAPI { api := &PublicFilterAPI{ backend: backend, chainDb: backend.ChainDb(), events: NewEventSystem(backend, lightMode), filters: make(map[rpc.ID]*filter), timeout: timeout, + borLogs: borLogs, } go api.timeoutLoop(timeout) @@ -347,7 +349,9 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([ // Block filter requested, construct a single-shot filter filter = NewBlockFilter(api.backend, *crit.BlockHash, crit.Addresses, crit.Topics) // Block bor filter - borLogsFilter = NewBorBlockLogsFilter(api.backend, sprint, *crit.BlockHash, crit.Addresses, crit.Topics) + if api.borLogs { + borLogsFilter = NewBorBlockLogsFilter(api.backend, sprint, *crit.BlockHash, crit.Addresses, crit.Topics) + } } else { // Convert the RPC block numbers into internal representations begin := rpc.LatestBlockNumber.Int64() @@ -361,7 +365,9 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([ // Construct the range filter filter = NewRangeFilter(api.backend, begin, end, crit.Addresses, crit.Topics) // Block bor filter - borLogsFilter = NewBorBlockLogsRangeFilter(api.backend, sprint, begin, end, crit.Addresses, crit.Topics) + if api.borLogs { + borLogsFilter = NewBorBlockLogsRangeFilter(api.backend, sprint, begin, end, crit.Addresses, crit.Topics) + } } // Run the filter and return all the logs @@ -369,14 +375,19 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([ if err != nil { return nil, err } - // Run the filter and return all the logs - borBlockLogs, err := borLogsFilter.Logs(ctx) - if err != nil { - return nil, err + + if borLogsFilter != nil { + // Run the filter and return all the logs + borBlockLogs, err := borLogsFilter.Logs(ctx) + if err != nil { + return nil, err + } + + return returnLogs(types.MergeBorLogs(logs, borBlockLogs)), err } // merge bor block logs and receipt logs and return it - return returnLogs(types.MergeBorLogs(logs, borBlockLogs)), err + return returnLogs(logs), err } // UninstallFilter removes the filter with the given filter id. diff --git a/les/client.go b/les/client.go index 9c8bdbdd2619e451a770c795629384e3da430e3b..2236aa3e20a7f2351ad904749d0fb82fb9c672cb 100644 --- a/les/client.go +++ b/les/client.go @@ -299,7 +299,7 @@ func (s *LightEthereum) APIs() []rpc.API { }, { Namespace: "eth", Version: "1.0", - Service: filters.NewPublicFilterAPI(s.ApiBackend, true, 5*time.Minute), + Service: filters.NewPublicFilterAPI(s.ApiBackend, true, 5*time.Minute, false), Public: true, }, { Namespace: "net",