Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 0 additions & 67 deletions core/rawdb/accessors_rollup_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package rawdb
import (
"bytes"
"encoding/binary"
"math/big"

"github.com/morph-l2/go-ethereum/common"
"github.com/morph-l2/go-ethereum/core/types"
Expand All @@ -12,26 +11,6 @@ import (
"github.com/morph-l2/go-ethereum/rlp"
)

func WriteRollupBatch(db ethdb.KeyValueWriter, batch *types.RollupBatch) {
bz, err := batch.Encode()
if err != nil {
log.Crit("failed to RLP encode batch", "batch index", batch.Index, "err", err)
}
if err = db.Put(RollupBatchKey(batch.Index), bz); err != nil {
log.Crit("failed to store batch", "batch index", batch.Index, "err", err)
}

// stores batchHash -> batchIndex
if err = db.Put(RollupBatchIndexKey(batch.Hash), encodeBigEndian(batch.Index)); err != nil {
log.Crit("failed to store batch index", "batch hash", batch.Hash.Hex(), "batch index", batch.Index, "err", err)
}

// stores latest batch index
if err = db.Put(rollupHeadBatchKey, encodeBigEndian(batch.Index)); err != nil {
log.Crit("failed to store latest batch index", "batch index", batch.Index, "err", err)
}
}

func ReadLatestBatchIndex(db ethdb.Reader) *uint64 {
data, err := db.Get(rollupHeadBatchKey)
if err != nil && isNotFoundErr(err) {
Expand Down Expand Up @@ -76,17 +55,6 @@ func ReadRollupBatch(db ethdb.Reader, batchIndex uint64) (*types.RollupBatch, er
return rb, nil
}

func WriteBatchSignature(db ethdb.KeyValueWriter, batchHash common.Hash, signature types.BatchSignature) {
bz, err := rlp.EncodeToBytes(&signature)
if err != nil {
log.Crit("failed to RLP encode batch signature", "batch hash", batchHash, "signer index", signature.Signer, "err", err)
}

if err = db.Put(RollupBatchSignatureSignerKey(batchHash, signature.Signer), bz); err != nil {
log.Crit("failed to store batch signature", "batch index", batchHash, "signer", signature.Signer, "err", err)
}
}

func ReadBatchSignatures(db ethdb.Database, batchHash common.Hash) ([]*types.BatchSignature, error) {
prefix := RollupBatchSignatureKey(batchHash)
it := db.NewIterator(prefix, nil)
Expand All @@ -110,38 +78,3 @@ func ReadBatchSignatures(db ethdb.Database, batchHash common.Hash) ([]*types.Bat
}
return bss, nil
}

func WriteBatchL1DataFee(db ethdb.Database, batchIndex uint64, l1DataFee *big.Int) {
if err := db.Put(RollupBatchL1DataFeeKey(batchIndex), l1DataFee.Bytes()); err != nil {
log.Crit("failed to store batch l1DataFee", "batch index", batchIndex, "l1DataFee", l1DataFee.String(), "err", err)
}
}

func WriteHeadBatchIndexHasFee(db ethdb.Database, batchIndex uint64) {
if err := db.Put(rollupBatchHeadBatchHasFeeKey, encodeBigEndian(batchIndex)); err != nil {
log.Crit("failed to store head batch which has fee collected", "batch index", batchIndex, "err", err)
}
}

func ReadBatchL1DataFee(db ethdb.Database, batchIndex uint64) *big.Int {
data, err := db.Get(RollupBatchL1DataFeeKey(batchIndex))
if err != nil && isNotFoundErr(err) {
return nil
}
if err != nil {
log.Crit("failed to read batch from database", "err", err)
}
return new(big.Int).SetBytes(data)
}

func ReadLatestBatchIndexHasFee(db ethdb.Reader) *uint64 {
data, err := db.Get(rollupBatchHeadBatchHasFeeKey)
if err != nil && isNotFoundErr(err) {
return nil
}
if err != nil {
log.Crit("failed to read batchIndex from database", "err", err)
}
index := binary.BigEndian.Uint64(data)
return &index
}
18 changes: 0 additions & 18 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,6 @@ type RPCRollupBatch struct {

Sidecar types.BlobTxSidecar `json:"sidecar"`
Signatures []RPCBatchSignature `json:"signatures"`

CollectedL1Fee *hexutil.Big `json:"collectedL1Fee"`
}

type RPCBatchSignature struct {
Expand Down Expand Up @@ -646,12 +644,6 @@ func (api *MorphAPI) GetRollupBatchByIndex(ctx context.Context, index uint64) (*
sidecar = *rollupBatch.Sidecar
}

var collectedL1Fee *hexutil.Big
l1DataFee := rawdb.ReadBatchL1DataFee(api.eth.ChainDb(), index)
if l1DataFee != nil {
collectedL1Fee = (*hexutil.Big)(l1DataFee)
}

return &RPCRollupBatch{
Version: rollupBatch.Version,
Hash: rollupBatch.Hash,
Expand All @@ -665,19 +657,9 @@ func (api *MorphAPI) GetRollupBatchByIndex(ctx context.Context, index uint64) (*
NumL1Messages: rollupBatch.NumL1Messages,
Sidecar: sidecar,
Signatures: rpcSignatures,
CollectedL1Fee: collectedL1Fee,
}, nil
}

func (api *MorphAPI) GetRollupBatchL1FeeByIndex(ctx context.Context, index uint64) (*hexutil.Big, error) {
var collectedL1Fee *hexutil.Big
l1DataFee := rawdb.ReadBatchL1DataFee(api.eth.ChainDb(), index)
if l1DataFee != nil {
collectedL1Fee = (*hexutil.Big)(l1DataFee)
}
return collectedL1Fee, nil
}

// DiskAndHeaderRoot represents both the disk state root and header root for a block.
type DiskAndHeaderRoot struct {
DiskRoot common.Hash `json:"diskRoot"`
Expand Down
12 changes: 0 additions & 12 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import (
"github.com/morph-l2/go-ethereum/p2p/enode"
"github.com/morph-l2/go-ethereum/params"
"github.com/morph-l2/go-ethereum/rlp"
"github.com/morph-l2/go-ethereum/rollup/batch"
"github.com/morph-l2/go-ethereum/rpc"
)

Expand Down Expand Up @@ -92,9 +91,6 @@ type Ethereum struct {

p2pServer *p2p.Server

// Batch Handler
batchHandler *batch.Handler

lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
}

Expand Down Expand Up @@ -258,9 +254,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth.miner = miner.New(eth, config.Miner, eth.engine)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

// new batch handler
eth.batchHandler = batch.NewBatchHandler(chainDb, eth.blockchain)

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
if eth.APIBackend.allowUnprotectedTxs {
log.Info("Unprotected transactions allowed")
Expand Down Expand Up @@ -390,7 +383,6 @@ func (s *Ethereum) Downloader() *downloader.Downloader { return s.handler.downlo
func (s *Ethereum) Synced() bool { return atomic.LoadUint32(&s.handler.acceptTxs) == 1 }
func (s *Ethereum) ArchiveMode() bool { return s.config.NoPruning }
func (s *Ethereum) BloomIndexer() *core.ChainIndexer { return s.bloomIndexer }
func (s *Ethereum) BatchHandler() *batch.Handler { return s.batchHandler }
func (s *Ethereum) SyncMode() downloader.SyncMode {
mode, _ := s.handler.chainSync.modeAndLocalHead()
return mode
Expand All @@ -413,9 +405,6 @@ func (s *Ethereum) Protocols() []p2p.Protocol {
// Start implements node.Lifecycle, starting all internal goroutines needed by the
// Ethereum protocol implementation.
func (s *Ethereum) Start() error {
// start the batch handler
s.batchHandler.Start()

//eth.StartENRUpdater(s.blockchain, s.p2pServer.LocalNode())

// Start the bloom bits servicing goroutines
Expand Down Expand Up @@ -447,7 +436,6 @@ func (s *Ethereum) Stop() error {
close(s.closeBloomHandler)
s.txPool.Stop()
s.miner.Close()
s.batchHandler.Stop()
s.blockchain.Stop()
s.engine.Close()
rawdb.PopUncleanShutdownMarker(s.chainDb)
Expand Down
23 changes: 4 additions & 19 deletions eth/catalyst/l2_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (api *l2ConsensusAPI) ValidateL2Block(params ExecutableL2Data) (*GenericRes
return nil, fmt.Errorf("wrong parent hash: %s, expected parent hash is %s", params.ParentHash, parent.Hash())
}

block, err := api.executableDataToBlock(params, nil)
block, err := api.executableDataToBlock(params)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func (api *l2ConsensusAPI) ValidateL2Block(params ExecutableL2Data) (*GenericRes
}, nil
}

func (api *l2ConsensusAPI) NewL2Block(params ExecutableL2Data, batchHash *common.Hash) (err error) {
func (api *l2ConsensusAPI) NewL2Block(params ExecutableL2Data) (err error) {
api.newBlockLock.Lock()
defer api.newBlockLock.Unlock()

Expand All @@ -198,7 +198,7 @@ func (api *l2ConsensusAPI) NewL2Block(params ExecutableL2Data, batchHash *common
return fmt.Errorf("wrong parent hash: %s, expected parent hash is %s", params.ParentHash, parent.Hash())
}

block, err := api.executableDataToBlock(params, batchHash)
block, err := api.executableDataToBlock(params)
if err != nil {
return err
}
Expand Down Expand Up @@ -263,16 +263,6 @@ func (api *l2ConsensusAPI) NewSafeL2Block(params SafeL2Data) (header *types.Head
return header, api.eth.BlockChain().WriteStateAndSetHead(block, receipts, stateDB, procTime)
}

func (api *l2ConsensusAPI) CommitBatch(batch types.RollupBatch, signatures []types.BatchSignature) error {
log.Info("commit batch", "batch index", batch.Index)
return api.eth.BatchHandler().ImportBatch(&batch, signatures)
}

func (api *l2ConsensusAPI) AppendBatchSignature(batchHash common.Hash, signature types.BatchSignature) {
log.Info("append batch signature", "batch hash", fmt.Sprintf("%x", batchHash))
api.eth.BatchHandler().ImportBatchSig(batchHash, signature)
}

func (api *l2ConsensusAPI) safeDataToBlock(params SafeL2Data) (*types.Block, error) {
var batchHash common.Hash
if params.BatchHash != nil {
Expand Down Expand Up @@ -300,11 +290,7 @@ func (api *l2ConsensusAPI) safeDataToBlock(params SafeL2Data) (*types.Block, err
return types.NewBlockWithHeader(header).WithBody(txs, nil), nil
}

func (api *l2ConsensusAPI) executableDataToBlock(params ExecutableL2Data, batchHash *common.Hash) (*types.Block, error) {
var bh common.Hash
if batchHash != nil {
bh = *batchHash
}
func (api *l2ConsensusAPI) executableDataToBlock(params ExecutableL2Data) (*types.Block, error) {
header := &types.Header{
ParentHash: params.ParentHash,
Number: big.NewInt(int64(params.Number)),
Expand All @@ -314,7 +300,6 @@ func (api *l2ConsensusAPI) executableDataToBlock(params ExecutableL2Data, batchH
Coinbase: params.Miner,
BaseFee: params.BaseFee,
NextL1MsgIndex: params.NextL1MessageIndex,
BatchHash: bh,
}
header.Difficulty = l2.Difficulty
header.Nonce = l2.Nonce
Expand Down
4 changes: 2 additions & 2 deletions eth/catalyst/l2_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestNewL2Block(t *testing.T) {
LogsBloom: block.Bloom().Bytes(),
}

err = api.NewL2Block(l2Data, nil)
err = api.NewL2Block(l2Data)
require.NoError(t, err)

currentState, err := ethService.BlockChain().State()
Expand All @@ -205,7 +205,7 @@ func TestNewL2Block(t *testing.T) {
validResp, err := api.ValidateL2Block(*resp)
require.NoError(t, err)
require.True(t, validResp.Success)
err = api.NewL2Block(*resp, nil)
err = api.NewL2Block(*resp)
require.NoError(t, err)
currentState, err = ethService.BlockChain().State()
require.NoError(t, err)
Expand Down
15 changes: 2 additions & 13 deletions ethclient/authclient/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (ec *Client) ValidateL2Block(ctx context.Context, executableL2Data *catalys
}

// NewL2Block executes L2 Block, and set the block to chain
func (ec *Client) NewL2Block(ctx context.Context, executableL2Data *catalyst.ExecutableL2Data, batchHash *common.Hash) error {
return ec.c.CallContext(ctx, nil, "engine_newL2Block", executableL2Data, batchHash)
func (ec *Client) NewL2Block(ctx context.Context, executableL2Data *catalyst.ExecutableL2Data) error {
return ec.c.CallContext(ctx, nil, "engine_newL2Block", executableL2Data)
}

// NewSafeL2Block executes a safe L2 Block, and set the block to chain
Expand All @@ -49,16 +49,6 @@ func (ec *Client) NewSafeL2Block(ctx context.Context, safeL2Data *catalyst.SafeL
return &header, err
}

// CommitBatch commit the batch, with the signatures
func (ec *Client) CommitBatch(ctx context.Context, batch *types.RollupBatch, signatures []types.BatchSignature) error {
return ec.c.CallContext(ctx, nil, "engine_commitBatch", batch, signatures)
}

// AppendBlsSignature append a new bls signature to the batch
func (ec *Client) AppendBlsSignature(ctx context.Context, batchHash common.Hash, signature types.BatchSignature) error {
return ec.c.CallContext(ctx, nil, "engine_appendBatchSignature", batchHash, signature)
}

// SetBlockTags sets the safe and finalized block by hash
func (ec *Client) SetBlockTags(ctx context.Context, safeBlockHash common.Hash, finalizedBlockHash common.Hash) error {
return ec.c.CallContext(ctx, nil, "engine_setBlockTags", safeBlockHash, finalizedBlockHash)
Expand All @@ -80,4 +70,3 @@ func (ec *Client) AssembleL2BlockV2(ctx context.Context, parentHash common.Hash,
err := ec.c.CallContext(ctx, &result, "engine_assembleL2BlockV2", parentHash, timestamp, txs)
return result, err
}

12 changes: 0 additions & 12 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,6 @@ func (ec *Client) GetRollupBatchByIndex(ctx context.Context, batchIndex uint64)
return rpcRollupBatch, err
}

// GetRollupBatchL1FeeByIndex query the batch to be rollup by batchIndex
func (ec *Client) GetRollupBatchL1FeeByIndex(ctx context.Context, batchIndex uint64) (*big.Int, error) {
var fee *hexutil.Big
err := ec.c.CallContext(ctx, &fee, "morph_getRollupBatchL1FeeByIndex", batchIndex)
if err != nil {
return nil, err
} else if fee == nil {
return nil, nil
}
return (*big.Int)(fee), err
}

// State Access

// NetworkID returns the network ID (also known as the chain ID) for this chain.
Expand Down
58 changes: 0 additions & 58 deletions rollup/batch/block_context.go

This file was deleted.

Loading
Loading