Skip to content

Commit

Permalink
Move some code to separate function for linter
Browse files Browse the repository at this point in the history
  • Loading branch information
joshklop committed Jun 19, 2023
1 parent 0ec74ea commit ce5666b
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions l1/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,29 @@ func (c *Client) Run(ctx context.Context) error {
}
}

// Set the chain head to the max confirmed log, if it exists.
if maxConfirmed := c.confirmationQueue.MaxConfirmed(l1Height); maxConfirmed != nil {
head := &core.L1Head{
BlockNumber: maxConfirmed.BlockNumber.Uint64(),
BlockHash: new(felt.Felt).SetBigInt(maxConfirmed.BlockHash),
StateRoot: new(felt.Felt).SetBigInt(maxConfirmed.GlobalRoot),
}
if err := c.l2Chain.SetL1Head(head); err != nil {
return fmt.Errorf("l1 head for block %d and state root %s: %w", head.BlockNumber, head.StateRoot.String(), err)
}
c.confirmationQueue.Remove(maxConfirmed.Raw.BlockNumber)
c.log.Infow("Updated l1 head",
"blockNumber", head.BlockNumber,
"blockHash", head.BlockHash.ShortString(),
"stateRoot", head.StateRoot.ShortString())
if err := c.setL1Height(l1Height); err != nil {
return err
}
}
}
}

func (c *Client) setL1Height(l1Height uint64) error {
// Set the chain head to the max confirmed log, if it exists.
if maxConfirmed := c.confirmationQueue.MaxConfirmed(l1Height); maxConfirmed != nil {
head := &core.L1Head{
BlockNumber: maxConfirmed.BlockNumber.Uint64(),
BlockHash: new(felt.Felt).SetBigInt(maxConfirmed.BlockHash),
StateRoot: new(felt.Felt).SetBigInt(maxConfirmed.GlobalRoot),
}
if err := c.l2Chain.SetL1Head(head); err != nil {
return fmt.Errorf("l1 head for block %d and state root %s: %w", head.BlockNumber, head.StateRoot.String(), err)
}
c.confirmationQueue.Remove(maxConfirmed.Raw.BlockNumber)
c.log.Infow("Updated l1 head",
"blockNumber", head.BlockNumber,
"blockHash", head.BlockHash.ShortString(),
"stateRoot", head.StateRoot.ShortString())
}
return nil
}

0 comments on commit ce5666b

Please sign in to comment.