Skip to content

Commit

Permalink
historysegment: add testnet&mainnet hard code;
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbundler committed Dec 8, 2023
1 parent 080828f commit 507c0c2
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 66 deletions.
34 changes: 15 additions & 19 deletions cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,29 +726,28 @@ func exportSegment(ctx *cli.Context) error {
}
latest := headerChain.CurrentHeader()
if _, ok := engine.(consensus.PoSA); !ok {
return errors.New("current chain is not POSA consensus, cannot generate history segment")
return errors.New("cannot generate history segment because consensus engine is not PoSA")
}
if !chainConfig.IsLuban(latest.Number) {
return errors.New("current chain is not enable Luban hard fork, cannot generate history segment")
return errors.New("luban hard fork is not enabled , cannot generate history segment")
}

var (
boundStartBlock = params.BoundStartBlock
historySegmentLength = params.HistorySegmentLength
)
// TODO(0xbundler): for testing
//switch genesisHash {
//case params.BSCGenesisHash, params.ChapelGenesisHash, params.RialtoGenesisHash:
// boundStartBlock = params.BoundStartBlock
// historySegmentLength = params.HistorySegmentLength
//default:
if ctx.IsSet(utils.BoundStartBlockFlag.Name) {
boundStartBlock = ctx.Uint64(utils.BoundStartBlockFlag.Name)
}
if ctx.IsSet(utils.HistorySegmentLengthFlag.Name) {
historySegmentLength = ctx.Uint64(utils.HistorySegmentLengthFlag.Name)
}
//}
switch genesisHash {
case params.BSCGenesisHash, params.ChapelGenesisHash, params.RialtoGenesisHash:
boundStartBlock = params.BoundStartBlock
historySegmentLength = params.HistorySegmentLength
default:
if ctx.IsSet(utils.BoundStartBlockFlag.Name) {
boundStartBlock = ctx.Uint64(utils.BoundStartBlockFlag.Name)
}
if ctx.IsSet(utils.HistorySegmentLengthFlag.Name) {
historySegmentLength = ctx.Uint64(utils.HistorySegmentLengthFlag.Name)
}
}
if boundStartBlock == 0 || historySegmentLength == 0 {
return fmt.Errorf("wrong params, boundStartBlock: %v, historySegmentLength: %v", boundStartBlock, historySegmentLength)
}
Expand Down Expand Up @@ -812,7 +811,7 @@ func exportSegment(ctx *cli.Context) error {
}
segments = append(segments, segment)
}
if err = params.ValidateHisSegments(params.NewHistoryBlock(0, genesisHash, td.Uint64()), segments); err != nil {
if err = params.ValidateHistorySegments(params.NewHistoryBlock(0, genesisHash, td.Uint64()), segments); err != nil {
return err
}
output, err := json.MarshalIndent(segments, "", " ")
Expand Down Expand Up @@ -903,9 +902,6 @@ func simpleHeaderChain(db ethdb.Database, genesisHash common.Hash) (*params.Chai
if err != nil {
return nil, nil, nil, err
}
if _, ok := engine.(consensus.PoSA); !ok {
return nil, nil, nil, errors.New("current chain is not POSA, cannot generate history segment")
}
headerChain, err := core.NewHeaderChain(db, chainConfig, engine, func() bool {
return true
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var (
utils.BLSPasswordFileFlag,
utils.BLSWalletDirFlag,
utils.VoteJournalDirFlag,
utils.HistorySegEnableFlag,
utils.HistorySegEnabledFlag,
utils.HistorySegCustomFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags)

Expand Down
6 changes: 3 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
}

// History segment
HistorySegEnableFlag = &cli.BoolFlag{
HistorySegEnabledFlag = &cli.BoolFlag{
Name: "history-segment",
Usage: "Enable history segment feature, it will auto prune history segments by hard-code segment hash",
Value: false,
Expand Down Expand Up @@ -2152,8 +2152,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
}

// parse History Segment flags
if ctx.IsSet(HistorySegEnableFlag.Name) {
cfg.HistorySegmentEnable = ctx.Bool(HistorySegEnableFlag.Name)
if ctx.IsSet(HistorySegEnabledFlag.Name) {
cfg.HistorySegmentEnabled = ctx.Bool(HistorySegEnabledFlag.Name)
}
if ctx.IsSet(HistorySegCustomFlag.Name) {
cfg.HistorySegmentCustomFile = ctx.String(HistorySegCustomFlag.Name)
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (db *nofreezedb) AncientDatadir() (string, error) {
}

func (db *nofreezedb) AncientReset(tail, head uint64) error {
return errNotSupported
return nil
}

// NewDatabase creates a high level database on top of a given key-value data
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/prunedfreezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (f *prunedfreezer) TruncateTail(tail uint64) (uint64, error) {
}

func (f *prunedfreezer) AncientReset(tail, head uint64) error {
return errNotSupported
return nil
}

// Sync flushes meta data tables to disk.
Expand Down
6 changes: 3 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
hsm *params.HistorySegmentManager
lastSegment *params.HistorySegment
)
if config.HistorySegmentEnable {
if config.HistorySegmentEnabled {
hsm, lastSegment, err = GetHistorySegmentAndLastSegment(chainDb, genesisHash, config.HistorySegmentCustomFile)
if err != nil {
return nil, err
Expand Down Expand Up @@ -267,12 +267,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
txLookupLimit := &config.TransactionHistory
// if enable HistorySegment, just skip txLookupLimit params,
// may cause regenerate tx index, but it will also generate new block index
if config.HistorySegmentEnable {
if config.HistorySegmentEnabled {
txLookupLimit = nil
}
bcOps = append(bcOps, func(bc *core.BlockChain) (*core.BlockChain, error) {
// if enable history segment, try prune ancient data when restart
if config.HistorySegmentEnable {
if config.HistorySegmentEnabled {
if err = truncateAncientTail(chainDb, lastSegment); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ type Config struct {
OverrideVerkle *uint64 `toml:",omitempty"`

// History Segment
HistorySegmentEnable bool `toml:",omitempty"`
HistorySegmentEnabled bool `toml:",omitempty"`
HistorySegmentCustomFile string `toml:",omitempty"`
}

Expand Down
10 changes: 5 additions & 5 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 507c0c2

Please sign in to comment.