Skip to content

Commit

Permalink
Merge branch 'main' into bloom_rm
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov committed Dec 3, 2024
2 parents 60e963e + d78797f commit 1472c7d
Show file tree
Hide file tree
Showing 105 changed files with 294 additions and 428 deletions.
2 changes: 1 addition & 1 deletion cmd/devnet/services/polygon/proofgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/erigontech/erigon-lib/common/hexutility"
"github.com/erigontech/erigon-lib/crypto"
"github.com/erigontech/erigon-lib/rlp"
"github.com/erigontech/erigon-lib/trie"
"github.com/erigontech/erigon/accounts/abi/bind"
"github.com/erigontech/erigon/cl/merkle_tree"
"github.com/erigontech/erigon/cmd/devnet/devnet"
Expand All @@ -41,7 +42,6 @@ import (
bortypes "github.com/erigontech/erigon/polygon/bor/types"
"github.com/erigontech/erigon/rpc"
"github.com/erigontech/erigon/turbo/jsonrpc"
"github.com/erigontech/erigon/turbo/trie"
)

var ErrTokenIndexOutOfRange = errors.New("index is grater than the number of tokens in transaction")
Expand Down
3 changes: 1 addition & 2 deletions cmd/integration/commands/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
block, pruneTo, unwind uint64
unwindEvery uint64
batchSizeStr string
reset, warmup, noCommit bool
reset, noCommit bool
resetPruneAt bool
bucket string
datadirCli, toChaindata string
Expand Down Expand Up @@ -116,7 +116,6 @@ func withUnwindEvery(cmd *cobra.Command) {

func withReset(cmd *cobra.Command) {
cmd.Flags().BoolVar(&reset, "reset", false, "reset given stage")
cmd.Flags().BoolVar(&warmup, "warmup", false, "warmup relevant tables by parallel random reads")
}

func withResetPruneAt(cmd *cobra.Command) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/reset_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ var cmdResetState = &cobra.Command{
return
}

if err = reset2.ResetState(db, ctx, chain, "", log.Root()); err != nil {
if err = reset2.ResetState(db, agg, ctx, chain, "", log.Root()); err != nil {
if !errors.Is(err, context.Canceled) {
logger.Error(err.Error())
}
Expand Down
18 changes: 3 additions & 15 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,6 @@ func stageSnapshots(db kv.RwDB, ctx context.Context, logger log.Logger) error {

br, bw := blocksIO(db, logger)
_, _, _, _, _ = newSync(ctx, db, nil /* miningConfig */, logger)
chainConfig, _ := fromdb.ChainConfig(db), fromdb.PruneMode(db)

return db.Update(ctx, func(tx kv.RwTx) error {
if reset {
Expand All @@ -655,7 +654,7 @@ func stageSnapshots(db kv.RwDB, ctx context.Context, logger log.Logger) error {
}
}
dirs := datadir.New(datadirCli)
if err := reset2.ResetBlocks(tx, db, agg, br, bw, dirs, *chainConfig, logger); err != nil {
if err := reset2.ResetBlocks(tx, db, agg, br, bw, dirs, logger); err != nil {
return fmt.Errorf("resetting blocks: %w", err)
}
ac := agg.BeginFilesRo()
Expand Down Expand Up @@ -701,7 +700,6 @@ func stageHeaders(db kv.RwDB, ctx context.Context, logger log.Logger) error {
defer agg.Close()
br, bw := blocksIO(db, logger)
_, _, _, _, _ = newSync(ctx, db, nil /* miningConfig */, logger)
chainConfig, _ := fromdb.ChainConfig(db), fromdb.PruneMode(db)

if integritySlow {
if err := db.View(ctx, func(tx kv.Tx) error {
Expand All @@ -721,7 +719,7 @@ func stageHeaders(db kv.RwDB, ctx context.Context, logger log.Logger) error {

return db.Update(ctx, func(tx kv.RwTx) error {
if reset {
if err := reset2.ResetBlocks(tx, db, agg, br, bw, dirs, *chainConfig, logger); err != nil {
if err := reset2.ResetBlocks(tx, db, agg, br, bw, dirs, logger); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -1031,11 +1029,8 @@ func stageExec(db kv.RwDB, ctx context.Context, logger log.Logger) error {
defer sn.Close()
defer borSn.Close()
defer agg.Close()
if warmup {
return reset2.WarmupExec(ctx, db)
}
if reset {
if err := reset2.ResetExec(ctx, db, chain, "", logger); err != nil {
if err := reset2.ResetExec(ctx, db, agg, chain, "", logger); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -1177,10 +1172,6 @@ func stageCustomTrace(db kv.RwDB, ctx context.Context, logger log.Logger) error
defer sn.Close()
defer borSn.Close()
defer agg.Close()
if warmup {
panic("not implemented")
//return reset2.WarmupExec(ctx, db)
}
if reset {
if err := reset2.Reset(ctx, db, stages.CustomTrace); err != nil {
return err
Expand Down Expand Up @@ -1218,9 +1209,6 @@ func stagePatriciaTrie(db kv.RwDB, ctx context.Context, logger log.Logger) error
defer agg.Close()
_, _, _, _, _ = newSync(ctx, db, nil /* miningConfig */, logger)

if warmup {
return reset2.Warmup(ctx, db, log.LvlInfo, stages.Execution)
}
if reset {
return reset2.Reset(ctx, db, stages.Execution)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func requestDomains(chainDb, stateDb kv.RwDB, ctx context.Context, readDomain st
}
case "code":
for _, addr := range addrs {
code, err := r.ReadAccountCode(libcommon.BytesToAddress(addr), 0, libcommon.Hash{})
code, err := r.ReadAccountCode(libcommon.BytesToAddress(addr), 0)
if err != nil {
logger.Error("failed to read code", "addr", addr, "err", err)
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/pics/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/kv/memdb"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon-lib/trie"
"github.com/erigontech/erigon/accounts/abi/bind"
"github.com/erigontech/erigon/accounts/abi/bind/backends"
"github.com/erigontech/erigon/cmd/pics/contracts"
Expand All @@ -43,7 +44,6 @@ import (
"github.com/erigontech/erigon/core/types"
"github.com/erigontech/erigon/params"
"github.com/erigontech/erigon/turbo/stages/mock"
"github.com/erigontech/erigon/turbo/trie"
)

/*func statePicture(t *trie.Trie, number int, keyCompression int, codeCompressed bool, valCompressed bool,
Expand Down
2 changes: 1 addition & 1 deletion cmd/verkle/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
"github.com/erigontech/erigon-lib/log/v3"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/types/accounts"
"github.com/erigontech/erigon/cmd/verkle/verkletrie"
"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon/eth/stagedsync/stages"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/verkle/verkletrie/incrementAccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/erigontech/erigon-lib/log/v3"

"github.com/erigontech/erigon-lib/common/debug"
"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon-lib/types/accounts"
)

func IncrementAccount(vTx kv.RwTx, tx kv.Tx, workers uint64, verkleWriter *VerkleTreeWriter, from, to uint64, tmpdir string) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/verkle/verkletrie/pedersen_hashstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/common/debug"
"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon-lib/types/accounts"
)

func RegeneratePedersenAccounts(outTx kv.RwTx, readTx kv.Tx, workers uint64, verkleWriter *VerkleTreeWriter) error {
Expand Down
4 changes: 2 additions & 2 deletions cmd/verkle/verkletrie/verkle_tree_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"github.com/erigontech/erigon-lib/log/v3"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/trie/vtree"
"github.com/erigontech/erigon-lib/types/accounts"
"github.com/erigontech/erigon/core/rawdb"
"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon/turbo/trie/vtree"
)

func int256ToVerkleFormat(x *uint256.Int, buffer []byte) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/verkle/verkletrie/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
libcommon "github.com/erigontech/erigon-lib/common"
"github.com/holiman/uint256"

"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon/turbo/trie/vtree"
"github.com/erigontech/erigon-lib/trie/vtree"
"github.com/erigontech/erigon-lib/types/accounts"
)

type regeneratePedersenAccountsJob struct {
Expand Down
2 changes: 1 addition & 1 deletion consensus/aura/aura_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import (
"github.com/erigontech/erigon-lib/kv/memdb"

"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon-lib/trie"
"github.com/erigontech/erigon/accounts/abi"
"github.com/erigontech/erigon/consensus/aura"
"github.com/erigontech/erigon/core"
"github.com/erigontech/erigon/core/state"
"github.com/erigontech/erigon/core/types"
"github.com/erigontech/erigon/turbo/stages/mock"
"github.com/erigontech/erigon/turbo/trie"
)

// Check that the first block of Gnosis Chain, which doesn't have any transactions,
Expand Down
2 changes: 1 addition & 1 deletion consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ import (
"github.com/erigontech/erigon-lib/kv/dbutils"
"github.com/erigontech/erigon-lib/log/v3"
"github.com/erigontech/erigon-lib/rlp"
"github.com/erigontech/erigon-lib/types/accounts"
"github.com/erigontech/erigon/consensus"
"github.com/erigontech/erigon/core/state"
"github.com/erigontech/erigon/core/tracing"
"github.com/erigontech/erigon/core/types"
"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon/core/vm/evmtypes"
"github.com/erigontech/erigon/params"
"github.com/erigontech/erigon/rpc"
Expand Down
2 changes: 1 addition & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import (
"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/rlp"
libstate "github.com/erigontech/erigon-lib/state"
"github.com/erigontech/erigon-lib/types/accounts"
"github.com/erigontech/erigon/consensus"
"github.com/erigontech/erigon/consensus/merge"
"github.com/erigontech/erigon/consensus/misc"
"github.com/erigontech/erigon/core/state"
"github.com/erigontech/erigon/core/types"
"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon/core/vm"
"github.com/erigontech/erigon/params"
"github.com/erigontech/erigon/polygon/heimdall"
Expand Down
39 changes: 7 additions & 32 deletions core/rawdb/rawdbreset/reset_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/erigontech/erigon/turbo/services"
)

func ResetState(db kv.RwDB, ctx context.Context, chain string, tmpDir string, logger log.Logger) error {
func ResetState(db kv.RwDB, agg *state.Aggregator, ctx context.Context, chain string, tmpDir string, logger log.Logger) error {
// don't reset senders here
if err := db.Update(ctx, ResetTxLookup); err != nil {
return err
Expand All @@ -45,13 +45,13 @@ func ResetState(db kv.RwDB, ctx context.Context, chain string, tmpDir string, lo
return err
}

if err := ResetExec(ctx, db, chain, tmpDir, logger); err != nil {
if err := ResetExec(ctx, db, agg, chain, tmpDir, logger); err != nil {
return err
}
return nil
}

func ResetBlocks(tx kv.RwTx, db kv.RoDB, agg *state.Aggregator, br services.FullBlockReader, bw *blockio.BlockWriter, dirs datadir.Dirs, cc chain.Config, logger log.Logger) error {
func ResetBlocks(tx kv.RwTx, db kv.RoDB, agg *state.Aggregator, br services.FullBlockReader, bw *blockio.BlockWriter, dirs datadir.Dirs, logger log.Logger) error {
// keep Genesis
if err := rawdb.TruncateBlocks(context.Background(), tx, 1); err != nil {
return err
Expand Down Expand Up @@ -144,7 +144,7 @@ func ResetPolygonSync(tx kv.RwTx, db kv.RoDB, agg *state.Aggregator, br services
}
}

if err := ResetBlocks(tx, db, agg, br, bw, dirs, cc, logger); err != nil {
if err := ResetBlocks(tx, db, agg, br, bw, dirs, logger); err != nil {
return err
}

Expand All @@ -158,22 +158,12 @@ func ResetSenders(ctx context.Context, db kv.RwDB, tx kv.RwTx) error {
return clearStageProgress(tx, stages.Senders)
}

func WarmupExec(ctx context.Context, db kv.RwDB) (err error) {
for _, tbl := range stateBuckets {
backup.WarmupTable(ctx, db, tbl, log.LvlInfo, backup.ReadAheadThreads)
}
for _, tbl := range stateHistoryV3Buckets {
backup.WarmupTable(ctx, db, tbl, log.LvlInfo, backup.ReadAheadThreads)
}
return
}

func ResetExec(ctx context.Context, db kv.RwDB, chain string, tmpDir string, logger log.Logger) (err error) {
func ResetExec(ctx context.Context, db kv.RwDB, agg *state.Aggregator, chain string, tmpDir string, logger log.Logger) (err error) {
cleanupList := make([]string, 0)
cleanupList = append(cleanupList, stateBuckets...)
cleanupList = append(cleanupList, stateHistoryBuckets...)
cleanupList = append(cleanupList, stateHistoryV3Buckets...)
cleanupList = append(cleanupList, stateV3Buckets...)
cleanupList = append(cleanupList, agg.DomainTables(kv.AccountsDomain, kv.StorageDomain, kv.CodeDomain, kv.CommitmentDomain, kv.ReceiptDomain)...)
cleanupList = append(cleanupList, agg.InvertedIndexTables(kv.LogAddrIdxPos, kv.LogTopicIdxPos, kv.TracesFromIdxPos, kv.TracesToIdxPos)...)

return db.Update(ctx, func(tx kv.RwTx) error {
if err := clearStageProgress(tx, stages.Execution); err != nil {
Expand Down Expand Up @@ -212,21 +202,6 @@ var stateBuckets = []string{
kv.PlainContractCode, kv.ContractCode, kv.IncarnationMap,
}
var stateHistoryBuckets = []string{
kv.Receipts,
}
var stateHistoryV3Buckets = []string{
kv.TblAccountHistoryKeys, kv.TblAccountHistoryVals, kv.TblAccountIdx,
kv.TblStorageHistoryKeys, kv.TblStorageHistoryVals, kv.TblStorageIdx,
kv.TblCodeHistoryKeys, kv.TblCodeHistoryVals, kv.TblCodeIdx,
kv.TblLogAddressKeys, kv.TblLogAddressIdx,
kv.TblLogTopicsKeys, kv.TblLogTopicsIdx,
kv.TblTracesFromKeys, kv.TblTracesFromIdx,
kv.TblTracesToKeys, kv.TblTracesToIdx,
}
var stateV3Buckets = []string{
kv.TblAccountVals, kv.TblStorageVals, kv.TblCodeVals, kv.TblCommitmentVals, kv.TblReceiptVals,
kv.TblCommitmentHistoryKeys, kv.TblCommitmentHistoryVals, kv.TblCommitmentIdx,
kv.TblReceiptHistoryKeys, kv.TblReceiptHistoryVals, kv.TblReceiptIdx,
kv.TblPruningProgress,
kv.ChangeSets3,
}
Expand Down
13 changes: 5 additions & 8 deletions core/state/cached_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package state
import (
"github.com/erigontech/erigon-lib/common"

"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon-lib/types/accounts"
"github.com/erigontech/erigon/turbo/shards"
)

Expand Down Expand Up @@ -78,14 +78,11 @@ func (cr *CachedReader) ReadAccountStorage(address common.Address, incarnation u

// ReadAccountCode is called when code of an account needs to be fetched from the state
// Usually, one of (address;incarnation) or codeHash is enough to uniquely identify the code
func (cr *CachedReader) ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) ([]byte, error) {
if codeHash == emptyCodeHashH {
return nil, nil
}
func (cr *CachedReader) ReadAccountCode(address common.Address, incarnation uint64) ([]byte, error) {
if c, ok := cr.cache.GetCode(address.Bytes(), incarnation); ok {
return c, nil
}
c, err := cr.r.ReadAccountCode(address, incarnation, codeHash)
c, err := cr.r.ReadAccountCode(address, incarnation)
if err != nil {
return nil, err
}
Expand All @@ -95,8 +92,8 @@ func (cr *CachedReader) ReadAccountCode(address common.Address, incarnation uint
return c, nil
}

func (cr *CachedReader) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error) {
c, err := cr.ReadAccountCode(address, incarnation, codeHash)
func (cr *CachedReader) ReadAccountCodeSize(address common.Address, incarnation uint64) (int, error) {
c, err := cr.ReadAccountCode(address, incarnation)
return len(c), err
}

Expand Down
13 changes: 4 additions & 9 deletions core/state/cached_reader3.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
package state

import (
"bytes"

"github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/kv/kvcache"

"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon-lib/types/accounts"
)

// CachedReader3 is a wrapper for an instance of type StateReader
Expand Down Expand Up @@ -83,19 +81,16 @@ func (r *CachedReader3) ReadAccountStorage(address common.Address, incarnation u
return enc, nil
}

func (r *CachedReader3) ReadAccountCode(address common.Address, incarnation uint64, codeHash common.Hash) ([]byte, error) {
if bytes.Equal(codeHash.Bytes(), emptyCodeHash) {
return nil, nil
}
func (r *CachedReader3) ReadAccountCode(address common.Address, incarnation uint64) ([]byte, error) {
code, err := r.cache.GetCode(address[:])
if len(code) == 0 {
return nil, nil
}
return code, err
}

func (r *CachedReader3) ReadAccountCodeSize(address common.Address, incarnation uint64, codeHash common.Hash) (int, error) {
code, err := r.ReadAccountCode(address, incarnation, codeHash)
func (r *CachedReader3) ReadAccountCodeSize(address common.Address, incarnation uint64) (int, error) {
code, err := r.ReadAccountCode(address, incarnation)
return len(code), err
}

Expand Down
2 changes: 1 addition & 1 deletion core/state/cached_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/erigontech/erigon-lib/common"

"github.com/erigontech/erigon/core/types/accounts"
"github.com/erigontech/erigon-lib/types/accounts"
"github.com/erigontech/erigon/turbo/shards"
)

Expand Down
Loading

0 comments on commit 1472c7d

Please sign in to comment.