2020-10-16 12:15:10 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/core/forkid"
|
2020-10-25 08:38:55 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
2020-10-16 12:15:10 +00:00
|
|
|
)
|
|
|
|
|
2020-10-24 17:03:52 +00:00
|
|
|
// Forks is a data type to record a list of forks passed by this node
|
2020-10-16 12:15:10 +00:00
|
|
|
type Forks struct {
|
|
|
|
GenesisHash common.Hash `json:"genesis"`
|
2020-10-25 21:34:00 +00:00
|
|
|
Forks []uint64 `json:"forks"`
|
2020-10-16 12:15:10 +00:00
|
|
|
}
|
|
|
|
|
2020-10-25 21:34:00 +00:00
|
|
|
// 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) {
|
2020-10-25 08:38:55 +00:00
|
|
|
tx, err := api.dbReader.Begin(ctx, ethdb.RO)
|
2020-10-16 12:15:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return Forks{}, err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
2020-10-24 06:57:09 +00:00
|
|
|
chainConfig, genesisHash, err := getChainConfigWithGenesis(tx)
|
|
|
|
if err != nil {
|
|
|
|
return Forks{}, err
|
|
|
|
}
|
2020-10-16 12:15:10 +00:00
|
|
|
forksBlocks := forkid.GatherForks(chainConfig)
|
|
|
|
|
2020-10-25 21:34:00 +00:00
|
|
|
return Forks{genesisHash, forksBlocks}, nil
|
2020-10-16 12:15:10 +00:00
|
|
|
}
|