Skip to content

Commit

Permalink
e3: close context
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored and calmbeing committed Apr 24, 2023
1 parent cbab545 commit 0b713ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
20 changes: 15 additions & 5 deletions eth/stagedsync/stage_hashstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,9 @@ func (p *Promoter) PromoteOnHistoryV3(logPrefix string, agg *state.AggregatorV3,
defer collector.Close()

if storage {
if err := agg.Storage().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k, _ []byte) error {
sc := agg.Storage().MakeContext()
defer sc.Close()
if err := sc.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k, _ []byte) error {
accBytes, err := p.tx.GetOne(kv.PlainState, k[:20])
if err != nil {
return err
Expand Down Expand Up @@ -600,7 +602,9 @@ func (p *Promoter) PromoteOnHistoryV3(logPrefix string, agg *state.AggregatorV3,
codeCollector := etl.NewCollector(logPrefix, p.dirs.Tmp, etl.NewSortableBuffer(etl.BufferOptimalSize))
defer codeCollector.Close()

if err := agg.Accounts().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k, _ []byte) error {
ac := agg.Accounts().MakeContext()
defer ac.Close()
if err := ac.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k, _ []byte) error {
newV, err := p.tx.GetOne(kv.PlainState, k)
if err != nil {
return err
Expand Down Expand Up @@ -714,7 +718,9 @@ func (p *Promoter) UnwindOnHistoryV3(logPrefix string, agg *state.AggregatorV3,

acc := accounts.NewAccount()
if codes {
if err = agg.Accounts().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
ac := agg.Accounts().MakeContext()
defer ac.Close()
if err = ac.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
if len(v) == 0 {
return nil
}
Expand Down Expand Up @@ -747,7 +753,9 @@ func (p *Promoter) UnwindOnHistoryV3(logPrefix string, agg *state.AggregatorV3,
}

if storage {
if err = agg.Storage().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
sc := agg.Storage().MakeContext()
defer sc.Close()
if err = sc.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
val, err := p.tx.GetOne(kv.PlainState, k[:20])
if err != nil {
return err
Expand All @@ -772,7 +780,9 @@ func (p *Promoter) UnwindOnHistoryV3(logPrefix string, agg *state.AggregatorV3,
return collector.Load(p.tx, kv.HashedStorage, etl.IdentityLoadFunc, etl.TransformArgs{Quit: p.ctx.Done()})
}

if err = agg.Accounts().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
ac := agg.Accounts().MakeContext()
defer ac.Close()
if err = ac.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
newK, err := transformPlainStateKey(k)
if err != nil {
return err
Expand Down
17 changes: 13 additions & 4 deletions eth/stagedsync/stage_interhashes.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ func (p *HashPromoter) PromoteOnHistoryV3(logPrefix string, agg *state.Aggregato

if storage {
compositeKey := make([]byte, length.Hash+length.Hash)
if err := agg.Storage().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
sc := agg.Storage().MakeContext()
defer sc.Close()
if err := sc.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
addrHash, err := common.HashData(k[:length.Addr])
if err != nil {
return err
Expand All @@ -241,7 +243,9 @@ func (p *HashPromoter) PromoteOnHistoryV3(logPrefix string, agg *state.Aggregato
return nil
}

if err := agg.Accounts().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
ac := agg.Accounts().MakeContext()
defer ac.Close()
if err := ac.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
newK, err := transformPlainStateKey(k)
if err != nil {
return err
Expand Down Expand Up @@ -358,7 +362,9 @@ func (p *HashPromoter) UnwindOnHistoryV3(logPrefix string, agg *state.Aggregator
var deletedAccounts [][]byte

if storage {
if err = agg.Storage().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
sc := agg.Storage().MakeContext()
defer sc.Close()
if err = sc.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
// Plain state not unwind yet, it means - if key not-exists in PlainState but has value from ChangeSets - then need mark it as "created" in RetainList
enc, err := p.tx.GetOne(kv.PlainState, k[:20])
if err != nil {
Expand All @@ -385,7 +391,10 @@ func (p *HashPromoter) UnwindOnHistoryV3(logPrefix string, agg *state.Aggregator
}
return nil
}
if err = agg.Accounts().MakeContext().IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {

ac := agg.Accounts().MakeContext()
defer ac.Close()
if err = ac.IterateRecentlyChanged(txnFrom, txnTo, p.tx, func(k []byte, v []byte) error {
newK, err := transformPlainStateKey(k)
if err != nil {
return err
Expand Down

0 comments on commit 0b713ff

Please sign in to comment.