Skip to content

Commit

Permalink
move StateHistoryStartFrom to HistoryReaderV3
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis19 committed Dec 12, 2024
1 parent 4ddeb05 commit 8aafcb0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 36 deletions.
27 changes: 16 additions & 11 deletions core/state/history_reader_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/kv/kv_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/kv/remotedb/kv_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/kv/temporal/kv_temporal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 0 additions & 20 deletions erigon-lib/state/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8aafcb0

Please sign in to comment.