Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 6 additions & 2 deletions ccip-sdk/src/api/api.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
)
}
})

Expand Down
9 changes: 2 additions & 7 deletions ccip-sdk/src/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import {
getBlockNumberAtOrAfter,
getDataBytes,
linkAbortSignals,
memoizeBlockInfo,
parseTypeAndVersion,
resolveTokenDecimals,
} from '../utils.ts'
Expand Down Expand Up @@ -494,13 +495,7 @@ export class EVMChain extends Chain<typeof ChainFamily.EVM> {
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
Expand Down
21 changes: 21 additions & 0 deletions ccip-sdk/src/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions ccip-sdk/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
Expand Down
8 changes: 8 additions & 0 deletions ccip-sdk/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ const SELECTORS: Selectors = {
selector: 15293031020466096408n,
name: 'lisk-mainnet',
network_type: 'MAINNET',
deprecated: true,
family: 'EVM',
},
'1284': {
Expand Down Expand Up @@ -815,6 +816,7 @@ const SELECTORS: Selectors = {
selector: 5298399861320400553n,
name: 'ethereum-testnet-sepolia-lisk-1',
network_type: 'TESTNET',
deprecated: true,
family: 'EVM',
},
'4217': {
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 2 additions & 6 deletions ccip-sdk/src/solana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ import {
getAddressBytes,
getDataBytes,
leToBigInt,
memoizeBlockInfo,
parseTypeAndVersion,
passesTypeAndVersion,
toLeArray,
Expand Down Expand Up @@ -278,12 +279,7 @@ export class SolanaChain extends Chain<typeof ChainFamily.Solana> {
// 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,
Expand Down
9 changes: 2 additions & 7 deletions ccip-sdk/src/ton/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
bytesToBuffer,
decodeAddress,
decodeOnRampAddress,
memoizeBlockInfo,
parseTypeAndVersion,
passesTypeAndVersion,
} from '../utils.ts'
Expand Down Expand Up @@ -251,13 +252,7 @@ export class TONChain extends Chain<typeof ChainFamily.TON> {
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,
Expand Down
57 changes: 57 additions & 0 deletions ccip-sdk/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
jsonStringify,
leToBigInt,
linkAbortSignals,
memoizeBlockInfo,
parseTypeAndVersion,
passesTypeAndVersion,
scaleDecimals,
Expand Down Expand Up @@ -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)
}
})
})
25 changes: 25 additions & 0 deletions ccip-sdk/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<B extends number | bigint | string, R>(
fn: (block: B) => Promise<R>,
): ((block: B) => Promise<R>) & { cache: Cache<(block: B) => Promise<R>> } {
const cached = memoize(fn, { async: true, maxArgs: 1, maxSize: 100, expires: 600e3 })
const memoized = (block: B): Promise<R> =>
(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
Expand Down
Loading