Fixes issue #1139 - crash when running chaindata mode (#1140)

* Fixes issue #1139 - crash when running chaindata mode

* Cleaning up error messages as per feedback
This commit is contained in:
Thomas Jay Rush 2020-09-26 17:01:11 -04:00
parent 5b4445ecea
commit 784bc9dc85
8 changed files with 45 additions and 13 deletions

View File

@ -79,9 +79,9 @@ The following table shows the current implementation status of turbo-geth's RPC
| web3_clientVersion | Yes | |
| web3_sha3 | Yes | |
| | | |
| net_listening | HC | (hard coded returns true) |
| net_listening | HC | (remote only hard coded returns true) |
| net_peerCount | HC | (hard coded 25 - work continues on Sentry) |
| net_version | Yes | |
| net_version | Yes | remote only |
| | | |
| eth_blockNumber | Yes | |
| eth_chainID | Yes | |
@ -119,10 +119,10 @@ The following table shows the current implementation status of turbo-geth's RPC
| eth_getFilterChanges | - | |
| eth_getFilterLogs | - | |
| eth_uninstallFilter | - | |
| eth_getLogs | Yes | |
| eth_getLogs | Yes | remote only |
| | | |
| eth_accounts | - | |
| eth_sendRawTransaction | Yes | |
| eth_sendRawTransaction | Yes | remote only |
| eth_sendTransaction | - | |
| eth_sign | - | |
| eth_signTransaction | - | |

View File

@ -2,11 +2,16 @@ package commands
import (
"context"
"fmt"
"github.com/ledgerwatch/turbo-geth/common"
)
// Etherbase is the address that mining rewards will be send to
// Coinbase is the address that mining rewards will be sent to
func (api *APIImpl) Coinbase(_ context.Context) (common.Address, error) {
if api.ethBackend == nil {
// We're running in --chaindata mode or otherwise cannot get the backend
return common.Address{}, fmt.Errorf(NotAvailableChainData, "eth_coinbase")
}
return api.ethBackend.Etherbase()
}

View File

@ -68,7 +68,7 @@ func (api *PrivateDebugAPIImpl) AccountRange(ctx context.Context, blockNrOrHash
blockNumber, _, err = stages.GetStageProgress(api.dbReader, stages.Execution)
if err != nil {
return state.IteratorDump{}, fmt.Errorf("las block has not found: %w", err)
return state.IteratorDump{}, fmt.Errorf("last block has not found: %w", err)
}
} else {
blockNumber = uint64(number)

View File

@ -0,0 +1,7 @@
package commands
// NotImplemented is the URI prefix for smartcard wallets.
const NotImplemented = "the function %s is currently not implemented"
// NotAvailableChainData x
const NotAvailableChainData = "the function %s is not available, please use --private.api.addr option instead of --chaindata option"

View File

@ -259,6 +259,11 @@ func (f *Filter) Logs(ctx context.Context, api *APIImpl) ([]*types.Log, error) {
end = latest
}
if api.ethBackend == nil {
// We're running in --chaindata mode or otherwise cannot get the backend
return nil, fmt.Errorf(NotAvailableChainData, "eth_getLogs")
}
// Gather all indexed logs, and finish with non indexed ones
var logs []*types.Log
size, sections, _ := api.ethBackend.BloomStatus()

View File

@ -2,6 +2,7 @@ package commands
import (
"context"
"fmt"
"strconv"
"github.com/ledgerwatch/turbo-geth/common/hexutil"
@ -9,24 +10,26 @@ import (
"github.com/ledgerwatch/turbo-geth/ethdb"
)
// NetAPI the interface for the net_ RPC commands
type NetAPI interface {
Listening(_ context.Context) (bool, error)
Version(_ context.Context) (string, error)
PeerCount(_ context.Context) (hexutil.Uint, error)
}
// NetAPIImpl data structure to store things needed for net_ commands
type NetAPIImpl struct {
ethBackend ethdb.Backend
}
// NewtNetAPIImpl returns NetAPIImplImpl instance
// NewNetAPIImpl returns NetAPIImplImpl instance
func NewNetAPIImpl(eth ethdb.Backend) *NetAPIImpl {
return &NetAPIImpl{
ethBackend: eth,
}
}
// Listen implements RPC call for net_listening
// Listening implements RPC call for net_listening
// TODO(tjayrush) remove hard coded value
func (api *NetAPIImpl) Listening(_ context.Context) (bool, error) {
return true, nil
@ -34,10 +37,16 @@ func (api *NetAPIImpl) Listening(_ context.Context) (bool, error) {
// Version implements RPC call for net_version
func (api *NetAPIImpl) Version(_ context.Context) (string, error) {
if api.ethBackend == nil {
// We're running in --chaindata mode or otherwise cannot get the backend
return "", fmt.Errorf(NotAvailableChainData, "net_version")
}
res, err := api.ethBackend.NetVersion()
if err != nil {
return "", err
}
return strconv.FormatUint(res, 10), nil
}

View File

@ -2,12 +2,18 @@ package commands
import (
"context"
"fmt"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil"
)
// SendRawTransaction send a raw transaction
func (api *APIImpl) SendRawTransaction(_ context.Context, encodedTx hexutil.Bytes) (common.Hash, error) {
if api.ethBackend == nil {
// We're running in --chaindata mode or otherwise cannot get the backend
return common.Hash{}, fmt.Errorf(NotAvailableChainData, "eth_sendRawTransaction")
}
res, err := api.ethBackend.AddLocal(encodedTx)
return common.BytesToHash(res), err
}

View File

@ -21,29 +21,29 @@ type CallParams []CallParam
// Call Implements trace_call
func (api *TraceAPIImpl) Call(ctx context.Context, call CallParam, blockNr rpc.BlockNumber) ([]interface{}, error) {
var stub []interface{}
return stub, fmt.Errorf("function trace_call not implemented")
return stub, fmt.Errorf(NotImplemented, "trace_call")
}
// CallMany Implements trace_call
func (api *TraceAPIImpl) CallMany(ctx context.Context, calls CallParams) ([]interface{}, error) {
var stub []interface{}
return stub, fmt.Errorf("function trace_callMany not implemented")
return stub, fmt.Errorf(NotImplemented, "trace_callMany")
}
// RawTransaction Implements trace_rawtransaction
func (api *TraceAPIImpl) RawTransaction(ctx context.Context, txHash common.Hash, traceTypes []string) ([]interface{}, error) {
var stub []interface{}
return stub, fmt.Errorf("function trace_rawTransaction not implemented")
return stub, fmt.Errorf(NotImplemented, "trace_rawTransaction")
}
// ReplayBlockTransactions Implements trace_replayBlockTransactions
func (api *TraceAPIImpl) ReplayBlockTransactions(ctx context.Context, blockNr rpc.BlockNumber, traceTypes []string) ([]interface{}, error) {
var stub []interface{}
return stub, fmt.Errorf("function trace_replayBlockTransactions not implemented")
return stub, fmt.Errorf(NotImplemented, "trace_replayBlockTransactions")
}
// ReplayTransaction Implements trace_replaytransactions
func (api *TraceAPIImpl) ReplayTransaction(ctx context.Context, txHash common.Hash, traceTypes []string) ([]interface{}, error) {
var stub []interface{}
return stub, fmt.Errorf("function trace_replayTransaction not implemented")
return stub, fmt.Errorf(NotImplemented, "trace_replayTransaction")
}