Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
joanestebanr committed Sep 19, 2024
1 parent db81a26 commit fc9e393
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions l1infotreesync/migrations/l1infotreesync0002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- +migrate Down
DROP TABLE IF EXISTS initial_info;

-- +migrate Up

CREATE TABLE initial_info (
block_num INTEGER NOT NULL REFERENCES block(num) ON DELETE CASCADE,
leaf_count INTEGER NOT NULL,
l1_info_root VARCHAR NOT NULL,
)

20 changes: 20 additions & 0 deletions l1infotreesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ type L1InfoTreeLeaf struct {
Hash common.Hash `meddler:"hash,hash"`
}

// L1InfoTreeInitial representation of the initial info of the L1 Info tree for this rollup
type L1InfoTreeInitial struct {
BlockNumber uint64 `meddler:"block_num"`
LeafCount uint32 `meddler:"leaf_count"`
L1InfoRoot common.Hash `meddler:"l1_info_root,hash"`
}

// Hash as expected by the tree
func (l *L1InfoTreeLeaf) hash() common.Hash {
var res [treeTypes.DefaultHeight]byte
Expand Down Expand Up @@ -309,6 +316,7 @@ func (p *processor) ProcessBlock(ctx context.Context, b sync.Block) error {
// TODO: indicate that l1 Info tree indexes before the one on this
// event are not safe to use
log.Debugf("TODO: handle InitL1InfoRootMap event")
err = processEventInitL1InfoRootMap(tx, b.Num, event.InitL1InfoRootMap)
}
}

Expand All @@ -319,6 +327,18 @@ func (p *processor) ProcessBlock(ctx context.Context, b sync.Block) error {
return nil
}

func processEventInitL1InfoRootMap(tx db.Txer, blockNumber uint64, event *InitL1InfoRootMap) error {
info := L1InfoTreeInitial{
BlockNumber: blockNumber,
LeafCount: event.LeafCount,
L1InfoRoot: event.CurrentL1InfoRoot,
}
if err := meddler.Insert(tx, "l1info_initial", info); err != nil {
return fmt.Errorf("err: %w", err)
}
return nil
}

func (p *processor) getLastIndex(tx db.Querier) (uint32, error) {
var lastProcessedIndex uint32
row := tx.QueryRow("SELECT position FROM l1info_leaf ORDER BY block_num DESC, block_pos DESC LIMIT 1;")
Expand Down

0 comments on commit fc9e393

Please sign in to comment.