diff --git a/state/aggregator22.go b/state/aggregator22.go index 230a074fa..2b6dcad75 100644 --- a/state/aggregator22.go +++ b/state/aggregator22.go @@ -1293,7 +1293,16 @@ type AggregatorStep struct { } func (a *Aggregator22) MakeSteps() []*AggregatorStep { - accountSteps := a.accounts.MakeSteps() + to := a.maxTxNum.Load() + indexedMax := cmp.Min( + cmp.Min(a.accounts.endIndexedTxNumMinimax(), a.storage.endIndexedTxNumMinimax()), + a.code.endIndexedTxNumMinimax(), + ) + if to != indexedMax { + log.Warn("[snapshots] not all files are indexed", "files", to/a.aggregationStep, "indexed", indexedMax/a.aggregationStep) + to = cmp.Min(to, indexedMax) + } + accountSteps := a.accounts.MakeSteps(to) steps := make([]*AggregatorStep, len(accountSteps)) for i, accountStep := range accountSteps { steps[i] = &AggregatorStep{ @@ -1301,11 +1310,11 @@ func (a *Aggregator22) MakeSteps() []*AggregatorStep { accounts: accountStep, } } - storageSteps := a.storage.MakeSteps() + storageSteps := a.storage.MakeSteps(to) for i, storageStep := range storageSteps { steps[i].storage = storageStep } - codeSteps := a.code.MakeSteps() + codeSteps := a.code.MakeSteps(to) for i, codeStep := range codeSteps { steps[i].code = codeStep } diff --git a/state/history.go b/state/history.go index 628e83ce9..410eb40c5 100644 --- a/state/history.go +++ b/state/history.go @@ -1676,12 +1676,17 @@ type HistoryStep struct { historyFile ctxItem } -func (h *History) MakeSteps() []*HistoryStep { +// MakeSteps [0, toTxNum) +func (h *History) MakeSteps(toTxNum uint64) []*HistoryStep { var steps []*HistoryStep h.InvertedIndex.files.Ascend(func(item *filesItem) bool { if item.index == nil { return false } + if item.startTxNum >= toTxNum { + return true + } + step := &HistoryStep{ compressVals: h.compressVals, indexItem: item, @@ -1700,6 +1705,9 @@ func (h *History) MakeSteps() []*HistoryStep { if item.index == nil { return false } + if item.startTxNum >= toTxNum { + return true + } steps[i].historyItem = item steps[i].historyFile = ctxItem{ startTxNum: item.startTxNum, diff --git a/state/merge.go b/state/merge.go index bd7bf98df..33a9299c5 100644 --- a/state/merge.go +++ b/state/merge.go @@ -55,6 +55,16 @@ func (ii *InvertedIndex) endTxNumMinimax() uint64 { } return minimax } +func (ii *InvertedIndex) endIndexedTxNumMinimax() uint64 { + var max uint64 + ii.files.Ascend(func(item *filesItem) bool { + if item.index != nil { + max = cmp.Max(max, item.endTxNum) + } + return true + }) + return max +} func (h *History) endTxNumMinimax() uint64 { minimax := h.InvertedIndex.endTxNumMinimax() @@ -66,6 +76,17 @@ func (h *History) endTxNumMinimax() uint64 { } return minimax } +func (h *History) endIndexedTxNumMinimax() uint64 { + var max uint64 + h.files.Ascend(func(item *filesItem) bool { + if item.index == nil { + return false + } + max = cmp.Max(max, item.endTxNum) + return true + }) + return cmp.Min(max, h.InvertedIndex.endIndexedTxNumMinimax()) +} type DomainRanges struct { valuesStartTxNum uint64