From ff8f3006011463957ba8eb86af94cbd1ec28e133 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Feb 2026 22:04:49 +0000 Subject: [PATCH] feat(chain): compute difficulty locally during P2P sync P2PSync now calls NextDifficulty() for each block instead of hardcoding difficulty=0. Co-Authored-By: Charon --- chain/p2psync.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/chain/p2psync.go b/chain/p2psync.go index 72cb8a8..a109824 100644 --- a/chain/p2psync.go +++ b/chain/p2psync.go @@ -116,9 +116,13 @@ func (c *Chain) P2PSync(ctx context.Context, conn P2PConnection, opts SyncOption log.Printf("p2p sync: processing block %d", blockHeight) } - // P2P path: difficulty=0 (TODO: compute from LWMA) + blockDiff, err := c.NextDifficulty(blockHeight) + if err != nil { + return fmt.Errorf("p2p sync: compute difficulty for block %d: %w", blockHeight, err) + } + if err := c.processBlockBlobs(entry.Block, entry.Txs, - blockHeight, 0, opts); err != nil { + blockHeight, blockDiff, opts); err != nil { return fmt.Errorf("p2p sync: process block %d: %w", blockHeight, err) } }