From f9fa32c0410ac4f5b27eb9c1f91af5491d020ce3 Mon Sep 17 00:00:00 2001 From: blxdyx Date: Tue, 26 Nov 2024 13:16:48 +0800 Subject: [PATCH] discard_commit --- core/state/rw_v3.go | 1 + erigon-lib/state/domain_shared.go | 12 ++++++------ eth/stagedsync/exec3.go | 8 +++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/state/rw_v3.go b/core/state/rw_v3.go index 57dcbf56f0d..548873e1dc9 100644 --- a/core/state/rw_v3.go +++ b/core/state/rw_v3.go @@ -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. diff --git a/erigon-lib/state/domain_shared.go b/erigon-lib/state/domain_shared.go index e7cf0c15e0d..9fb12293544 100644 --- a/erigon-lib/state/domain_shared.go +++ b/erigon-lib/state/domain_shared.go @@ -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 { @@ -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 { @@ -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) @@ -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() diff --git a/eth/stagedsync/exec3.go b/eth/stagedsync/exec3.go index ce9ec1ac7b4..0920737d2c3 100644 --- a/eth/stagedsync/exec3.go +++ b/eth/stagedsync/exec3.go @@ -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) @@ -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 {