mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 04:57:17 +00:00
331dcd45eb
* squash * add --database flag to integration * clean * split to 2 buckets * split to 2 buckets * split to 2 buckets * split to 2 buckets * split to 2 buckets * save progress * save progress * improve test * improve test * save progress * change app logic * change app logic * return err from rawdb package * don't clean automatically * don't clean automatically * clean * clean * clean * don't rely on `make clean` * improve cbor code * clean * clean * clean * fix tests * rebase master * stop on error: headers stage * make TxDb walk and multiwalk safe * Fix panics Co-authored-by: Alexey Akhunov <akhounov@gmail.com>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package commands
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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 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
|
|
}
|
|
|
|
tx, err := api.dbReader.Begin(ctx, ethdb.RO)
|
|
if err != nil {
|
|
return Forks{}, err
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
chainConfig, genesisHash, err := getChainConfigWithGenesis(tx)
|
|
if err != nil {
|
|
return Forks{}, err
|
|
}
|
|
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
|
|
}
|