Skip to content

Commit 5ff1079

Browse files
Revert "[wip] sd: removing txNum field " (#19508)
Reverts #19489 Lets do this in v3.5.0 Co-authored-by: Alexey Sharov <AskAlexSharov@gmail.com>
1 parent f354eef commit 5ff1079

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

db/state/execctx/domain_shared.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ type SharedDomains struct {
8989

9090
logger log.Logger
9191

92+
txNum uint64
93+
currentStep kv.Step
9294
trace bool //nolint
9395
commitmentCapture bool
9496
mem kv.TemporalMemBatch
@@ -166,6 +168,8 @@ func (sd *SharedDomains) Merge(sdTxNum uint64, other *SharedDomains, otherTxNum
166168
sd.sdCtx.SetPendingUpdate(otherUpd)
167169
}
168170

171+
sd.txNum = otherTxNum
172+
sd.currentStep = kv.Step(otherTxNum / sd.stepSize)
169173
return nil
170174
}
171175

@@ -308,6 +312,15 @@ func (sd *SharedDomains) IndexAdd(table kv.InvertedIdx, key []byte, txNum uint64
308312

309313
func (sd *SharedDomains) StepSize() uint64 { return sd.stepSize }
310314

315+
// SetTxNum sets txNum for all domains as well as common txNum for all domains
316+
// Requires for sd.rwTx because of commitment evaluation in shared domains if stepSize is reached
317+
func (sd *SharedDomains) SetTxNum(txNum uint64) {
318+
sd.txNum = txNum
319+
sd.currentStep = kv.Step(txNum / sd.stepSize)
320+
}
321+
322+
func (sd *SharedDomains) TxNum() uint64 { return sd.txNum }
323+
311324
func (sd *SharedDomains) SetTrace(b, capture bool) []string {
312325
sd.trace = b
313326
sd.commitmentCapture = capture
@@ -327,6 +340,7 @@ func (sd *SharedDomains) Close() {
327340
return
328341
}
329342

343+
sd.SetTxNum(0)
330344
sd.ResetPendingUpdates()
331345

332346
//sd.walLock.Lock()
@@ -612,6 +626,7 @@ func (sd *SharedDomains) SeekCommitment(ctx context.Context, tx kv.TemporalTx) (
612626
if err != nil {
613627
return 0, 0, err
614628
}
629+
sd.SetTxNum(txNum)
615630
return txNum, blockNum, nil
616631
}
617632

db/state/squeeze.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ func RebuildCommitmentFiles(ctx context.Context, rwDb kv.TemporalRwDB, txNumsRea
485485
return nil, err
486486
}
487487

488+
domains.SetTxNum(lastTxnumInShard - 1)
488489
currentTxNum := lastTxnumInShard - 1
489490
domains.GetCommitmentCtx().SetLimitedHistoryStateReader(rwTx, lastTxnumInShard) // this helps to read state from correct file during commitment
490491

execution/commitment/commitmentdb/commitment_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ var (
3232
)
3333

3434
type sd interface {
35+
SetTxNum(blockNum uint64)
3536
AsGetter(tx kv.TemporalTx) kv.TemporalGetter
3637
AsPutDel(tx kv.TemporalTx) kv.TemporalPutDel
3738
StepSize() uint64
39+
TxNum() uint64
3840

3941
Trace() bool
4042
CommitmentCapture() bool

execution/stagedsync/exec3_parallel.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ func (pe *parallelExecutor) exec(ctx context.Context, execStage *StageState, u U
282282

283283
if applyResult.BlockNum > lastBlockResult.BlockNum {
284284
uncommittedBlocks++
285+
pe.doms.SetTxNum(applyResult.lastTxNum)
285286
lastBlockResult = *applyResult
286287
}
287288

execution/stagedsync/exec3_serial.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ func (se *serialExecutor) executeBlock(ctx context.Context, tasks []exec.Task, i
527527
return false, err
528528
}
529529

530+
se.doms.SetTxNum(txTask.TxNum)
530531
se.lastBlockResult = &blockResult{
531532
BlockNum: txTask.BlockNumber(),
532533
lastTxNum: txTask.TxNum,

execution/stagedsync/stage_execute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ func unwindExec3State(ctx context.Context,
351351
}
352352

353353
sd.Unwind(txUnwindTo, changeset)
354+
sd.SetTxNum(txUnwindTo)
354355
return nil
355356
}
356357

0 commit comments

Comments
 (0)