Skip to content

Commit

Permalink
[sdk] remove duplicate call to applyAffects in SerialTransactionExecu…
Browse files Browse the repository at this point in the history
…tor (#20689)

## Description 

Describe the changes or additions included in this PR.

## Test plan 

How did you test the new or updated feature?

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
hayes-mysten authored Dec 19, 2024
1 parent f7a2117 commit dc0e21e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-rules-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui': patch
---

Remove duplicate applyEffects in serial transaction executor
6 changes: 5 additions & 1 deletion sdk/typescript/src/transactions/ObjectCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,16 @@ export class InMemoryCache extends AsyncCache {

export interface ObjectCacheOptions {
cache?: AsyncCache;
onEffects?: (effects: typeof bcs.TransactionEffects.$inferType) => Promise<void>;
}

export class ObjectCache {
#cache: AsyncCache;
#onEffects?: (effects: typeof bcs.TransactionEffects.$inferType) => Promise<void>;

constructor({ cache = new InMemoryCache() }: ObjectCacheOptions) {
constructor({ cache = new InMemoryCache(), onEffects }: ObjectCacheOptions) {
this.#cache = cache;
this.#onEffects = onEffects;
}

asPlugin(): TransactionPlugin {
Expand Down Expand Up @@ -291,6 +294,7 @@ export class ObjectCache {
await Promise.all([
this.#cache.addObjects(addedObjects),
this.#cache.deleteObjects(deletedIds),
this.#onEffects?.(effects),
]);
}
}
8 changes: 3 additions & 5 deletions sdk/typescript/src/transactions/executor/serial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { toBase64 } from '@mysten/bcs';

import { bcs } from '../../bcs/index.js';
import type { bcs } from '../../bcs/index.js';
import type { SuiClient, SuiTransactionBlockResponseOptions } from '../../client/index.js';
import type { Signer } from '../../cryptography/keypair.js';
import type { ObjectCacheOptions } from '../ObjectCache.js';
Expand Down Expand Up @@ -32,11 +32,12 @@ export class SerialTransactionExecutor {
this.#cache = new CachingTransactionExecutor({
client: options.client,
cache: options.cache,
onEffects: (effects) => this.#cacheGasCoin(effects),
});
}

async applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {
return Promise.all([this.#cacheGasCoin(effects), this.#cache.cache.applyEffects(effects)]);
return this.#cache.applyEffects(effects);
}

#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {
Expand Down Expand Up @@ -104,9 +105,6 @@ export class SerialTransactionExecutor {
});

const effectsBytes = Uint8Array.from(results.rawEffects!);
const effects = bcs.TransactionEffects.parse(effectsBytes);
await this.applyEffects(effects);

return {
digest: results.digest,
effects: toBase64(effectsBytes),
Expand Down

0 comments on commit dc0e21e

Please sign in to comment.