Skip to content

Commit

Permalink
remove DS LER (0xPolygonHermez#3511)
Browse files Browse the repository at this point in the history
* remove DS LER

* remove DS LER
  • Loading branch information
ToniRamirezM authored Apr 15, 2024
1 parent 592d9cc commit dd05baa
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 27 deletions.
4 changes: 1 addition & 3 deletions sequencer/datastreamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package sequencer

import (
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/ethereum/go-ethereum/common"
)

func (f *finalizer) DSSendL2Block(batchNumber uint64, blockResponse *state.ProcessBlockResponse, l1InfoTreeIndex uint32, localExitRoot common.Hash) error {
func (f *finalizer) DSSendL2Block(batchNumber uint64, blockResponse *state.ProcessBlockResponse, l1InfoTreeIndex uint32) error {
forkID := f.stateIntf.GetForkIDByBatchNumber(batchNumber)

// Send data to streamer
Expand All @@ -21,7 +20,6 @@ func (f *finalizer) DSSendL2Block(batchNumber uint64, blockResponse *state.Proce
ForkID: uint16(forkID),
BlockHash: blockResponse.BlockHash,
StateRoot: blockResponse.BlockHash, //From etrog, the blockhash is the block root
LocalExitRoot: localExitRoot,
}

l2Transactions := []state.DSL2Transaction{}
Expand Down
2 changes: 1 addition & 1 deletion sequencer/forcedbatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (f *finalizer) handleProcessForcedBatchResponse(ctx context.Context, newBat
}

// Send L2 block to data streamer
err = f.DSSendL2Block(newBatchNumber, forcedL2BlockResponse, 0, batchResponse.NewLocalExitRoot)
err = f.DSSendL2Block(newBatchNumber, forcedL2BlockResponse, 0)
if err != nil {
//TODO: we need to halt/rollback the L2 block if we had an error sending to the data streamer?
log.Errorf("error sending L2 block %d to data streamer, error: %v", forcedL2BlockResponse.BlockNumber, err)
Expand Down
2 changes: 1 addition & 1 deletion sequencer/l2block.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (f *finalizer) storeL2Block(ctx context.Context, l2Block *L2Block) error {
}

// Send L2 block to data streamer
err = f.DSSendL2Block(f.wipBatch.batchNumber, blockResponse, l2Block.getL1InfoTreeIndex(), l2Block.batchResponse.NewLocalExitRoot)
err = f.DSSendL2Block(f.wipBatch.batchNumber, blockResponse, l2Block.getL1InfoTreeIndex())
if err != nil {
//TODO: we need to halt/rollback the L2 block if we had an error sending to the data streamer?
log.Errorf("error sending L2 block %d [%d] to data streamer, error: %v", blockResponse.BlockNumber, l2Block.trackingNum, err)
Expand Down
6 changes: 0 additions & 6 deletions state/datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type DSL2Block struct {
Coinbase common.Address // 20 bytes
ForkID uint16 // 2 bytes
ChainID uint32 // 4 bytes
LocalExitRoot common.Hash // 32 bytes
BlockHash common.Hash // 32 bytes
StateRoot common.Hash // 32 bytes
}
Expand All @@ -81,7 +80,6 @@ type DSL2BlockStart struct {
Coinbase common.Address // 20 bytes
ForkID uint16 // 2 bytes
ChainID uint32 // 4 bytes
LocalExitRoot common.Hash // 32 bytes
}

// Encode returns the encoded DSL2BlockStart as a byte slice
Expand All @@ -97,7 +95,6 @@ func (b DSL2BlockStart) Encode() []byte {
bytes = append(bytes, b.Coinbase.Bytes()...)
bytes = binary.BigEndian.AppendUint16(bytes, b.ForkID)
bytes = binary.BigEndian.AppendUint32(bytes, b.ChainID)
bytes = append(bytes, b.LocalExitRoot.Bytes()...)
return bytes
}

Expand All @@ -113,7 +110,6 @@ func (b DSL2BlockStart) Decode(data []byte) DSL2BlockStart {
b.Coinbase = common.BytesToAddress(data[96:116])
b.ForkID = binary.BigEndian.Uint16(data[116:118])
b.ChainID = binary.BigEndian.Uint32(data[118:122])
b.LocalExitRoot = common.BytesToHash(data[122:154])
return b
}

Expand Down Expand Up @@ -293,7 +289,6 @@ func GenerateDataStreamerFile(ctx context.Context, streamServer *datastreamer.St
Coinbase: genesisL2Block.Coinbase,
ForkID: genesisL2Block.ForkID,
ChainID: uint32(chainID),
LocalExitRoot: genesisL2Block.LocalExitRoot,
}

log.Infof("Genesis block: %+v", genesisBlock)
Expand Down Expand Up @@ -531,7 +526,6 @@ func GenerateDataStreamerFile(ctx context.Context, streamServer *datastreamer.St
Coinbase: l2Block.Coinbase,
ForkID: l2Block.ForkID,
ChainID: uint32(chainID),
LocalExitRoot: l2Block.LocalExitRoot,
}

previousTimestamp = l2Block.Timestamp
Expand Down
19 changes: 8 additions & 11 deletions state/pgstatestorage/datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// GetDSGenesisBlock returns the genesis block
func (p *PostgresStorage) GetDSGenesisBlock(ctx context.Context, dbTx pgx.Tx) (*state.DSL2Block, error) {
const genesisL2BlockSQL = `SELECT 0 as batch_num, l2b.block_num, l2b.received_at, '0x0000000000000000000000000000000000000000' as global_exit_root, '0x0000000000000000000000000000000000000000' as block_global_exit_root, l2b.header->>'miner' AS coinbase, 0 as fork_id, l2b.block_hash, l2b.state_root, '0x0000000000000000000000000000000000000000' as local_exit_root
const genesisL2BlockSQL = `SELECT 0 as batch_num, l2b.block_num, l2b.received_at, '0x0000000000000000000000000000000000000000' as global_exit_root, '0x0000000000000000000000000000000000000000' as block_global_exit_root, l2b.header->>'miner' AS coinbase, 0 as fork_id, l2b.block_hash, l2b.state_root
FROM state.l2block l2b
WHERE l2b.block_num = 0`

Expand All @@ -29,7 +29,7 @@ func (p *PostgresStorage) GetDSGenesisBlock(ctx context.Context, dbTx pgx.Tx) (*

// GetDSL2Blocks returns the L2 blocks
func (p *PostgresStorage) GetDSL2Blocks(ctx context.Context, firstBatchNumber, lastBatchNumber uint64, dbTx pgx.Tx) ([]*state.DSL2Block, error) {
const l2BlockSQL = `SELECT l2b.batch_num, l2b.block_num, l2b.received_at, b.global_exit_root, COALESCE(l2b.header->>'globalExitRoot', '') AS block_global_exit_root, l2b.header->>'miner' AS coinbase, f.fork_id, l2b.block_hash, l2b.state_root, b.local_exit_root
const l2BlockSQL = `SELECT l2b.batch_num, l2b.block_num, l2b.received_at, b.global_exit_root, COALESCE(l2b.header->>'globalExitRoot', '') AS block_global_exit_root, l2b.header->>'miner' AS coinbase, f.fork_id, l2b.block_hash, l2b.state_root
FROM state.l2block l2b, state.batch b, state.fork_id f
WHERE l2b.batch_num BETWEEN $1 AND $2 AND l2b.batch_num = b.batch_num AND l2b.batch_num between f.from_batch_num AND f.to_batch_num
ORDER BY l2b.block_num ASC`
Expand All @@ -56,13 +56,12 @@ func (p *PostgresStorage) GetDSL2Blocks(ctx context.Context, firstBatchNumber, l
func scanL2Block(row pgx.Row) (*state.DSL2Block, error) {
l2Block := state.DSL2Block{}
var (
gerStr string
blockGERStr string
coinbaseStr string
timestamp time.Time
blockHashStr string
stateRootStr string
localExitRootStr string
gerStr string
blockGERStr string
coinbaseStr string
timestamp time.Time
blockHashStr string
stateRootStr string
)
if err := row.Scan(
&l2Block.BatchNumber,
Expand All @@ -74,7 +73,6 @@ func scanL2Block(row pgx.Row) (*state.DSL2Block, error) {
&l2Block.ForkID,
&blockHashStr,
&stateRootStr,
&localExitRootStr,
); err != nil {
return &l2Block, err
}
Expand All @@ -83,7 +81,6 @@ func scanL2Block(row pgx.Row) (*state.DSL2Block, error) {
l2Block.Timestamp = timestamp.Unix()
l2Block.BlockHash = common.HexToHash(blockHashStr)
l2Block.StateRoot = common.HexToHash(stateRootStr)
l2Block.LocalExitRoot = common.HexToHash(localExitRootStr)

if l2Block.ForkID >= state.FORKID_ETROG {
l2Block.GlobalExitRoot = common.HexToHash(blockGERStr)
Expand Down
4 changes: 1 addition & 3 deletions state/test/datastream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func TestL2BlockStartEncode(t *testing.T) {
Coinbase: common.HexToAddress("0x08"),
ForkID: 9,
ChainID: 10,
LocalExitRoot: common.HexToHash("0x0a"),
}

encoded := l2BlockStart.Encode()
Expand All @@ -36,8 +35,7 @@ func TestL2BlockStartEncode(t *testing.T) {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
0, 9,
0, 0, 0, 10,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10}
0, 0, 0, 10}

assert.Equal(t, expected, encoded)
}
Expand Down
2 changes: 0 additions & 2 deletions tools/datastreamer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,6 @@ func printEntry(entry datastreamer.FileEntry) {
printColored(color.FgHiWhite, fmt.Sprintf("%d\n", blockStart.ForkID))
printColored(color.FgGreen, "Chain ID........: ")
printColored(color.FgHiWhite, fmt.Sprintf("%d\n", blockStart.ChainID))
printColored(color.FgGreen, "Local Exit Root.: ")
printColored(color.FgHiWhite, fmt.Sprintf("%s\n", blockStart.LocalExitRoot))
case state.EntryTypeL2Tx:
dsTx := state.DSL2Transaction{}.Decode(entry.Data)
printColored(color.FgGreen, "Entry Type......: ")
Expand Down

0 comments on commit dd05baa

Please sign in to comment.