Skip to content

Commit 43f1689

Browse files
committed
fix TestGenerateChain
1 parent 7c49c0f commit 43f1689

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

db/integrity/commitment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ func CheckCommitmentHistAtBlk(ctx context.Context, db kv.TemporalRoDB, br servic
755755
}
756756
// commitment branch data view: as of beginning of the block
757757
// plain state data view: as of end of the block
758-
splitStateReader := commitmentdb.NewSplitHistoryReader(tx, minTxNum, toTxNum)
758+
splitStateReader := commitmentdb.NewSplitHistoryReader(tx, minTxNum, toTxNum /* withHistory */, true)
759759
sd.GetCommitmentCtx().SetStateReader(splitStateReader)
760760
sd.GetCommitmentCtx().SetTrace(logger.Enabled(ctx, log.LvlTrace))
761761
sd.GetCommitmentContext().SetDeferBranchUpdates(false)

execution/commitment/backtester/backtester.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (bt Backtester) backtestBlock(ctx context.Context, tx kv.TemporalTx, block
210210
// A history reader that reads:
211211
// - commitment data as-of the beginning of the block
212212
// - account/storage/code data as-of the end of the block
213-
sd.GetCommitmentCtx().SetStateReader(commitmentdb.NewSplitHistoryReader(tx, fromTxNum, toTxNum))
213+
sd.GetCommitmentCtx().SetStateReader(commitmentdb.NewSplitHistoryReader(tx, fromTxNum, toTxNum /* withHistory */, false))
214214
sd.GetCommitmentCtx().SetTrace(bt.logger.Enabled(ctx, log.LvlTrace))
215215
sd.GetCommitmentCtx().EnableCsvMetrics(deriveBlockMetricsFilePrefix(blockOutputDir))
216216
latestTxNum, latestBlockNum, err := sd.SeekCommitment(ctx, tx)

execution/commitment/commitmentdb/reader.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,55 +133,65 @@ func (r *LimitedHistoryStateReader) Clone(tx kv.TemporalTx) StateReader {
133133
return NewLimitedHistoryStateReader(tx, r.sharedDomains, r.limitReadAsOfTxNum)
134134
}
135135

136-
// splitStateReader implements commitmentdb.StateReader using (potentially) different state readers for commitment
136+
// SplitStateReader implements commitmentdb.StateReader using (potentially) different state readers for commitment
137137
// data and account/storage/code data.
138-
type splitStateReader struct {
138+
type SplitStateReader struct {
139139
commitmentReader StateReader
140140
plainStateReader StateReader
141141
withHistory bool
142142
}
143143

144-
var _ StateReader = (*splitStateReader)(nil)
144+
var _ StateReader = (*SplitStateReader)(nil)
145145

146-
func (r *splitStateReader) WithHistory() bool {
146+
func (r *SplitStateReader) WithHistory() bool {
147147
return r.withHistory
148148
}
149149

150-
func (r *splitStateReader) CheckDataAvailable(_ kv.Domain, _ kv.Step) error {
150+
func (r *SplitStateReader) CheckDataAvailable(_ kv.Domain, _ kv.Step) error {
151151
return nil
152152
}
153153

154-
func (r *splitStateReader) Read(d kv.Domain, plainKey []byte, stepSize uint64) ([]byte, kv.Step, error) {
154+
func (r *SplitStateReader) Read(d kv.Domain, plainKey []byte, stepSize uint64) ([]byte, kv.Step, error) {
155155
if d == kv.CommitmentDomain {
156156
return r.commitmentReader.Read(d, plainKey, stepSize)
157157
}
158158
return r.plainStateReader.Read(d, plainKey, stepSize)
159159
}
160160

161-
func (r *splitStateReader) Clone(tx kv.TemporalTx) StateReader {
161+
func (r *SplitStateReader) Clone(tx kv.TemporalTx) StateReader {
162162
return NewCommitmentSplitStateReader(r.commitmentReader.Clone(tx), r.plainStateReader.Clone(tx), r.withHistory)
163163
}
164164

165-
func NewCommitmentSplitStateReader(commitmentReader StateReader, plainStateReader StateReader, withHistory bool) *splitStateReader {
166-
return &splitStateReader{
165+
func NewCommitmentSplitStateReader(commitmentReader StateReader, plainStateReader StateReader, withHistory bool) *SplitStateReader {
166+
return &SplitStateReader{
167167
commitmentReader: commitmentReader,
168168
plainStateReader: plainStateReader,
169169
withHistory: withHistory,
170170
}
171171
}
172172

173-
func NewCommitmentReplayStateReader(ttx, tx kv.TemporalTx, tsd sd, plainStateAsOf uint64) *splitStateReader {
174-
// Claim that during replay we do not operate on history, so we can temporarily save commitment state
175-
return NewCommitmentSplitStateReader(NewLatestStateReader(ttx, tsd), NewHistoryStateReader(tx, plainStateAsOf), false)
173+
type CommitmentReplayStateReader struct {
174+
*SplitStateReader
175+
}
176+
177+
func NewCommitmentReplayStateReader(ttx, tx kv.TemporalTx, tsd sd, plainStateAsOf uint64) *CommitmentReplayStateReader {
178+
return &CommitmentReplayStateReader{
179+
NewCommitmentSplitStateReader(NewLatestStateReader(ttx, tsd), NewHistoryStateReader(tx, plainStateAsOf), false),
180+
}
181+
}
182+
183+
func (crsr *CommitmentReplayStateReader) Clone(tx kv.TemporalTx) StateReader {
184+
// do nothing
185+
return crsr
176186
}
177187

178188
// A history reader that reads:
179189
// - commitment data as-of commitmentAsOf txnum
180190
// - account/storage/code data as-of plainsStateAsOf txnum
181-
func NewSplitHistoryReader(tx kv.TemporalTx, commitmentAsOf uint64, plainStateAsOf uint64) *splitStateReader {
182-
return &splitStateReader{
191+
func NewSplitHistoryReader(tx kv.TemporalTx, commitmentAsOf uint64, plainStateAsOf uint64, withHistory bool) *SplitStateReader {
192+
return &SplitStateReader{
183193
commitmentReader: NewHistoryStateReader(tx, commitmentAsOf),
184194
plainStateReader: NewHistoryStateReader(tx, plainStateAsOf),
185-
withHistory: false, // we lie, it is without history so we can exercise SharedDomain's in-memory DomainPut(kv.CommitmmentDomain)
195+
withHistory: withHistory,
186196
}
187197
}

0 commit comments

Comments
 (0)