2019-12-02 13:47:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-05-07 06:28:15 +00:00
|
|
|
"fmt"
|
2019-12-02 13:47:00 +00:00
|
|
|
"os"
|
|
|
|
|
2022-01-19 03:49:07 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli"
|
|
|
|
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/commands"
|
Fix trace error in Polygon | Pass Engin to the Base API (#6131)
So there is an issue with tracing certain blocks/transactions on
Polygon, for example:
```
> '{"method": "trace_transaction","params":["0xb198d93f640343a98f90d93aa2b74b4fc5c64f3a649f1608d2bfd1004f9dee0e"],"id":1,"jsonrpc":"2.0"}'
```
gives the error `first run for txIndex 1 error: insufficient funds for
gas * price + value: address 0x10AD27A96CDBffC90ab3b83bF695911426A69f5E
have 16927727762862809 want 17594166808296934`
The reason is that this transaction is from the author of the block,
which doesn't have enough ETH to pay for the gas fee + tx value if he's
not the block author receiving transactions fees.
The issue is that currently the APIs are using `ethash.NewFaker()`
Engine for running traces, etc. which doesn't know how to get the author
for a specific block (which is consensus dependant); as it was noting in
several TODO comments.
The fix is to pass the Engine to the BaseAPI, which can then be used to
create the right Block Context. I chose to split the current Engine
interface in 2, with Reader and Writer, so that the BaseAPI only
receives the Reader one, which might be safer (even though it's only
used for getting the block Author).
2022-12-04 05:17:39 +00:00
|
|
|
"github.com/ledgerwatch/erigon/consensus/ethash"
|
2023-05-07 06:28:15 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/debug"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2020-08-19 11:46:20 +00:00
|
|
|
"github.com/spf13/cobra"
|
2019-12-02 13:47:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd, cfg := cli.RootCommand()
|
2022-01-19 03:49:07 +00:00
|
|
|
rootCtx, rootCancel := common.RootContext()
|
2020-08-19 11:46:20 +00:00
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
2022-02-12 12:47:19 +00:00
|
|
|
ctx := cmd.Context()
|
2023-05-07 06:28:15 +00:00
|
|
|
var logger log.Logger
|
|
|
|
var err error
|
|
|
|
if logger, err = debug.SetupCobra(cmd, "rpcdaemon"); err != nil {
|
|
|
|
logger.Error("Setting up", "error", err)
|
|
|
|
return err
|
|
|
|
}
|
2023-07-06 16:09:52 +00:00
|
|
|
db, borDb, backend, engineBackend, txPool, mining, stateCache, blockReader, ff, agg, err := cli.RemoteServices(ctx, *cfg, logger, rootCancel)
|
2020-08-19 11:46:20 +00:00
|
|
|
if err != nil {
|
2023-05-07 06:28:15 +00:00
|
|
|
logger.Error("Could not connect to DB", "err", err)
|
2020-08-19 11:46:20 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-10-10 06:06:54 +00:00
|
|
|
defer db.Close()
|
2022-02-14 12:00:54 +00:00
|
|
|
if borDb != nil {
|
|
|
|
defer borDb.Close()
|
|
|
|
}
|
2019-12-02 13:47:00 +00:00
|
|
|
|
Fix trace error in Polygon | Pass Engin to the Base API (#6131)
So there is an issue with tracing certain blocks/transactions on
Polygon, for example:
```
> '{"method": "trace_transaction","params":["0xb198d93f640343a98f90d93aa2b74b4fc5c64f3a649f1608d2bfd1004f9dee0e"],"id":1,"jsonrpc":"2.0"}'
```
gives the error `first run for txIndex 1 error: insufficient funds for
gas * price + value: address 0x10AD27A96CDBffC90ab3b83bF695911426A69f5E
have 16927727762862809 want 17594166808296934`
The reason is that this transaction is from the author of the block,
which doesn't have enough ETH to pay for the gas fee + tx value if he's
not the block author receiving transactions fees.
The issue is that currently the APIs are using `ethash.NewFaker()`
Engine for running traces, etc. which doesn't know how to get the author
for a specific block (which is consensus dependant); as it was noting in
several TODO comments.
The fix is to pass the Engine to the BaseAPI, which can then be used to
create the right Block Context. I chose to split the current Engine
interface in 2, with Reader and Writer, so that the BaseAPI only
receives the Reader one, which might be safer (even though it's only
used for getting the block Author).
2022-12-04 05:17:39 +00:00
|
|
|
// TODO: Replace with correct consensus Engine
|
|
|
|
engine := ethash.NewFaker()
|
2023-07-06 16:09:52 +00:00
|
|
|
apiList := commands.APIList(db, borDb, backend, engineBackend, txPool, mining, ff, stateCache, blockReader, agg, *cfg, engine, logger)
|
2023-05-17 16:36:15 +00:00
|
|
|
if err := cli.StartRpcServer(ctx, *cfg, apiList, nil, logger); err != nil {
|
2023-05-07 06:28:15 +00:00
|
|
|
logger.Error(err.Error())
|
2021-03-25 06:42:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
2022-01-25 16:44:35 +00:00
|
|
|
|
2021-03-25 06:42:45 +00:00
|
|
|
return nil
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 12:39:34 +00:00
|
|
|
if err := cmd.ExecuteContext(rootCtx); err != nil {
|
2023-05-07 06:28:15 +00:00
|
|
|
fmt.Printf("ExecuteContext: %v\n", err)
|
2020-08-19 11:46:20 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2019-12-02 13:47:00 +00:00
|
|
|
}
|