diff --git a/web3.js/module.d.ts b/web3.js/module.d.ts index 40e5d2ac0e..e4c76f67c7 100644 --- a/web3.js/module.d.ts +++ b/web3.js/module.d.ts @@ -46,7 +46,7 @@ declare module '@solana/web3.js' { value: T; }; - export type Commitment = 'max' | 'recent'; + export type Commitment = 'max' | 'recent' | 'root' | 'single'; export type SignatureStatusConfig = { searchTransactionHistory: boolean; diff --git a/web3.js/module.flow.js b/web3.js/module.flow.js index 80b8405399..4f34bd617f 100644 --- a/web3.js/module.flow.js +++ b/web3.js/module.flow.js @@ -59,7 +59,7 @@ declare module '@solana/web3.js' { value: T, }; - declare export type Commitment = 'max' | 'recent'; + declare export type Commitment = 'max' | 'recent' | 'root' | 'single'; declare export type SignatureStatusConfig = { searchTransactionHistory: boolean, diff --git a/web3.js/src/connection.js b/web3.js/src/connection.js index bfedc9efff..ee681ea576 100644 --- a/web3.js/src/connection.js +++ b/web3.js/src/connection.js @@ -89,12 +89,16 @@ function notificationResultAndContext(resultDescription: any) { /** * The level of commitment desired when querying state - * 'max': Query the most recent block which has reached max voter lockout - * 'recent': Query the most recent block + *
+ * 'max': Query the most recent block which has been finalized by the cluster + * 'recent': Query the most recent block which has reached 1 confirmation by the connected node + * 'root': Query the most recent block which has been rooted by the connected node + * 'single': Query the most recent block which has reached 1 confirmation by the cluster + ** - * @typedef {'max' | 'recent'} Commitment + * @typedef {'max' | 'recent' | 'root' | 'single'} Commitment */ -export type Commitment = 'max' | 'recent'; +export type Commitment = 'max' | 'recent' | 'root' | 'single'; /** * Configuration object for changing query behavior diff --git a/web3.js/test/connection.test.js b/web3.js/test/connection.test.js index 021eb798b1..c96479d907 100644 --- a/web3.js/test/connection.test.js +++ b/web3.js/test/connection.test.js @@ -1031,12 +1031,15 @@ test('get confirmed block', async () => { test('get recent blockhash', async () => { const connection = new Connection(url); + for (const commitment of ['max', 'recent', 'root', 'single']) { + mockGetRecentBlockhash(commitment); - mockGetRecentBlockhash(); - - const {blockhash, feeCalculator} = await connection.getRecentBlockhash(); - expect(blockhash.length).toBeGreaterThanOrEqual(43); - expect(feeCalculator.lamportsPerSignature).toBeGreaterThanOrEqual(0); + const {blockhash, feeCalculator} = await connection.getRecentBlockhash( + commitment, + ); + expect(blockhash.length).toBeGreaterThanOrEqual(43); + expect(feeCalculator.lamportsPerSignature).toBeGreaterThanOrEqual(0); + } }); test('get block time', async () => {