@mysten/sui 1.1.2 → 1.2.0
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/CHANGELOG.md +6 -0
- package/dist/cjs/transactions/ObjectCache.js +7 -6
- package/dist/cjs/transactions/ObjectCache.js.map +2 -2
- package/dist/cjs/transactions/executor/caching.d.ts +3 -2
- package/dist/cjs/transactions/executor/caching.js +6 -2
- package/dist/cjs/transactions/executor/caching.js.map +2 -2
- package/dist/cjs/transactions/executor/parallel.d.ts +13 -0
- package/dist/cjs/transactions/executor/parallel.js +96 -9
- package/dist/cjs/transactions/executor/parallel.js.map +2 -2
- package/dist/cjs/transactions/executor/serial.d.ts +1 -1
- package/dist/cjs/transactions/executor/serial.js +20 -2
- package/dist/cjs/transactions/executor/serial.js.map +2 -2
- package/dist/cjs/transactions/json-rpc-resolver.js +4 -4
- package/dist/cjs/transactions/json-rpc-resolver.js.map +2 -2
- package/dist/cjs/version.d.ts +2 -2
- package/dist/cjs/version.js +2 -2
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/transactions/ObjectCache.js +7 -6
- package/dist/esm/transactions/ObjectCache.js.map +2 -2
- package/dist/esm/transactions/executor/caching.d.ts +3 -2
- package/dist/esm/transactions/executor/caching.js +6 -2
- package/dist/esm/transactions/executor/caching.js.map +2 -2
- package/dist/esm/transactions/executor/parallel.d.ts +13 -0
- package/dist/esm/transactions/executor/parallel.js +96 -9
- package/dist/esm/transactions/executor/parallel.js.map +2 -2
- package/dist/esm/transactions/executor/serial.d.ts +1 -1
- package/dist/esm/transactions/executor/serial.js +20 -2
- package/dist/esm/transactions/executor/serial.js.map +2 -2
- package/dist/esm/transactions/json-rpc-resolver.js +4 -4
- package/dist/esm/transactions/json-rpc-resolver.js.map +2 -2
- package/dist/esm/version.d.ts +2 -2
- package/dist/esm/version.js +2 -2
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/transactions/ObjectCache.ts +7 -7
- package/src/transactions/executor/caching.ts +6 -1
- package/src/transactions/executor/parallel.ts +114 -7
- package/src/transactions/executor/serial.ts +12 -1
- package/src/transactions/json-rpc-resolver.ts +6 -5
- package/src/version.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -151,12 +151,13 @@ class ObjectCache {
|
|
|
151
151
|
}
|
|
152
152
|
if (cached2.initialSharedVersion && !input.UnresolvedObject.initialSharedVersion) {
|
|
153
153
|
input.UnresolvedObject.initialSharedVersion = cached2.initialSharedVersion;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
154
|
+
} else {
|
|
155
|
+
if (cached2.version && !input.UnresolvedObject.version) {
|
|
156
|
+
input.UnresolvedObject.version = cached2.version;
|
|
157
|
+
}
|
|
158
|
+
if (cached2.digest && !input.UnresolvedObject.digest) {
|
|
159
|
+
input.UnresolvedObject.digest = cached2.digest;
|
|
160
|
+
}
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
163
|
await Promise.all(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/transactions/ObjectCache.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../bcs/index.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport type { OpenMoveTypeSignature } from './data/internal.js';\nimport type { TransactionPlugin } from './json-rpc-resolver.js';\n\nexport interface ObjectCacheEntry {\n\tobjectId: string;\n\tversion: string;\n\tdigest: string;\n\towner: string | null;\n\tinitialSharedVersion: string | null;\n}\n\nexport interface MoveFunctionCacheEntry {\n\tpackage: string;\n\tmodule: string;\n\tfunction: string;\n\tparameters: OpenMoveTypeSignature[];\n}\n\nexport interface CacheEntryTypes {\n\tOwnedObject: ObjectCacheEntry;\n\tSharedOrImmutableObject: ObjectCacheEntry;\n\tMoveFunction: MoveFunctionCacheEntry;\n\tCustom: unknown;\n}\nexport abstract class AsyncCache {\n\tprotected abstract get<T extends keyof CacheEntryTypes>(\n\t\ttype: T,\n\t\tkey: string,\n\t): Promise<CacheEntryTypes[T] | null>;\n\tprotected abstract set<T extends keyof CacheEntryTypes>(\n\t\ttype: T,\n\t\tkey: string,\n\t\tvalue: CacheEntryTypes[T],\n\t): Promise<void>;\n\tprotected abstract delete<T extends keyof CacheEntryTypes>(type: T, key: string): Promise<void>;\n\tabstract clear<T extends keyof CacheEntryTypes>(type?: T): Promise<void>;\n\n\tasync getObject(id: string) {\n\t\tconst [owned, shared] = await Promise.all([\n\t\t\tthis.get('OwnedObject', id),\n\t\t\tthis.get('SharedOrImmutableObject', id),\n\t\t]);\n\n\t\treturn owned ?? shared ?? null;\n\t}\n\n\tasync getObjects(ids: string[]) {\n\t\treturn Promise.all([...ids.map((id) => this.getObject(id))]);\n\t}\n\n\tasync addObject(object: ObjectCacheEntry) {\n\t\tif (object.owner) {\n\t\t\tawait this.set('OwnedObject', object.objectId, object);\n\t\t} else {\n\t\t\tawait this.set('SharedOrImmutableObject', object.objectId, object);\n\t\t}\n\n\t\treturn object;\n\t}\n\n\tasync addObjects(objects: ObjectCacheEntry[]) {\n\t\tawait Promise.all(objects.map(async (object) => this.addObject(object)));\n\t}\n\n\tasync deleteObject(id: string) {\n\t\tawait Promise.all([this.delete('OwnedObject', id), this.delete('SharedOrImmutableObject', id)]);\n\t}\n\n\tasync deleteObjects(ids: string[]) {\n\t\tawait Promise.all(ids.map((id) => this.deleteObject(id)));\n\t}\n\n\tasync getMoveFunctionDefinition(ref: { package: string; module: string; function: string }) {\n\t\tconst functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;\n\t\treturn this.get('MoveFunction', functionName);\n\t}\n\n\tasync addMoveFunctionDefinition(functionEntry: MoveFunctionCacheEntry) {\n\t\tconst pkg = normalizeSuiAddress(functionEntry.package);\n\t\tconst functionName = `${pkg}::${functionEntry.module}::${functionEntry.function}`;\n\t\tconst entry = {\n\t\t\t...functionEntry,\n\t\t\tpackage: pkg,\n\t\t};\n\n\t\tawait this.set('MoveFunction', functionName, entry);\n\n\t\treturn entry;\n\t}\n\n\tasync deleteMoveFunctionDefinition(ref: { package: string; module: string; function: string }) {\n\t\tconst functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;\n\t\tawait this.delete('MoveFunction', functionName);\n\t}\n\n\tasync getCustom<T>(key: string) {\n\t\treturn this.get('Custom', key) as Promise<T | null>;\n\t}\n\n\tasync setCustom<T>(key: string, value: T) {\n\t\treturn this.set('Custom', key, value);\n\t}\n\n\tasync deleteCustom(key: string) {\n\t\treturn this.delete('Custom', key);\n\t}\n}\n\nexport class InMemoryCache extends AsyncCache {\n\t#caches = {\n\t\tOwnedObject: new Map<string, ObjectCacheEntry>(),\n\t\tSharedOrImmutableObject: new Map<string, ObjectCacheEntry>(),\n\t\tMoveFunction: new Map<string, MoveFunctionCacheEntry>(),\n\t\tCustom: new Map<string, unknown>(),\n\t};\n\n\tprotected async get<T extends keyof CacheEntryTypes>(type: T, key: string) {\n\t\treturn (this.#caches[type].get(key) as CacheEntryTypes[T]) ?? null;\n\t}\n\n\tprotected async set<T extends keyof CacheEntryTypes>(\n\t\ttype: T,\n\t\tkey: string,\n\t\tvalue: CacheEntryTypes[T],\n\t) {\n\t\t(this.#caches[type] as Map<string, typeof value>).set(key, value as never);\n\t}\n\n\tprotected async delete<T extends keyof CacheEntryTypes>(type: T, key: string) {\n\t\tthis.#caches[type].delete(key);\n\t}\n\n\tasync clear<T extends keyof CacheEntryTypes>(type?: T) {\n\t\tif (type) {\n\t\t\tthis.#caches[type].clear();\n\t\t} else {\n\t\t\tfor (const cache of Object.values(this.#caches)) {\n\t\t\t\tcache.clear();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport interface ObjectCacheOptions {\n\tcache?: AsyncCache;\n}\n\nexport class ObjectCache {\n\t#cache: AsyncCache;\n\n\tconstructor({ cache = new InMemoryCache() }: ObjectCacheOptions) {\n\t\tthis.#cache = cache;\n\t}\n\n\tasPlugin(): TransactionPlugin {\n\t\treturn async (transactionData, _options, next) => {\n\t\t\tconst unresolvedObjects = transactionData.inputs\n\t\t\t\t.filter((input) => input.UnresolvedObject)\n\t\t\t\t.map((input) => input.UnresolvedObject!.objectId);\n\n\t\t\tconst cached = (await this.#cache.getObjects(unresolvedObjects)).filter(\n\t\t\t\t(obj) => obj !== null,\n\t\t\t);\n\n\t\t\tconst byId = new Map(cached.map((obj) => [obj!.objectId, obj]));\n\n\t\t\tfor (const input of transactionData.inputs) {\n\t\t\t\tif (!input.UnresolvedObject) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst cached = byId.get(input.UnresolvedObject.objectId);\n\n\t\t\t\tif (!cached) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (cached.initialSharedVersion && !input.UnresolvedObject.initialSharedVersion) {\n\t\t\t\t\tinput.UnresolvedObject.initialSharedVersion = cached.initialSharedVersion;\n\t\t\t\t}\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAoC;AAJpC;AA6BO,MAAe,WAAW;AAAA,EAahC,MAAM,UAAU,IAAY;AAC3B,UAAM,CAAC,OAAO,MAAM,IAAI,MAAM,QAAQ,IAAI;AAAA,MACzC,KAAK,IAAI,eAAe,EAAE;AAAA,MAC1B,KAAK,IAAI,2BAA2B,EAAE;AAAA,IACvC,CAAC;AAED,WAAO,SAAS,UAAU;AAAA,EAC3B;AAAA,EAEA,MAAM,WAAW,KAAe;AAC/B,WAAO,QAAQ,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC,CAAC,C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;AAEjD,YAAM,UAAU,MAAM,mBAAK,QAAO,WAAW,iBAAiB,GAAG;AAAA,QAChE,CAAC,QAAQ,QAAQ;AAAA,MAClB;AAEA,YAAM,OAAO,IAAI,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAK,UAAU,GAAG,CAAC,CAAC;AAE9D,iBAAW,SAAS,gBAAgB,QAAQ;AAC3C,YAAI,CAAC,MAAM,kBAAkB;AAC5B;AAAA,QACD;AAEA,cAAMA,UAAS,KAAK,IAAI,MAAM,iBAAiB,QAAQ;AAEvD,YAAI,CAACA,SAAQ;AACZ;AAAA,QACD;AAEA,YAAIA,QAAO,wBAAwB,CAAC,MAAM,iBAAiB,sBAAsB;AAChF,gBAAM,iBAAiB,uBAAuBA,QAAO;AAAA,QACtD;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../bcs/index.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport type { OpenMoveTypeSignature } from './data/internal.js';\nimport type { TransactionPlugin } from './json-rpc-resolver.js';\n\nexport interface ObjectCacheEntry {\n\tobjectId: string;\n\tversion: string;\n\tdigest: string;\n\towner: string | null;\n\tinitialSharedVersion: string | null;\n}\n\nexport interface MoveFunctionCacheEntry {\n\tpackage: string;\n\tmodule: string;\n\tfunction: string;\n\tparameters: OpenMoveTypeSignature[];\n}\n\nexport interface CacheEntryTypes {\n\tOwnedObject: ObjectCacheEntry;\n\tSharedOrImmutableObject: ObjectCacheEntry;\n\tMoveFunction: MoveFunctionCacheEntry;\n\tCustom: unknown;\n}\nexport abstract class AsyncCache {\n\tprotected abstract get<T extends keyof CacheEntryTypes>(\n\t\ttype: T,\n\t\tkey: string,\n\t): Promise<CacheEntryTypes[T] | null>;\n\tprotected abstract set<T extends keyof CacheEntryTypes>(\n\t\ttype: T,\n\t\tkey: string,\n\t\tvalue: CacheEntryTypes[T],\n\t): Promise<void>;\n\tprotected abstract delete<T extends keyof CacheEntryTypes>(type: T, key: string): Promise<void>;\n\tabstract clear<T extends keyof CacheEntryTypes>(type?: T): Promise<void>;\n\n\tasync getObject(id: string) {\n\t\tconst [owned, shared] = await Promise.all([\n\t\t\tthis.get('OwnedObject', id),\n\t\t\tthis.get('SharedOrImmutableObject', id),\n\t\t]);\n\n\t\treturn owned ?? shared ?? null;\n\t}\n\n\tasync getObjects(ids: string[]) {\n\t\treturn Promise.all([...ids.map((id) => this.getObject(id))]);\n\t}\n\n\tasync addObject(object: ObjectCacheEntry) {\n\t\tif (object.owner) {\n\t\t\tawait this.set('OwnedObject', object.objectId, object);\n\t\t} else {\n\t\t\tawait this.set('SharedOrImmutableObject', object.objectId, object);\n\t\t}\n\n\t\treturn object;\n\t}\n\n\tasync addObjects(objects: ObjectCacheEntry[]) {\n\t\tawait Promise.all(objects.map(async (object) => this.addObject(object)));\n\t}\n\n\tasync deleteObject(id: string) {\n\t\tawait Promise.all([this.delete('OwnedObject', id), this.delete('SharedOrImmutableObject', id)]);\n\t}\n\n\tasync deleteObjects(ids: string[]) {\n\t\tawait Promise.all(ids.map((id) => this.deleteObject(id)));\n\t}\n\n\tasync getMoveFunctionDefinition(ref: { package: string; module: string; function: string }) {\n\t\tconst functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;\n\t\treturn this.get('MoveFunction', functionName);\n\t}\n\n\tasync addMoveFunctionDefinition(functionEntry: MoveFunctionCacheEntry) {\n\t\tconst pkg = normalizeSuiAddress(functionEntry.package);\n\t\tconst functionName = `${pkg}::${functionEntry.module}::${functionEntry.function}`;\n\t\tconst entry = {\n\t\t\t...functionEntry,\n\t\t\tpackage: pkg,\n\t\t};\n\n\t\tawait this.set('MoveFunction', functionName, entry);\n\n\t\treturn entry;\n\t}\n\n\tasync deleteMoveFunctionDefinition(ref: { package: string; module: string; function: string }) {\n\t\tconst functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;\n\t\tawait this.delete('MoveFunction', functionName);\n\t}\n\n\tasync getCustom<T>(key: string) {\n\t\treturn this.get('Custom', key) as Promise<T | null>;\n\t}\n\n\tasync setCustom<T>(key: string, value: T) {\n\t\treturn this.set('Custom', key, value);\n\t}\n\n\tasync deleteCustom(key: string) {\n\t\treturn this.delete('Custom', key);\n\t}\n}\n\nexport class InMemoryCache extends AsyncCache {\n\t#caches = {\n\t\tOwnedObject: new Map<string, ObjectCacheEntry>(),\n\t\tSharedOrImmutableObject: new Map<string, ObjectCacheEntry>(),\n\t\tMoveFunction: new Map<string, MoveFunctionCacheEntry>(),\n\t\tCustom: new Map<string, unknown>(),\n\t};\n\n\tprotected async get<T extends keyof CacheEntryTypes>(type: T, key: string) {\n\t\treturn (this.#caches[type].get(key) as CacheEntryTypes[T]) ?? null;\n\t}\n\n\tprotected async set<T extends keyof CacheEntryTypes>(\n\t\ttype: T,\n\t\tkey: string,\n\t\tvalue: CacheEntryTypes[T],\n\t) {\n\t\t(this.#caches[type] as Map<string, typeof value>).set(key, value as never);\n\t}\n\n\tprotected async delete<T extends keyof CacheEntryTypes>(type: T, key: string) {\n\t\tthis.#caches[type].delete(key);\n\t}\n\n\tasync clear<T extends keyof CacheEntryTypes>(type?: T) {\n\t\tif (type) {\n\t\t\tthis.#caches[type].clear();\n\t\t} else {\n\t\t\tfor (const cache of Object.values(this.#caches)) {\n\t\t\t\tcache.clear();\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport interface ObjectCacheOptions {\n\tcache?: AsyncCache;\n}\n\nexport class ObjectCache {\n\t#cache: AsyncCache;\n\n\tconstructor({ cache = new InMemoryCache() }: ObjectCacheOptions) {\n\t\tthis.#cache = cache;\n\t}\n\n\tasPlugin(): TransactionPlugin {\n\t\treturn async (transactionData, _options, next) => {\n\t\t\tconst unresolvedObjects = transactionData.inputs\n\t\t\t\t.filter((input) => input.UnresolvedObject)\n\t\t\t\t.map((input) => input.UnresolvedObject!.objectId);\n\n\t\t\tconst cached = (await this.#cache.getObjects(unresolvedObjects)).filter(\n\t\t\t\t(obj) => obj !== null,\n\t\t\t);\n\n\t\t\tconst byId = new Map(cached.map((obj) => [obj!.objectId, obj]));\n\n\t\t\tfor (const input of transactionData.inputs) {\n\t\t\t\tif (!input.UnresolvedObject) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst cached = byId.get(input.UnresolvedObject.objectId);\n\n\t\t\t\tif (!cached) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (cached.initialSharedVersion && !input.UnresolvedObject.initialSharedVersion) {\n\t\t\t\t\tinput.UnresolvedObject.initialSharedVersion = cached.initialSharedVersion;\n\t\t\t\t} else {\n\t\t\t\t\tif (cached.version && !input.UnresolvedObject.version) {\n\t\t\t\t\t\tinput.UnresolvedObject.version = cached.version;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (cached.digest && !input.UnresolvedObject.digest) {\n\t\t\t\t\t\tinput.UnresolvedObject.digest = cached.digest;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tawait Promise.all(\n\t\t\t\ttransactionData.commands.map(async (commands) => {\n\t\t\t\t\tif (commands.MoveCall) {\n\t\t\t\t\t\tconst def = await this.getMoveFunctionDefinition({\n\t\t\t\t\t\t\tpackage: commands.MoveCall.package,\n\t\t\t\t\t\t\tmodule: commands.MoveCall.module,\n\t\t\t\t\t\t\tfunction: commands.MoveCall.function,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (def) {\n\t\t\t\t\t\t\tcommands.MoveCall._argumentTypes = def.parameters;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\tawait next();\n\n\t\t\tawait Promise.all(\n\t\t\t\ttransactionData.commands.map(async (commands) => {\n\t\t\t\t\tif (commands.MoveCall?._argumentTypes) {\n\t\t\t\t\t\tawait this.#cache.addMoveFunctionDefinition({\n\t\t\t\t\t\t\tpackage: commands.MoveCall.package,\n\t\t\t\t\t\t\tmodule: commands.MoveCall.module,\n\t\t\t\t\t\t\tfunction: commands.MoveCall.function,\n\t\t\t\t\t\t\tparameters: commands.MoveCall._argumentTypes,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t\t);\n\t\t};\n\t}\n\n\tasync clear() {\n\t\tawait this.#cache.clear();\n\t}\n\n\tasync getMoveFunctionDefinition(ref: { package: string; module: string; function: string }) {\n\t\treturn this.#cache.getMoveFunctionDefinition(ref);\n\t}\n\n\tasync getObjects(ids: string[]) {\n\t\treturn this.#cache.getObjects(ids);\n\t}\n\n\tasync deleteObjects(ids: string[]) {\n\t\treturn this.#cache.deleteObjects(ids);\n\t}\n\n\tasync clearOwnedObjects() {\n\t\tawait this.#cache.clear('OwnedObject');\n\t}\n\n\tasync clearCustom() {\n\t\tawait this.#cache.clear('Custom');\n\t}\n\n\tasync getCustom<T>(key: string) {\n\t\treturn this.#cache.getCustom<T>(key);\n\t}\n\n\tasync setCustom<T>(key: string, value: T) {\n\t\treturn this.#cache.setCustom(key, value);\n\t}\n\n\tasync deleteCustom(key: string) {\n\t\treturn this.#cache.deleteCustom(key);\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\tif (!effects.V2) {\n\t\t\tthrow new Error(`Unsupported transaction effects version ${effects.$kind}`);\n\t\t}\n\n\t\tconst { lamportVersion, changedObjects } = effects.V2;\n\n\t\tconst deletedIds: string[] = [];\n\t\tconst addedObjects: ObjectCacheEntry[] = [];\n\n\t\tchangedObjects.map(async ([id, change]) => {\n\t\t\tif (change.outputState.NotExist) {\n\t\t\t\tawait this.#cache.deleteObject(id);\n\t\t\t} else if (change.outputState.ObjectWrite) {\n\t\t\t\tconst [digest, owner] = change.outputState.ObjectWrite;\n\n\t\t\t\taddedObjects.push({\n\t\t\t\t\tobjectId: id,\n\t\t\t\t\tdigest,\n\t\t\t\t\tversion: lamportVersion,\n\t\t\t\t\towner: owner.AddressOwner ?? owner.ObjectOwner ?? null,\n\t\t\t\t\tinitialSharedVersion: owner.Shared?.initialSharedVersion ?? null,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\tawait Promise.all([\n\t\t\tthis.#cache.addObjects(addedObjects),\n\t\t\tthis.#cache.deleteObjects(deletedIds),\n\t\t]);\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAoC;AAJpC;AA6BO,MAAe,WAAW;AAAA,EAahC,MAAM,UAAU,IAAY;AAC3B,UAAM,CAAC,OAAO,MAAM,IAAI,MAAM,QAAQ,IAAI;AAAA,MACzC,KAAK,IAAI,eAAe,EAAE;AAAA,MAC1B,KAAK,IAAI,2BAA2B,EAAE;AAAA,IACvC,CAAC;AAED,WAAO,SAAS,UAAU;AAAA,EAC3B;AAAA,EAEA,MAAM,WAAW,KAAe;AAC/B,WAAO,QAAQ,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC,CAAC,CAAC;AAAA,EAC5D;AAAA,EAEA,MAAM,UAAU,QAA0B;AACzC,QAAI,OAAO,OAAO;AACjB,YAAM,KAAK,IAAI,eAAe,OAAO,UAAU,MAAM;AAAA,IACtD,OAAO;AACN,YAAM,KAAK,IAAI,2BAA2B,OAAO,UAAU,MAAM;AAAA,IAClE;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,WAAW,SAA6B;AAC7C,UAAM,QAAQ,IAAI,QAAQ,IAAI,OAAO,WAAW,KAAK,UAAU,MAAM,CAAC,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,aAAa,IAAY;AAC9B,UAAM,QAAQ,IAAI,CAAC,KAAK,OAAO,eAAe,EAAE,GAAG,KAAK,OAAO,2BAA2B,EAAE,CAAC,CAAC;AAAA,EAC/F;AAAA,EAEA,MAAM,cAAc,KAAe;AAClC,UAAM,QAAQ,I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teTransactionBlockParams, SuiClient } from '../../client/index.js';
|
|
3
3
|
import type { Signer } from '../../cryptography/keypair.js';
|
|
4
|
+
import type { BuildTransactionOptions } from '../json-rpc-resolver.js';
|
|
4
5
|
import type { ObjectCacheOptions } from '../ObjectCache.js';
|
|
5
6
|
import { ObjectCache } from '../ObjectCache.js';
|
|
6
7
|
import type { Transaction } from '../Transaction.js';
|
|
@@ -15,9 +16,9 @@ export declare class CachingTransactionExecutor {
|
|
|
15
16
|
* Immutable objects, Shared objects, and Move function definitions will be preserved
|
|
16
17
|
*/
|
|
17
18
|
reset(): Promise<void>;
|
|
18
|
-
buildTransaction({ transaction }: {
|
|
19
|
+
buildTransaction({ transaction, ...options }: {
|
|
19
20
|
transaction: Transaction;
|
|
20
|
-
}): Promise<Uint8Array>;
|
|
21
|
+
} & BuildTransactionOptions): Promise<Uint8Array>;
|
|
21
22
|
executeTransaction({ transaction, options, ...input }: {
|
|
22
23
|
transaction: Transaction | Uint8Array;
|
|
23
24
|
} & Omit<ExecuteTransactionBlockParams, 'transactionBlock'>): Promise<import("../../client/index.js").SuiTransactionBlockResponse>;
|
|
@@ -60,10 +60,14 @@ class CachingTransactionExecutor {
|
|
|
60
60
|
await this.cache.clearOwnedObjects();
|
|
61
61
|
await this.cache.clearCustom();
|
|
62
62
|
}
|
|
63
|
-
async buildTransaction({
|
|
63
|
+
async buildTransaction({
|
|
64
|
+
transaction,
|
|
65
|
+
...options
|
|
66
|
+
}) {
|
|
64
67
|
transaction.addBuildPlugin(this.cache.asPlugin());
|
|
65
68
|
return transaction.build({
|
|
66
|
-
client: __privateGet(this, _client)
|
|
69
|
+
client: __privateGet(this, _client),
|
|
70
|
+
...options
|
|
67
71
|
});
|
|
68
72
|
}
|
|
69
73
|
async executeTransaction({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/executor/caching.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '../../bcs/index.js';\nimport type { ExecuteTransactionBlockParams, SuiClient } from '../../client/index.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { ObjectCache } from '../ObjectCache.js';\nimport type { Transaction } from '../Transaction.js';\nimport { isTransaction } from '../Transaction.js';\n\nexport class CachingTransactionExecutor {\n\t#client: SuiClient;\n\tcache: ObjectCache;\n\n\tconstructor({\n\t\tclient,\n\t\t...options\n\t}: ObjectCacheOptions & {\n\t\tclient: SuiClient;\n\t}) {\n\t\tthis.#client = client;\n\t\tthis.cache = new ObjectCache(options);\n\t}\n\n\t/**\n\t * Clears all Owned objects\n\t * Immutable objects, Shared objects, and Move function definitions will be preserved\n\t */\n\tasync reset() {\n\t\tawait this.cache.clearOwnedObjects();\n\t\tawait this.cache.clearCustom();\n\t}\n\n\tasync buildTransaction({
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAoB;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '../../bcs/index.js';\nimport type { ExecuteTransactionBlockParams, SuiClient } from '../../client/index.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { BuildTransactionOptions } from '../json-rpc-resolver.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { ObjectCache } from '../ObjectCache.js';\nimport type { Transaction } from '../Transaction.js';\nimport { isTransaction } from '../Transaction.js';\n\nexport class CachingTransactionExecutor {\n\t#client: SuiClient;\n\tcache: ObjectCache;\n\n\tconstructor({\n\t\tclient,\n\t\t...options\n\t}: ObjectCacheOptions & {\n\t\tclient: SuiClient;\n\t}) {\n\t\tthis.#client = client;\n\t\tthis.cache = new ObjectCache(options);\n\t}\n\n\t/**\n\t * Clears all Owned objects\n\t * Immutable objects, Shared objects, and Move function definitions will be preserved\n\t */\n\tasync reset() {\n\t\tawait this.cache.clearOwnedObjects();\n\t\tawait this.cache.clearCustom();\n\t}\n\n\tasync buildTransaction({\n\t\ttransaction,\n\t\t...options\n\t}: { transaction: Transaction } & BuildTransactionOptions) {\n\t\ttransaction.addBuildPlugin(this.cache.asPlugin());\n\t\treturn transaction.build({\n\t\t\tclient: this.#client,\n\t\t\t...options,\n\t\t});\n\t}\n\n\tasync executeTransaction({\n\t\ttransaction,\n\t\toptions,\n\t\t...input\n\t}: {\n\t\ttransaction: Transaction | Uint8Array;\n\t} & Omit<ExecuteTransactionBlockParams, 'transactionBlock'>) {\n\t\tconst bytes = isTransaction(transaction)\n\t\t\t? await this.buildTransaction({ transaction })\n\t\t\t: transaction;\n\n\t\tconst results = await this.#client.executeTransactionBlock({\n\t\t\t...input,\n\t\t\ttransactionBlock: bytes,\n\t\t\toptions: {\n\t\t\t\t...options,\n\t\t\t\tshowRawEffects: true,\n\t\t\t},\n\t\t});\n\n\t\tif (results.rawEffects) {\n\t\t\tconst effects = bcs.TransactionEffects.parse(Uint8Array.from(results.rawEffects));\n\t\t\tawait this.applyEffects(effects);\n\t\t}\n\n\t\treturn results;\n\t}\n\n\tasync signAndExecuteTransaction({\n\t\toptions,\n\t\ttransaction,\n\t\t...input\n\t}: {\n\t\ttransaction: Transaction;\n\n\t\tsigner: Signer;\n\t} & Omit<ExecuteTransactionBlockParams, 'transactionBlock' | 'signature'>) {\n\t\ttransaction.setSenderIfNotSet(input.signer.toSuiAddress());\n\t\tconst bytes = await this.buildTransaction({ transaction });\n\t\tconst { signature } = await input.signer.signTransaction(bytes);\n\t\tconst results = await this.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignature,\n\t\t\toptions,\n\t\t});\n\n\t\treturn results;\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\tawait this.cache.applyEffects(effects);\n\t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AI2E;AAC1E,gBAAY,kBAAkB,MAAM,OAAO,aAAa,CAAC;AACzD,UAAM,QAAQ,MAAM,KAAK,iBAAiB,EAAE,YAAY,CAAC;AACzD,UAAM,EAAE,UAAU,IAAI,MAAM,MAAM,OAAO,gBAAgB,KAAK;AAC9D,UAAM,UAAU,MAAM,KAAK,mBAAmB;AAAA,MAC7C,aAAa;AAAA,MACb;AAAA,MACA;AAAA,IACD,CAAC;AAED,WAAO;AAAA,EACR;AAAA,EAEA,MAAM,aAAa,SAAmD;AACrE,UAAM,KAAK,MAAM,aAAa,OAAO;AAAA,EACtC;AACD;AArFC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,10 +5,23 @@ import { Transaction } from '../Transaction.js';
|
|
|
5
5
|
export interface ParallelTransactionExecutorOptions extends Omit<ObjectCacheOptions, 'address'> {
|
|
6
6
|
client: SuiClient;
|
|
7
7
|
signer: Signer;
|
|
8
|
+
/** The number of coins to create in a batch when refilling the gas pool */
|
|
8
9
|
coinBatchSize?: number;
|
|
10
|
+
/** The initial balance of each coin created for the gas pool */
|
|
9
11
|
initialCoinBalance?: bigint;
|
|
12
|
+
/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */
|
|
10
13
|
minimumCoinBalance?: bigint;
|
|
14
|
+
/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */
|
|
15
|
+
defaultGasBudget?: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Time to wait before/after the expected epoch boundary before re-fetching the gas pool (in milliseconds).
|
|
18
|
+
* Building transactions will be paused for up to 2x this duration around each epoch boundary to ensure the
|
|
19
|
+
* gas price is up-to-date for the next epoch.
|
|
20
|
+
* */
|
|
21
|
+
epochBoundaryWindow?: number;
|
|
22
|
+
/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */
|
|
11
23
|
maxPoolSize?: number;
|
|
24
|
+
/** An initial list of coins used to fund the gas pool, uses all owned SUI coins by default */
|
|
12
25
|
sourceCoins?: string[];
|
|
13
26
|
}
|
|
14
27
|
export declare class ParallelTransactionExecutor {
|
|
@@ -34,6 +34,14 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
34
34
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
35
35
|
return value;
|
|
36
36
|
};
|
|
37
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
38
|
+
set _(value) {
|
|
39
|
+
__privateSet(obj, member, value, setter);
|
|
40
|
+
},
|
|
41
|
+
get _() {
|
|
42
|
+
return __privateGet(obj, member, getter);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
37
45
|
var __privateMethod = (obj, member, method) => {
|
|
38
46
|
__accessCheck(obj, member, "access private method");
|
|
39
47
|
return method;
|
|
@@ -49,24 +57,31 @@ var import_Transaction = require("../Transaction.js");
|
|
|
49
57
|
var import_caching = require("./caching.js");
|
|
50
58
|
var import_queue = require("./queue.js");
|
|
51
59
|
var import_serial = require("./serial.js");
|
|
52
|
-
var _signer, _client, _coinBatchSize, _initialCoinBalance, _minimumCoinBalance, _maxPoolSize, _sourceCoins, _coinPool, _cache, _objectIdQueues, _buildQueue, _executeQueue, _getUsedObjects, getUsedObjects_fn, _execute, execute_fn, _getGasCoin, getGasCoin_fn, _refillCoinPool, refillCoinPool_fn;
|
|
60
|
+
var _signer, _client, _coinBatchSize, _initialCoinBalance, _minimumCoinBalance, _epochBoundaryWindow, _defaultGasBudget, _maxPoolSize, _sourceCoins, _coinPool, _cache, _objectIdQueues, _buildQueue, _executeQueue, _lastDigest, _cacheLock, _pendingTransactions, _gasPrice, _getUsedObjects, getUsedObjects_fn, _execute, execute_fn, _updateCache, updateCache_fn, _waitForLastDigest, waitForLastDigest_fn, _getGasCoin, getGasCoin_fn, _getGasPrice, getGasPrice_fn, _refillCoinPool, refillCoinPool_fn;
|
|
53
61
|
const PARALLEL_EXECUTOR_DEFAULTS = {
|
|
54
62
|
coinBatchSize: 20,
|
|
55
63
|
initialCoinBalance: 200000000n,
|
|
56
64
|
minimumCoinBalance: 50000000n,
|
|
57
|
-
maxPoolSize: 50
|
|
65
|
+
maxPoolSize: 50,
|
|
66
|
+
epochBoundaryWindow: 1e3
|
|
58
67
|
};
|
|
59
68
|
class ParallelTransactionExecutor {
|
|
60
69
|
constructor(options) {
|
|
61
70
|
__privateAdd(this, _getUsedObjects);
|
|
62
71
|
__privateAdd(this, _execute);
|
|
72
|
+
/** Helper for synchronizing cache updates, by ensuring only one update happens at a time. This can also be used to wait for any pending cache updates */
|
|
73
|
+
__privateAdd(this, _updateCache);
|
|
74
|
+
__privateAdd(this, _waitForLastDigest);
|
|
63
75
|
__privateAdd(this, _getGasCoin);
|
|
76
|
+
__privateAdd(this, _getGasPrice);
|
|
64
77
|
__privateAdd(this, _refillCoinPool);
|
|
65
78
|
__privateAdd(this, _signer, void 0);
|
|
66
79
|
__privateAdd(this, _client, void 0);
|
|
67
80
|
__privateAdd(this, _coinBatchSize, void 0);
|
|
68
81
|
__privateAdd(this, _initialCoinBalance, void 0);
|
|
69
82
|
__privateAdd(this, _minimumCoinBalance, void 0);
|
|
83
|
+
__privateAdd(this, _epochBoundaryWindow, void 0);
|
|
84
|
+
__privateAdd(this, _defaultGasBudget, void 0);
|
|
70
85
|
__privateAdd(this, _maxPoolSize, void 0);
|
|
71
86
|
__privateAdd(this, _sourceCoins, void 0);
|
|
72
87
|
__privateAdd(this, _coinPool, []);
|
|
@@ -74,11 +89,17 @@ class ParallelTransactionExecutor {
|
|
|
74
89
|
__privateAdd(this, _objectIdQueues, /* @__PURE__ */ new Map());
|
|
75
90
|
__privateAdd(this, _buildQueue, new import_queue.SerialQueue());
|
|
76
91
|
__privateAdd(this, _executeQueue, void 0);
|
|
92
|
+
__privateAdd(this, _lastDigest, null);
|
|
93
|
+
__privateAdd(this, _cacheLock, null);
|
|
94
|
+
__privateAdd(this, _pendingTransactions, 0);
|
|
95
|
+
__privateAdd(this, _gasPrice, null);
|
|
77
96
|
__privateSet(this, _signer, options.signer);
|
|
78
97
|
__privateSet(this, _client, options.client);
|
|
79
98
|
__privateSet(this, _coinBatchSize, options.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize);
|
|
80
99
|
__privateSet(this, _initialCoinBalance, options.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance);
|
|
81
100
|
__privateSet(this, _minimumCoinBalance, options.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance);
|
|
101
|
+
__privateSet(this, _defaultGasBudget, options.defaultGasBudget ?? __privateGet(this, _minimumCoinBalance));
|
|
102
|
+
__privateSet(this, _epochBoundaryWindow, options.epochBoundaryWindow ?? PARALLEL_EXECUTOR_DEFAULTS.epochBoundaryWindow);
|
|
82
103
|
__privateSet(this, _maxPoolSize, options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize);
|
|
83
104
|
__privateSet(this, _cache, new import_caching.CachingTransactionExecutor({
|
|
84
105
|
client: options.client,
|
|
@@ -88,7 +109,8 @@ class ParallelTransactionExecutor {
|
|
|
88
109
|
__privateSet(this, _sourceCoins, options.sourceCoins ? new Map(options.sourceCoins.map((id) => [id, null])) : null);
|
|
89
110
|
}
|
|
90
111
|
resetCache() {
|
|
91
|
-
|
|
112
|
+
__privateSet(this, _gasPrice, null);
|
|
113
|
+
return __privateMethod(this, _updateCache, updateCache_fn).call(this, () => __privateGet(this, _cache).reset());
|
|
92
114
|
}
|
|
93
115
|
async executeTransaction(transaction) {
|
|
94
116
|
const { promise, resolve, reject } = promiseWithResolvers();
|
|
@@ -125,6 +147,8 @@ _client = new WeakMap();
|
|
|
125
147
|
_coinBatchSize = new WeakMap();
|
|
126
148
|
_initialCoinBalance = new WeakMap();
|
|
127
149
|
_minimumCoinBalance = new WeakMap();
|
|
150
|
+
_epochBoundaryWindow = new WeakMap();
|
|
151
|
+
_defaultGasBudget = new WeakMap();
|
|
128
152
|
_maxPoolSize = new WeakMap();
|
|
129
153
|
_sourceCoins = new WeakMap();
|
|
130
154
|
_coinPool = new WeakMap();
|
|
@@ -132,6 +156,10 @@ _cache = new WeakMap();
|
|
|
132
156
|
_objectIdQueues = new WeakMap();
|
|
133
157
|
_buildQueue = new WeakMap();
|
|
134
158
|
_executeQueue = new WeakMap();
|
|
159
|
+
_lastDigest = new WeakMap();
|
|
160
|
+
_cacheLock = new WeakMap();
|
|
161
|
+
_pendingTransactions = new WeakMap();
|
|
162
|
+
_gasPrice = new WeakMap();
|
|
135
163
|
_getUsedObjects = new WeakSet();
|
|
136
164
|
getUsedObjects_fn = async function(transaction) {
|
|
137
165
|
const usedObjects = /* @__PURE__ */ new Set();
|
|
@@ -159,8 +187,18 @@ _execute = new WeakSet();
|
|
|
159
187
|
execute_fn = async function(transaction, usedObjects) {
|
|
160
188
|
let gasCoin;
|
|
161
189
|
try {
|
|
162
|
-
|
|
190
|
+
transaction.setSenderIfNotSet(__privateGet(this, _signer).toSuiAddress());
|
|
191
|
+
await __privateGet(this, _buildQueue).runTask(async () => {
|
|
192
|
+
const data = transaction.getData();
|
|
193
|
+
if (!data.gasData.price) {
|
|
194
|
+
transaction.setGasPrice(await __privateMethod(this, _getGasPrice, getGasPrice_fn).call(this));
|
|
195
|
+
}
|
|
196
|
+
if (!data.gasData.budget) {
|
|
197
|
+
transaction.setGasBudget(__privateGet(this, _defaultGasBudget));
|
|
198
|
+
}
|
|
199
|
+
await __privateMethod(this, _updateCache, updateCache_fn).call(this);
|
|
163
200
|
gasCoin = await __privateMethod(this, _getGasCoin, getGasCoin_fn).call(this);
|
|
201
|
+
__privateWrapper(this, _pendingTransactions)._++;
|
|
164
202
|
transaction.setGasPayment([
|
|
165
203
|
{
|
|
166
204
|
objectId: gasCoin.id,
|
|
@@ -168,9 +206,9 @@ execute_fn = async function(transaction, usedObjects) {
|
|
|
168
206
|
digest: gasCoin.digest
|
|
169
207
|
}
|
|
170
208
|
]);
|
|
171
|
-
|
|
172
|
-
return __privateGet(this, _cache).buildTransaction({ transaction });
|
|
209
|
+
await __privateGet(this, _cache).buildTransaction({ transaction, onlyTransactionKind: true });
|
|
173
210
|
});
|
|
211
|
+
const bytes = await transaction.build({ client: __privateGet(this, _client) });
|
|
174
212
|
const { signature } = await __privateGet(this, _signer).signTransaction(bytes);
|
|
175
213
|
const results = await __privateGet(this, _cache).executeTransaction({
|
|
176
214
|
transaction: bytes,
|
|
@@ -199,6 +237,7 @@ execute_fn = async function(transaction, usedObjects) {
|
|
|
199
237
|
__privateGet(this, _sourceCoins).set(gasResult.ref.objectId, gasResult.ref);
|
|
200
238
|
}
|
|
201
239
|
}
|
|
240
|
+
__privateSet(this, _lastDigest, results.digest);
|
|
202
241
|
return {
|
|
203
242
|
digest: results.digest,
|
|
204
243
|
effects: (0, import_bcs.toB64)(effectsBytes)
|
|
@@ -210,7 +249,12 @@ execute_fn = async function(transaction, usedObjects) {
|
|
|
210
249
|
}
|
|
211
250
|
__privateGet(this, _sourceCoins).set(gasCoin.id, null);
|
|
212
251
|
}
|
|
213
|
-
await
|
|
252
|
+
await __privateMethod(this, _updateCache, updateCache_fn).call(this, async () => {
|
|
253
|
+
await Promise.all([
|
|
254
|
+
__privateGet(this, _cache).cache.deleteObjects([...usedObjects]),
|
|
255
|
+
__privateMethod(this, _waitForLastDigest, waitForLastDigest_fn).call(this)
|
|
256
|
+
]);
|
|
257
|
+
});
|
|
214
258
|
throw error;
|
|
215
259
|
} finally {
|
|
216
260
|
usedObjects.forEach((objectId) => {
|
|
@@ -221,11 +265,33 @@ execute_fn = async function(transaction, usedObjects) {
|
|
|
221
265
|
__privateGet(this, _objectIdQueues).delete(objectId);
|
|
222
266
|
}
|
|
223
267
|
});
|
|
268
|
+
__privateWrapper(this, _pendingTransactions)._--;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
_updateCache = new WeakSet();
|
|
272
|
+
updateCache_fn = async function(fn) {
|
|
273
|
+
if (__privateGet(this, _cacheLock)) {
|
|
274
|
+
await __privateGet(this, _cacheLock);
|
|
275
|
+
}
|
|
276
|
+
__privateSet(this, _cacheLock, fn?.().then(
|
|
277
|
+
() => {
|
|
278
|
+
__privateSet(this, _cacheLock, null);
|
|
279
|
+
},
|
|
280
|
+
() => {
|
|
281
|
+
}
|
|
282
|
+
) ?? null);
|
|
283
|
+
};
|
|
284
|
+
_waitForLastDigest = new WeakSet();
|
|
285
|
+
waitForLastDigest_fn = async function() {
|
|
286
|
+
const digest = __privateGet(this, _lastDigest);
|
|
287
|
+
if (digest) {
|
|
288
|
+
__privateSet(this, _lastDigest, null);
|
|
289
|
+
await __privateGet(this, _client).waitForTransaction({ digest });
|
|
224
290
|
}
|
|
225
291
|
};
|
|
226
292
|
_getGasCoin = new WeakSet();
|
|
227
293
|
getGasCoin_fn = async function() {
|
|
228
|
-
if (__privateGet(this, _coinPool).length === 0 && __privateGet(this,
|
|
294
|
+
if (__privateGet(this, _coinPool).length === 0 && __privateGet(this, _pendingTransactions) <= __privateGet(this, _maxPoolSize)) {
|
|
229
295
|
await __privateMethod(this, _refillCoinPool, refillCoinPool_fn).call(this);
|
|
230
296
|
}
|
|
231
297
|
if (__privateGet(this, _coinPool).length === 0) {
|
|
@@ -234,11 +300,31 @@ getGasCoin_fn = async function() {
|
|
|
234
300
|
const coin = __privateGet(this, _coinPool).shift();
|
|
235
301
|
return coin;
|
|
236
302
|
};
|
|
303
|
+
_getGasPrice = new WeakSet();
|
|
304
|
+
getGasPrice_fn = async function() {
|
|
305
|
+
const remaining = __privateGet(this, _gasPrice) ? __privateGet(this, _gasPrice).expiration - __privateGet(this, _epochBoundaryWindow) - Date.now() : 0;
|
|
306
|
+
if (remaining > 0) {
|
|
307
|
+
return __privateGet(this, _gasPrice).price;
|
|
308
|
+
}
|
|
309
|
+
if (__privateGet(this, _gasPrice)) {
|
|
310
|
+
const timeToNextEpoch = Math.max(
|
|
311
|
+
__privateGet(this, _gasPrice).expiration + __privateGet(this, _epochBoundaryWindow) - Date.now(),
|
|
312
|
+
1e3
|
|
313
|
+
);
|
|
314
|
+
await new Promise((resolve) => setTimeout(resolve, timeToNextEpoch));
|
|
315
|
+
}
|
|
316
|
+
const state = await __privateGet(this, _client).getLatestSuiSystemState();
|
|
317
|
+
__privateSet(this, _gasPrice, {
|
|
318
|
+
price: BigInt(state.referenceGasPrice),
|
|
319
|
+
expiration: Number.parseInt(state.epochStartTimestampMs, 10) + Number.parseInt(state.epochDurationMs, 10)
|
|
320
|
+
});
|
|
321
|
+
return __privateMethod(this, _getGasPrice, getGasPrice_fn).call(this);
|
|
322
|
+
};
|
|
237
323
|
_refillCoinPool = new WeakSet();
|
|
238
324
|
refillCoinPool_fn = async function() {
|
|
239
325
|
const batchSize = Math.min(
|
|
240
326
|
__privateGet(this, _coinBatchSize),
|
|
241
|
-
__privateGet(this, _maxPoolSize) - (__privateGet(this, _coinPool).length + __privateGet(this,
|
|
327
|
+
__privateGet(this, _maxPoolSize) - (__privateGet(this, _coinPool).length + __privateGet(this, _pendingTransactions)) + 1
|
|
242
328
|
);
|
|
243
329
|
if (batchSize === 0) {
|
|
244
330
|
return;
|
|
@@ -278,6 +364,7 @@ refillCoinPool_fn = async function() {
|
|
|
278
364
|
coinResults.push(results[i]);
|
|
279
365
|
}
|
|
280
366
|
txb.transferObjects(coinResults, address);
|
|
367
|
+
await __privateMethod(this, _updateCache, updateCache_fn).call(this, () => __privateMethod(this, _waitForLastDigest, waitForLastDigest_fn).call(this));
|
|
281
368
|
const result = await __privateGet(this, _client).signAndExecuteTransaction({
|
|
282
369
|
transaction: txb,
|
|
283
370
|
signer: __privateGet(this, _signer),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/transactions/executor/parallel.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toB64 } from '@mysten/bcs';\n\nimport { bcs } from '../../bcs/index.js';\nimport type { SuiObjectRef } from '../../bcs/types.js';\nimport type { SuiClient } from '../../client/index.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\nimport { getGasCoinFromEffects } from './serial.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n} satisfies Omit<ParallelTransactionExecutorOptions, 'signer' | 'client'>;\nexport interface ParallelTransactionExecutorOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: SuiClient;\n\tsigner: Signer;\n\tcoinBatchSize?: number;\n\tinitialCoinBalance?: bigint;\n\tminimumCoinBalance?: bigint;\n\tmaxPoolSize?: number;\n\tsourceCoins?: string[];\n}\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: SuiClient;\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, SuiObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#coinBatchSize = options.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\tthis.#initialCoinBalance =\n\t\t\toptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\tthis.#minimumCoinBalance =\n\t\t\toptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t\tthis.#sourceCoins = options.sourceCoins\n\t\t\t? new Map(options.sourceCoins.map((id) => [id, null]))\n\t\t\t: null;\n\t}\n\n\tresetCache() {\n\t\treturn this.#cache.reset();\n\t}\n\n\tasync executeTransaction(transaction: Transaction) {\n\t\tconst { promise, resolve, reject } = promiseWithResolvers<{\n\t\t\tdigest: string;\n\t\t\teffects: string;\n\t\t}>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute(transaction: Transaction, usedObjects: Set<string>) {\n\t\tlet gasCoin!: CoinWithBalance;\n\t\ttry {\n\t\t\tconst bytes = await this.#buildQueue.runTask(async () => {\n\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t{\n\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t},\n\t\t\t\t]);\n\t\t\t\ttransaction.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\t\t\treturn this.#cache.buildTransaction({ transaction: transaction });\n\t\t\t});\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignature,\n\t\t\t\toptions: {\n\t\t\t\t\tshowEffects: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst effectsBytes = Uint8Array.from(results.rawEffects!);\n\t\t\tconst effects = bcs.TransactionEffects.parse(effectsBytes);\n\n\t\t\tconst gasResult = getGasCoinFromEffects(effects);\n\t\t\tconst gasUsed = effects.V2?.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasResult.owner === this.#signer.toSuiAddress()) {\n\t\t\t\tconst totalUsed =\n\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\tBigInt(gasUsed.storageCost) +\n\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\n\t\t\t\tif (gasCoin.balance >= this.#minimumCoinBalance) {\n\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\tid: gasResult.ref.objectId,\n\t\t\t\t\t\tversion: gasResult.ref.version,\n\t\t\t\t\t\tdigest: gasResult.ref.digest,\n\t\t\t\t\t\tbalance: gasCoin.balance - totalUsed,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t}\n\t\t\t\t\tthis.#sourceCoins.set(gasResult.ref.objectId, gasResult.ref);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tdigest: results.digest,\n\t\t\t\teffects: toB64(effectsBytes),\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set(gasCoin.id, null);\n\t\t\t}\n\n\t\t\tawait this.#cache.cache.deleteObjects([...usedObjects]);\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#executeQueue.activeTasks <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#executeQueue.activeTasks) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toSuiAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst coins = await this.#client.multiGetObjects({\n\t\t\t\t\tids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...coins\n\t\t\t\t\t\t.filter((coin): coin is typeof coin & { data: object } => coin.data !== null)\n\t\t\t\t\t\t.map(({ data }) => ({\n\t\t\t\t\t\t\tobjectId: data.objectId,\n\t\t\t\t\t\t\tversion: data.version,\n\t\t\t\t\t\t\tdigest: data.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst results = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(results[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tconst result = await this.#client.signAndExecuteTransaction({\n\t\t\ttransaction: txb,\n\t\t\tsigner: this.#signer,\n\t\t\toptions: {\n\t\t\t\tshowRawEffects: true,\n\t\t\t},\n\t\t});\n\n\t\tconst effects = bcs.TransactionEffects.parse(Uint8Array.from(result.rawEffects!));\n\t\teffects.V2?.changedObjects.forEach(([id, { outputState }], i) => {\n\t\t\tif (i === effects.V2?.gasObjectIndex || !outputState.ObjectWrite) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid,\n\t\t\t\tversion: effects.V2!.lamportVersion,\n\t\t\t\tdigest: outputState.ObjectWrite[0],\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = getGasCoinFromEffects(effects).ref;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, gasObject);\n\n\t\tawait this.#client.waitForTransaction({ digest: result.digest });\n\t}\n}\n\nfunction promiseWithResolvers<T>() {\n\tlet resolve: (value: T) => void;\n\tlet reject: (reason: any) => void;\n\n\tconst promise = new Promise<T>((_resolve, _reject) => {\n\t\tresolve = _resolve;\n\t\treject = _reject;\n\t});\n\n\treturn { promise, resolve: resolve!, reject: reject! };\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toB64 } from '@mysten/bcs';\n\nimport { bcs } from '../../bcs/index.js';\nimport type { SuiObjectRef } from '../../bcs/types.js';\nimport type { SuiClient } from '../../client/index.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\nimport { getGasCoinFromEffects } from './serial.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n\tepochBoundaryWindow: 1_000,\n} satisfies Omit<ParallelTransactionExecutorOptions, 'signer' | 'client'>;\nexport interface ParallelTransactionExecutorOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: SuiClient;\n\tsigner: Signer;\n\t/** The number of coins to create in a batch when refilling the gas pool */\n\tcoinBatchSize?: number;\n\t/** The initial balance of each coin created for the gas pool */\n\tinitialCoinBalance?: bigint;\n\t/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */\n\tminimumCoinBalance?: bigint;\n\t/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */\n\tdefaultGasBudget?: bigint;\n\t/**\n\t * Time to wait before/after the expected epoch boundary before re-fetching the gas pool (in milliseconds).\n\t * Building transactions will be paused for up to 2x this duration around each epoch boundary to ensure the\n\t * gas price is up-to-date for the next epoch.\n\t * */\n\tepochBoundaryWindow?: number;\n\t/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */\n\tmaxPoolSize?: number;\n\t/** An initial list of coins used to fund the gas pool, uses all owned SUI coins by default */\n\tsourceCoins?: string[];\n}\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: SuiClient;\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#epochBoundaryWindow: number;\n\t#defaultGasBudget: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, SuiObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\t#lastDigest: string | null = null;\n\t#cacheLock: Promise<void> | null = null;\n\t#pendingTransactions = 0;\n\t#gasPrice: null | {\n\t\tprice: bigint;\n\t\texpiration: number;\n\t} = null;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#coinBatchSize = options.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\tthis.#initialCoinBalance =\n\t\t\toptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\tthis.#minimumCoinBalance =\n\t\t\toptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\tthis.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;\n\t\tthis.#epochBoundaryWindow =\n\t\t\toptions.epochBoundaryWindow ?? PARALLEL_EXECUTOR_DEFAULTS.epochBoundaryWindow;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t\tthis.#sourceCoins = options.sourceCoins\n\t\t\t? new Map(options.sourceCoins.map((id) => [id, null]))\n\t\t\t: null;\n\t}\n\n\tresetCache() {\n\t\tthis.#gasPrice = null;\n\t\treturn this.#updateCache(() => this.#cache.reset());\n\t}\n\n\tasync executeTransaction(transaction: Transaction) {\n\t\tconst { promise, resolve, reject } = promiseWithResolvers<{\n\t\t\tdigest: string;\n\t\t\teffects: string;\n\t\t}>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute(transaction: Transaction, usedObjects: Set<string>) {\n\t\tlet gasCoin!: CoinWithBalance;\n\t\ttry {\n\t\t\ttransaction.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\t\tawait this.#buildQueue.runTask(async () => {\n\t\t\t\tconst data = transaction.getData();\n\n\t\t\t\tif (!data.gasData.price) {\n\t\t\t\t\ttransaction.setGasPrice(await this.#getGasPrice());\n\t\t\t\t}\n\n\t\t\t\tif (!data.gasData.budget) {\n\t\t\t\t\ttransaction.setGasBudget(this.#defaultGasBudget);\n\t\t\t\t}\n\n\t\t\t\tawait this.#updateCache();\n\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\tthis.#pendingTransactions++;\n\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t{\n\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t},\n\t\t\t\t]);\n\n\t\t\t\t// Resolve cached references\n\t\t\t\tawait this.#cache.buildTransaction({ transaction, onlyTransactionKind: true });\n\t\t\t});\n\n\t\t\tconst bytes = await transaction.build({ client: this.#client });\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignature,\n\t\t\t\toptions: {\n\t\t\t\t\tshowEffects: true,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst effectsBytes = Uint8Array.from(results.rawEffects!);\n\t\t\tconst effects = bcs.TransactionEffects.parse(effectsBytes);\n\n\t\t\tconst gasResult = getGasCoinFromEffects(effects);\n\t\t\tconst gasUsed = effects.V2?.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasResult.owner === this.#signer.toSuiAddress()) {\n\t\t\t\tconst totalUsed =\n\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\tBigInt(gasUsed.storageCost) +\n\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\n\t\t\t\tif (gasCoin.balance >= this.#minimumCoinBalance) {\n\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\tid: gasResult.ref.objectId,\n\t\t\t\t\t\tversion: gasResult.ref.version,\n\t\t\t\t\t\tdigest: gasResult.ref.digest,\n\t\t\t\t\t\tbalance: gasCoin.balance - totalUsed,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t}\n\t\t\t\t\tthis.#sourceCoins.set(gasResult.ref.objectId, gasResult.ref);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.#lastDigest = results.digest;\n\n\t\t\treturn {\n\t\t\t\tdigest: results.digest,\n\t\t\t\teffects: toB64(effectsBytes),\n\t\t\t};\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set(gasCoin.id, null);\n\t\t\t}\n\n\t\t\tawait this.#updateCache(async () => {\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tthis.#cache.cache.deleteObjects([...usedObjects]),\n\t\t\t\t\tthis.#waitForLastDigest(),\n\t\t\t\t]);\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.#pendingTransactions--;\n\t\t}\n\t}\n\n\t/** Helper for synchronizing cache updates, by ensuring only one update happens at a time. This can also be used to wait for any pending cache updates */\n\tasync #updateCache(fn?: () => Promise<void>) {\n\t\tif (this.#cacheLock) {\n\t\t\tawait this.#cacheLock;\n\t\t}\n\n\t\tthis.#cacheLock =\n\t\t\tfn?.().then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#cacheLock = null;\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t) ?? null;\n\t}\n\n\tasync #waitForLastDigest() {\n\t\tconst digest = this.#lastDigest;\n\t\tif (digest) {\n\t\t\tthis.#lastDigest = null;\n\t\t\tawait this.#client.waitForTransaction({ digest });\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #getGasPrice(): Promise<bigint> {\n\t\tconst remaining = this.#gasPrice\n\t\t\t? this.#gasPrice.expiration - this.#epochBoundaryWindow - Date.now()\n\t\t\t: 0;\n\n\t\tif (remaining > 0) {\n\t\t\treturn this.#gasPrice!.price;\n\t\t}\n\n\t\tif (this.#gasPrice) {\n\t\t\tconst timeToNextEpoch = Math.max(\n\t\t\t\tthis.#gasPrice.expiration + this.#epochBoundaryWindow - Date.now(),\n\t\t\t\t1_000,\n\t\t\t);\n\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, timeToNextEpoch));\n\t\t}\n\n\t\tconst state = await this.#client.getLatestSuiSystemState();\n\n\t\tthis.#gasPrice = {\n\t\t\tprice: BigInt(state.referenceGasPrice),\n\t\t\texpiration:\n\t\t\t\tNumber.parseInt(state.epochStartTimestampMs, 10) +\n\t\t\t\tNumber.parseInt(state.epochDurationMs, 10),\n\t\t};\n\n\t\treturn this.#getGasPrice();\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toSuiAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst coins = await this.#client.multiGetObjects({\n\t\t\t\t\tids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...coins\n\t\t\t\t\t\t.filter((coin): coin is typeof coin & { data: object } => coin.data !== null)\n\t\t\t\t\t\t.map(({ data }) => ({\n\t\t\t\t\t\t\tobjectId: data.objectId,\n\t\t\t\t\t\t\tversion: data.version,\n\t\t\t\t\t\t\tdigest: data.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst results = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(results[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tawait this.#updateCache(() => this.#waitForLastDigest());\n\n\t\tconst result = await this.#client.signAndExecuteTransaction({\n\t\t\ttransaction: txb,\n\t\t\tsigner: this.#signer,\n\t\t\toptions: {\n\t\t\t\tshowRawEffects: true,\n\t\t\t},\n\t\t});\n\n\t\tconst effects = bcs.TransactionEffects.parse(Uint8Array.from(result.rawEffects!));\n\t\teffects.V2?.changedObjects.forEach(([id, { outputState }], i) => {\n\t\t\tif (i === effects.V2?.gasObjectIndex || !outputState.ObjectWrite) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid,\n\t\t\t\tversion: effects.V2!.lamportVersion,\n\t\t\t\tdigest: outputState.ObjectWrite[0],\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = getGasCoinFromEffects(effects).ref;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, gasObject);\n\n\t\tawait this.#client.waitForTransaction({ digest: result.digest });\n\t}\n}\n\nfunction promiseWithResolvers<T>() {\n\tlet resolve: (value: T) => void;\n\tlet reject: (reason: any) => void;\n\n\tconst promise = new Promise<T>((_resolve, _reject) => {\n\t\tresolve = _resolve;\n\t\treject = _reject;\n\t});\n\n\treturn { promise, resolve: resolve!, reject: reject! };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAsB;AAEtB,IAAAA,cAAoB;AAKpB,yBAA4B;AAC5B,qBAA2C;AAC3C,mBAA2C;AAC3C,oBAAsC;AAbtC;AAeA,MAAM,6BAA6B;AAAA,EAClC,eAAe;AAAA,EACf,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,aAAa;AAAA,EACb,qBAAqB;AACtB;AA8BO,MAAM,4BAA4B;AAAA,EAuBxC,YAAY,SAA6C;AAkEzD,uBAAM;AA+BN,uBAAM;AA4GN;AAAA,uBAAM;AAcN,uBAAM;AAQN,uBAAM;AAaN,uBAAM;AA8BN,uBAAM;AApSN;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kCAA+B,CAAC;AAChC;AACA,wCAAkB,oBAAI,IAA4B;AAClD,oCAAc,IAAI,yBAAY;AAC9B;AACA,oCAA6B;AAC7B,mCAAmC;AACnC,6CAAuB;AACvB,kCAGI;AAGH,uBAAK,SAAU,QAAQ;AACvB,uB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AChE,QAAI,MAAM,QAAQ,IAAI,kBAAkB,CAAC,YAAY,aAAa;AACjE;AAAA,IACD;AAEA,uBAAK,WAAU,KAAK;AAAA,MACnB;AAAA,MACA,SAAS,QAAQ,GAAI;AAAA,MACrB,QAAQ,YAAY,YAAY,CAAC;AAAA,MACjC,SAAS,OAAO,mBAAK,oBAAmB;AAAA,IACzC,CAAC;AAAA,EACF,CAAC;AAED,MAAI,CAAC,mBAAK,eAAc;AACvB,uBAAK,cAAe,oBAAI,IAAI;AAAA,EAC7B;AAEA,QAAM,gBAAY,qCAAsB,OAAO,EAAE;AACjD,qBAAK,cAAc,IAAI,UAAU,UAAU,SAAS;AAEpD,QAAM,mBAAK,SAAQ,mBAAmB,EAAE,QAAQ,OAAO,OAAO,CAAC;AAChE;AAGD,SAAS,uBAA0B;AAClC,MAAI;AACJ,MAAI;AAEJ,QAAM,UAAU,IAAI,QAAW,CAAC,UAAU,YAAY;AACrD,cAAU;AACV,aAAS;AAAA,EACV,CAAC;AAED,SAAO,EAAE,SAAS,SAAmB,OAAgB;AACtD;",
|
|
6
6
|
"names": ["import_bcs", "promise"]
|
|
7
7
|
}
|
|
@@ -11,7 +11,7 @@ export declare class SerialTransactionExecutor {
|
|
|
11
11
|
});
|
|
12
12
|
applyEffects(effects: typeof bcs.TransactionEffects.$inferType): Promise<[void, void]>;
|
|
13
13
|
buildTransaction(transaction: Transaction): Promise<Uint8Array>;
|
|
14
|
-
resetCache(): Promise<void>;
|
|
14
|
+
resetCache(): Promise<[void, void]>;
|
|
15
15
|
executeTransaction(transaction: Transaction | Uint8Array): Promise<{
|
|
16
16
|
digest: string;
|
|
17
17
|
effects: string;
|
|
@@ -34,6 +34,10 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
34
34
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
35
35
|
return value;
|
|
36
36
|
};
|
|
37
|
+
var __privateMethod = (obj, member, method) => {
|
|
38
|
+
__accessCheck(obj, member, "access private method");
|
|
39
|
+
return method;
|
|
40
|
+
};
|
|
37
41
|
var serial_exports = {};
|
|
38
42
|
__export(serial_exports, {
|
|
39
43
|
SerialTransactionExecutor: () => SerialTransactionExecutor,
|
|
@@ -45,15 +49,18 @@ var import_bcs2 = require("../../bcs/index.js");
|
|
|
45
49
|
var import_Transaction = require("../Transaction.js");
|
|
46
50
|
var import_caching = require("./caching.js");
|
|
47
51
|
var import_queue = require("./queue.js");
|
|
48
|
-
var _queue, _signer, _cache, _cacheGasCoin, _buildTransaction;
|
|
52
|
+
var _queue, _signer, _cache, _client, _lastDigest, _cacheGasCoin, _buildTransaction, _waitForLastTransaction, waitForLastTransaction_fn;
|
|
49
53
|
class SerialTransactionExecutor {
|
|
50
54
|
constructor({
|
|
51
55
|
signer,
|
|
52
56
|
...options
|
|
53
57
|
}) {
|
|
58
|
+
__privateAdd(this, _waitForLastTransaction);
|
|
54
59
|
__privateAdd(this, _queue, new import_queue.SerialQueue());
|
|
55
60
|
__privateAdd(this, _signer, void 0);
|
|
56
61
|
__privateAdd(this, _cache, void 0);
|
|
62
|
+
__privateAdd(this, _client, void 0);
|
|
63
|
+
__privateAdd(this, _lastDigest, null);
|
|
57
64
|
__privateAdd(this, _cacheGasCoin, async (effects) => {
|
|
58
65
|
if (!effects.V2) {
|
|
59
66
|
return;
|
|
@@ -75,6 +82,7 @@ class SerialTransactionExecutor {
|
|
|
75
82
|
return __privateGet(this, _cache).buildTransaction({ transaction: copy });
|
|
76
83
|
});
|
|
77
84
|
__privateSet(this, _signer, signer);
|
|
85
|
+
__privateSet(this, _client, options.client);
|
|
78
86
|
__privateSet(this, _cache, new import_caching.CachingTransactionExecutor({
|
|
79
87
|
client: options.client,
|
|
80
88
|
cache: options.cache
|
|
@@ -87,7 +95,7 @@ class SerialTransactionExecutor {
|
|
|
87
95
|
return __privateGet(this, _queue).runTask(() => __privateGet(this, _buildTransaction).call(this, transaction));
|
|
88
96
|
}
|
|
89
97
|
resetCache() {
|
|
90
|
-
return __privateGet(this, _cache).reset();
|
|
98
|
+
return Promise.all([__privateGet(this, _cache).reset(), __privateMethod(this, _waitForLastTransaction, waitForLastTransaction_fn).call(this)]);
|
|
91
99
|
}
|
|
92
100
|
executeTransaction(transaction) {
|
|
93
101
|
return __privateGet(this, _queue).runTask(async () => {
|
|
@@ -103,6 +111,7 @@ class SerialTransactionExecutor {
|
|
|
103
111
|
const effectsBytes = Uint8Array.from(results.rawEffects);
|
|
104
112
|
const effects = import_bcs2.bcs.TransactionEffects.parse(effectsBytes);
|
|
105
113
|
await this.applyEffects(effects);
|
|
114
|
+
__privateSet(this, _lastDigest, results.digest);
|
|
106
115
|
return {
|
|
107
116
|
digest: results.digest,
|
|
108
117
|
effects: (0, import_bcs.toB64)(effectsBytes)
|
|
@@ -113,8 +122,17 @@ class SerialTransactionExecutor {
|
|
|
113
122
|
_queue = new WeakMap();
|
|
114
123
|
_signer = new WeakMap();
|
|
115
124
|
_cache = new WeakMap();
|
|
125
|
+
_client = new WeakMap();
|
|
126
|
+
_lastDigest = new WeakMap();
|
|
116
127
|
_cacheGasCoin = new WeakMap();
|
|
117
128
|
_buildTransaction = new WeakMap();
|
|
129
|
+
_waitForLastTransaction = new WeakSet();
|
|
130
|
+
waitForLastTransaction_fn = async function() {
|
|
131
|
+
if (__privateGet(this, _lastDigest)) {
|
|
132
|
+
await __privateGet(this, _client).waitForTransaction({ digest: __privateGet(this, _lastDigest) });
|
|
133
|
+
__privateSet(this, _lastDigest, null);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
118
136
|
function getGasCoinFromEffects(effects) {
|
|
119
137
|
if (!effects.V2) {
|
|
120
138
|
throw new Error("Unexpected effects version");
|