Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get logs #1028

Merged
merged 24 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,9 @@ clean:
# You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'.

devtools:
# See: ./cmd/hack/binary-deps/main.go
env GOBIN= go install golang.org/x/tools/cmd/stringer
env GOBIN= go install github.com/kevinburke/go-bindata/go-bindata
env GOBIN= go install github.com/fjl/gencodec
env GOBIN= go install google.golang.org/protobuf/cmd/protoc-gen-go # generates proto messages
env GOBIN= go install google.golang.org/grpc/cmd/protoc-gen-go-grpc # generates grpc services
env GOBIN= go install ./cmd/abigen
@type "npm" 2> /dev/null || echo 'Please install node.js and npm'
@type "solc" 2> /dev/null || echo 'Please install solc'
Expand All @@ -140,6 +137,11 @@ bindings:
go generate ./tests/contracts/
go generate ./cmd/tester/contracts/
go generate ./core/state/contracts/

grpc:
# See also: ./cmd/hack/binary-deps/main.go
env GOBIN= go install google.golang.org/protobuf/cmd/protoc-gen-go # generates proto messages
env GOBIN= go install google.golang.org/grpc/cmd/protoc-gen-go-grpc # generates grpc services
go generate ./ethdb

simulator-genesis:
Expand Down
6 changes: 6 additions & 0 deletions cmd/rpcdaemon/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ It should return something like this (depending on how far your turbo-geth node
````
{"jsonrpc":"2.0","id":1,"result":823909}
````

### For Developers

**Code generation**: `go.mod` stores right version of generators, use `mage grpc` to install it and generate code.

`protoc` version not managed but recommended version is 3.*, [install instruction](https://grpc.io/docs/protoc-installation/)
34 changes: 22 additions & 12 deletions cmd/rpcdaemon/commands/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil"
"github.com/ledgerwatch/turbo-geth/core/rawdb"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/rpc"
"github.com/ledgerwatch/turbo-geth/turbo/adapter/ethapi"
Expand All @@ -17,17 +17,9 @@ import (
// GetBlockByNumber see https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbynumber
// see internal/ethapi.PublicBlockChainAPI.GetBlockByNumber
func (api *APIImpl) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (map[string]interface{}, error) {
var blockNum uint64
if number == rpc.LatestBlockNumber || number == rpc.PendingBlockNumber {
var err error
blockNum, _, err = stages.GetStageProgress(api.dbReader, stages.Execution)
if err != nil {
return nil, fmt.Errorf("getting latest block number: %v", err)
}
} else if number == rpc.EarliestBlockNumber {
blockNum = 0
} else {
blockNum = uint64(number.Int64())
blockNum, err := getBlockNumber(number, api.dbReader)
if err != nil {
return nil, err
}
additionalFields := make(map[string]interface{})

Expand Down Expand Up @@ -71,6 +63,24 @@ func (api *APIImpl) GetBlockByHash(ctx context.Context, hash common.Hash, fullTx
return response, err
}

func (api *APIImpl) GetHeaderByNumber(_ context.Context, number rpc.BlockNumber) (*types.Header, error) {
header := rawdb.ReadHeaderByNumber(api.dbReader, uint64(number.Int64()))
if header == nil {
return nil, fmt.Errorf("block header not found: %d", number.Int64())
}

return header, nil
}

func (api *APIImpl) GetHeaderByHash(_ context.Context, hash common.Hash) (*types.Header, error) {
header := rawdb.ReadHeaderByHash(api.dbReader, hash)
if header == nil {
return nil, fmt.Errorf("block header not found: %s", hash.String())
}

return header, nil
}

func APIList(db ethdb.KV, eth ethdb.Backend, cfg cli.Flags, customApiList []rpc.API) []rpc.API {
var defaultAPIList []rpc.API

Expand Down
19 changes: 7 additions & 12 deletions cmd/rpcdaemon/commands/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"github.com/ledgerwatch/turbo-geth/eth/filters"

"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil"
"github.com/ledgerwatch/turbo-geth/core"
Expand All @@ -23,7 +25,7 @@ type EthAPI interface {
GetBlockByHash(ctx context.Context, hash common.Hash, fullTx bool) (map[string]interface{}, error)
GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error)
GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error)
GetLogs(ctx context.Context, hash common.Hash) ([][]*types.Log, error)
GetLogs(ctx context.Context, crit filters.FilterCriteria) ([]*types.Log, error)
Call(ctx context.Context, args ethapi.CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *map[common.Address]ethapi.Account) (hexutil.Bytes, error)
EstimateGas(ctx context.Context, args ethapi.CallArgs) (hexutil.Uint64, error)
SendRawTransaction(ctx context.Context, encodedTx hexutil.Bytes) (common.Hash, error)
Expand Down Expand Up @@ -83,18 +85,11 @@ func (api *APIImpl) Syncing(ctx context.Context) (interface{}, error) {
}

func (api *APIImpl) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*hexutil.Uint, error) {
var blockNum uint64
if blockNr == rpc.LatestBlockNumber || blockNr == rpc.PendingBlockNumber {
var err error
blockNum, _, err = stages.GetStageProgress(api.dbReader, stages.Execution)
if err != nil {
return nil, fmt.Errorf("getting latest block number: %v", err)
}
} else if blockNr == rpc.EarliestBlockNumber {
blockNum = 0
} else {
blockNum = uint64(blockNr.Int64())
blockNum, err := getBlockNumber(blockNr, api.dbReader)
if err != nil {
return nil, err
}

block := rawdb.ReadBlockByNumber(api.dbReader, blockNum)
if block == nil {
return nil, fmt.Errorf("block not found: %d", blockNum)
Expand Down
11 changes: 11 additions & 0 deletions cmd/rpcdaemon/commands/get_chain_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package commands

import (
"github.com/ledgerwatch/turbo-geth/core/rawdb"
"github.com/ledgerwatch/turbo-geth/params"
)

func getChainConfig(db rawdb.DatabaseReader) *params.ChainConfig {
genesisHash := rawdb.ReadBlockByNumber(db, 0).Hash()
return rawdb.ReadChainConfig(db, genesisHash)
}
Loading