@helium/spl-utils 0.0.26 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/tpuClient.js +410 -0
- package/lib/cjs/tpuClient.js.map +1 -0
- package/lib/cjs/transaction.js +150 -3
- package/lib/cjs/transaction.js.map +1 -1
- package/lib/esm/src/tpuClient.js +397 -0
- package/lib/esm/src/tpuClient.js.map +1 -0
- package/lib/esm/src/transaction.js +122 -2
- package/lib/esm/src/transaction.js.map +1 -1
- package/lib/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/src/tpuClient.d.ts +153 -0
- package/lib/types/src/tpuClient.d.ts.map +1 -0
- package/lib/types/src/transaction.d.ts +9 -1
- package/lib/types/src/transaction.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TpuConnection = exports.LeaderTpuService = exports.TpuClient = exports.RecentLeaderSlots = exports.MAX_FANOUT_SLOTS = exports.DEFAULT_FANOUT_SLOTS = exports.MAX_SLOT_SKIP_DISTANCE = exports.LeaderTpuCache = void 0;
|
|
16
|
+
// Taken from https://raw.githubusercontent.com/lmvdz/tpu-client/main/src/index.ts bec of supply chain risk
|
|
17
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
+
const denque_1 = __importDefault(require("denque"));
|
|
19
|
+
const dgram_1 = __importDefault(require("dgram"));
|
|
20
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
21
|
+
class LeaderTpuCache {
|
|
22
|
+
constructor(connection, startSlot) {
|
|
23
|
+
this.connection = connection;
|
|
24
|
+
this.first_slot = startSlot;
|
|
25
|
+
}
|
|
26
|
+
static load(connection, startSlot) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
const leaderTpuCache = new LeaderTpuCache(connection, startSlot);
|
|
29
|
+
leaderTpuCache.connection.getEpochInfo().then((epochInfo) => {
|
|
30
|
+
leaderTpuCache.slots_in_epoch = epochInfo.slotsInEpoch;
|
|
31
|
+
leaderTpuCache
|
|
32
|
+
.fetchSlotLeaders(leaderTpuCache.first_slot, leaderTpuCache.slots_in_epoch)
|
|
33
|
+
.then((leaders) => {
|
|
34
|
+
leaderTpuCache.leaders = leaders;
|
|
35
|
+
leaderTpuCache.fetchClusterTpuSockets().then((leaderTpuMap) => {
|
|
36
|
+
leaderTpuCache.leaderTpuMap = leaderTpuMap;
|
|
37
|
+
resolve(leaderTpuCache);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
fetchClusterTpuSockets() {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const map = new Map();
|
|
46
|
+
this.connection
|
|
47
|
+
.getClusterNodes()
|
|
48
|
+
.then((contactInfo) => {
|
|
49
|
+
contactInfo.forEach((contactInfo) => {
|
|
50
|
+
map.set(contactInfo.pubkey, contactInfo.tpu);
|
|
51
|
+
});
|
|
52
|
+
resolve(map);
|
|
53
|
+
})
|
|
54
|
+
.catch((error) => {
|
|
55
|
+
reject(error);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
fetchSlotLeaders(start_slot, slots_in_epoch) {
|
|
60
|
+
const fanout = Math.min(2 * exports.MAX_FANOUT_SLOTS, slots_in_epoch);
|
|
61
|
+
return this.connection.getSlotLeaders(start_slot, fanout);
|
|
62
|
+
}
|
|
63
|
+
lastSlot() {
|
|
64
|
+
return this.first_slot + this.leaders.length - 1;
|
|
65
|
+
}
|
|
66
|
+
getSlotLeader(slot) {
|
|
67
|
+
if (slot >= this.first_slot) {
|
|
68
|
+
const index = slot - this.first_slot;
|
|
69
|
+
return this.leaders[index];
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
getLeaderSockets(fanout_slots) {
|
|
76
|
+
return new Promise((resolve) => {
|
|
77
|
+
const leaderSet = new Set();
|
|
78
|
+
const leaderSockets = new Array();
|
|
79
|
+
let checkedSlots = 0;
|
|
80
|
+
this.leaders.forEach((leader) => {
|
|
81
|
+
const tpu_socket = this.leaderTpuMap.get(leader.toBase58());
|
|
82
|
+
if (tpu_socket !== undefined && tpu_socket !== null) {
|
|
83
|
+
if (!leaderSet.has(leader.toBase58())) {
|
|
84
|
+
leaderSet.add(leader.toBase58());
|
|
85
|
+
leaderSockets.push(tpu_socket);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
console.log("TPU not available for leader: ", leader.toBase58());
|
|
90
|
+
}
|
|
91
|
+
checkedSlots++;
|
|
92
|
+
if (checkedSlots === fanout_slots) {
|
|
93
|
+
resolve(leaderSockets);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.LeaderTpuCache = LeaderTpuCache;
|
|
100
|
+
exports.MAX_SLOT_SKIP_DISTANCE = 48;
|
|
101
|
+
exports.DEFAULT_FANOUT_SLOTS = 12;
|
|
102
|
+
exports.MAX_FANOUT_SLOTS = 100;
|
|
103
|
+
class RecentLeaderSlots {
|
|
104
|
+
//@ts-check
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param current_slot {number}
|
|
108
|
+
*/
|
|
109
|
+
constructor(current_slot) {
|
|
110
|
+
this.recent_slots = new denque_1.default();
|
|
111
|
+
this.recent_slots.push(current_slot);
|
|
112
|
+
}
|
|
113
|
+
//@ts-check
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* @param current_slot {number}
|
|
117
|
+
*/
|
|
118
|
+
recordSlot(current_slot) {
|
|
119
|
+
this.recent_slots.push(current_slot);
|
|
120
|
+
while (this.recent_slots.length > 12) {
|
|
121
|
+
this.recent_slots.pop();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//@ts-check
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @returns {number}
|
|
128
|
+
*/
|
|
129
|
+
estimatedCurrentSlot() {
|
|
130
|
+
if (this.recent_slots.isEmpty()) {
|
|
131
|
+
throw new Error("recent slots is empty");
|
|
132
|
+
}
|
|
133
|
+
const sortedRecentSlots = this.recent_slots.toArray().sort((a, b) => a - b);
|
|
134
|
+
const max_index = sortedRecentSlots.length - 1;
|
|
135
|
+
const median_index = max_index / 2;
|
|
136
|
+
const median_recent_slot = sortedRecentSlots[median_index];
|
|
137
|
+
const expected_current_slot = median_recent_slot + (max_index - median_index);
|
|
138
|
+
const max_reasonable_current_slot = expected_current_slot + exports.MAX_SLOT_SKIP_DISTANCE;
|
|
139
|
+
return sortedRecentSlots
|
|
140
|
+
.reverse()
|
|
141
|
+
.find((slot) => slot <= max_reasonable_current_slot);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.RecentLeaderSlots = RecentLeaderSlots;
|
|
145
|
+
class TpuClient {
|
|
146
|
+
//@ts-check
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* @param connection {Connection}
|
|
150
|
+
* @param config {TpuClientConfig}
|
|
151
|
+
*/
|
|
152
|
+
constructor(connection, config = { fanoutSlots: exports.DEFAULT_FANOUT_SLOTS }) {
|
|
153
|
+
this.connection = connection;
|
|
154
|
+
this.exit = false;
|
|
155
|
+
this.sendSocket = dgram_1.default.createSocket("udp4");
|
|
156
|
+
this.fanoutSlots = Math.max(Math.min(config.fanoutSlots, exports.MAX_FANOUT_SLOTS), 1);
|
|
157
|
+
}
|
|
158
|
+
//@ts-check
|
|
159
|
+
/**
|
|
160
|
+
*
|
|
161
|
+
* @param connection {Connection}
|
|
162
|
+
* @param websocketUrl {string}
|
|
163
|
+
* @param config {TpuClientConfig}
|
|
164
|
+
* @returns {Promise<TpuClient>}
|
|
165
|
+
*/
|
|
166
|
+
static load(connection, websocketUrl = "", config = { fanoutSlots: exports.DEFAULT_FANOUT_SLOTS }) {
|
|
167
|
+
return new Promise((resolve) => {
|
|
168
|
+
const tpuClient = new TpuClient(connection, config);
|
|
169
|
+
LeaderTpuService.load(tpuClient.connection, websocketUrl).then((leaderTpuService) => {
|
|
170
|
+
tpuClient.leaderTpuService = leaderTpuService;
|
|
171
|
+
resolve(tpuClient);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
//@ts-check
|
|
176
|
+
/**
|
|
177
|
+
*
|
|
178
|
+
* @param transaction {Transaction}
|
|
179
|
+
* @param signers {Array<Signer>}
|
|
180
|
+
* @returns {Promise<string>}
|
|
181
|
+
*/
|
|
182
|
+
sendTransaction(transaction, signers) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
if (transaction.nonceInfo) {
|
|
185
|
+
transaction.sign(...signers);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
transaction.recentBlockhash = (yield this.connection.getRecentBlockhash()).blockhash;
|
|
189
|
+
transaction.sign(...signers);
|
|
190
|
+
}
|
|
191
|
+
const rawTransaction = transaction.serialize();
|
|
192
|
+
return this.sendRawTransaction(rawTransaction);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
//@ts-check
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* @param rawTransaction {Buffer | number[] | Uint8ARray}
|
|
199
|
+
* @returns {Promise<string>}
|
|
200
|
+
*/
|
|
201
|
+
sendRawTransaction(rawTransaction) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
return new Promise((resolve, reject) => {
|
|
204
|
+
this.leaderTpuService
|
|
205
|
+
.leaderTpuSockets(this.fanoutSlots)
|
|
206
|
+
.then((tpu_addresses) => {
|
|
207
|
+
tpu_addresses.forEach((tpu_address) => {
|
|
208
|
+
this.sendSocket.send(rawTransaction, parseInt(tpu_address.split(":")[1]), tpu_address.split(":")[0], (error) => {
|
|
209
|
+
if (!error) {
|
|
210
|
+
const message = web3_js_1.Transaction.from(rawTransaction);
|
|
211
|
+
resolve(bs58_1.default.encode(message.signature));
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
console.error(error);
|
|
215
|
+
reject(error);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
exports.TpuClient = TpuClient;
|
|
225
|
+
class LeaderTpuService {
|
|
226
|
+
//@ts-check
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
* @param connection {Connection}
|
|
230
|
+
*/
|
|
231
|
+
constructor(connection) {
|
|
232
|
+
this.connection = connection;
|
|
233
|
+
}
|
|
234
|
+
//@ts-check
|
|
235
|
+
/**
|
|
236
|
+
*
|
|
237
|
+
* @param connection {Connection}
|
|
238
|
+
* @param websocket_url {string}
|
|
239
|
+
* @returns {Promise<LeaderTpuService}
|
|
240
|
+
*/
|
|
241
|
+
static load(connection, websocket_url = "") {
|
|
242
|
+
return new Promise((resolve) => {
|
|
243
|
+
const leaderTpuService = new LeaderTpuService(connection);
|
|
244
|
+
leaderTpuService.connection.getSlot("processed").then((start_slot) => {
|
|
245
|
+
leaderTpuService.recentSlots = new RecentLeaderSlots(start_slot);
|
|
246
|
+
LeaderTpuCache.load(connection, start_slot).then((leaderTpuCache) => {
|
|
247
|
+
leaderTpuService.leaderTpuCache = leaderTpuCache;
|
|
248
|
+
if (websocket_url !== "") {
|
|
249
|
+
leaderTpuService.subscription = connection.onSlotUpdate((slotUpdate) => {
|
|
250
|
+
if (slotUpdate.type === "completed") {
|
|
251
|
+
slotUpdate.slot++;
|
|
252
|
+
}
|
|
253
|
+
leaderTpuService.recentSlots.recordSlot(slotUpdate.slot);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
leaderTpuService.subscription = null;
|
|
258
|
+
}
|
|
259
|
+
leaderTpuService.run();
|
|
260
|
+
resolve(leaderTpuService);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
//@ts-check
|
|
266
|
+
/**
|
|
267
|
+
*
|
|
268
|
+
* @param fanout_slots {number}
|
|
269
|
+
* @returns {Promise<string[]>}
|
|
270
|
+
*/
|
|
271
|
+
leaderTpuSockets(fanout_slots) {
|
|
272
|
+
return this.leaderTpuCache.getLeaderSockets(fanout_slots);
|
|
273
|
+
}
|
|
274
|
+
//@ts-check
|
|
275
|
+
/**
|
|
276
|
+
* @returns {void}
|
|
277
|
+
*/
|
|
278
|
+
run() {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
const last_cluster_refresh = Date.now();
|
|
281
|
+
let sleep_ms = 1000;
|
|
282
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
sleep_ms = 1000;
|
|
284
|
+
if (Date.now() - last_cluster_refresh > 1000 * 5 * 60) {
|
|
285
|
+
try {
|
|
286
|
+
this.leaderTpuCache.leaderTpuMap =
|
|
287
|
+
yield this.leaderTpuCache.fetchClusterTpuSockets();
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
console.warn("Failed to fetch cluster tpu sockets", error);
|
|
291
|
+
sleep_ms = 1000;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const estimatedCurrentSlot = this.recentSlots.estimatedCurrentSlot();
|
|
295
|
+
if (estimatedCurrentSlot >=
|
|
296
|
+
this.leaderTpuCache.last_epoch_info_slot -
|
|
297
|
+
this.leaderTpuCache.slots_in_epoch) {
|
|
298
|
+
try {
|
|
299
|
+
const epochInfo = yield this.connection.getEpochInfo("recent");
|
|
300
|
+
this.leaderTpuCache.slots_in_epoch = epochInfo.slotsInEpoch;
|
|
301
|
+
this.leaderTpuCache.last_epoch_info_slot = estimatedCurrentSlot;
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
console.warn("failed to get epoch info");
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (estimatedCurrentSlot >=
|
|
308
|
+
this.leaderTpuCache.lastSlot() - exports.MAX_FANOUT_SLOTS) {
|
|
309
|
+
try {
|
|
310
|
+
const slot_leaders = yield this.leaderTpuCache.fetchSlotLeaders(estimatedCurrentSlot, this.leaderTpuCache.slots_in_epoch);
|
|
311
|
+
this.leaderTpuCache.first_slot = estimatedCurrentSlot;
|
|
312
|
+
this.leaderTpuCache.leaders = slot_leaders;
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
console.warn(`Failed to fetch slot leaders (current estimated slot: ${estimatedCurrentSlot})`, error);
|
|
316
|
+
sleep_ms = 1000;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
this.run();
|
|
320
|
+
}), sleep_ms);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
exports.LeaderTpuService = LeaderTpuService;
|
|
325
|
+
class TpuConnection extends web3_js_1.Connection {
|
|
326
|
+
//@ts-check
|
|
327
|
+
/**
|
|
328
|
+
*
|
|
329
|
+
* @param endpoint {string}
|
|
330
|
+
* @param commitmentOrConfig {Commitment | ConnectionConfig}
|
|
331
|
+
*/
|
|
332
|
+
constructor(endpoint, commitmentOrConfig) {
|
|
333
|
+
super(endpoint, commitmentOrConfig);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
*
|
|
337
|
+
* @param transaction {Transaction}
|
|
338
|
+
* @param signers {Array<Signer>}
|
|
339
|
+
* @returns {Promise<string>}
|
|
340
|
+
*/
|
|
341
|
+
//@ts-ignore
|
|
342
|
+
sendTransaction(transaction, signers) {
|
|
343
|
+
return this.tpuClient.sendTransaction(transaction, signers);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
*
|
|
347
|
+
* @param rawTransaction {Buffer | Array<number> | Uint8Array}
|
|
348
|
+
* @returns {Promise<string>}
|
|
349
|
+
*/
|
|
350
|
+
//@ts-ignore
|
|
351
|
+
sendRawTransaction(rawTransaction) {
|
|
352
|
+
return this.tpuClient.sendRawTransaction(rawTransaction);
|
|
353
|
+
}
|
|
354
|
+
///@ts-check
|
|
355
|
+
/**
|
|
356
|
+
*
|
|
357
|
+
* @param connection {TpuConnection}
|
|
358
|
+
* @param transaction {Transaction}
|
|
359
|
+
* @param signers {Array<Signer>}
|
|
360
|
+
* @param options {ConfirmOptions}
|
|
361
|
+
* @returns {Promise<TransactionSignature>}
|
|
362
|
+
*/
|
|
363
|
+
sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
364
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
365
|
+
const signature = yield this.sendTransaction(transaction, signers);
|
|
366
|
+
const status = (yield connection.confirmTransaction(signature, options.commitment)).value;
|
|
367
|
+
if (status.err) {
|
|
368
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
369
|
+
}
|
|
370
|
+
return signature;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
//@ts-check
|
|
374
|
+
/**
|
|
375
|
+
*
|
|
376
|
+
* @param connection {TpuConnection}
|
|
377
|
+
* @param rawTransaction {Buffer | Array<number> | Uint8Array}
|
|
378
|
+
* @param options {ConfirmOptions}
|
|
379
|
+
* @returns {Promise<string>}
|
|
380
|
+
*/
|
|
381
|
+
sendAndConfirmRawTransaction(connection, rawTransaction, options) {
|
|
382
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
383
|
+
const signature = yield this.sendRawTransaction(rawTransaction);
|
|
384
|
+
const status = (yield connection.confirmTransaction(signature, options.commitment)).value;
|
|
385
|
+
if (status.err) {
|
|
386
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
387
|
+
}
|
|
388
|
+
return signature;
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
//@ts-check
|
|
392
|
+
/**
|
|
393
|
+
*
|
|
394
|
+
* @param endpoint {string}
|
|
395
|
+
* @param commitmentOrConfig {Commitment | ConnectionConfig}
|
|
396
|
+
* @returns {Promise<TpuConnection>}
|
|
397
|
+
*/
|
|
398
|
+
static load(endpoint, commitmentOrConfig) {
|
|
399
|
+
return new Promise((resolve) => {
|
|
400
|
+
const tpuConnection = new TpuConnection(endpoint, commitmentOrConfig);
|
|
401
|
+
//@ts-ignore
|
|
402
|
+
TpuClient.load(tpuConnection).then((tpuClient) => {
|
|
403
|
+
tpuConnection.tpuClient = tpuClient;
|
|
404
|
+
resolve(tpuConnection);
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
exports.TpuConnection = TpuConnection;
|
|
410
|
+
//# sourceMappingURL=TpuClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TpuClient.js","sourceRoot":"","sources":["../../src/TpuClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2GAA2G;AAC3G,6CASyB;AACzB,oDAA2C;AAC3C,kDAA0B;AAC1B,gDAAwB;AAExB,MAAa,cAAc;IAOzB,YAAoB,UAAsB,EAAE,SAAiB;QA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,EAAE,kBAAkB,CAAC,CAAC;YACtE,YAAY;YACZ,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;gBAC/C,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;gBACpC,OAAO,CAAC,aAAa,CAAC,CAAC;YACzB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlHD,sCAkHC"}
|
package/lib/cjs/transaction.js
CHANGED
|
@@ -8,9 +8,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
11
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.bufferToTransaction = exports.stringToTransaction = exports.sendAndConfirmWithRetry = exports.awaitTransactionSignatureConfirmation = exports.executeBig = exports.execute = exports.sendMultipleInstructions = exports.sendInstructions = void 0;
|
|
26
|
+
exports.bulkSendRawTransactions = exports.bulkSendTransactions = exports.bufferToTransaction = exports.stringToTransaction = exports.sendAndConfirmWithRetry = exports.awaitTransactionSignatureConfirmation = exports.executeBig = exports.execute = exports.sendMultipleInstructions = exports.sendInstructions = void 0;
|
|
13
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
|
+
const accountFetchCache_1 = require("./accountFetchCache");
|
|
29
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
14
30
|
const anchorError_1 = require("./anchorError");
|
|
15
31
|
function sleep(ms) {
|
|
16
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -32,7 +48,7 @@ function sendInstructions(provider, instructions, signers = [], payer = provider
|
|
|
32
48
|
return "";
|
|
33
49
|
}
|
|
34
50
|
let tx = new web3_js_1.Transaction();
|
|
35
|
-
tx.recentBlockhash = (yield provider.connection.
|
|
51
|
+
tx.recentBlockhash = (yield provider.connection.getLatestBlockhash()).blockhash;
|
|
36
52
|
tx.feePayer = payer || provider.wallet.publicKey;
|
|
37
53
|
tx.add(...instructions);
|
|
38
54
|
if (signers.length > 0) {
|
|
@@ -61,7 +77,7 @@ function truthy(value) {
|
|
|
61
77
|
}
|
|
62
78
|
function sendMultipleInstructions(provider, instructionGroups, signerGroups, payer, finality = "confirmed", idlErrors = new Map()) {
|
|
63
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const recentBlockhash = (yield provider.connection.
|
|
80
|
+
const recentBlockhash = (yield provider.connection.getLatestBlockhash("confirmed")).blockhash;
|
|
65
81
|
const ixAndSigners = instructionGroups
|
|
66
82
|
.map((instructions, i) => {
|
|
67
83
|
const signers = signerGroups[i];
|
|
@@ -143,6 +159,7 @@ exports.executeBig = executeBig;
|
|
|
143
159
|
function getUnixTime() {
|
|
144
160
|
return new Date().valueOf() / 1000;
|
|
145
161
|
}
|
|
162
|
+
const SEND_TRANSACTION_INTERVAL = 10;
|
|
146
163
|
const awaitTransactionSignatureConfirmation = (txid, timeout, connection, commitment = "recent", queryStatus = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
164
|
let done = false;
|
|
148
165
|
let status = {
|
|
@@ -319,4 +336,134 @@ function bufferToTransaction(solanaTransaction) {
|
|
|
319
336
|
return web3_js_1.Transaction.from(solanaTransaction);
|
|
320
337
|
}
|
|
321
338
|
exports.bufferToTransaction = bufferToTransaction;
|
|
339
|
+
function withRetries(tries, input) {
|
|
340
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
341
|
+
for (let i = 0; i < tries; i++) {
|
|
342
|
+
try {
|
|
343
|
+
return yield input();
|
|
344
|
+
}
|
|
345
|
+
catch (e) {
|
|
346
|
+
console.log(`Retrying ${i}...`, e);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
throw new Error("Failed after retries");
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const TX_BATCH_SIZE = 200;
|
|
353
|
+
function bulkSendTransactions(provider, txs, onProgress, triesRemaining = 5 // Number of blockhashes to try resending txs with before giving up
|
|
354
|
+
) {
|
|
355
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
let ret = [];
|
|
357
|
+
// attempt to chunk by blockhash bounds (so signing doesn't take too long)
|
|
358
|
+
for (let chunk of (0, accountFetchCache_1.chunks)(txs, TX_BATCH_SIZE)) {
|
|
359
|
+
const thisRet = [];
|
|
360
|
+
// Continually send in bulk while resetting blockhash until we send them all
|
|
361
|
+
while (true) {
|
|
362
|
+
const recentBlockhash = yield withRetries(5, () => provider.connection.getLatestBlockhash("confirmed"));
|
|
363
|
+
const signedTxs = yield Promise.all(chunk.map((tx) => __awaiter(this, void 0, void 0, function* () {
|
|
364
|
+
tx.recentBlockhash = recentBlockhash.blockhash;
|
|
365
|
+
// @ts-ignore
|
|
366
|
+
const signed = yield provider.wallet.signTransaction(tx);
|
|
367
|
+
tx.signatures[0].signature;
|
|
368
|
+
return signed;
|
|
369
|
+
})));
|
|
370
|
+
const txsWithSigs = signedTxs.map((tx, index) => {
|
|
371
|
+
return {
|
|
372
|
+
transaction: chunk[index],
|
|
373
|
+
sig: bs58_1.default.encode(tx.signatures[0].signature),
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
const confirmedTxs = yield bulkSendRawTransactions(provider.connection, signedTxs.map((s) => s.serialize()), (_a) => {
|
|
377
|
+
var { totalProgress } = _a, rest = __rest(_a, ["totalProgress"]);
|
|
378
|
+
return onProgress &&
|
|
379
|
+
onProgress(Object.assign(Object.assign({}, rest), { totalProgress: totalProgress + ret.length }));
|
|
380
|
+
}, recentBlockhash.lastValidBlockHeight);
|
|
381
|
+
thisRet.push(...confirmedTxs);
|
|
382
|
+
if (confirmedTxs.length == signedTxs.length) {
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
const retSet = new Set(thisRet);
|
|
386
|
+
chunk = txsWithSigs
|
|
387
|
+
.filter(({ sig }) => !retSet.has(sig))
|
|
388
|
+
.map(({ transaction }) => transaction);
|
|
389
|
+
triesRemaining--;
|
|
390
|
+
if (triesRemaining <= 0) {
|
|
391
|
+
throw new Error(`Failed to submit all txs after ${triesRemaining} blockhashes expired`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
ret.push(...thisRet);
|
|
395
|
+
}
|
|
396
|
+
return ret;
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
exports.bulkSendTransactions = bulkSendTransactions;
|
|
400
|
+
// Returns the list of succesfully sent txns
|
|
401
|
+
// NOTE: The return signatures are ordered by confirmation, not by order they are passed
|
|
402
|
+
// This list should be in order. Seom txns may fail
|
|
403
|
+
// due to blockhash exp
|
|
404
|
+
function bulkSendRawTransactions(connection, txs, onProgress, lastValidBlockHeight) {
|
|
405
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
406
|
+
const txBatchSize = TX_BATCH_SIZE;
|
|
407
|
+
let totalProgress = 0;
|
|
408
|
+
const ret = [];
|
|
409
|
+
if (!lastValidBlockHeight) {
|
|
410
|
+
const blockhash = yield withRetries(5, () => connection.getLatestBlockhash("confirmed"));
|
|
411
|
+
lastValidBlockHeight = blockhash.lastValidBlockHeight;
|
|
412
|
+
}
|
|
413
|
+
for (let chunk of (0, accountFetchCache_1.chunks)(txs, txBatchSize)) {
|
|
414
|
+
let currentBatchProgress = 0;
|
|
415
|
+
let pendingCount = txs.length;
|
|
416
|
+
let txids = [];
|
|
417
|
+
let lastRetry = 0;
|
|
418
|
+
while (pendingCount > 0) {
|
|
419
|
+
if ((yield withRetries(5, () => connection.getBlockHeight())) >
|
|
420
|
+
lastValidBlockHeight) {
|
|
421
|
+
return ret;
|
|
422
|
+
}
|
|
423
|
+
// only resend txs every 4s
|
|
424
|
+
if (lastRetry < new Date().valueOf() - 4 * 1000) {
|
|
425
|
+
lastRetry = new Date().valueOf();
|
|
426
|
+
txids = [];
|
|
427
|
+
for (const tx of chunk) {
|
|
428
|
+
const txid = yield connection.sendRawTransaction(tx, {
|
|
429
|
+
skipPreflight: true,
|
|
430
|
+
});
|
|
431
|
+
txids.push(txid);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
const statuses = yield getAllTxns(connection, txids);
|
|
435
|
+
const completed = statuses.filter((status) => status !== null);
|
|
436
|
+
totalProgress += completed.length;
|
|
437
|
+
currentBatchProgress += completed.length;
|
|
438
|
+
onProgress &&
|
|
439
|
+
onProgress({
|
|
440
|
+
totalProgress: totalProgress,
|
|
441
|
+
currentBatchProgress: currentBatchProgress,
|
|
442
|
+
currentBatchSize: txBatchSize,
|
|
443
|
+
});
|
|
444
|
+
const failures = completed
|
|
445
|
+
.map((status) => { var _a; return status !== null && ((_a = status.meta) === null || _a === void 0 ? void 0 : _a.err); })
|
|
446
|
+
.filter(truthy);
|
|
447
|
+
if (failures.length > 0) {
|
|
448
|
+
console.error(failures);
|
|
449
|
+
throw new Error("Failed to run txs");
|
|
450
|
+
}
|
|
451
|
+
pendingCount -= completed.length;
|
|
452
|
+
chunk = chunk.filter((_, index) => statuses[index] === null);
|
|
453
|
+
ret.push(...completed
|
|
454
|
+
.map((status, idx) => (status ? txids[idx] : null))
|
|
455
|
+
.filter(truthy));
|
|
456
|
+
yield sleep(1000); // Wait one seconds before querying again
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return ret;
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
exports.bulkSendRawTransactions = bulkSendRawTransactions;
|
|
463
|
+
const MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS = 200;
|
|
464
|
+
function getAllTxns(connection, txids) {
|
|
465
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
466
|
+
return (yield Promise.all((0, accountFetchCache_1.chunks)(txids, MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS).map((txids) => connection.getTransactions(txids, "confirmed")))).flat();
|
|
467
|
+
});
|
|
468
|
+
}
|
|
322
469
|
//# sourceMappingURL=transaction.js.map
|