diff --git a/core/state/intra_block_state_zkevm.go b/core/state/intra_block_state_zkevm.go index 654b19d7b2f..c39287f3ff4 100644 --- a/core/state/intra_block_state_zkevm.go +++ b/core/state/intra_block_state_zkevm.go @@ -31,7 +31,6 @@ type ReadOnlyHermezDb interface { GetBatchGlobalExitRoots(fromBatchNum, toBatchNum uint64) (*[]dstypes.GerUpdate, error) GetBlockGlobalExitRoot(l2BlockNo uint64) (libcommon.Hash, error) GetBlockL1BlockHash(l2BlockNo uint64) (libcommon.Hash, error) - GetGerForL1BlockHash(l1BlockHash libcommon.Hash) (libcommon.Hash, error) GetIntermediateTxStateRoot(blockNum uint64, txhash libcommon.Hash) (libcommon.Hash, error) GetReusedL1InfoTreeIndex(blockNum uint64) (bool, error) GetSequenceByBatchNo(batchNo uint64) (*zktypes.L1BatchInfo, error) diff --git a/go.mod b/go.mod index 67ff8e5b4d5..499bc11544d 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/emicklei/dot v1.0.0 github.com/emirpasic/gods v1.18.1 github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c - github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240819202640-e541bb90668f + github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240829075742-c69f9871e8c9 github.com/gateway-fm/vectorized-poseidon-gold v1.0.0 github.com/gballet/go-verkle v0.0.0-20221121182333-31427a1f2d35 github.com/go-stack/stack v1.8.1 @@ -182,6 +182,7 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect + github.com/ledgerwatch/interfaces v0.0.0-20230412092010-e1c4a1a4279e // indirect github.com/lib/pq v1.10.7 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-cidranger v1.1.0 // indirect @@ -197,6 +198,7 @@ require ( github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect + github.com/matryer/moq v0.3.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect diff --git a/go.sum b/go.sum index 5b003fe02d0..ccc7a5928f9 100644 --- a/go.sum +++ b/go.sum @@ -240,6 +240,8 @@ github.com/garslo/gogen v0.0.0-20170307003452-d6ebae628c7c h1:uYNKzPntb8c6DKvP9E github.com/garslo/gogen v0.0.0-20170307003452-d6ebae628c7c/go.mod h1:Q0X6pkwTILDlzrGEckF6HKjXe48EgsY/l7K7vhY4MW8= github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240819202640-e541bb90668f h1:QWDcgNitBfcFrNMZYdLMuSSSWBfA1tGpRIXd1CJuJ1g= github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240819202640-e541bb90668f/go.mod h1:Ky//z32wQOTY/drV858kr8dECBD9OBV9Xzy+aG6TxSk= +github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240829075742-c69f9871e8c9 h1:GLP1WB+Mec7b7vO+4egFlE2zlpFJH9i0o4kW48WT2JI= +github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240829075742-c69f9871e8c9/go.mod h1:Ky//z32wQOTY/drV858kr8dECBD9OBV9Xzy+aG6TxSk= github.com/gateway-fm/vectorized-poseidon-gold v1.0.0 h1:Du0ZW+fkZhgRNGx/gAkHnMj3/Rl8uJkAEe+ZDPX3PDw= github.com/gateway-fm/vectorized-poseidon-gold v1.0.0/go.mod h1:VLGQpyjrOg8+FugH/+d8tfYd/c3z4Xqa+zbUBITygaw= github.com/gballet/go-verkle v0.0.0-20221121182333-31427a1f2d35 h1:I8QswD9gf3VEpr7bpepKKOm7ChxFITIG+oc1I5/S0no= @@ -520,6 +522,8 @@ github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7 github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230404044759-5dec854ce336 h1:Yxmt4Wyd0RCLr7UJJAl0ApCP/f5qkWfvHfgPbnI8ghM= github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230404044759-5dec854ce336/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo= +github.com/ledgerwatch/interfaces v0.0.0-20230412092010-e1c4a1a4279e h1:mT6GE/XsuUVQGTcZjrq0KoINds2fKa8VsHhGbe2PF54= +github.com/ledgerwatch/interfaces v0.0.0-20230412092010-e1c4a1a4279e/go.mod h1:ugQv1QllJzBny3cKZKxUrSnykkjkBgm27eQM6dnGAcc= github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og= github.com/ledgerwatch/log/v3 v3.7.0/go.mod h1:J2Jl6zV/58LeA6LTaVVnCGyf1/cYYSEOOLHY4ZN8S2A= github.com/ledgerwatch/secp256k1 v1.0.0 h1:Usvz87YoTG0uePIV8woOof5cQnLXGYa162rFf3YnwaQ= @@ -575,6 +579,8 @@ github.com/maticnetwork/crand v1.0.2 h1:Af0tAivC8zrxXDpGWNWVT/0s1fOz8w0eRbahZgUR github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxpj5ZKxfHjyg= github.com/maticnetwork/polyproto v0.0.2 h1:cPxuxbIDItdwGnucc3lZB58U8Zfe1mH73PWTGd15554= github.com/maticnetwork/polyproto v0.0.2/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o= +github.com/matryer/moq v0.3.1 h1:kLDiBJoGcusWS2BixGyTkF224aSCD8nLY24tj/NcTCs= +github.com/matryer/moq v0.3.1/go.mod h1:RJ75ZZZD71hejp39j4crZLsEDszGk6iH4v4YsWFKH4s= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= diff --git a/zk/hermez_db/db.go b/zk/hermez_db/db.go index 3d6fff913fd..cb2f71d8f0d 100644 --- a/zk/hermez_db/db.go +++ b/zk/hermez_db/db.go @@ -33,9 +33,7 @@ const BLOCK_L1_INFO_TREE_INDEX = "block_l1_info_tree_index" // block const BLOCK_L1_INFO_TREE_INDEX_PROGRESS = "block_l1_info_tree_progress" // block number -> l1 info tree progress const L1_INJECTED_BATCHES = "l1_injected_batches" // index increasing by 1 -> injected batch for the start of the chain const BLOCK_INFO_ROOTS = "block_info_roots" // block number -> block info root hash -const L1_BLOCK_HASHES = "l1_block_hashes" // l1 block hash -> true const BLOCK_L1_BLOCK_HASHES = "block_l1_block_hashes" // block number -> l1 block hash -const L1_BLOCK_HASH_GER = "l1_block_hash_ger" // l1 block hash -> GER const INTERMEDIATE_TX_STATEROOTS = "hermez_intermediate_tx_stateRoots" // l2blockno -> stateRoot const BATCH_WITNESSES = "hermez_batch_witnesses" // batch number -> witness const BATCH_COUNTERS = "hermez_batch_counters" // block number -> counters @@ -70,9 +68,7 @@ var HermezDbTables = []string{ BLOCK_L1_INFO_TREE_INDEX_PROGRESS, L1_INJECTED_BATCHES, BLOCK_INFO_ROOTS, - L1_BLOCK_HASHES, BLOCK_L1_BLOCK_HASHES, - L1_BLOCK_HASH_GER, INTERMEDIATE_TX_STATEROOTS, BATCH_WITNESSES, BATCH_COUNTERS, @@ -690,53 +686,6 @@ func (db *HermezDb) DeleteReusedL1InfoTreeIndexes(fromBlock, toBlock uint64) err return nil } -func (db *HermezDb) WriteGerForL1BlockHash(l1BlockHash common.Hash, ger common.Hash) error { - return db.tx.Put(L1_BLOCK_HASH_GER, l1BlockHash.Bytes(), ger.Bytes()) -} - -func (db *HermezDbReader) GetGerForL1BlockHash(l1BlockHash common.Hash) (common.Hash, error) { - bytes, err := db.tx.GetOne(L1_BLOCK_HASH_GER, l1BlockHash.Bytes()) - if err != nil { - return common.Hash{}, err - } - - return common.BytesToHash(bytes), nil -} - -func (db *HermezDb) DeleteL1BlockHashGers(l1BlockHashes *[]common.Hash) error { - for _, l1BlockHash := range *l1BlockHashes { - err := db.tx.Delete(L1_BLOCK_HASH_GER, l1BlockHash.Bytes()) - if err != nil { - return err - } - } - - return nil -} - -func (db *HermezDb) WriteL1BlockHash(l1BlockHash common.Hash) error { - return db.tx.Put(L1_BLOCK_HASHES, l1BlockHash.Bytes(), []byte{1}) -} - -func (db *HermezDbReader) CheckL1BlockHashWritten(l1BlockHash common.Hash) (bool, error) { - bytes, err := db.tx.GetOne(L1_BLOCK_HASHES, l1BlockHash.Bytes()) - if err != nil { - return false, err - } - return len(bytes) > 0, nil -} - -func (db *HermezDb) DeleteL1BlockHashes(l1BlockHashes *[]common.Hash) error { - for _, l1BlockHash := range *l1BlockHashes { - err := db.tx.Delete(L1_BLOCK_HASHES, l1BlockHash.Bytes()) - if err != nil { - return err - } - } - - return nil -} - func (db *HermezDb) WriteBlockGlobalExitRoot(l2BlockNo uint64, ger common.Hash) error { return db.tx.Put(BLOCK_GLOBAL_EXIT_ROOTS, Uint64ToBytes(l2BlockNo), ger.Bytes()) } diff --git a/zk/stages/stage_batches.go b/zk/stages/stage_batches.go index 71b3706cba9..5b0fd305dbe 100644 --- a/zk/stages/stage_batches.go +++ b/zk/stages/stage_batches.go @@ -60,11 +60,6 @@ type HermezDb interface { DeleteReusedL1InfoTreeIndexes(fromBlockNum, toBlockNum uint64) error WriteBlockL1BlockHash(l2BlockNo uint64, l1BlockHash common.Hash) error DeleteBlockL1BlockHashes(fromBlockNum, toBlockNum uint64) error - WriteL1BlockHash(l1BlockHash common.Hash) error - CheckL1BlockHashWritten(l1BlockHash common.Hash) (bool, error) - DeleteL1BlockHashes(l1BlockHashes *[]common.Hash) error - WriteGerForL1BlockHash(l1BlockHash, ger common.Hash) error - DeleteL1BlockHashGers(l1BlockHashes *[]common.Hash) error WriteBatchGlobalExitRoot(batchNumber uint64, ger *types.GerUpdate) error WriteIntermediateTxStateRoot(l2BlockNumber uint64, txHash common.Hash, rpcRoot common.Hash) error WriteBlockL1InfoTreeIndex(blockNumber uint64, l1Index uint64) error @@ -592,11 +587,6 @@ func UnwindBatchesStage(u *stagedsync.UnwindState, tx kv.RwTx, cfg BatchesCfg, c return fmt.Errorf("get block global exit roots error: %v", err) } - l1BlockHashes, err := hermezDb.GetBlockL1BlockHashes(fromBlock, toBlock) - if err != nil { - return fmt.Errorf("get block l1 block hashes error: %v", err) - } - if err := hermezDb.DeleteGlobalExitRoots(&gers); err != nil { return fmt.Errorf("delete global exit roots error: %v", err) } @@ -609,14 +599,6 @@ func UnwindBatchesStage(u *stagedsync.UnwindState, tx kv.RwTx, cfg BatchesCfg, c return fmt.Errorf("delete block global exit roots error: %v", err) } - if err := hermezDb.DeleteL1BlockHashes(&l1BlockHashes); err != nil { - return fmt.Errorf("delete l1 block hashes error: %v", err) - } - - if err := hermezDb.DeleteL1BlockHashGers(&l1BlockHashes); err != nil { - return fmt.Errorf("delete l1 block hash gers error: %v", err) - } - if err := hermezDb.DeleteBlockL1BlockHashes(fromBlock, toBlock); err != nil { return fmt.Errorf("delete block l1 block hashes error: %v", err) } @@ -804,25 +786,8 @@ func writeL2Block(eriDb ErigonDb, hermezDb HermezDb, l2Block *types.FullL2Block, } if l2Block.L1BlockHash != emptyHash { - l1BlockHashWritten, err := hermezDb.CheckL1BlockHashWritten(l2Block.L1BlockHash) - if err != nil { - return fmt.Errorf("get global exit root error: %v", err) - } - - if !l1BlockHashWritten { - if err := hermezDb.WriteBlockL1BlockHash(l2Block.L2BlockNumber, l2Block.L1BlockHash); err != nil { - return fmt.Errorf("write block global exit root error: %v", err) - } - - if err := hermezDb.WriteL1BlockHash(l2Block.L1BlockHash); err != nil { - return fmt.Errorf("write global exit root error: %v", err) - } - - if l2Block.GlobalExitRoot != emptyHash { - if err := hermezDb.WriteGerForL1BlockHash(l2Block.L1BlockHash, l2Block.GlobalExitRoot); err != nil { - return fmt.Errorf("write ger for l1 block hash error: %v", err) - } - } + if err := hermezDb.WriteBlockL1BlockHash(l2Block.L2BlockNumber, l2Block.L1BlockHash); err != nil { + return fmt.Errorf("write block global exit root error: %v", err) } }