Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

feat(driver): check verified blocks in L2 EE #295

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *State) init(ctx context.Context) error {
func (s *State) startSubscriptions(ctx context.Context) {
s.l1HeadSub = rpc.SubscribeChainHead(s.rpc.L1, s.l1HeadCh)
s.l2HeadSub = rpc.SubscribeChainHead(s.rpc.L2, s.l2HeadCh)
s.l2HeaderSyncedSub = rpc.SubscribeXchainSynced(s.rpc.TaikoL1, s.crossChainSynced)
s.l2HeaderSyncedSub = rpc.SubscribeCrossChainSynced(s.rpc.TaikoL1, s.crossChainSynced)
s.l2BlockVerifiedSub = rpc.SubscribeBlockVerified(s.rpc.TaikoL1, s.blockVerifiedCh)
s.l2BlockProposedSub = rpc.SubscribeBlockProposed(s.rpc.TaikoL1, s.blockProposedCh)
s.l2BlockProvenSub = rpc.SubscribeBlockProven(s.rpc.TaikoL1, s.blockProvenCh)
Expand All @@ -173,15 +173,15 @@ func (s *State) startSubscriptions(ctx context.Context) {
}
case e := <-s.blockVerifiedCh:
log.Info("📈 Block verified", "blockID", e.Id, "hash", common.Hash(e.BlockHash), "reward", e.Reward)
case e := <-s.crossChainSynced:
// Verify the protocol synced block, check if it exists in
// Verify the protocol verified block, check if it exists in
// L2 execution engine.
if s.GetL2Head().Number.Cmp(e.SrcHeight) >= 0 {
if err := s.VerifyL2Block(ctx, e.SrcHeight, e.BlockHash); err != nil {
if s.GetL2Head().Number.Cmp(e.Id) >= 0 {
if err := s.VerifyL2Block(ctx, e.Id, e.BlockHash); err != nil {
log.Error("Check new verified L2 block error", "error", err)
continue
}
}
case e := <-s.crossChainSynced:
id, err := s.getSyncedHeaderID(e.Raw.BlockNumber, e.BlockHash)
if err != nil {
log.Error("Get synced header block ID error", "error", err)
Expand Down Expand Up @@ -277,14 +277,21 @@ func (s *State) VerifyL2Block(ctx context.Context, height *big.Int, hash common.
return err
}

if header.Hash() != hash {
// TODO(david): do not exit but re-sync from genesis?
log.Crit(
"Verified block hash mismatch",
"protocolBlockHash", hash,
"block number in L2 execution engine", header.Number,
"block hash in L2 execution engine", header.Hash(),
)
if header.Hash() == hash {
return nil
}

// Verified block hash mismatch, try to resync from geneis.
log.Error(
"Verified block hash mismatch",
"height", height,
"protocolBlockHash", hash,
"l2EEBlockNumber", header.Number,
"l2EEBlockHash", header.Hash(),
)

if _, _, err := s.ResetL1Current(ctx, &HeightOrID{ID: common.Big0}); err != nil {
return fmt.Errorf("failed to reset L1 current: %w", err)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/rpc/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ func SubscribeBlockProposed(
})
}

// SubscribeXchainSynced subscribes the protocol's XchainSynced events.
func SubscribeXchainSynced(
// SubscribeCrossChainSynced subscribes the protocol's CrossChainSynced events.
func SubscribeCrossChainSynced(
taikoL1 *bindings.TaikoL1Client,
ch chan *bindings.TaikoL1ClientCrossChainSynced,
) event.Subscription {
return SubscribeEvent("CrossChainSynced", func(ctx context.Context) (event.Subscription, error) {
sub, err := taikoL1.WatchCrossChainSynced(nil, ch, nil)
if err != nil {
log.Error("Create TaikoL1.XchainSynced subscription error", "error", err)
log.Error("Create TaikoL1.CrossChainSynced subscription error", "error", err)
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/rpc/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestSubscribeBlockProposed(t *testing.T) {
}

func TestSubscribeSubscribeXchainSynced(t *testing.T) {
require.NotNil(t, SubscribeXchainSynced(
require.NotNil(t, SubscribeCrossChainSynced(
newTestClient(t).TaikoL1,
make(chan *bindings.TaikoL1ClientCrossChainSynced, 1024)),
)
Expand Down