diff --git a/core/state/history_reader_v3.go b/core/state/history_reader_v3.go index e9ec010db6e..dc37f71292c 100644 --- a/core/state/history_reader_v3.go +++ b/core/state/history_reader_v3.go @@ -53,19 +53,24 @@ func (hr *HistoryReaderV3) SetTxNum(txNum uint64) { hr.txNum = txNum } func (hr *HistoryReaderV3) GetTxNum() uint64 { return hr.txNum } func (hr *HistoryReaderV3) SetTrace(trace bool) { hr.trace = trace } -// Returns the earliest known txnum in history files for state history -// This is the smallest txNum found across: +// Gets the txNum where Account, Storage and Code history begins. +// If the node is an archive node all history will be available therefore +// the result will be 0. // -// - Account history -// -// - Storage history -// -// - Code history -// -// Not considered in the calculation are Commitment history and Receipt history, as -// there are separate functions handling them. +// For non-archive node old history files get deleted, so this number will vary +// but the goal is to know where the historical data begins. func (hr *HistoryReaderV3) StateHistoryStartFrom() uint64 { - return hr.ttx.StateHistoryStartFrom() + var earliestTxNum uint64 = 0 + // get the first txnum where accounts, storage , and code are all available in history files + // This is max(HistoryStart(Accounts), HistoryStart(Storage), HistoryStart(Code)) + stateDomainNames := []kv.Domain{kv.AccountsDomain, kv.StorageDomain, kv.CodeDomain} + for _, domainName := range stateDomainNames { + domainStartingTxNum := hr.ttx.HistoryStartFrom(domainName) + if domainStartingTxNum > earliestTxNum { + earliestTxNum = domainStartingTxNum + } + } + return earliestTxNum } func (hr *HistoryReaderV3) ReadSet() map[string]*state.KvList { return nil } diff --git a/erigon-lib/kv/kv_interface.go b/erigon-lib/kv/kv_interface.go index 837d8cf916d..c3a0b0bffad 100644 --- a/erigon-lib/kv/kv_interface.go +++ b/erigon-lib/kv/kv_interface.go @@ -464,8 +464,8 @@ type TemporalTx interface { Tx TemporalGetter - // return the earliest known txnum in state history (excluding commitment and receipt history) - StateHistoryStartFrom() uint64 + // return the earliest known txnum in history of a given domain + HistoryStartFrom(domainName Domain) uint64 // DomainGetAsOf - state as of given `ts` // Example: GetAsOf(Account, key, txNum) - retuns account's value before `txNum` transaction changed it diff --git a/erigon-lib/kv/remotedb/kv_remote.go b/erigon-lib/kv/remotedb/kv_remote.go index ceba1009b7b..6e64863ebb4 100644 --- a/erigon-lib/kv/remotedb/kv_remote.go +++ b/erigon-lib/kv/remotedb/kv_remote.go @@ -627,7 +627,7 @@ func (c *remoteCursorDupSort) LastDup() ([]byte, error) { return c.las // Temporal Methods -func (tx *tx) StateHistoryStartFrom() uint64 { +func (tx *tx) HistoryStartFrom(name kv.Domain) uint64 { // TODO: not yet implemented, return 0 for now return 0 } diff --git a/erigon-lib/kv/temporal/kv_temporal.go b/erigon-lib/kv/temporal/kv_temporal.go index 3846f208c31..6fe2c53fd2e 100644 --- a/erigon-lib/kv/temporal/kv_temporal.go +++ b/erigon-lib/kv/temporal/kv_temporal.go @@ -194,8 +194,8 @@ func (tx *Tx) Commit() error { return mdbxTx.Commit() } -func (tx *Tx) StateHistoryStartFrom() uint64 { - return tx.filesTx.StateHistoryStartFrom() +func (tx *Tx) HistoryStartFrom(name kv.Domain) uint64 { + return tx.filesTx.HistoryStartFrom(name) } func (tx *Tx) RangeAsOf(name kv.Domain, fromKey, toKey []byte, asOfTs uint64, asc order.By, limit int) (stream.KV, error) { diff --git a/erigon-lib/state/aggregator.go b/erigon-lib/state/aggregator.go index ad89f2e4fde..ae37d1931e8 100644 --- a/erigon-lib/state/aggregator.go +++ b/erigon-lib/state/aggregator.go @@ -1729,26 +1729,6 @@ func (a *Aggregator) BuildFilesInBackground(txNum uint64) chan struct{} { return fin } -// Gets the txNum where Account, Storage and Code history begins. -// If the node is an archive node all history will be available therefore -// the result will be 0. -// -// For non-archive node old history files get deleted, so this number will vary -// but the goal is to know where the historical data begins -func (ac *AggregatorRoTx) StateHistoryStartFrom() uint64 { - var earliestTxNum uint64 = 0 - // get the first txnum where accounts, storage , and code are all available in history files - // This is max(HistoryStart(Accounts), HistoryStart(Storage), HistoryStart(Code)) - stateDomainNames := []kv.Domain{kv.AccountsDomain, kv.StorageDomain, kv.CodeDomain} - for _, domainName := range stateDomainNames { - domainStartingTxNum := ac.HistoryStartFrom(domainName) - if domainStartingTxNum > earliestTxNum { - earliestTxNum = domainStartingTxNum - } - } - return earliestTxNum -} - // Returns the first known txNum found in history files of a given domain func (ac *AggregatorRoTx) HistoryStartFrom(domainName kv.Domain) uint64 { return ac.d[domainName].HistoryStartFrom()