diff --git a/CHANGELOG.md b/CHANGELOG.md index 36589587..84f8cc33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- SDK (EVM): `getLogs` treats `maximum [from, to] blocks distance: N` (mova, JSON-RPC `-32000`) as a block-range error and pages with at most N blocks. Before, it failed every call with its default 10000-block page. A depth limit, such as `fromBlock is too far from the latest block`, is still not a range error, because a smaller page does not fix it +- SDK (EVM, Solana, TON): a failed `getBlockInfo` for a tag (`latest`, `finalized`) or a depth is no longer also an unhandled promise rejection. micro-memoize's `forceUpdate` cached a wrapper of each forced call that nothing read, and that wrapper rethrew the failure; after one successful call for a tag, every failed one leaked. `getBlockInfo` now caches only positive block numbers and calls the RPC for tags and depths, as before + ## [1.18.0] - 2026-11-20 - SDK: export `encodeAddressToAny` and `isCantonPartyId` from the package root. `encodeAddressToAny` encodes an address of any chain family the way CCIP messages carry it, e.g. a Canton party as `keccak256(partyId)`; `isCantonPartyId` checks the `hint::1220<64 hex>` party form it hashes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69d118b7..889ab366 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -844,9 +844,28 @@ Use `.check()` for custom validation with helpful error messages: 1. Run quality gates locally 1. Write tests for new functionality -1. Update CHANGELOG.md +1. Update `CHANGELOG.md` when the change needs it (see [Changelog entries](#changelog-entries)) 1. Keep commits focused and atomic +### Changelog entries + +Add a `CHANGELOG.md` entry only for important features and API changes that affect the main use cases of users. Do not add an entry for smaller methods or functions, even when the package exports them. + +Add an entry for: + +- A new feature or a new chain family. +- A change to the behavior, signature, or output of an existing public API. +- A breaking change or a deprecation that users must act on. +- A user-visible bug fix. + +Skip the entry for: + +- New helper methods, functions, or types that support an existing feature. +- Internal refactors with no behavior change. +- Changes to tests, docs, comments, or build tooling. + +Put the entry under `[Unreleased]` at the top of the file. Follow the format of the existing entries. + ## Signed commits Commits pushed to remote branches must be signed (the pre-push hook enforces it). diff --git a/ccip-sdk/src/api/api.integration.test.ts b/ccip-sdk/src/api/api.integration.test.ts index 93eddb59..d9688bf8 100644 --- a/ccip-sdk/src/api/api.integration.test.ts +++ b/ccip-sdk/src/api/api.integration.test.ts @@ -258,9 +258,13 @@ describe( { limit: 5 }, ) - // May have 0 results if no messages are currently ready for manual exec + // A verified message can be ready before its first execution attempt. for (const msg of page.data) { - assert.equal(msg.status, 'FAILED', 'Manual exec messages should have FAILED status') + assert.partialDeepStrictEqual( + msg, + { readyForManualExecution: true }, + `Message ${msg.messageId} should be ready for manual execution`, + ) } }) diff --git a/ccip-sdk/src/evm/index.ts b/ccip-sdk/src/evm/index.ts index 44ee582a..29a6d595 100644 --- a/ccip-sdk/src/evm/index.ts +++ b/ccip-sdk/src/evm/index.ts @@ -134,6 +134,7 @@ import { getBlockNumberAtOrAfter, getDataBytes, linkAbortSignals, + memoizeBlockInfo, parseTypeAndVersion, resolveTokenDecimals, } from '../utils.ts' @@ -494,13 +495,7 @@ export class EVMChain extends Chain { this.provider = provider destroyOnAbort(this.abort, this.provider) - const getBlockInfo = memoize(this.getBlockInfo.bind(this), { - async: true, - maxArgs: 1, - maxSize: 100, - expires: 600e3, - forceUpdate: ([k]) => (typeof k !== 'number' && typeof k !== 'bigint') || k <= 0, - }) + const getBlockInfo = memoizeBlockInfo(this.getBlockInfo.bind(this)) this.getBlockInfo = getBlockInfo /** ethers doesn't support logs' new `blockTimestamp` property; to workaround having to do diff --git a/ccip-sdk/src/fetch.test.ts b/ccip-sdk/src/fetch.test.ts index ffcc504f..9a65f6f6 100644 --- a/ccip-sdk/src/fetch.test.ts +++ b/ccip-sdk/src/fetch.test.ts @@ -382,6 +382,27 @@ describe('parseLogRangeError', () => { assert.ok(result !== null) }) + it('parses mova "maximum [from, to] blocks distance: 1000" wrapped by ethers', () => { + // ethers v6 wraps the RPC error it cannot coalesce; the limit is in .error.message + const err = Object.assign(new Error('could not coalesce error'), { + code: 'UNKNOWN_ERROR', + error: { code: -32000, message: 'maximum [from, to] blocks distance: 1000' }, + }) + assert.deepEqual(parseLogRangeError(err), { maxRange: 1000 }) + }) + + it('returns null for a depth limit ("fromBlock is too far from the latest block")', () => { + // jovay: the RPC serves only the last N blocks; a smaller page does not help + const err = { + error: { + code: -32000, + message: + 'PARAM_VERIFY_ERROR: fromBlock is too far from the latest block, maximum allowed distance is 100000 blocks', + }, + } + assert.equal(parseLogRangeError(err), null) + }) + it('handles JSON-RPC error code -32005', () => { const rpcErr = { code: -32005, message: 'block range is too large' } const result = parseLogRangeError(rpcErr) diff --git a/ccip-sdk/src/fetch.ts b/ccip-sdk/src/fetch.ts index 1b4879e7..9467cf11 100644 --- a/ccip-sdk/src/fetch.ts +++ b/ccip-sdk/src/fetch.ts @@ -1188,6 +1188,10 @@ export function parseLogRangeError(err: unknown): LogRangeErrorInfo | null { /limit exceeded/i, // some providers: "Cannot request logs over more than 100 blocks" /\bmore than (\d+) blocks?\b/i, + // mova (-32000): "maximum [from, to] blocks distance: 1000". It must not match a + // depth limit such as "fromBlock is too far from the latest block, maximum allowed + // distance is 100000 blocks": a smaller page does not fix that error. + /\bblocks?\s+distance\b\D*(\d+)/i, /too many (?:results|logs|blocks)/i, /response size exceeded/i, ] diff --git a/ccip-sdk/src/selectors.ts b/ccip-sdk/src/selectors.ts index 64df0299..f335d57d 100644 --- a/ccip-sdk/src/selectors.ts +++ b/ccip-sdk/src/selectors.ts @@ -533,6 +533,7 @@ const SELECTORS: Selectors = { selector: 15293031020466096408n, name: 'lisk-mainnet', network_type: 'MAINNET', + deprecated: true, family: 'EVM', }, '1284': { @@ -815,6 +816,7 @@ const SELECTORS: Selectors = { selector: 5298399861320400553n, name: 'ethereum-testnet-sepolia-lisk-1', network_type: 'TESTNET', + deprecated: true, family: 'EVM', }, '4217': { @@ -1782,6 +1784,12 @@ const SELECTORS: Selectors = { network_type: 'MAINNET', family: 'EVM', }, + '2026110701': { + selector: 16138070312089718605n, + name: 'private-testnet-lignite', + network_type: 'TESTNET', + family: 'EVM', + }, '2494104990': { selector: 13231703482326770598n, name: 'tron-testnet-shasta-evm', diff --git a/ccip-sdk/src/solana/index.ts b/ccip-sdk/src/solana/index.ts index 793cdf8d..79c5611b 100644 --- a/ccip-sdk/src/solana/index.ts +++ b/ccip-sdk/src/solana/index.ts @@ -111,6 +111,7 @@ import { getAddressBytes, getDataBytes, leToBigInt, + memoizeBlockInfo, parseTypeAndVersion, passesTypeAndVersion, toLeArray, @@ -278,12 +279,7 @@ export class SolanaChain extends Chain { // cache whole signature lists per address (up to 30min), to speed up consecutive // paginations over the same address this.connection.getSignaturesForAddress = cacheGetSignaturesForAddress(this.connection) - this.getBlockInfo = memoize(this.getBlockInfo.bind(this), { - async: true, - maxSize: 100, - expires: 600e3, - forceUpdate: ([k]) => typeof k !== 'number' || k <= 0, - }) + this.getBlockInfo = memoizeBlockInfo(this.getBlockInfo.bind(this)) this.getTransaction = memoize(this.getTransaction.bind(this), { async: true, maxArgs: 1, diff --git a/ccip-sdk/src/ton/index.ts b/ccip-sdk/src/ton/index.ts index d68cbdb5..51b56943 100644 --- a/ccip-sdk/src/ton/index.ts +++ b/ccip-sdk/src/ton/index.ts @@ -59,6 +59,7 @@ import { bytesToBuffer, decodeAddress, decodeOnRampAddress, + memoizeBlockInfo, parseTypeAndVersion, passesTypeAndVersion, } from '../utils.ts' @@ -251,13 +252,7 @@ export class TONChain extends Chain { expires: 5e3, }) - this.getBlockInfo = memoize(this.getBlockInfo.bind(this), { - async: true, - maxArgs: 1, - maxSize: 100, - expires: 600e3, - forceUpdate: ([k]) => (typeof k !== 'number' && typeof k !== 'bigint') || k <= 0, - }) + this.getBlockInfo = memoizeBlockInfo(this.getBlockInfo.bind(this)) this.typeAndVersion = memoize(this.typeAndVersion.bind(this), { maxArgs: 1, diff --git a/ccip-sdk/src/utils.test.ts b/ccip-sdk/src/utils.test.ts index fc9080af..a5b0f3db 100644 --- a/ccip-sdk/src/utils.test.ts +++ b/ccip-sdk/src/utils.test.ts @@ -26,6 +26,7 @@ import { jsonStringify, leToBigInt, linkAbortSignals, + memoizeBlockInfo, parseTypeAndVersion, passesTypeAndVersion, scaleDecimals, @@ -1683,3 +1684,59 @@ describe('sleep abort hygiene', () => { assert.equal(getEventListeners(controller.signal, 'abort').length, 0) }) }) + +describe('memoizeBlockInfo', () => { + type Block = number | bigint | 'latest' | 'finalized' + const fake = () => { + const calls: Block[] = [] + const state = { fail: false } + const fn = (block: Block) => { + calls.push(block) + if (state.fail) return Promise.reject(new Error('503 Service Unavailable')) + const number = typeof block === 'string' ? 100 : Number(block) + return Promise.resolve({ number, timestamp: number * 10 }) + } + return { calls, fn, state } + } + + it('caches a positive block number, and calls fn for every tag or depth', async () => { + const { calls, fn } = fake() + const getBlockInfo = memoizeBlockInfo(fn) + assert.deepEqual(await getBlockInfo(5), { number: 5, timestamp: 50 }) + await getBlockInfo(5) + await getBlockInfo(5n) + await getBlockInfo('latest') + await getBlockInfo('latest') + await getBlockInfo(-3) + await getBlockInfo(-3) + assert.deepEqual(calls, [5, 5n, 'latest', 'latest', -3, -3]) + }) + + it('serves a seeded positive block from .cache', async () => { + const { calls, fn } = fake() + const getBlockInfo = memoizeBlockInfo(fn) + getBlockInfo.cache.set([7], Promise.resolve({ number: 7, timestamp: 1 })) + assert.deepEqual(await getBlockInfo(7), { number: 7, timestamp: 1 }) + assert.deepEqual(calls, []) + }) + + it('a failed tag call rejects only to its caller (no unhandled rejection)', async () => { + const { fn, state } = fake() + const getBlockInfo = memoizeBlockInfo(fn) + const unhandled: unknown[] = [] + const onUnhandled = (reason: unknown) => unhandled.push(reason) + process.on('unhandledRejection', onUnhandled) + try { + // With micro-memoize's forceUpdate, a success cached the tag; the next, + // failed call went through the forced path and left an unread cached + // wrapper that rejected unhandled. + await getBlockInfo('latest') + state.fail = true + await assert.rejects(getBlockInfo('latest'), /503/) + await new Promise((resolve) => setImmediate(resolve)) + assert.deepEqual(unhandled, []) + } finally { + process.off('unhandledRejection', onUnhandled) + } + }) +}) diff --git a/ccip-sdk/src/utils.ts b/ccip-sdk/src/utils.ts index 84071a42..82957aac 100644 --- a/ccip-sdk/src/utils.ts +++ b/ccip-sdk/src/utils.ts @@ -12,6 +12,7 @@ import { toBeArray, toBigInt, } from 'ethers' +import { type Cache, memoize } from 'micro-memoize' import yaml from 'yaml' // Re-export the codec helpers moved to ./shared/codec.ts (kept here for back-compat; @@ -503,6 +504,30 @@ export function convertKeysToCamelCase( return converted } +/** + * Memoizes a chain's `getBlockInfo`: a positive block number is cached (10 min, + * 100 entries); a tag (`latest`, `finalized`, …) or a depth (`<= 0`) always calls `fn`. + * + * It does not use micro-memoize's `forceUpdate` for the uncached calls: a forced call + * caches a wrapper of the new promise that nothing reads (forced keys are never read + * from the cache) and returns the unwrapped promise. The wrapper rethrows a rejection, + * so every failed `getBlockInfo('latest')` was also an unhandled rejection. + * + * @param fn - The chain's own (unmemoized, bound) `getBlockInfo`. + * @returns `fn` with the cache in front of the positive block numbers; `.cache` is the + * cache of those, so a caller can seed it. + */ +export function memoizeBlockInfo( + fn: (block: B) => Promise, +): ((block: B) => Promise) & { cache: Cache<(block: B) => Promise> } { + const cached = memoize(fn, { async: true, maxArgs: 1, maxSize: 100, expires: 600e3 }) + const memoized = (block: B): Promise => + (typeof block === 'number' || typeof block === 'bigint') && block > 0 + ? cached(block) + : fn(block) + return Object.assign(memoized, { cache: cached.cache }) +} + /** * Promise-based sleep utility. * Plain timer + explicit listener detach: allocates no AbortSignal.timeout/any