Skip to content

Commit 5df08fd

Browse files
committed
save
1 parent b361505 commit 5df08fd

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

db/integrity/rcache_no_duplicates.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ func RCacheNoDupsRange(ctx context.Context, fromBlock, toBlock uint64, tx kv.Tem
6767
var _min, _max uint64
6868
_min, _ = txNumsReader.Min(tx, fromBlock)
6969
_max, _ = txNumsReader.Max(tx, fromBlock)
70+
71+
it, err := rawdb.ReceiptCacheV2Stream(tx, fromTxNum, toTxNum)
72+
if err != nil {
73+
return err
74+
}
75+
defer it.Close()
76+
7077
for txNum := fromTxNum; txNum <= toTxNum; txNum++ {
7178
r, found, err := rawdb.ReadReceiptCacheV2(tx, rawdb.RCacheV2Query{
7279
TxNum: txNum,

db/kv/stream/stream.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,29 @@ func (m *TransformedDuo[K, v]) Close() {
312312
}
313313
}
314314

315+
// TransformedDuoV - analog `map` (in terms of map-filter-reduce pattern) but with different value type
316+
type TransformedDuoV[K, V, VR any] struct {
317+
it Duo[K, V]
318+
transform func(K, V) (K, VR, error)
319+
}
320+
321+
func TransformDuoV[K, V, VR any](it Duo[K, V], transform func(K, V) (K, VR, error)) *TransformedDuoV[K, V, VR] {
322+
return &TransformedDuoV[K, V, VR]{it: it, transform: transform}
323+
}
324+
func (m *TransformedDuoV[K, V, VR]) HasNext() bool { return m.it.HasNext() }
325+
func (m *TransformedDuoV[K, V, VR]) Next() (k K, vr VR, err error) {
326+
k, v, err := m.it.Next()
327+
if err != nil {
328+
return k, vr, err
329+
}
330+
return m.transform(k, v)
331+
}
332+
func (m *TransformedDuoV[K, V, VR]) Close() {
333+
if x, ok := m.it.(Closer); ok {
334+
x.Close()
335+
}
336+
}
337+
315338
// FilteredDuo - analog `map` (in terms of map-filter-reduce pattern)
316339
// please avoid reading from Disk/DB more elements and then filter them. Better
317340
// push-down filter conditions to lower-level iterator to reduce disk reads amount.

db/rawdb/accessors_chain.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/erigontech/erigon/db/kv"
3737
"github.com/erigontech/erigon/db/kv/dbutils"
3838
"github.com/erigontech/erigon/db/kv/rawdbv3"
39+
"github.com/erigontech/erigon/db/kv/stream"
3940
"github.com/erigontech/erigon/db/rawdb/utils"
4041
"github.com/erigontech/erigon/execution/rlp"
4142
"github.com/erigontech/erigon/execution/types"
@@ -1222,6 +1223,27 @@ type RCacheV2Query struct {
12221223
DontCalcBloom bool // avoid calculating bloom (can be bottleneck)
12231224
}
12241225

1226+
func ReceiptCacheV2Stream(tx kv.TemporalTx, fromTxNum, toTxNum uint64) (stream.Duo[uint64, *types.Receipt], error) {
1227+
it, err := tx.Debug().HistoryKeyTrace(kv.RCacheDomain, receiptCacheKey, fromTxNum, toTxNum)
1228+
if err != nil {
1229+
return nil, err
1230+
}
1231+
1232+
return stream.TransformDuoV(it, func(txNum uint64, v []byte) (uint64, *types.Receipt, error) {
1233+
if len(v) == 0 {
1234+
return txNum, nil, nil
1235+
}
1236+
1237+
receipt := &types.ReceiptForStorage{}
1238+
if err := rlp.DecodeBytes(v, receipt); err != nil {
1239+
return txNum, nil, fmt.Errorf("%w, of txNum %d, len(v)=%d", err, txNum, len(v))
1240+
}
1241+
res := (*types.Receipt)(receipt)
1242+
//res.DeriveFieldsV4ForCachedReceipt(query.BlockHash, query.BlockNum, query.TxnHash, !query.DontCalcBloom)
1243+
return txNum, res, nil
1244+
}), nil
1245+
}
1246+
12251247
func ReadReceiptCacheV2(tx kv.TemporalTx, query RCacheV2Query) (*types.Receipt, bool, error) {
12261248
v, ok, err := tx.HistorySeek(kv.RCacheDomain, receiptCacheKey, query.TxNum+1 /*history storing value BEFORE-change*/)
12271249
if err != nil {

0 commit comments

Comments
 (0)