Skip to content

Commit d3eecac

Browse files
authored
feat: update commitment variants (#15253)
* feat: update commitment variants * fix: make pretty * fix: deprecate, but leave in commitment types
1 parent 3bcae03 commit d3eecac

12 files changed

+132
-126
lines changed

module.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ declare module '@solana/web3.js' {
7777
};
7878

7979
export type Commitment =
80-
| 'max'
81-
| 'recent'
82-
| 'root'
83-
| 'single'
84-
| 'singleGossip';
80+
| 'processed'
81+
| 'confirmed'
82+
| 'finalized'
83+
| 'recent' // Deprecated as of v1.5.5
84+
| 'single' // Deprecated as of v1.5.5
85+
| 'singleGossip' // Deprecated as of v1.5.5
86+
| 'root' // Deprecated as of v1.5.5
87+
| 'max'; // Deprecated as of v1.5.5
8588

8689
export type LargestAccountsFilter = 'circulating' | 'nonCirculating';
8790

module.flow.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ declare module '@solana/web3.js' {
9090
};
9191

9292
declare export type Commitment =
93-
| 'max'
94-
| 'recent'
95-
| 'root'
96-
| 'single'
97-
| 'singleGossip';
93+
| 'processed'
94+
| 'confirmed'
95+
| 'finalized'
96+
| 'recent' // Deprecated as of v1.5.5
97+
| 'single' // Deprecated as of v1.5.5
98+
| 'singleGossip' // Deprecated as of v1.5.5
99+
| 'root' // Deprecated as of v1.5.5
100+
| 'max'; // Deprecated as of v1.5.5
98101

99102
declare export type LargestAccountsFilter = 'circulating' | 'nonCirculating';
100103

src/connection.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,22 @@ function notificationResultAndContext(resultDescription: any) {
145145
/**
146146
* The level of commitment desired when querying state
147147
* <pre>
148-
* 'max': Query the most recent block which has been finalized by the cluster
149-
* 'recent': Query the most recent block which has reached 1 confirmation by the connected node
150-
* 'root': Query the most recent block which has been rooted by the connected node
151-
* 'single': Query the most recent block which has reached 1 confirmation by the cluster
152-
* 'singleGossip': Query the most recent block which has reached 1 confirmation according to votes seen in gossip
148+
* 'processed': Query the most recent block which has reached 1 confirmation by the connected node
149+
* 'confirmed': Query the most recent block which has reached 1 confirmation by the cluster
150+
* 'finalized': Query the most recent block which has been finalized by the cluster
153151
* </pre>
154152
*
155-
* @typedef {'max' | 'recent' | 'root' | 'single' | 'singleGossip'} Commitment
153+
* @typedef {'processed' | 'confirmed' | 'finalized'} Commitment
156154
*/
157-
export type Commitment = 'max' | 'recent' | 'root' | 'single' | 'singleGossip';
155+
export type Commitment =
156+
| 'processed'
157+
| 'confirmed'
158+
| 'finalized'
159+
| 'recent' // Deprecated as of v1.5.5
160+
| 'single' // Deprecated as of v1.5.5
161+
| 'singleGossip' // Deprecated as of v1.5.5
162+
| 'root' // Deprecated as of v1.5.5
163+
| 'max'; // Deprecated as of v1.5.5
158164

159165
/**
160166
* Filter for largest accounts query
@@ -2291,13 +2297,16 @@ export class Connection {
22912297

22922298
let timeoutMs = 60 * 1000;
22932299
switch (subscriptionCommitment) {
2300+
case 'processed':
22942301
case 'recent':
22952302
case 'single':
2303+
case 'confirmed':
22962304
case 'singleGossip': {
22972305
timeoutMs = 30 * 1000;
22982306
break;
22992307
}
23002308
// exhaust enums to ensure full coverage
2309+
case 'finalized':
23012310
case 'max':
23022311
case 'root':
23032312
}
@@ -2876,7 +2885,7 @@ export class Connection {
28762885
try {
28772886
const startTime = Date.now();
28782887
for (let i = 0; i < 50; i++) {
2879-
const {blockhash} = await this.getRecentBlockhash('max');
2888+
const {blockhash} = await this.getRecentBlockhash('finalized');
28802889

28812890
if (this._blockhashInfo.recentBlockhash != blockhash) {
28822891
this._blockhashInfo = {

src/loader.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class Loader {
6868
// Fetch program account info to check if it has already been created
6969
const programInfo = await connection.getAccountInfo(
7070
program.publicKey,
71-
'singleGossip',
71+
'confirmed',
7272
);
7373

7474
let transaction: Transaction | null = null;
@@ -128,7 +128,7 @@ export class Loader {
128128
transaction,
129129
[payer, program],
130130
{
131-
commitment: 'singleGossip',
131+
commitment: 'confirmed',
132132
},
133133
);
134134
}
@@ -169,7 +169,7 @@ export class Loader {
169169
});
170170
transactions.push(
171171
sendAndConfirmTransaction(connection, transaction, [payer, program], {
172-
commitment: 'singleGossip',
172+
commitment: 'confirmed',
173173
}),
174174
);
175175

@@ -209,7 +209,7 @@ export class Loader {
209209
transaction,
210210
[payer, program],
211211
{
212-
commitment: 'singleGossip',
212+
commitment: 'confirmed',
213213
},
214214
);
215215
}

test/bpf-loader.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (process.env.TEST_LIVE) {
2222
it('load BPF C program', async () => {
2323
const data = await fs.readFile('test/fixtures/noop-c/noop.so');
2424

25-
const connection = new Connection(url, 'singleGossip');
25+
const connection = new Connection(url, 'confirmed');
2626
const {feeCalculator} = await connection.getRecentBlockhash();
2727
const fees =
2828
feeCalculator.lamportsPerSignature *
@@ -59,13 +59,13 @@ if (process.env.TEST_LIVE) {
5959
programId: program.publicKey,
6060
});
6161
await sendAndConfirmTransaction(connection, transaction, [from], {
62-
commitment: 'singleGossip',
63-
preflightCommitment: 'singleGossip',
62+
commitment: 'confirmed',
63+
preflightCommitment: 'confirmed',
6464
});
6565
}).timeout(5000);
6666

6767
describe('load BPF Rust program', () => {
68-
const connection = new Connection(url, 'singleGossip');
68+
const connection = new Connection(url, 'confirmed');
6969

7070
let program = new Account();
7171
let payerAccount = new Account();
@@ -141,8 +141,8 @@ if (process.env.TEST_LIVE) {
141141
transaction,
142142
[payerAccount],
143143
{
144-
commitment: 'max', // `getParsedConfirmedTransaction` requires max commitment
145-
preflightCommitment: connection.commitment || 'max',
144+
commitment: 'finalized', // `getParsedConfirmedTransaction` requires max commitment
145+
preflightCommitment: connection.commitment || 'finalized',
146146
},
147147
);
148148

0 commit comments

Comments
 (0)