Skip to content

Commit 8df2154

Browse files
committed
save
1 parent ee9a671 commit 8df2154

File tree

4 files changed

+39
-58
lines changed

4 files changed

+39
-58
lines changed

core/snaptype/block_types.go

+7-13
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"fmt"
2424
"path/filepath"
2525

26-
"github.com/holiman/uint256"
27-
2826
"github.com/erigontech/erigon-lib/chain"
2927
"github.com/erigontech/erigon-lib/chain/networkname"
3028
"github.com/erigontech/erigon-lib/chain/snapcfg"
@@ -39,7 +37,6 @@ import (
3937
"github.com/erigontech/erigon-lib/rlp"
4038
"github.com/erigontech/erigon-lib/seg"
4139
"github.com/erigontech/erigon/core/types"
42-
"github.com/erigontech/erigon/txnprovider/txpool"
4340
)
4441

4542
func init() {
@@ -256,11 +253,6 @@ var (
256253
txnHashIdx.LogLvl(log.LvlDebug)
257254
txnHash2BlockNumIdx.LogLvl(log.LvlDebug)
258255

259-
chainId, _ := uint256.FromBig(chainConfig.ChainID)
260-
261-
parseCtx := txpool.NewTxnParseContext(*chainId)
262-
parseCtx.WithSender(false)
263-
slot := txpool.TxnSlot{}
264256
bodyBuf, word := make([]byte, 0, 4096), make([]byte, 0, 4096)
265257

266258
defer d.EnableReadAhead().DisableReadAhead()
@@ -305,19 +297,21 @@ var (
305297

306298
firstTxByteAndlengthOfAddress := 21
307299
isSystemTx := len(word) == 0
300+
var txnHash common.Hash
308301
if isSystemTx { // system-txs hash:pad32(txnID)
309-
slot.IDHash = common.Hash{}
310-
binary.BigEndian.PutUint64(slot.IDHash[:], baseTxnID.U64()+ti)
302+
binary.BigEndian.PutUint64(txnHash[:], baseTxnID.U64()+ti)
311303
} else {
312-
if _, err = parseCtx.ParseTransaction(word[firstTxByteAndlengthOfAddress:], 0, &slot, nil, true /* hasEnvelope */, false /* wrappedWithBlobs */, nil /* validateHash */); err != nil {
304+
txn, err := types.DecodeTransaction(word[firstTxByteAndlengthOfAddress:])
305+
if err != nil {
313306
return fmt.Errorf("ParseTransaction: %w, blockNum: %d, i: %d", err, blockNum, ti)
314307
}
308+
txnHash = txn.Hash()
315309
}
316310

317-
if err := txnHashIdx.AddKey(slot.IDHash[:], offset); err != nil {
311+
if err := txnHashIdx.AddKey(txnHash[:], offset); err != nil {
318312
return err
319313
}
320-
if err := txnHash2BlockNumIdx.AddKey(slot.IDHash[:], blockNum); err != nil {
314+
if err := txnHash2BlockNumIdx.AddKey(txnHash[:], blockNum); err != nil {
321315
return err
322316
}
323317

erigon-lib/downloader/snaptype/type.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func BuildIndexWithSnapName(ctx context.Context, info FileInfo, cfg recsplit.Rec
554554
func ExtractRange(ctx context.Context, f FileInfo, extractor RangeExtractor, indexBuilder IndexBuilder, firstKey FirstKeyGetter, chainDB kv.RoDB, chainConfig *chain.Config, tmpDir string, workers int, lvl log.Lvl, logger log.Logger) (uint64, error) {
555555
var lastKeyValue uint64
556556

557-
sn, err := seg.NewCompressor(ctx, "Snapshot "+f.Type.Name(), f.Path, tmpDir, seg.DefaultCfg, log.LvlTrace, logger)
557+
sn, err := seg.NewCompressor(ctx, "Snapshot "+f.Type.Name(), f.Path, tmpDir, seg.DefaultCfg, lvl, logger)
558558

559559
if err != nil {
560560
return lastKeyValue, err

turbo/snapshotsync/freezeblocks/block_snapshots.go

+24-29
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"sync/atomic"
3232
"time"
3333

34-
"github.com/holiman/uint256"
3534
"golang.org/x/sync/errgroup"
3635
"golang.org/x/sync/semaphore"
3736

@@ -63,7 +62,6 @@ import (
6362
"github.com/erigontech/erigon/polygon/heimdall"
6463
"github.com/erigontech/erigon/turbo/services"
6564
"github.com/erigontech/erigon/turbo/snapshotsync"
66-
"github.com/erigontech/erigon/txnprovider/txpool"
6765
)
6866

6967
type RoSnapshots struct {
@@ -587,29 +585,35 @@ func DumpTxs(ctx context.Context, db kv.RoDB, chainConfig *chain.Config, blockFr
587585
warmupCtx, cancel := context.WithCancel(ctx)
588586
defer cancel()
589587

590-
chainID, _ := uint256.FromBig(chainConfig.ChainID)
591-
592588
numBuf := make([]byte, 8)
593589

594-
parse := func(ctx *txpool.TxnParseContext, v, valueBuf []byte, senders []common2.Address, j int) ([]byte, error) {
590+
parse := func(v, valueBuf []byte, senders []common2.Address, j int) ([]byte, error) {
595591
var sender [20]byte
596-
slot := txpool.TxnSlot{}
597-
598-
if _, err := ctx.ParseTransaction(v, 0, &slot, sender[:], false /* hasEnvelope */, false /* wrappedWithBlobs */, nil); err != nil {
599-
return valueBuf, err
592+
txn2, err := types.DecodeTransaction(v)
593+
if err != nil {
594+
return nil, err
600595
}
596+
hash := txn2.Hash()
597+
hashFirstByte := hash[:1]
601598
if len(senders) > 0 {
599+
txn2.SetSender(senders[j])
602600
sender = senders[j]
601+
} else {
602+
signer := types.LatestSignerForChainID(chainConfig.ChainID)
603+
sender, err = txn2.Sender(*signer)
604+
if err != nil {
605+
return nil, err
606+
}
603607
}
604608

605609
valueBuf = valueBuf[:0]
606-
valueBuf = append(valueBuf, slot.IDHash[:1]...)
610+
valueBuf = append(valueBuf, hashFirstByte...)
607611
valueBuf = append(valueBuf, sender[:]...)
608612
valueBuf = append(valueBuf, v...)
609613
return valueBuf, nil
610614
}
611615

612-
addSystemTx := func(ctx *txpool.TxnParseContext, tx kv.Tx, txId types.BaseTxnID) error {
616+
addSystemTx := func(tx kv.Tx, txId types.BaseTxnID) error {
613617
binary.BigEndian.PutUint64(numBuf, txId.U64())
614618
tv, err := tx.GetOne(kv.EthTx, numBuf)
615619
if err != nil {
@@ -622,12 +626,10 @@ func DumpTxs(ctx context.Context, db kv.RoDB, chainConfig *chain.Config, blockFr
622626
return nil
623627
}
624628

625-
ctx.WithSender(false)
626-
627629
valueBuf := bufPool.Get().(*[16 * 4096]byte)
628630
defer bufPool.Put(valueBuf)
629631

630-
parsed, err := parse(ctx, tv, valueBuf[:], nil, 0)
632+
parsed, err := parse(tv, valueBuf[:], nil, 0)
631633
if err != nil {
632634
return err
633635
}
@@ -689,16 +691,14 @@ func DumpTxs(ctx context.Context, db kv.RoDB, chainConfig *chain.Config, blockFr
689691
parsers.SetLimit(workers)
690692

691693
valueBufs := make([][]byte, workers)
692-
parseCtxs := make([]*txpool.TxnParseContext, workers)
693694

694695
for i := 0; i < workers; i++ {
695696
valueBuf := bufPool.Get().(*[16 * 4096]byte)
696697
defer bufPool.Put(valueBuf)
697698
valueBufs[i] = valueBuf[:]
698-
parseCtxs[i] = txpool.NewTxnParseContext(*chainID)
699699
}
700700

701-
if err := addSystemTx(parseCtxs[0], tx, body.BaseTxnID); err != nil {
701+
if err := addSystemTx(tx, body.BaseTxnID); err != nil {
702702
return false, err
703703
}
704704

@@ -715,14 +715,9 @@ func DumpTxs(ctx context.Context, db kv.RoDB, chainConfig *chain.Config, blockFr
715715
j++
716716

717717
parsers.Go(func() error {
718-
parseCtx := parseCtxs[tx%workers]
719-
720-
parseCtx.WithSender(len(senders) == 0)
721-
parseCtx.WithAllowPreEip2s(blockNum <= chainConfig.HomesteadBlock.Uint64())
722-
723-
valueBuf, err := parse(parseCtx, tv, valueBufs[tx%workers], senders, tx)
724-
718+
valueBuf, err := parse(tv, valueBufs[tx%workers], senders, tx)
725719
if err != nil {
720+
log.Warn("[snapshots] DumpTxs parsing", "err", err, "blockNum", blockNum, "rlp", hex.EncodeToString(v))
726721
return fmt.Errorf("%w, block: %d", err, blockNum)
727722
}
728723

@@ -753,21 +748,21 @@ func DumpTxs(ctx context.Context, db kv.RoDB, chainConfig *chain.Config, blockFr
753748
return false, fmt.Errorf("ForAmount parser: %w", err)
754749
}
755750

756-
if err := addSystemTx(parseCtxs[0], tx, types.BaseTxnID(body.BaseTxnID.LastSystemTx(body.TxCount))); err != nil {
751+
if err := addSystemTx(tx, types.BaseTxnID(body.BaseTxnID.LastSystemTx(body.TxCount))); err != nil {
757752
return false, err
758753
}
759754

760755
select {
761756
case <-ctx.Done():
762757
return false, ctx.Err()
763758
case <-logEvery.C:
764-
var m runtime.MemStats
765759
if lvl >= log.LvlInfo {
760+
var m runtime.MemStats
766761
dbg.ReadMemStats(&m)
762+
logger.Log(lvl, "[snapshots] Dumping txs", "block num", blockNum, "alloc", common2.ByteCount(m.Alloc), "sys", common2.ByteCount(m.Sys))
763+
} else {
764+
logger.Log(lvl, "[snapshots] Dumping txs", "block num", blockNum)
767765
}
768-
logger.Log(lvl, "[snapshots] Dumping txs", "block num", blockNum,
769-
"alloc", common2.ByteCount(m.Alloc), "sys", common2.ByteCount(m.Sys),
770-
)
771766
default:
772767
}
773768
return true, nil

turbo/snapshotsync/freezeblocks/dump_test.go

+7-15
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import (
3232
"github.com/erigontech/erigon-lib/common/math"
3333
"github.com/erigontech/erigon-lib/crypto"
3434
"github.com/erigontech/erigon-lib/log/v3"
35-
"github.com/erigontech/erigon/txnprovider/txpool"
36-
3735
"github.com/erigontech/erigon-lib/rlp"
3836
"github.com/erigontech/erigon/core"
3937
"github.com/erigontech/erigon/core/types"
@@ -119,24 +117,21 @@ func TestDump(t *testing.T) {
119117

120118
for _, test := range tests {
121119
m := createDumpTestKV(t, test.chainConfig, test.chainSize)
122-
chainID, _ := uint256.FromBig(m.ChainConfig.ChainID)
123120
t.Run("txs", func(t *testing.T) {
124121
require := require.New(t)
125-
slot := txpool.TxnSlot{}
126-
parseCtx := txpool.NewTxnParseContext(*chainID)
127-
parseCtx.WithSender(false)
128-
var sender [20]byte
129122

130123
var systemTxs int
131124
var nonceList []uint64
125+
132126
_, err := freezeblocks.DumpTxs(m.Ctx, m.DB, m.ChainConfig, 0, uint64(2*test.chainSize), nil, func(v []byte) error {
133127
if v == nil {
134128
systemTxs++
135129
} else {
136-
if _, err := parseCtx.ParseTransaction(v[1+20:], 0, &slot, sender[:], false /* hasEnvelope */, false /* wrappedWithBlobs */, nil); err != nil {
130+
txn, err := types.DecodeTransaction(v[1+20:])
131+
if err != nil {
137132
return err
138133
}
139-
nonceList = append(nonceList, slot.Nonce)
134+
nonceList = append(nonceList, txn.GetNonce())
140135
}
141136
return nil
142137
}, 1, log.LvlInfo, log.New())
@@ -147,21 +142,18 @@ func TestDump(t *testing.T) {
147142
})
148143
t.Run("txs_not_from_zero", func(t *testing.T) {
149144
require := require.New(t)
150-
slot := txpool.TxnSlot{}
151-
parseCtx := txpool.NewTxnParseContext(*chainID)
152-
parseCtx.WithSender(false)
153-
var sender [20]byte
154145

155146
var systemTxs int
156147
var nonceList []uint64
157148
_, err := freezeblocks.DumpTxs(m.Ctx, m.DB, m.ChainConfig, 2, uint64(test.chainSize), nil, func(v []byte) error {
158149
if v == nil {
159150
systemTxs++
160151
} else {
161-
if _, err := parseCtx.ParseTransaction(v[1+20:], 0, &slot, sender[:], false /* hasEnvelope */, false /* wrappedWithBlobs */, nil); err != nil {
152+
txn, err := types.DecodeTransaction(v[1+20:])
153+
if err != nil {
162154
return err
163155
}
164-
nonceList = append(nonceList, slot.Nonce)
156+
nonceList = append(nonceList, txn.GetNonce())
165157
}
166158
return nil
167159
}, 1, log.LvlInfo, log.New())

0 commit comments

Comments
 (0)