Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Sep 24, 2024
1 parent f9e35c4 commit b754a8b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion l1infotreesync/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func buildAppender(client EthClienter, globalExitRoot, rollupManager common.Addr
)
}
log.Infof("updateL1InfoTreeSignatureV2: expected root: %s",
common.BytesToHash(l1InfoTreeUpdate.CurrentL1InfoRoot[:]).String())
common.BytesToHash(l1InfoTreeUpdate.CurrentL1InfoRoot[:]))

return nil
}
Expand Down
2 changes: 0 additions & 2 deletions l1infotreesync/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ func TestStressAndReorgs(t *testing.T) {
reorgFrom := block.Hash()
err = client.Fork(reorgFrom)
require.NoError(t, err)

fmt.Println("reorg from block:", block.Number().Uint64()+1)
} else {
updateL1InfoTreeAndRollupExitTree(i, j, uint32(j%maxRollupID)+1)
}
Expand Down
5 changes: 0 additions & 5 deletions l1infotreesync/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ func (p *processor) Reorg(ctx context.Context, firstReorgedBlock uint64) error {
return err
}

_, err = tx.Exec(`DELETE FROM l1info_leaf WHERE block_num >= $1;`, firstReorgedBlock)
if err != nil {
return err
}

if err = p.l1InfoTree.Reorg(tx, firstReorgedBlock); err != nil {
return err
}
Expand Down
2 changes: 0 additions & 2 deletions reorgdetector/reorgdetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ func (rd *ReorgDetector) detectReorgInTrackedList(ctx context.Context) error {
continue
}

log.Info("[ReorgDetector] Reorg detected", " blockNum ", hdr.Num)

// Notify the subscriber about the reorg
rd.notifySubscriber(id, hdr)

Expand Down
9 changes: 3 additions & 6 deletions sync/evmdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ func NewEVMDriver(
}

func (d *EVMDriver) Sync(ctx context.Context) {
syncID := 0
reset:
var (
lastProcessedBlock uint64
attempts int
err error
)

syncID++
for {
lastProcessedBlock, err = d.processor.GetLastProcessedBlock(ctx)
if err != nil {
Expand All @@ -87,19 +85,18 @@ reset:
cancellableCtx, cancel := context.WithCancel(ctx)
defer cancel()

log.Info("Starting sync. syncID: ", syncID, " lastProcessedBlock", lastProcessedBlock)
log.Info("Starting sync...", " lastProcessedBlock", lastProcessedBlock)
// start downloading
downloadCh := make(chan EVMBlock, d.downloadBufferSize)
go d.downloader.Download(cancellableCtx, lastProcessedBlock+1, downloadCh)

for {
select {
case b := <-downloadCh:
d.log.Debug("handleNewBlock: ", b.Num, b.Hash, " syncID ", syncID)
d.log.Debug("handleNewBlock", " blockNum: ", b.Num, " blockHash: ", b.Hash)
d.handleNewBlock(ctx, b)
d.log.Debug("handleNewBlock done: ", b.Num, b.Hash, " syncID ", syncID)
case firstReorgedBlock := <-d.reorgSub.ReorgedBlock:
d.log.Debug("handleReorg: ", firstReorgedBlock, " syncID ", syncID)
d.log.Debug("handleReorg from block: ", firstReorgedBlock)
d.handleReorg(ctx, cancel, firstReorgedBlock)
goto reset
}
Expand Down
24 changes: 12 additions & 12 deletions tree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ func TestCheckExpectedRoot(t *testing.T) {
indexToCheck := uint32(numOfLeavesToAdd - 1)

treeDB := createTreeDB()
merkletree := tree.NewAppendOnlyTree(treeDB, "")
merkleTree := tree.NewAppendOnlyTree(treeDB, "")

addLeaves(merkletree, treeDB, numOfLeavesToAdd, 0)
addLeaves(merkleTree, treeDB, numOfLeavesToAdd, 0)

expectedRoot, err := merkletree.GetLastRoot(context.Background())
expectedRoot, err := merkleTree.GetLastRoot(context.Background())
require.NoError(t, err)

addLeaves(merkletree, treeDB, numOfLeavesToAdd, numOfLeavesToAdd)
addLeaves(merkleTree, treeDB, numOfLeavesToAdd, numOfLeavesToAdd)

root2, err := merkletree.GetRootByIndex(context.Background(), indexToCheck)
root2, err := merkleTree.GetRootByIndex(context.Background(), indexToCheck)
require.NoError(t, err)
require.Equal(t, expectedRoot.Hash, root2.Hash)
require.Equal(t, expectedRoot.Index, root2.Index)
Expand All @@ -70,31 +70,31 @@ func TestCheckExpectedRoot(t *testing.T) {
numOfLeavesToAdd := 10
indexToCheck := uint32(numOfLeavesToAdd - 1)
treeDB := createTreeDB()
merkletree := tree.NewAppendOnlyTree(treeDB, "")
merkleTree := tree.NewAppendOnlyTree(treeDB, "")

addLeaves(merkletree, treeDB, numOfLeavesToAdd, 0)
addLeaves(merkleTree, treeDB, numOfLeavesToAdd, 0)

expectedRoot, err := merkletree.GetLastRoot(context.Background())
expectedRoot, err := merkleTree.GetLastRoot(context.Background())
require.NoError(t, err)

addLeaves(merkletree, treeDB, numOfLeavesToAdd, numOfLeavesToAdd)
addLeaves(merkleTree, treeDB, numOfLeavesToAdd, numOfLeavesToAdd)

// reorg tree
tx, err := db.NewTx(context.Background(), treeDB)
require.NoError(t, err)
require.NoError(t, merkletree.Reorg(tx, uint64(indexToCheck+1)))
require.NoError(t, merkleTree.Reorg(tx, uint64(indexToCheck+1)))
require.NoError(t, tx.Commit())

// rebuild cache on adding new leaf
tx, err = db.NewTx(context.Background(), treeDB)
require.NoError(t, err)
require.NoError(t, merkletree.AddLeaf(tx, uint64(indexToCheck+1), 0, types.Leaf{
require.NoError(t, merkleTree.AddLeaf(tx, uint64(indexToCheck+1), 0, types.Leaf{
Index: indexToCheck + 1,
Hash: common.HexToHash(fmt.Sprintf("%x", indexToCheck+1)),
}))
require.NoError(t, tx.Commit())

root2, err := merkletree.GetRootByIndex(context.Background(), indexToCheck)
root2, err := merkleTree.GetRootByIndex(context.Background(), indexToCheck)
require.NoError(t, err)
require.Equal(t, expectedRoot.Hash, root2.Hash)
require.Equal(t, expectedRoot.Index, root2.Index)
Expand Down

0 comments on commit b754a8b

Please sign in to comment.