Skip to content

Commit

Permalink
discard_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blxdyx committed Nov 23, 2024
1 parent 3197707 commit 09661b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/state/rw_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ func (rs *StateV3) ApplyState4(ctx context.Context, txTask *TxTask) error {
}

if (txTask.TxNum+1)%rs.domains.StepSize() == 0 /*&& txTask.TxNum > 0 */ {
rs.domains.ResetCommitment()
// We do not update txNum before commitment cuz otherwise committed state will be in the beginning of next file, not in the latest.
// That's why we need to make txnum++ on SeekCommitment to get exact txNum for the latest committed state.
//fmt.Printf("[commitment] running due to txNum reached aggregation step %d\n", txNum/rs.domains.StepSize())
_, err := rs.domains.ComputeCommitment(ctx, true, txTask.BlockNum,
fmt.Sprintf("applying step %d", txTask.TxNum/rs.domains.StepSize()))
if err != nil {
return fmt.Errorf("StateV3.ComputeCommitment: %w", err)
}
//_, err := rs.domains.ComputeCommitment(ctx, true, txTask.BlockNum,
// fmt.Sprintf("applying step %d", txTask.TxNum/rs.domains.StepSize()))
//if err != nil {
// return fmt.Errorf("StateV3.ComputeCommitment: %w", err)
//}
}

txTask.ReadLists, txTask.WriteLists = nil, nil
Expand Down
5 changes: 5 additions & 0 deletions erigon-lib/state/domain_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,10 @@ func (sd *SharedDomains) ClearRam(resetCommitment bool) {
sd.estSize = 0
}

func (sd *SharedDomains) ResetCommitment() {
sd.sdCtx.updates.Reset()
}

func (sd *SharedDomains) put(domain kv.Domain, key string, val []byte) {
// disable mutex - because work on parallel execution postponed after E3 release.
//sd.muMaps.Lock()
Expand Down Expand Up @@ -1297,6 +1301,7 @@ func (sdc *SharedDomainsCommitmentContext) TouchKey(d kv.Domain, key string, val
func (sdc *SharedDomainsCommitmentContext) ComputeCommitment(ctx context.Context, saveState bool, blockNum uint64, logPrefix string) (rootHash []byte, err error) {
if dbg.DiscardCommitment() {
sdc.updates.Reset()
return nil, nil
}
sdc.ResetBranchCache()
defer sdc.ResetBranchCache()
Expand Down
5 changes: 5 additions & 0 deletions eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ func flushAndCheckCommitmentV3(ctx context.Context, header *types.Header, applyT
panic(fmt.Errorf("%d != %d", doms.BlockNum(), header.Number.Uint64()))
}

if header.Number.Uint64() != 0 {
doms.ResetCommitment()
return true, nil
}

rh, err := doms.ComputeCommitment(ctx, true, header.Number.Uint64(), e.LogPrefix())
if err != nil {
return false, fmt.Errorf("StateV3.Apply: %w", err)
Expand Down

0 comments on commit 09661b7

Please sign in to comment.