Skip to content

Commit

Permalink
refactor: l1syncer error traces
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Staykov committed Nov 13, 2024
1 parent 57f6f52 commit 8b368d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions zk/l1infotree/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ LOOP:

tree, err := InitialiseL1InfoTree(hermezDb)
if err != nil {
return nil, err
return nil, fmt.Errorf("InitialiseL1InfoTree: %w", err)
}

// process the logs in chunks
Expand All @@ -153,7 +153,7 @@ LOOP:

headersMap, err := u.syncer.L1QueryHeaders(chunk)
if err != nil {
return nil, err
return nil, fmt.Errorf("L1QueryHeaders: %w", err)
}

for _, l := range chunk {
Expand All @@ -163,13 +163,13 @@ LOOP:
if header == nil {
header, err = u.syncer.GetHeader(l.BlockNumber)
if err != nil {
return nil, err
return nil, fmt.Errorf("GetHeader: %w", err)
}
}

tmpUpdate, err := createL1InfoTreeUpdate(l, header)
if err != nil {
return nil, err
return nil, fmt.Errorf("createL1InfoTreeUpdate: %w", err)
}

leafHash := HashLeafData(tmpUpdate.GER, tmpUpdate.ParentHash, tmpUpdate.Timestamp)
Expand All @@ -185,7 +185,7 @@ LOOP:

newRoot, err := tree.AddLeaf(uint32(u.latestUpdate.Index), leafHash)
if err != nil {
return nil, err
return nil, fmt.Errorf("tree.AddLeaf: %w", err)
}
log.Debug("New L1 Index",
"index", u.latestUpdate.Index,
Expand All @@ -197,13 +197,13 @@ LOOP:
)

if err = handleL1InfoTreeUpdate(hermezDb, u.latestUpdate); err != nil {
return nil, err
return nil, fmt.Errorf("handleL1InfoTreeUpdate: %w", err)
}
if err = hermezDb.WriteL1InfoTreeLeaf(u.latestUpdate.Index, leafHash); err != nil {
return nil, err
return nil, fmt.Errorf("WriteL1InfoTreeLeaf: %w", err)
}
if err = hermezDb.WriteL1InfoTreeRoot(common.BytesToHash(newRoot[:]), u.latestUpdate.Index); err != nil {
return nil, err
return nil, fmt.Errorf("WriteL1InfoTreeRoot: %w", err)
}

processed++
Expand All @@ -218,7 +218,7 @@ LOOP:
u.progress = allLogs[len(allLogs)-1].BlockNumber + 1
}
if err = stages.SaveStageProgress(tx, stages.L1InfoTree, u.progress); err != nil {
return nil, err
return nil, fmt.Errorf("SaveStageProgress: %w", err)
}

return allLogs, nil
Expand All @@ -242,7 +242,7 @@ func chunkLogs(slice []types.Log, chunkSize int) [][]types.Log {
func InitialiseL1InfoTree(hermezDb *hermez_db.HermezDb) (*L1InfoTree, error) {
leaves, err := hermezDb.GetAllL1InfoTreeLeaves()
if err != nil {
return nil, err
return nil, fmt.Errorf("GetAllL1InfoTreeLeaves: %w", err)
}

allLeaves := make([][32]byte, len(leaves))
Expand All @@ -252,7 +252,7 @@ func InitialiseL1InfoTree(hermezDb *hermez_db.HermezDb) (*L1InfoTree, error) {

tree, err := NewL1InfoTree(32, allLeaves)
if err != nil {
return nil, err
return nil, fmt.Errorf("NewL1InfoTree: %w", err)
}

return tree, nil
Expand Down Expand Up @@ -289,10 +289,10 @@ func handleL1InfoTreeUpdate(
) error {
var err error
if err = hermezDb.WriteL1InfoTreeUpdate(update); err != nil {
return err
return fmt.Errorf("WriteL1InfoTreeUpdate: %w", err)
}
if err = hermezDb.WriteL1InfoTreeUpdateToGer(update); err != nil {
return err
return fmt.Errorf("WriteL1InfoTreeUpdateToGer: %w", err)
}
return nil
}
8 changes: 4 additions & 4 deletions zk/stages/stage_l1_info_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ func SpawnL1InfoTreeStage(
var err error
tx, err = cfg.db.BeginRw(ctx)
if err != nil {
return err
return fmt.Errorf("cfg.db.BeginRw: %w", err)
}
defer tx.Rollback()
}

if err := cfg.updater.WarmUp(tx); err != nil {
return err
return fmt.Errorf("cfg.updater.WarmUp: %w", err)
}

allLogs, err := cfg.updater.CheckForInfoTreeUpdates(logPrefix, tx)
if err != nil {
return err
return fmt.Errorf("CheckForInfoTreeUpdates: %w", err)
}

var latestIndex uint64
Expand All @@ -65,7 +65,7 @@ func SpawnL1InfoTreeStage(

if freshTx {
if funcErr = tx.Commit(); funcErr != nil {
return funcErr
return fmt.Errorf("tx.Commit: %w", funcErr)
}
}

Expand Down
6 changes: 3 additions & 3 deletions zk/syncer/l1_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,17 @@ func (s *L1Syncer) RunQueryBlocks(lastCheckedBlock uint64) {

func (s *L1Syncer) GetHeader(number uint64) (*ethTypes.Header, error) {
em := s.getNextEtherman()
return em.HeaderByNumber(context.Background(), new(big.Int).SetUint64(number))
return em.HeaderByNumber(s.ctx, new(big.Int).SetUint64(number))
}

func (s *L1Syncer) GetBlock(number uint64) (*ethTypes.Block, error) {
em := s.getNextEtherman()
return em.BlockByNumber(context.Background(), new(big.Int).SetUint64(number))
return em.BlockByNumber(s.ctx, new(big.Int).SetUint64(number))
}

func (s *L1Syncer) GetTransaction(hash common.Hash) (ethTypes.Transaction, bool, error) {
em := s.getNextEtherman()
return em.TransactionByHash(context.Background(), hash)
return em.TransactionByHash(s.ctx, hash)
}

func (s *L1Syncer) GetPreElderberryAccInputHash(ctx context.Context, addr *common.Address, batchNum uint64) (common.Hash, error) {
Expand Down

0 comments on commit 8b368d0

Please sign in to comment.