Polygon
准备好在生产环境中调用了吗?
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Polygon
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
A chain reorganization is when Polygon discards a block (or a short run of blocks) it had at the tip and replaces it with a different one, so a block your application already saw is no longer part of the canonical chain. On Polygon PoS this happens because Bor validators occasionally produce competing blocks at the same height and, with ~2-second blocks propagating across a global validator set, nodes can briefly disagree on the head before converging. Reorgs here are shallow — usually a block or two deep — and routine rather than alarming, but they are real until a Heimdall checkpoint anchors the chain to Ethereum L1. If your code treats the latest block as permanent, a reorg silently corrupts state: a credited deposit gets undone, an event you reacted to never happened, balances disagree with PolygonScan. That is why any service reading chain 137 from https://polygon.therpc.io/YOUR_API_KEY must detect reorgs and recover from them.
parentHash does not match the hash of the block you recorded as its parent, the chain reorganized — exactly what the monitorReorgs example watches for.monitorReorgs example) so a changed hash at a known height flags a reorg. In a subscription system, verify each newBlockHeaders event's parentHash against your last recorded hash and trigger recovery on a mismatch. Either way, key your bookkeeping on hash, not number.findCommonAncestor to locate where the chains diverge, roll back all state derived from the orphaned blocks above that ancestor, then re-process the canonical blocks forward. Because Polygon reorgs are shallow, this rollback typically spans only a block or two.parentHash the instant the new head arrives within Polygon's ~2s window. Fall back to polling when you need a simpler, connection-resilient setup or when a subscription is unavailable; combine both for defense in depth on chain 137.