diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 4bd36bab32..32b5ce13ff 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -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) } @@ -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, "", " ") @@ -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 }) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index beca2d3307..35b822a1ef 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -166,7 +166,7 @@ var ( utils.BLSPasswordFileFlag, utils.BLSWalletDirFlag, utils.VoteJournalDirFlag, - utils.HistorySegEnableFlag, + utils.HistorySegEnabledFlag, utils.HistorySegCustomFlag, }, utils.NetworkFlags, utils.DatabasePathFlags) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 748516840f..c29725bf3c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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, @@ -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) diff --git a/core/rawdb/database.go b/core/rawdb/database.go index e0998ef753..84aad5b9ca 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -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 diff --git a/core/rawdb/prunedfreezer.go b/core/rawdb/prunedfreezer.go index 9f3541bc6f..9cb3978c1a 100644 --- a/core/rawdb/prunedfreezer.go +++ b/core/rawdb/prunedfreezer.go @@ -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. diff --git a/eth/backend.go b/eth/backend.go index 11c5666d1e..ee62a1865a 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -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 @@ -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 } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index ea68cb7443..c1c84d0fa4 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -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"` } diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 841e471b6a..0a378d5ec9 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -71,7 +71,7 @@ func (c Config) MarshalTOML() (interface{}, error) { RPCTxFeeCap float64 OverrideCancun *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` - HistorySegmentEnable bool `toml:",omitempty"` + HistorySegmentEnabled bool `toml:",omitempty"` HistorySegmentCustomFile string `toml:",omitempty"` } var enc Config @@ -129,7 +129,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.RPCTxFeeCap = c.RPCTxFeeCap enc.OverrideCancun = c.OverrideCancun enc.OverrideVerkle = c.OverrideVerkle - enc.HistorySegmentEnable = c.HistorySegmentEnable + enc.HistorySegmentEnabled = c.HistorySegmentEnabled enc.HistorySegmentCustomFile = c.HistorySegmentCustomFile return &enc, nil } @@ -191,7 +191,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { RPCTxFeeCap *float64 OverrideCancun *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` - HistorySegmentEnable *bool `toml:",omitempty"` + HistorySegmentEnabled *bool `toml:",omitempty"` HistorySegmentCustomFile *string `toml:",omitempty"` } var dec Config @@ -360,8 +360,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverrideVerkle != nil { c.OverrideVerkle = dec.OverrideVerkle } - if dec.HistorySegmentEnable != nil { - c.HistorySegmentEnable = *dec.HistorySegmentEnable + if dec.HistorySegmentEnabled != nil { + c.HistorySegmentEnabled = *dec.HistorySegmentEnabled } if dec.HistorySegmentCustomFile != nil { c.HistorySegmentCustomFile = *dec.HistorySegmentCustomFile diff --git a/params/history_segment.go b/params/history_segment.go index bc51998cbc..27f75cdcec 100644 --- a/params/history_segment.go +++ b/params/history_segment.go @@ -16,8 +16,45 @@ const ( ) var ( - historySegmentsInBSCMainnet []HistorySegment - historySegmentsInBSCChapel []HistorySegment + historySegmentsInBSCMainnet = unmarshalHistorySegments(` +[ + { + "index": 0, + "re_genesis_number": 0, + "re_genesis_hash": "0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b", + "td": 1 + }, + { + "index": 1, + "re_genesis_number": 31268600, + "re_genesis_hash": "0x49bd8a17d31797ced6b466d91900cdd17a4c39cc685dc28ffd290196f417952c", + "td": 62131469, + "consensus_data": "0x7b226e756d626572223a33313236383539392c2268617368223a22307865663261363935356334383638373035623361376439323930313639376265613265303932366238313634386138373838393765386533333639383231306234222c2276616c696461746f7273223a7b22307830626163343932333836383632616433646634623636366263303936623035303562623639346461223a7b22696e6465783a6f6d6974656d707479223a312c22766f74655f61646472657373223a5b3137362c3139302c3139352c37322c3130342c32362c3234372c3130322c3131372c32382c3138342c35372c38372c3131302c3135362c38312c39302c392c3230302c3139312c3235302c34382c3136342c39382c3135302c3230342c3139372c3130322c31382c37332c31342c3138302c3132382c3230382c35392c3234392c37322c3232352c302c352c3138372c3230342c342c33332c3234392c31312c36312c37385d7d2c22307832343635313736633436316166623331366562633737336336316661656538356136353135646161223a7b22696e6465783a6f6d6974656d707479223a322c22766f74655f61646472657373223a5b3133382c3134362c35332c3130302c3139382c3235352c3231312c3132372c3137382c3235342c3135392c31372c3134322c3234382c3132382c3134362c3233322c3131382c34342c3132322c3232312c3138312c33382c3137312c3132362c3137372c3233312c3131342c3138362c3233392c3133332c32342c33312c3133372c34342c3131352c32372c3232342c3139332c3133372c32362c38302c3233302c3137362c39382c39382c3230302c32325d7d2c22307832643463343037626265343934333865643835396665393635623134306463663161616237316139223a7b22696e6465783a6f6d6974656d707479223a332c22766f74655f61646472657373223a5b3134372c3139332c3234372c3234362c3134362c3135372c33312c3232362c3136312c3132332c37382c32302c39372c37382c3234392c3235322c39312c3232302c3131332c36312c3130322c34392c3231342c3131372c36342c36332c3139302c3233392c3137322c38352c39372c32372c3234362c31382c3131322c31312c32372c3130312c3234342c3131362c37322c39372c3138342c31312c31352c3132352c3130362c3137365d7d2c22307833663334396262616665633135353138313962386265316566656132666334366361373439616131223a7b22696e6465783a6f6d6974656d707479223a342c22766f74655f61646472657373223a5b3133322c33362c3133382c36392c3134382c3130302c3233382c3139332c3136322c33302c3132372c3139392c3138332c32362c352c36312c3135302c36382c3233332c3138372c3134312c3136342c3133332c35392c3134332c3133352c34342c3231352c3139332c3231342c3137392c33362c3139312c32352c33342c3133302c3135322c34382c3130302c3130382c3233342c3232332c3138322c38382c3231312c3232322c302c3135345d7d2c22307836316464343831613131346132653736316335353462363431373432633937333836373839396433223a7b22696e6465783a6f6d6974656d707479223a352c22766f74655f61646472657373223a5b3133382c3132382c3135302c3132352c35372c3232382c362c3136302c3136392c3130302c34352c36352c3233332c302c3132322c33392c3235322c31372c38302c3136322c3130332c3230392c36372c3136392c3234372c3133342c3230352c34332c39342c3233362c3138392c3230342c36342c35342c33392c35352c352c33342c39312c3134392c3130392c39342c34372c3134332c39342c3138352c39332c33375d7d2c22307836383562316465643830313337383564363632336363313864323134333230623662623634373539223a7b22696e6465783a6f6d6974656d707479223a362c22766f74655f61646472657373223a5b3133382c39362c3234382c34322c3132332c3230372c3131362c3138302c3230332c352c35392c3135352c3235342c3133312c3230382c3233372c322c3136382c37382c3138372c31362c3133342c39332c3235332c3231362c3232362c3131302c3131372c35332c3139362c35382c32382c3230342c3231302c3130342c3233322c39362c3234352c322c33332c3130372c35352c3135372c3235322c3135332c3131332c3231312c38385d7d2c22307837306636353731363465356237353638396236346237666431666132373566333334663238653138223a7b22696e6465783a6f6d6974656d707479223a372c22766f74655f61646472657373223a5b3135302c3136322c3130362c3235302c31382c3134392c3231382c3132392c36352c3133332c3134372c3138392c31382c3132392c36382c39392c3231372c3234362c3232382c39322c35342c3136302c3232382c3132362c3138302c3230352c36322c39312c3130362c3234322c3135362c36352c3232362c3136332c3136352c39392c3130302c34382c32312c39302c37302c3131302c33332c3130312c3133332c3137352c35392c3136375d7d2c22307837326236316336303134333432643931343437306563376163323937356265333435373936633262223a7b22696e6465783a6f6d6974656d707479223a382c22766f74655f61646472657373223a5b3132392c3231392c342c33342c3136352c3235332c382c3232382c31332c3137372c3235322c33352c3130342c3231302c33362c39342c37352c32342c3137372c3230382c3138342c39322c3134362c32362c3137302c3137352c3231302c3232372c36352c3131382c31342c34312c3235322c39372c36322c3232312c35372c3234372c31382c38342c39372c37382c33322c38352c3139352c34302c3132322c38315d7d2c22307837616532663562396533383663643162353061343535303639366439353763623439303066303361223a7b22696e6465783a6f6d6974656d707479223a392c22766f74655f61646472657373223a5b3138342c37392c3133312c3235352c34352c3234342c36352c3134372c37332c3130332c3134372c3138342c37312c3234362c37382c3135372c3130392c3137372c3137392c3134392c35342c3133302c3138372c3134392c3233372c3230382c3135302c3233352c33302c3130352c3138372c3231312c38372c3139342c302c3135332c34342c3136372c3132382c38302c3230382c3230332c3232352c3132382c3230372c3137302c312c3134325d7d2c22307838623663386664393364366634636561343262626233343564626336663064666462356265633733223a7b22696e6465783a6f6d6974656d707479223a31302c22766f74655f61646472657373223a5b3136382c3136322c38372c372c37382c3133302c3138342c3132392c3230372c3136302c3131302c3234332c3233352c37382c3235342c3230322c362c31322c33372c34392c35332c3135342c3138392c31342c3137312c3133382c3234312c3232372c3233372c3235302c33322c33372c3235322c3136342c3130302c3137322c3135362c36332c3230392c33352c3234362c3139342c37342c31332c3132302c3133342c3134382c3133335d7d2c22307861366637396236303335396631343164663930613063373435313235623133316361616666643132223a7b22696e6465783a6f6d6974656d707479223a31312c22766f74655f61646472657373223a5b3138332c3131342c3232352c3132382c3235312c3234332c3133382c352c32382c3135312c3231382c3138382c3133382c3137302c312c33382c3136322c35312c3136392c3233322c34302c3230352c3137352c3230342c3131362c33342c3139362c3138372c33312c36342c34382c3136352c3130372c3136332c3130302c3139372c36352c332c3234322c3130372c3137332c3134352c38302c3133392c38322c33322c3138332c36355d7d2c22307862323138633564366166316639373961633432626336386439386135613064373936633661623031223a7b22696e6465783a6f6d6974656d707479223a31322c22766f74655f61646472657373223a5b3138322c38392c3137332c31352c3138392c3135392c38312c38382c3134372c3235332c3231352c36342c3137382c3135352c3136302c3131392c34352c3138392c3233332c3138302c39392c38392c33332c3232312c3134352c3138392c34312c39392c3136302c3235322c3133332c39342c34392c3234362c35312c3134332c36392c3137382c31372c3139362c3233332c3232322c3231392c3132372c34362c3137362c3135372c3233315d7d2c22307862346464363664376332633765353766363238323130313837313932666238396434623939646434223a7b22696e6465783a6f6d6974656d707479223a31332c22766f74655f61646472657373223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c22307862653830376464646230373436333963643966613631623437363736633036346663353064363263223a7b22696e6465783a6f6d6974656d707479223a31342c22766f74655f61646472657373223a5b3137372c3234322c3139392c32312c3131392c3232322c3234332c32302c37392c3137312c3233352c3131372c3136382c3136312c3230302c3230332c39312c38312c3230392c3230392c3138302c3136302c39342c3233362c3130332c3135322c3133392c3133342c3133332c302c3133392c3137302c32332c36392c3135382c3139362c33372c3231392c3137342c3138382c3133332c34372c37332c3130392c3230312c33332c3135302c3230355d7d2c22307863633865366430306331376562343331333530633663353064386238663035313736623930623131223a7b22696e6465783a6f6d6974656d707479223a31352c22766f74655f61646472657373223a5b3137392c3136332c3231322c3235342c3138342c33372c3137342c3135312c322c3131332c32312c3130322c3232332c39332c3139312c35362c3233322c34322c3232312c37372c3230392c3138312c3131352c3138352c39332c33362c3130322c3235302c3130312c312c3230342c3138342c33302c3135372c33382c3136332c38322c3138352c39372c38302c3230342c3139312c3132332c3130352c3132372c3230382c3136342c32355d7d2c22307863653266643735343465306232636339343639326434613730346465626566376263623631333238223a7b22696e6465783a6f6d6974656d707479223a31362c22766f74655f61646472657373223a5b3138322c37342c3139302c33372c39372c37362c3135362c3235332c35302c3232382c38362c3138302c3231332c33332c3234322c3135362c3133312c38372c3234342c3137352c37302c362c3135312c3133302c3135302c3230312c3139302c3134372c37332c36342c3131342c3137322c352c3235302c3133342c3232372c3231302c3132342c3230302c3231342c3131302c3130312c302c31352c3133392c3136332c36332c3138375d7d2c22307865326433613733396566666364336139393338376430313565323630656566616337326562656131223a7b22696e6465783a6f6d6974656d707479223a31372c22766f74655f61646472657373223a5b3134392c3130382c37312c31332c3232332c3234342c3134302c3138302c3134372c302c33322c31312c39352c3133312c37332c3132372c35382c36302c3230332c35382c3233352c3133312c3139372c3233372c3231372c3132392c3133332c3130352c332c3134322c39372c3230392c3135312c32342c37392c37342c3136362c3134372c3135382c3136352c3233332c3134352c33302c36322c3135322c3137322c3130392c33335d7d2c22307865396165333236316134373561323762623130323866313430626332613763383433333138616664223a7b22696e6465783a6f6d6974656d707479223a31382c22766f74655f61646472657373223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c22307865613061366533633531316262643130663435313965636533376463323438383765313162353564223a7b22696e6465783a6f6d6974656d707479223a31392c22766f74655f61646472657373223a5b3137382c3231322c3139382c34302c36302c36382c3136312c3139392c3138392c38302c35382c3137312c3136372c3130322c3131302c3135392c31322c3133312c31342c31352c3234302c32322c3139332c3139392c38302c3136352c3232382c3133352c38372c3136372c31392c3230382c3133312c3130372c32382c3137312c3235332c39322c34302c32372c32392c3232372c3138332c3132352c32382c32352c33332c3133315d7d2c22307865653232363337396462383363666663363831343935373330633131666464653739626134633063223a7b22696e6465783a6f6d6974656d707479223a32302c22766f74655f61646472657373223a5b3137342c3132332c3139382c3235302c3136332c3234302c3230342c36322c39362c3134372c3138322c35312c3235332c3132362c3232382c3234382c3130352c3131322c3134362c3130352c38382c3230382c3138332c3233362c3132382c36372c3132372c3134372c3130362c3230372c33332c34332c3132302c3234302c3230352c392c39352c36392c3130312c3235352c3234312c36382c3235332c36392c3134312c33352c35382c39315d7d2c22307865663032373465333138313063396466303266393866616664653066383431663465363661316364223a7b22696e6465783a6f6d6974656d707479223a32312c22766f74655f61646472657373223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d7d2c22726563656e7473223a7b223331323638353839223a22307838623663386664393364366634636561343262626233343564626336663064666462356265633733222c223331323638353930223a22307861366637396236303335396631343164663930613063373435313235623133316361616666643132222c223331323638353931223a22307862323138633564366166316639373961633432626336386439386135613064373936633661623031222c223331323638353932223a22307862346464363664376332633765353766363238323130313837313932666238396434623939646434222c223331323638353933223a22307862653830376464646230373436333963643966613631623437363736633036346663353064363263222c223331323638353934223a22307863633865366430306331376562343331333530633663353064386238663035313736623930623131222c223331323638353935223a22307863653266643735343465306232636339343639326434613730346465626566376263623631333238222c223331323638353936223a22307865326433613733396566666364336139393338376430313565323630656566616337326562656131222c223331323638353937223a22307865396165333236316134373561323762623130323866313430626332613763383433333138616664222c223331323638353938223a22307865613061366533633531316262643130663435313965636533376463323438383765313162353564222c223331323638353939223a22307865653232363337396462383363666663363831343935373330633131666464653739626134633063227d2c22726563656e745f666f726b5f686173686573223a7b223331323638353739223a226231396466346132222c223331323638353830223a226231396466346132222c223331323638353831223a226231396466346132222c223331323638353832223a226231396466346132222c223331323638353833223a226231396466346132222c223331323638353834223a226231396466346132222c223331323638353835223a226231396466346132222c223331323638353836223a226231396466346132222c223331323638353837223a226231396466346132222c223331323638353838223a226231396466346132222c223331323638353839223a226231396466346132222c223331323638353930223a226231396466346132222c223331323638353931223a226231396466346132222c223331323638353932223a226231396466346132222c223331323638353933223a226231396466346132222c223331323638353934223a226231396466346132222c223331323638353935223a226231396466346132222c223331323638353936223a226231396466346132222c223331323638353937223a226231396466346132222c223331323638353938223a226231396466346132222c223331323638353939223a226231396466346132227d2c226174746573746174696f6e3a6f6d6974656d707479223a7b22536f757263654e756d626572223a33313236383539372c22536f7572636548617368223a22307863653762343062643836353463306339653961653131373063393839666531353138323562356235306163313063313838326539383331366164643362343833222c225461726765744e756d626572223a33313236383539382c2254617267657448617368223a22307837323335343633626530633139623361626461366666653766393035633936613861643632616565393663616239396465613937303531626433346564313366227d7d" + } +]`) + historySegmentsInBSCChapel = unmarshalHistorySegments(` +[ + { + "index": 0, + "re_genesis_number": 0, + "re_genesis_hash": "0x6d3c66c5357ec91d5c43af47e234a939b22557cbb552dc45bebbceeed90fbe34", + "td": 1 + }, + { + "index": 1, + "re_genesis_number": 31268600, + "re_genesis_hash": "0x5faa1dcf2140c2fbaf9b713c74e34485d38218df6fc1797b19704d7c964d6943", + "td": 62348406, + "consensus_data": "0x7b226e756d626572223a33313236383539392c2268617368223a22307833336138623166303962626164356663623636323565333866353162663936656162313461383937636636366331633731306336366631383039323634353666222c2276616c696461746f7273223a7b22307831323834323134623962396338353534396162336432623937326466306465656636366163326339223a7b22696e6465783a6f6d6974656d707479223a312c22766f74655f61646472657373223a5b3134322c3133302c3134372c37362c3136392c3131362c3235332c3230352c3135312c3234332c34382c3135372c3233332c3130332c3231312c3230312c3139362c36332c3136372c31372c3136382c3231342c3131352c3137352c39332c3131372c37302c38382c36382c3139312c3133372c3130352c3230302c3230392c3134382c3134312c3134342c35352c37322c3137322c3132332c3133392c32332c33322c3235302c3130302c3232392c31325d7d2c22307833353535326331363730346432313433343766323966613737663737646136643735643763373532223a7b22696e6465783a6f6d6974656d707479223a322c22766f74655f61646472657373223a5b3138332c36362c3137332c37322c38352c3138362c3232372c34382c36362c3130372c3133302c36322c3131362c34352c3136332c33312c3132392c3130382c3230302c35392c3139332c3130392c3130352c3136392c31392c37352c3232342c3230372c3138302c3136312c3230392c3132362c3139352c37392c32372c39312c35302c3231332c3139342c342c36342c3138342c38332c3130372c33302c3133362c3234302c3234325d7d2c22307839383061373565636431333039656131326661326564383761383734346662666339623836336435223a7b22696e6465783a6f6d6974656d707479223a332c22766f74655f61646472657373223a5b3133372c332c3132322c3135342c3230362c35392c38392c312c3130312c3233342c32382c31322c39302c3139392c34332c3234362c302c3138332c3230302c3134302c33302c36372c39352c36352c3134372c34342c31372c35302c3137302c3232352c3139312c3136302c3138372c3130342c3232382c3130372c3135302c3230342c3137372c34342c35322c32312c3232382c3231362c34322c3234372c32332c3231365d7d2c22307861323935396433663935656165356463376437303134346365316237336234303362376562366530223a7b22696e6465783a6f6d6974656d707479223a342c22766f74655f61646472657373223a5b3138352c3131352c3139342c3231312c3133322c3133352c3232392c3134332c3231342c3232352c36392c37332c32372c31372c302c3132382c3235312c32302c3137322c3134352c39302c342c31372c3235322c3132302c3234312c3135382c392c3136332c3135332c3232312c3233382c31332c33322c3139382c35382c3131372c3231362c3234392c34382c3234312c3130352c36392c36382c3137332c34352c3139322c32375d7d2c22307862373162323134636238383535303038343433363565393563643939343263373237366537666438223a7b22696e6465783a6f6d6974656d707479223a352c22766f74655f61646472657373223a5b3136322c3131372c31342c3139382c3232312c3233372c36312c3230352c3139342c3234332c38312c3132302c33352c31362c3137362c3233342c3232302c372c3132352c3138312c3135342c3138382c3136302c3234302c3230352c33382c3131392c3131302c34362c3132322c3230332c3135392c35392c3230362c36342c3137372c3235302c38322c33332c3235332c32312c39372c33342c3130382c39382c39392c3230342c39355d7d2c22307866343734636630336363656666323861626336356339636261653539346637323563383065313264223a7b22696e6465783a6f6d6974656d707479223a362c22766f74655f61646472657373223a5b3135302c3230312c3138342c3130382c35322c302c3232392c34312c3139312c3232352c3133322c352c3131302c33372c3132342c372c3134382c31312c3138322c3130302c39392c3131312c3130342c3135382c3134312c33322c33392c3230302c35322c3130342c33312c3134332c3133352c3133392c3131352c36382c38322c39372c332c37382c3134382c3130372c3137382c3231372c312c3138302c3138342c3132305d7d7d2c22726563656e7473223a7b223331323638353936223a22307862373162323134636238383535303038343433363565393563643939343263373237366537666438222c223331323638353937223a22307866343734636630336363656666323861626336356339636261653539346637323563383065313264222c223331323638353938223a22307831323834323134623962396338353534396162336432623937326466306465656636366163326339222c223331323638353939223a22307833353535326331363730346432313433343766323966613737663737646136643735643763373532227d2c22726563656e745f666f726b5f686173686573223a7b223331323638353934223a226463353539303563222c223331323638353935223a226463353539303563222c223331323638353936223a226463353539303563222c223331323638353937223a226463353539303563222c223331323638353938223a226463353539303563222c223331323638353939223a226463353539303563227d2c226174746573746174696f6e3a6f6d6974656d707479223a7b22536f757263654e756d626572223a33313236383539372c22536f7572636548617368223a22307832656632326232643862366338616439303233616361336162393431313632616163313530336664666133323664303832333038373933636365346466353939222c225461726765744e756d626572223a33313236383539382c2254617267657448617368223a22307830643166383737333736613335393232616233366331613231346561663038353335663439656135613866336531316532373637326535386665326533666136227d7d" + }, + { + "index": 2, + "re_genesis_number": 33860600, + "re_genesis_hash": "0x4e5acd6301c45368469f3d0b59e3a0551cea55cfabb0d53b38f48bf463786621", + "td": 67529391, + "consensus_data": "0x7b226e756d626572223a33333836303539392c2268617368223a22307835383131616633393632353831303633656636393935346666613832326566616439333631636432336663303965653639666632343162313961336336373364222c2276616c696461746f7273223a7b22307831323834323134623962396338353534396162336432623937326466306465656636366163326339223a7b22696e6465783a6f6d6974656d707479223a312c22766f74655f61646472657373223a5b3134322c3133302c3134372c37362c3136392c3131362c3235332c3230352c3135312c3234332c34382c3135372c3233332c3130332c3231312c3230312c3139362c36332c3136372c31372c3136382c3231342c3131352c3137352c39332c3131372c37302c38382c36382c3139312c3133372c3130352c3230302c3230392c3134382c3134312c3134342c35352c37322c3137322c3132332c3133392c32332c33322c3235302c3130302c3232392c31325d7d2c22307833353535326331363730346432313433343766323966613737663737646136643735643763373532223a7b22696e6465783a6f6d6974656d707479223a322c22766f74655f61646472657373223a5b3138332c36362c3137332c37322c38352c3138362c3232372c34382c36362c3130372c3133302c36322c3131362c34352c3136332c33312c3132392c3130382c3230302c35392c3139332c3130392c3130352c3136392c31392c37352c3232342c3230372c3138302c3136312c3230392c3132362c3139352c37392c32372c39312c35302c3231332c3139342c342c36342c3138342c38332c3130372c33302c3133362c3234302c3234325d7d2c22307834373738383338366430656436633734386530336135333136306234623330656433373438636335223a7b22696e6465783a6f6d6974656d707479223a332c22766f74655f61646472657373223a5b302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c302c305d7d2c22307839383061373565636431333039656131326661326564383761383734346662666339623836336435223a7b22696e6465783a6f6d6974656d707479223a342c22766f74655f61646472657373223a5b3133372c332c3132322c3135342c3230362c35392c38392c312c3130312c3233342c32382c31322c39302c3139392c34332c3234362c302c3138332c3230302c3134302c33302c36372c39352c36352c3134372c34342c31372c35302c3137302c3232352c3139312c3136302c3138372c3130342c3232382c3130372c3135302c3230342c3137372c34342c35322c32312c3232382c3231362c34322c3234372c32332c3231365d7d2c22307861323935396433663935656165356463376437303134346365316237336234303362376562366530223a7b22696e6465783a6f6d6974656d707479223a352c22766f74655f61646472657373223a5b3138352c3131352c3139342c3231312c3133322c3133352c3232392c3134332c3231342c3232352c36392c37332c32372c31372c302c3132382c3235312c32302c3137322c3134352c39302c342c31372c3235322c3132302c3234312c3135382c392c3136332c3135332c3232312c3233382c31332c33322c3139382c35382c3131372c3231362c3234392c34382c3234312c3130352c36392c36382c3137332c34352c3139322c32375d7d2c22307862373162323134636238383535303038343433363565393563643939343263373237366537666438223a7b22696e6465783a6f6d6974656d707479223a362c22766f74655f61646472657373223a5b3136322c3131372c31342c3139382c3232312c3233372c36312c3230352c3139342c3234332c38312c3132302c33352c31362c3137362c3233342c3232302c372c3132352c3138312c3135342c3138382c3136302c3234302c3230352c33382c3131392c3131302c34362c3132322c3230332c3135392c35392c3230362c36342c3137372c3235302c38322c33332c3235332c32312c39372c33342c3130382c39382c39392c3230342c39355d7d2c22307866343734636630336363656666323861626336356339636261653539346637323563383065313264223a7b22696e6465783a6f6d6974656d707479223a372c22766f74655f61646472657373223a5b3135302c3230312c3138342c3130382c35322c302c3232392c34312c3139312c3232352c3133322c352c3131302c33372c3132342c372c3134382c31312c3138322c3130302c39392c3131312c3130342c3135382c3134312c33322c33392c3230302c35322c3130342c33312c3134332c3133352c3133392c3131352c36382c38322c39372c332c37382c3134382c3130372c3137382c3231372c312c3138302c3138342c3132305d7d7d2c22726563656e7473223a7b223333383630353936223a22307831323834323134623962396338353534396162336432623937326466306465656636366163326339222c223333383630353937223a22307833353535326331363730346432313433343766323966613737663737646136643735643763373532222c223333383630353938223a22307834373738383338366430656436633734386530336135333136306234623330656433373438636335222c223333383630353939223a22307839383061373565636431333039656131326661326564383761383734346662666339623836336435227d2c22726563656e745f666f726b5f686173686573223a7b223333383630353933223a226463353539303563222c223333383630353934223a226463353539303563222c223333383630353935223a226463353539303563222c223333383630353936223a226463353539303563222c223333383630353937223a226463353539303563222c223333383630353938223a226463353539303563222c223333383630353939223a226463353539303563227d2c226174746573746174696f6e3a6f6d6974656d707479223a7b22536f757263654e756d626572223a33333836303539372c22536f7572636548617368223a22307839326661356163363435376339656333383830306130666431633362333861366137373833633432343363306130613435643937343539623263613030363538222c225461726765744e756d626572223a33333836303539382c2254617267657448617368223a22307836356464343461663939336263663737326462393139356666643265646432653965313733366432363162353534386330376264306166376439363334396432227d7d" + } +]`) ) type HistoryBlock struct { @@ -121,7 +158,7 @@ func NewHistorySegmentManager(cfg *HistorySegmentConfig) (*HistorySegmentManager return nil, fmt.Errorf("LoadCustomSegments err %v", err) } } - if err = ValidateHisSegments(cfg.Genesis, segments); err != nil { + if err = ValidateHistorySegments(cfg.Genesis, segments); err != nil { return nil, err } return &HistorySegmentManager{ @@ -131,7 +168,7 @@ func NewHistorySegmentManager(cfg *HistorySegmentConfig) (*HistorySegmentManager } func NewHistorySegmentManagerWithSegments(genesis HistoryBlock, segments []HistorySegment) (*HistorySegmentManager, error) { - if err := ValidateHisSegments(genesis, segments); err != nil { + if err := ValidateHistorySegments(genesis, segments); err != nil { return nil, err } return &HistorySegmentManager{ @@ -142,7 +179,7 @@ func NewHistorySegmentManagerWithSegments(genesis HistoryBlock, segments []Histo }, nil } -func ValidateHisSegments(genesis HistoryBlock, segments []HistorySegment) error { +func ValidateHistorySegments(genesis HistoryBlock, segments []HistorySegment) error { if len(segments) == 0 { return errors.New("history segment length cannot be 0") } @@ -165,14 +202,14 @@ func ValidateHisSegments(genesis HistoryBlock, segments []HistorySegment) error return nil } -// HisSegments return all history segments -func (m *HistorySegmentManager) HisSegments() []HistorySegment { +// HistorySegments return all history segments +func (m *HistorySegmentManager) HistorySegments() []HistorySegment { return m.segments } // CurSegment return which segment include this block func (m *HistorySegmentManager) CurSegment(num uint64) *HistorySegment { - segments := m.HisSegments() + segments := m.HistorySegments() i := len(segments) - 1 for i >= 0 { if segments[i].ReGenesisNumber <= num { @@ -189,7 +226,7 @@ func (m *HistorySegmentManager) LastSegment(cur *HistorySegment) (*HistorySegmen if cur == nil { return nil, false } - segments := m.HisSegments() + segments := m.HistorySegments() if cur.Index == 0 || cur.Index >= uint64(len(segments)) { return nil, false } @@ -202,7 +239,7 @@ func (m *HistorySegmentManager) LastSegmentByNumber(num uint64) (*HistorySegment return m.LastSegment(cur) } -func unmarshalHisSegments(enc string) []HistorySegment { +func unmarshalHistorySegments(enc string) []HistorySegment { var ret []HistorySegment err := json.Unmarshal([]byte(enc), &ret) if err != nil { diff --git a/params/history_segment_test.go b/params/history_segment_test.go index d1be7d3904..5d870609da 100644 --- a/params/history_segment_test.go +++ b/params/history_segment_test.go @@ -23,33 +23,27 @@ var ( }, { Index: 2, - ReGenesisNumber: 33860530, + ReGenesisNumber: BoundStartBlock + HistorySegmentLength, ReGenesisHash: common.HexToHash("0xbf6d408bce0d531c41b00410e1c567e46b359db6e14d842cd8c8325039dff498"), }, } testGenesis = common.HexToHash("0x50b168d3ba07cc77c13a5469b9a1aad8752ba725ff989b76bc7df89dc936e866") ) -func TestNewHisSegmentManager_HardCode(t *testing.T) { +func TestNewHistorySegmentManager_HardCode(t *testing.T) { tests := []struct { cfg *HistorySegmentConfig }{ { cfg: &HistorySegmentConfig{ CustomPath: "", - Genesis: NewHistoryBlock(0, BSCGenesisHash, 0), + Genesis: NewHistoryBlock(0, BSCGenesisHash, 1), }, }, { cfg: &HistorySegmentConfig{ CustomPath: "", - Genesis: NewHistoryBlock(0, ChapelGenesisHash, 0), - }, - }, - { - cfg: &HistorySegmentConfig{ - CustomPath: "", - Genesis: NewHistoryBlock(0, RialtoGenesisHash, 0), + Genesis: NewHistoryBlock(0, ChapelGenesisHash, 1), }, }, } @@ -59,7 +53,7 @@ func TestNewHisSegmentManager_HardCode(t *testing.T) { } } -func TestHisSegmentManager_Validate(t *testing.T) { +func TestHistorySegmentManager_Validate(t *testing.T) { tests := []struct { genesis common.Hash segments []HistorySegment @@ -135,7 +129,7 @@ func TestHisSegmentManager_Validate(t *testing.T) { }, } for i, item := range tests { - err := ValidateHisSegments(NewHistoryBlock(0, item.genesis, 0), item.segments) + err := ValidateHistorySegments(NewHistoryBlock(0, item.genesis, 0), item.segments) if item.err { assert.Error(t, err, i) continue @@ -144,11 +138,11 @@ func TestHisSegmentManager_Validate(t *testing.T) { } } -func TestUnmarshalHisSegments(t *testing.T) { +func TestUnmarshalHistorySegments(t *testing.T) { enc, err := json.MarshalIndent(historySegmentsInTest, "", " ") assert.NoError(t, err) //t.Log(string(enc)) - segments := unmarshalHisSegments(string(enc)) + segments := unmarshalHistorySegments(string(enc)) assert.Equal(t, historySegmentsInTest, segments) } @@ -157,12 +151,12 @@ func TestIndexSegment(t *testing.T) { hsm := HistorySegmentManager{ segments: historySegmentsInTest, } - assert.Equal(t, segments[0], hsm.CurSegment(0)) - assert.Equal(t, segments[0], hsm.CurSegment(BoundStartBlock-1)) - assert.Equal(t, segments[1], hsm.CurSegment(BoundStartBlock)) - assert.Equal(t, segments[1], hsm.CurSegment(BoundStartBlock+HistorySegmentLength-1)) - assert.Equal(t, segments[2], hsm.CurSegment(BoundStartBlock+HistorySegmentLength)) - assert.Equal(t, segments[2], hsm.CurSegment(BoundStartBlock+HistorySegmentLength*2)) + assert.Equal(t, &segments[0], hsm.CurSegment(0)) + assert.Equal(t, &segments[0], hsm.CurSegment(BoundStartBlock-1)) + assert.Equal(t, &segments[1], hsm.CurSegment(BoundStartBlock)) + assert.Equal(t, &segments[1], hsm.CurSegment(BoundStartBlock+HistorySegmentLength-1)) + assert.Equal(t, &segments[2], hsm.CurSegment(BoundStartBlock+HistorySegmentLength)) + assert.Equal(t, &segments[2], hsm.CurSegment(BoundStartBlock+HistorySegmentLength*2)) var ( prev *HistorySegment @@ -172,10 +166,10 @@ func TestIndexSegment(t *testing.T) { assert.Equal(t, false, ok) prev, ok = hsm.LastSegment(&segments[1]) assert.Equal(t, true, ok) - assert.Equal(t, segments[0], prev) + assert.Equal(t, &segments[0], prev) prev, ok = hsm.LastSegment(&segments[2]) assert.Equal(t, true, ok) - assert.Equal(t, segments[1], prev) + assert.Equal(t, &segments[1], prev) _, ok = hsm.LastSegment(&HistorySegment{ Index: uint64(len(segments)), })