Skip to content

Commit

Permalink
rever block sync logic
Browse files Browse the repository at this point in the history
  • Loading branch information
blindchaser committed Oct 28, 2024
1 parent e007e86 commit 9222988
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/blocksync/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ func (pool *BlockPool) SetPeerRange(peerID types.NodeID, base int64, height int6
pool.mtx.Lock()
defer pool.mtx.Unlock()

blockSyncPeers := pool.peerManager.GetBlockSyncPeers()
if len(blockSyncPeers) > 0 && !blockSyncPeers[peerID] {
return
}

peer := pool.peers[peerID]
if peer != nil {
peer.base = base
Expand Down
1 change: 1 addition & 0 deletions internal/blocksync/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func (r *Reactor) handleMessage(ctx context.Context, envelope *p2p.Envelope, blo
return r.respondToPeer(ctx, msg, envelope.From, blockSyncCh)
case *bcproto.BlockResponse:
block, err := types.BlockFromProto(msg.Block)
fmt.Printf("[YIREN-DEBUG] Received block response from peer %s, block height: %d\n", envelope.From, block.Height)
if err != nil {
r.logger.Error("failed to convert block from proto",
"peer", envelope.From,
Expand Down
6 changes: 6 additions & 0 deletions internal/state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,19 @@ func (blockExec *BlockExecutor) ApplyBlock(
defer commitSpan.End()
}
// Lock mempool, commit app state, update mempoool.
commitStart := time.Now()
retainHeight, err := blockExec.Commit(ctx, state, block, fBlockRes.TxResults)
if err != nil {
return state, fmt.Errorf("commit failed for application: %w", err)
}
if commitSpan != nil {
commitSpan.End()
}
if time.Since(commitStart) > 1000*time.Millisecond {
blockExec.logger.Info("commit in blockExec",
"duration", time.Since(commitStart),
"height", block.Height)
}

// Update evpool with the latest state.
blockExec.evpool.Update(ctx, state, block.Evidence)
Expand Down

0 comments on commit 9222988

Please sign in to comment.