feat(chain): compute difficulty locally during P2P sync

P2PSync now calls NextDifficulty() for each block instead of
hardcoding difficulty=0.

Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
Claude 2026-02-21 22:04:49 +00:00
parent d456b8be9b
commit ff8f300601
No known key found for this signature in database
GPG key ID: AF404715446AEB41

View file

@ -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)
}
}