Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaubennassar committed Aug 6, 2024
1 parent 4f1db55 commit 5169949
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lastgersync/downloader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package lastgersync

type downloader struct {
}
3 changes: 3 additions & 0 deletions lastgersync/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package lastgersync

type driver struct{}
4 changes: 4 additions & 0 deletions lastgersync/lastgersync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package lastgersync

type LastGERSync struct {
}
38 changes: 38 additions & 0 deletions lastgersync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,41 @@ func (p *processor) GetLastProcessedBlockAndL1InfoTreeIndex(ctx context.Context)
defer tx.Rollback()
return p.getLastProcessedBlockAndL1InfoTreeIndexWithTx(tx)
}

func (p *processor) getLastProcessedBlockAndL1InfoTreeIndexWithTx(tx kv.Tx) (uint64, uint32, error) {
if lastProcessedBytes, err := tx.GetOne(lastProcessedTable, lastProcessedKey); err != nil {
return 0, 0, err
} else if lastProcessedBytes == nil {
return 0, 0, nil
} else {
lp := &lastProcessed{}
if err := lp.UnmarshalBinary(lastProcessedBytes); err != nil {
return 0, 0, err
}
return lp.block, lp.index, nil
}
}

func (p *processor) updateLastProcessedBlockAndL1InfoTreeIndex(ctx context.Context, blockNum uint64, index uint32) error {
tx, err := p.db.BeginRw(ctx)
if err != nil {
return err
}
if err := p.updateLastProcessedBlockAndL1InfoTreeIndexWithTx(tx, blockNum, index); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}

func (p *processor) updateLastProcessedBlockAndL1InfoTreeIndexWithTx(tx kv.RwTx, blockNum uint64, index uint32) error {
lp := &lastProcessed{
block: blockNum,
index: index,
}
value, err := lp.MarshalBinary()
if err != nil {
return err
}
return tx.Put(lastProcessedTable, lastProcessedKey, value)
}

0 comments on commit 5169949

Please sign in to comment.