Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(taiko-client): remove some unnecessary check and settings #18748

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func (t *SyncProgressTracker) ClearMeta() {
t.triggered = false
t.lastSyncedBlockID = nil
t.lastSyncedBlockHash = common.Hash{}
t.outOfSync = false
}

// NeedReSync checks if a new beacon sync request will be needed:
Expand All @@ -171,11 +170,6 @@ func (t *SyncProgressTracker) NeedReSync(newID *big.Int) (bool, error) {
t.mutex.RLock()
defer t.mutex.RUnlock()

// If the beacon sync has not been triggered yet, we will simply trigger it.
if !t.triggered {
return true, nil
}

if t.lastSyncedBlockID == nil {
return true, nil
}
Expand Down Expand Up @@ -242,22 +236,11 @@ func syncProgressed(last *ethereum.SyncProgress, new *ethereum.SyncProgress) boo
return false
}

if new == nil {
return true
}

// Block
if new.CurrentBlock > last.CurrentBlock {
return true
}

// Fast sync fields
if new.PulledStates > last.PulledStates {
return true
}

// Snap sync fields
if new.SyncedAccounts > last.SyncedAccounts ||
return new == nil ||
new.CurrentBlock > last.CurrentBlock ||
new.PulledStates > last.PulledStates ||
new.SyncedAccounts > last.SyncedAccounts ||
new.SyncedAccountBytes > last.SyncedAccountBytes ||
new.SyncedBytecodes > last.SyncedBytecodes ||
new.SyncedBytecodeBytes > last.SyncedBytecodeBytes ||
Expand All @@ -268,11 +251,7 @@ func syncProgressed(last *ethereum.SyncProgress, new *ethereum.SyncProgress) boo
new.HealedBytecodes > last.HealedBytecodes ||
new.HealedBytecodeBytes > last.HealedBytecodeBytes ||
new.HealingTrienodes > last.HealingTrienodes ||
new.HealingBytecode > last.HealingBytecode {
return true
}

return false
new.HealingBytecode > last.HealingBytecode
}

// MarkFinished marks the current beacon sync as finished.
Expand Down
46 changes: 20 additions & 26 deletions packages/taiko-client/driver/chain_syncer/blob/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,26 @@ func (s *Syncer) onBlockProposed(

// If we are not inserting a block whose parent block is the latest verified block in protocol,
// and the node hasn't just finished the P2P sync, we check if the L1 chain has been reorged.
if !s.progressTracker.Triggered() {
reorgCheckResult, err := s.checkReorg(ctx, meta.GetBlockID())
if err != nil {
return err
}

if reorgCheckResult.IsReorged {
log.Info(
"Reset L1Current cursor due to L1 reorg",
"l1CurrentHeightOld", s.state.GetL1Current().Number,
"l1CurrentHashOld", s.state.GetL1Current().Hash(),
"l1CurrentHeightNew", reorgCheckResult.L1CurrentToReset.Number,
"l1CurrentHashNew", reorgCheckResult.L1CurrentToReset.Hash(),
"lastInsertedBlockIDOld", s.lastInsertedBlockID,
"lastInsertedBlockIDNew", reorgCheckResult.LastHandledBlockIDToReset,
)
s.state.SetL1Current(reorgCheckResult.L1CurrentToReset)
s.lastInsertedBlockID = reorgCheckResult.LastHandledBlockIDToReset
s.reorgDetectedFlag = true
endIter()
reorgCheckResult, err := s.checkReorg(ctx, meta.GetBlockID())
if err != nil {
return err
}
if reorgCheckResult.IsReorged {
log.Info(
"Reset L1Current cursor due to L1 reorg",
"l1CurrentHeightOld", s.state.GetL1Current().Number,
"l1CurrentHashOld", s.state.GetL1Current().Hash(),
"l1CurrentHeightNew", reorgCheckResult.L1CurrentToReset.Number,
"l1CurrentHashNew", reorgCheckResult.L1CurrentToReset.Hash(),
"lastInsertedBlockIDOld", s.lastInsertedBlockID,
"lastInsertedBlockIDNew", reorgCheckResult.LastHandledBlockIDToReset,
)
s.state.SetL1Current(reorgCheckResult.L1CurrentToReset)
s.lastInsertedBlockID = reorgCheckResult.LastHandledBlockIDToReset
s.reorgDetectedFlag = true
endIter()

return nil
}
return nil
}
// Ignore those already inserted blocks.
if s.lastInsertedBlockID != nil && meta.GetBlockID().Cmp(s.lastInsertedBlockID) <= 0 {
Expand All @@ -217,10 +214,7 @@ func (s *Syncer) onBlockProposed(

// Fetch the L2 parent block, if the node is just finished a P2P sync, we simply use the tracker's
// last synced verified block as the parent, otherwise, we fetch the parent block from L2 EE.
var (
parent *types.Header
err error
)
var parent *types.Header
if s.progressTracker.Triggered() {
// Already synced through beacon sync, just skip this event.
if meta.GetBlockID().Cmp(s.progressTracker.LastSyncedBlockID()) <= 0 {
Expand Down
6 changes: 3 additions & 3 deletions packages/taiko-client/driver/chain_syncer/chain_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ func (s *L2ChainSyncer) AheadOfHeadToSync(heightToSync uint64) bool {

// If the L2 execution engine's chain is ahead of the block head to sync,
// we can mark the beacon sync progress as finished.
if s.progressTracker.LastSyncedBlockID() != nil {
if id := s.progressTracker.LastSyncedBlockID(); id != nil && s.state.GetL2Head().Number.Uint64() < id.Uint64() {
log.Info(
"L2 execution engine is ahead of the head to sync",
"heightToSync", heightToSync,
"executionEngineHead", s.state.GetL2Head().Number,
"lastSyncedBlockID", s.progressTracker.LastSyncedBlockID(),
"lastSyncedBlockID", id,
)
return s.state.GetL2Head().Number.Uint64() >= s.progressTracker.LastSyncedBlockID().Uint64()
return false
}

return true
Expand Down
5 changes: 5 additions & 0 deletions packages/taiko-client/driver/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"
"sync"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -126,6 +127,7 @@ func (s *State) eventLoop(ctx context.Context) {
l2BlockVerifiedV2Sub = rpc.SubscribeBlockVerifiedV2(s.rpc.TaikoL1, blockVerifiedV2Ch)
l2BlockProposedV2Sub = rpc.SubscribeBlockProposedV2(s.rpc.TaikoL1, blockProposedV2Ch)
l2TransitionProvedV2Sub = rpc.SubscribeTransitionProvedV2(s.rpc.TaikoL1, transitionProvedV2Ch)
tick = time.NewTicker(time.Minute * 10)
)

defer func() {
Expand All @@ -137,12 +139,15 @@ func (s *State) eventLoop(ctx context.Context) {
l2BlockVerifiedV2Sub.Unsubscribe()
l2BlockProposedV2Sub.Unsubscribe()
l2TransitionProvedV2Sub.Unsubscribe()
tick.Stop()
}()

for {
select {
case <-ctx.Done():
return
case <-tick.C:
log.Info("state log, current L2 head", "blockID", s.GetL2Head().Number)
case e := <-blockProposedCh:
s.setHeadBlockID(e.BlockId)
case e := <-blockProposedV2Ch:
Expand Down
Loading