Skip to content

Commit

Permalink
[sdk] stop re-using gas coins that get used by other commands in para… (
Browse files Browse the repository at this point in the history
MystenLabs#18412)

…llel executor

## 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:
  • Loading branch information
hayes-mysten authored and tx-tomcat committed Jul 29, 2024
1 parent b2ee941 commit 0347069
Show file tree
Hide file tree
Showing 28 changed files with 187 additions and 64 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-points-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui': patch
---

Parallel executor now only re-uses gasCoins if the gas coin is only used for gas
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.27.0"
compiler-version = "1.29.0"
edition = "2024.beta"
flavor = "sui"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.27.0"
compiler-version = "1.29.0"
edition = "2024.beta"
flavor = "sui"
12 changes: 11 additions & 1 deletion sdk/typescript/src/transactions/executor/parallel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { SuiClient } from '../../client/index.js';
import type { Signer } from '../../cryptography/index.js';
import type { ObjectCacheOptions } from '../ObjectCache.js';
import { Transaction } from '../Transaction.js';
import { TransactionDataBuilder } from '../TransactionData.js';
import { CachingTransactionExecutor } from './caching.js';
import { ParallelQueue, SerialQueue } from './queue.js';
import { getGasCoinFromEffects } from './serial.js';
Expand Down Expand Up @@ -225,7 +226,16 @@ export class ParallelTransactionExecutor {
BigInt(gasUsed.storageCost) -
BigInt(gasUsed.storageRebate);

if (gasCoin.balance >= this.#minimumCoinBalance) {
let usesGasCoin = false;
new TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {
if (arg.$kind === 'GasCoin') {
usesGasCoin = true;
}

return arg;
});

if (!usesGasCoin && gasCoin.balance >= this.#minimumCoinBalance) {
this.#coinPool.push({
id: gasResult.ref.objectId,
version: gasResult.ref.version,
Expand Down
11 changes: 6 additions & 5 deletions sdk/typescript/test/e2e/coin-metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { beforeEach, describe, expect, it } from 'vitest';
import { resolve } from 'path';
import { beforeAll, describe, expect, it } from 'vitest';

import { publishPackage, setup, TestToolbox } from './utils/setup';
import { setup, TestToolbox } from './utils/setup';

describe('Test Coin Metadata', () => {
let toolbox: TestToolbox;
let packageId: string;

beforeEach(async () => {
beforeAll(async () => {
toolbox = await setup();
const packagePath = __dirname + '/./data/coin_metadata';
({ packageId } = await publishPackage(packagePath));
const packagePath = resolve(__dirname, './data/coin_metadata');
packageId = await toolbox.getPackage(packagePath);
});

it('Test accessing coin metadata', async () => {
Expand Down
6 changes: 3 additions & 3 deletions sdk/typescript/test/e2e/coin-read.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { resolve } from 'path';
import { beforeAll, describe, expect, it } from 'vitest';

import { publishPackage, setup, TestToolbox } from './utils/setup';
import { setup, TestToolbox } from './utils/setup';

describe('CoinRead API', () => {
let toolbox: TestToolbox;
Expand All @@ -13,8 +14,7 @@ describe('CoinRead API', () => {

beforeAll(async () => {
[toolbox, publishToolbox] = await Promise.all([setup(), setup()]);
const packagePath = __dirname + '/./data/coin_metadata';
({ packageId } = await publishPackage(packagePath, publishToolbox));
packageId = await publishToolbox.getPackage(resolve(__dirname, './data/coin_metadata'));
testType = packageId + '::test::TEST';
});

Expand Down
11 changes: 6 additions & 5 deletions sdk/typescript/test/e2e/coin-with-balance.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { resolve } from 'path';
import { fromHEX, toB64 } from '@mysten/bcs';
import { beforeEach, describe, expect, it } from 'vitest';
import { beforeAll, describe, expect, it } from 'vitest';

import { bcs } from '../../src/bcs';
import { Ed25519Keypair } from '../../src/keypairs/ed25519';
import { Transaction } from '../../src/transactions';
import { coinWithBalance } from '../../src/transactions/intents/CoinWithBalance';
import { normalizeSuiAddress } from '../../src/utils';
import { publishPackage, setup, TestToolbox } from './utils/setup';
import { setup, TestToolbox } from './utils/setup';

describe('coinWithBalance', () => {
let toolbox: TestToolbox;
let publishToolbox: TestToolbox;
let packageId: string;
let testType: string;

beforeEach(async () => {
beforeAll(async () => {
[toolbox, publishToolbox] = await Promise.all([setup(), setup()]);
const packagePath = __dirname + '/./data/coin_metadata';
({ packageId } = await publishPackage(packagePath, publishToolbox));
const packagePath = resolve(__dirname, './data/coin_metadata');
packageId = await publishToolbox.getPackage(packagePath);
testType = normalizeSuiAddress(packageId) + '::test::TEST';
});

Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/test/e2e/data/coin_metadata/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.27.0"
compiler-version = "1.29.0"
edition = "2024.beta"
flavor = "sui"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module coin_metadata::test {
use sui::coin;
use sui::transfer;
use sui::url;
use sui::tx_context::{Self, TxContext};

public struct TEST has drop {}

Expand Down
10 changes: 10 additions & 0 deletions sdk/typescript/test/e2e/data/demo-bear/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "demo"
version = "0.0.1"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }

[addresses]
demo = "0x0"
58 changes: 58 additions & 0 deletions sdk/typescript/test/e2e/data/demo-bear/sources/demo_bear.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

module demo::demo_bear {
use std::string::{String, utf8};

use sui::package;
use sui::display;

/// our demo struct.
public struct DemoBear has key, store {
id: UID,
name: String
}

/// our OTW to create display.
public struct DEMO_BEAR has drop {}

// It's recommened to create Display using PTBs instead of
// directly on the contracts.
// We are only creating it here for demo purposes (one-step setup).
fun init(otw: DEMO_BEAR, ctx: &mut TxContext){
let publisher = package::claim(otw, ctx);
let keys = vector[
utf8(b"name"),
utf8(b"image_url"),
utf8(b"description"),
];


let values = vector[
// Let's add a demo name for our `DemoBear`
utf8(b"{name}"),
// Adding a happy bear image.
utf8(b"https://images.unsplash.com/photo-1589656966895-2f33e7653819?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8cG9sYXIlMjBiZWFyfGVufDB8fDB8fHww"),
// Description is static for all bears out there.
utf8(b"The greatest figure for demos"),
];

// Get a new `Display` object for the `Hero` type.
let mut display = display::new_with_fields<DemoBear>(
&publisher, keys, values, ctx
);

// Commit first version of `Display` to apply changes.
display::update_version(&mut display);

sui::transfer::public_transfer(display, ctx.sender());
sui::transfer::public_transfer(publisher, ctx.sender())
}

public fun new(name: String, ctx: &mut TxContext): DemoBear {
DemoBear {
id: object::new(ctx),
name: name
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

module display_test::boars {
use sui::object::{Self, UID};
use std::option::{Self, Option};
use sui::tx_context::{TxContext, sender};
use sui::tx_context::{sender};
use sui::transfer;
use sui::package;
use sui::url::{Self, Url};
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/test/e2e/data/dynamic_fields/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.27.0"
compiler-version = "1.29.0"
edition = "2024.beta"
flavor = "sui"
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
module dynamic_fields::dynamic_fields_test {
use sui::dynamic_field as dfield;
use sui::dynamic_object_field as dof;
use sui::object::{Self, UID};
use sui::tx_context::{Self, TxContext};
use sui::transfer;

public struct Test has key {
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/test/e2e/data/id_entry_args/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.27.0"
compiler-version = "1.29.0"
edition = "2024.beta"
flavor = "sui"
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

module id_entry_args::test {
use sui::tx_context::TxContext;
use sui::object::{Self, ID};

public entry fun test_id(id: ID, _ctx: &mut TxContext) {
assert!(object::id_to_address(&id) == @0xc2b5625c221264078310a084df0a3137956d20ee, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/typescript/test/e2e/data/serializer/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.27.0"
compiler-version = "1.29.0"
edition = "2024.beta"
flavor = "sui"
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

module serializer::serializer_tests {
use sui::tx_context::{Self, TxContext};
use sui::transfer;
use sui::object::{Self, UID};
use sui::clock::Clock;
use std::option::Option;
use sui::object::ID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

module serializer::serializer_tests {
use sui::tx_context::{Self, TxContext};
use sui::transfer;
use sui::object::{Self, UID};
use sui::clock::Clock;
use std::option::Option;
use sui::object::ID;
use std::string::String;
use std::ascii;

Expand Down
2 changes: 0 additions & 2 deletions sdk/typescript/test/e2e/data/tto/sources/tto1.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

module tto::tto {
use sui::object::{Self, UID};
use sui::tx_context::{Self, TxContext};
use sui::transfer::{Self, Receiving};

public struct A has key, store {
Expand Down
6 changes: 3 additions & 3 deletions sdk/typescript/test/e2e/dev-inspect.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { resolve } from 'path';
import { beforeAll, describe, expect, it } from 'vitest';

import { SuiClient } from '../../src/client';
import { Keypair } from '../../src/cryptography';
import { Transaction } from '../../src/transactions';
import { publishPackage, setup, TestToolbox } from './utils/setup';
import { setup, TestToolbox } from './utils/setup';

describe('Test dev inspect', () => {
let toolbox: TestToolbox;
let packageId: string;

beforeAll(async () => {
toolbox = await setup();
const packagePath = __dirname + '/./data/serializer';
({ packageId } = await publishPackage(packagePath));
packageId = await toolbox.getPackage(resolve(__dirname, './data/serializer'));
});

it('Dev inspect split + transfer', async () => {
Expand Down
6 changes: 3 additions & 3 deletions sdk/typescript/test/e2e/dynamic-fields.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { resolve } from 'path';
import { beforeAll, describe, expect, it } from 'vitest';

import { SuiObjectData } from '../../src/client';
import { publishPackage, setup, TestToolbox } from './utils/setup';
import { setup, TestToolbox } from './utils/setup';

describe('Dynamic Fields Reading API', () => {
let toolbox: TestToolbox;
Expand All @@ -13,8 +14,7 @@ describe('Dynamic Fields Reading API', () => {

beforeAll(async () => {
toolbox = await setup();
const packagePath = __dirname + '/./data/dynamic_fields';
({ packageId } = await publishPackage(packagePath, toolbox));
packageId = await toolbox.getPackage(resolve(__dirname, './data/dynamic_fields'));

await toolbox.client
.getOwnedObjects({
Expand Down
6 changes: 3 additions & 3 deletions sdk/typescript/test/e2e/id-entry-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { resolve } from 'path';
import { beforeAll, describe, expect, it } from 'vitest';

import { Transaction } from '../../src/transactions';
import { publishPackage, setup, TestToolbox } from './utils/setup';
import { setup, TestToolbox } from './utils/setup';

describe('Test ID as args to entry functions', () => {
let toolbox: TestToolbox;
let packageId: string;

beforeAll(async () => {
toolbox = await setup();
const packagePath = __dirname + '/./data/id_entry_args';
({ packageId } = await publishPackage(packagePath));
packageId = await toolbox.getPackage(resolve(__dirname, './data/id_entry_args'));
});

it('Test ID as arg to entry functions', async () => {
Expand Down
Loading

0 comments on commit 0347069

Please sign in to comment.