This commit is contained in:
Evgeny Danilenko 2020-10-26 00:34:00 +03:00 committed by GitHub
parent dd2c047cdf
commit b6687fc9aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 35 deletions

View File

@ -12,7 +12,7 @@ import (
// TgAPI TurboGeth specific routines
type TgAPI interface {
// System related (see ./tg_system.go)
Forks(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (Forks, error)
Forks(ctx context.Context) (Forks, error)
// Blocks related (see ./tg_blocks.go)
GetHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)

View File

@ -6,24 +6,16 @@ import (
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/core/forkid"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/rpc"
"github.com/ledgerwatch/turbo-geth/turbo/rpchelper"
)
// Forks is a data type to record a list of forks passed by this node
type Forks struct {
GenesisHash common.Hash `json:"genesis"`
Passed []uint64 `json:"passed"`
Next *uint64 `json:"next,omitempty"`
Forks []uint64 `json:"forks"`
}
// Forks implements tg_forks. Returns the genesis block hash and a sorted list of already passed fork block numbers as well as the next fork block (if applicable)
func (api *TgImpl) Forks(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (Forks, error) {
blockNumber, _, err := rpchelper.GetBlockNumber(blockNrOrHash, api.dbReader)
if err != nil {
return Forks{}, err
}
// Forks implements tg_forks. Returns the genesis block hash and a sorted list of all forks block numbers
func (api *TgImpl) Forks(ctx context.Context) (Forks, error) {
tx, err := api.dbReader.Begin(ctx, ethdb.RO)
if err != nil {
return Forks{}, err
@ -36,19 +28,5 @@ func (api *TgImpl) Forks(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHas
}
forksBlocks := forkid.GatherForks(chainConfig)
lastAddedIdx := -1
passedForks := make([]uint64, 0, len(forksBlocks))
for i, num := range forksBlocks {
if num <= blockNumber {
passedForks = append(passedForks, num)
lastAddedIdx = i
}
}
var nextFork *uint64
if len(forksBlocks) > lastAddedIdx+1 {
nextFork = new(uint64)
*nextFork = forksBlocks[lastAddedIdx+1]
}
return Forks{genesisHash, passedForks, nextFork}, nil
return Forks{genesisHash, forksBlocks}, nil
}

View File

@ -2799,11 +2799,7 @@ Filter(ctx context.Context, req TraceFilterRequest) (ParityTraces, error)
POST {{HOST}}
```
Returns the genesis block hash and a sorted list of already passed fork block numbers as well as the next fork block (if applicable)
**Parameters**
`QUANTITY|TAG or DATA` - Integer of a block number, the string `"earliest"`, `"latest"` or `"pending"`, or a 32 byte block hash
Returns the genesis block hash and a sorted list of all forks block numbers
**Returns**
@ -2812,8 +2808,7 @@ A structure of the type Forks
```
type Forks struct {
genesis common.Hash // the hash of the genesis block
passed []uint64 // array of block numbers passed by this client
next *uint64 // the next fork block (may be empty)
forks []uint64 // array of forks block numbers
}
```
@ -2834,7 +2829,6 @@ type Forks struct {
> {
> "jsonrpc":"2.0",
> "method":"tg_forks",
> "params":["latest"],
> "id":1
> }
> ```