Skip to content

Commit

Permalink
discard_commit
Browse files Browse the repository at this point in the history
  • Loading branch information
blxdyx committed Nov 26, 2024
1 parent fc37c30 commit f9fa32c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions core/state/rw_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func (rs *StateV3) ApplyState4(ctx context.Context, txTask *TxTask) error {
if (txTask.TxNum+1)%rs.domains.StepSize() == 0 /*&& txTask.TxNum > 0 */ {
if txTask.BlockNum != 0 {
rs.domains.ResetCommitment()
_ = rs.domains.SaveCommitment(txTask.BlockNum, txTask.Header.Root.Bytes())
} else {
//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.
Expand Down
12 changes: 6 additions & 6 deletions erigon-lib/state/domain_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (sd *SharedDomains) SeekCommitment(ctx context.Context, tx kv.Tx) (txsFromB
if err != nil {
return 0, err
}
if ok && bn != 0 {
if ok {
if bn > 0 {
lastBn, _, err := rawdbv3.TxNums.Last(tx)
if err != nil {
Expand All @@ -334,10 +334,6 @@ func (sd *SharedDomains) SeekCommitment(ctx context.Context, tx kv.Tx) (txsFromB
sd.SetTxNum(txn)
return 0, nil
}
if len(sd.aggTx.d[kv.CommitmentDomain].files) > 0 {
txn = sd.aggTx.d[kv.CommitmentDomain].files[len(sd.aggTx.d[kv.CommitmentDomain].files)-1].endTxNum
sd.SetTxNum(txn)
}
// handle case when we have no commitment, but have executed blocks
bnBytes, err := tx.GetOne(kv.SyncStageProgress, []byte("Execution")) //TODO: move stages to erigon-lib
if err != nil {
Expand All @@ -350,7 +346,7 @@ func (sd *SharedDomains) SeekCommitment(ctx context.Context, tx kv.Tx) (txsFromB
return 0, err
}
}
sd.logger.Info("seeking commitment", "bn", bn, "txn", tx)
sd.logger.Info("seeking commitment", "bn", bn, "txn", txn)
if bn == 0 && txn == 0 {
sd.SetBlockNum(0)
sd.SetTxNum(0)
Expand Down Expand Up @@ -394,6 +390,10 @@ func (sd *SharedDomains) ResetCommitment() {
sd.sdCtx.updates.Reset()
}

func (sd *SharedDomains) SaveCommitment(blockNum uint64, rootHash []byte) error {
return sd.sdCtx.storeCommitmentState(blockNum, rootHash)
}

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
8 changes: 5 additions & 3 deletions eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,10 @@ Loop:
aggTx := applyTx.(state2.HasAggTx).AggTx().(*state2.AggregatorRoTx)
aggTx.RestrictSubsetFileDeletions(true)
start := time.Now()
if _, err := doms.ComputeCommitment(ctx, true, blockNum, execStage.LogPrefix()); err != nil {
return err
}
_ = doms.SaveCommitment(blockNum, b.Root().Bytes())
//if _, err := doms.ComputeCommitment(ctx, true, blockNum, execStage.LogPrefix()); err != nil {
// return err
//}
ts += time.Since(start)
aggTx.RestrictSubsetFileDeletions(false)
doms.SavePastChangesetAccumulator(b.Hash(), blockNum, changeset)
Expand Down Expand Up @@ -933,6 +934,7 @@ func flushAndCheckCommitmentV3(ctx context.Context, header *types.Header, applyT
var err error
if header.Number.Uint64() != 0 {
doms.ResetCommitment()
_ = doms.SaveCommitment(doms.BlockNum(), header.Root.Bytes())
} else {
_, err := doms.ComputeCommitment(ctx, true, header.Number.Uint64(), e.LogPrefix())
if err != nil {
Expand Down

0 comments on commit f9fa32c

Please sign in to comment.