Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize FindMergeRange #13491

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions erigon-lib/chain/snapcfg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,27 @@ func doSort(in map[string]string) Preverified {

func newCfg(networkName string, preverified Preverified) *Cfg {
maxBlockNum, _ := preverified.MaxBlock(0)
return &Cfg{ExpectBlocks: maxBlockNum, Preverified: preverified, networkName: networkName}
cfg := &Cfg{ExpectBlocks: maxBlockNum, Preverified: preverified, networkName: networkName}
cfg.PreverifiedParsed = make([]*snaptype.FileInfo, len(preverified))
for i, p := range cfg.Preverified {
info, _, ok := snaptype.ParseFileName("", p.Name)
if !ok {
continue
}
cfg.PreverifiedParsed[i] = &info
}
return cfg
}

func NewNonSeededCfg(networkName string) *Cfg {
return newCfg(networkName, Preverified{})
}

type Cfg struct {
ExpectBlocks uint64
Preverified Preverified
networkName string
ExpectBlocks uint64
Preverified Preverified // immutable
PreverifiedParsed []*snaptype.FileInfo //Preverified field after `snaptype.ParseFileName("", p.Name)`
networkName string
}

// Seedable - can seed it over Bittorrent network to other nodes
Expand All @@ -398,12 +408,11 @@ func (c Cfg) IsFrozen(info snaptype.FileInfo) bool {
func (c Cfg) MergeLimit(t snaptype.Enum, fromBlock uint64) uint64 {
hasType := t == snaptype.MinCoreEnum

for _, p := range c.Preverified {
info, _, ok := snaptype.ParseFileName("", p.Name)
if !ok {
for _, info := range c.PreverifiedParsed {
if info == nil {
continue
}
if strings.Contains(p.Name, "caplin") {
if strings.Contains(info.Name(), "caplin") {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion turbo/snapshotsync/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (m *Merger) FindMergeRanges(currentRanges []Range, maxBlockNum uint64) (toM
cfg := snapcfg.KnownCfg(m.chainConfig.ChainName)
for i := len(currentRanges) - 1; i > 0; i-- {
r := currentRanges[i]
mergeLimit := snapcfg.MergeLimitFromCfg(cfg, snaptype.Unknown, r.From())
mergeLimit := cfg.MergeLimit(snaptype.Unknown, r.From())
if r.To()-r.From() >= mergeLimit {
continue
}
Expand Down
Loading