Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: made ResourceCache consider resource owner #3697

Merged
merged 134 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
24a2a10
using fuel core 0.41.0
Torres-ssf Jan 15, 2025
a2baaf8
update fuel-core schema
Torres-ssf Jan 15, 2025
a2c8588
add new scalars
Torres-ssf Jan 15, 2025
1514020
made getBalances support pagination
Torres-ssf Jan 15, 2025
c9fe8b4
made balance related queries use amount128 instead of amount
Torres-ssf Jan 15, 2025
3ead231
add todo test
Torres-ssf Jan 15, 2025
7675278
update return type of getMessageProof
Torres-ssf Jan 15, 2025
0e8a7be
add maxGas and txPoolStats to nodeInfoFragment
Torres-ssf Jan 15, 2025
90a0fdd
add TODO
Torres-ssf Jan 15, 2025
fcc5b5d
implement query for getAssetDetails
Torres-ssf Jan 15, 2025
ceb8d25
implement getAssetDetails method
Torres-ssf Jan 15, 2025
4563216
implement daCompressedBlock method
Torres-ssf Jan 15, 2025
cd7daa6
add new expiration policy
Torres-ssf Jan 15, 2025
4b4c49b
fix var name
Torres-ssf Jan 15, 2025
85ffa1a
fix test description
Torres-ssf Jan 15, 2025
f2f3ca9
add tests for new expiration policy
Torres-ssf Jan 15, 2025
73f4361
add expiration policy to TransactionRequest
Torres-ssf Jan 15, 2025
e5374ae
support expiration policy on BaseInvocationScope
Torres-ssf Jan 15, 2025
468f54b
adjust policies order
Torres-ssf Jan 15, 2025
c30108c
add e2e test for new expiration policy
Torres-ssf Jan 15, 2025
99e6a1b
unify 2 errors to conform with fuel core changes
Torres-ssf Jan 16, 2025
bca1a27
adjust tests
Torres-ssf Jan 16, 2025
757a692
fix test
Torres-ssf Jan 16, 2025
2a6990d
fix error message
Torres-ssf Jan 16, 2025
985bfc3
fix test
Torres-ssf Jan 16, 2025
5872e8d
adjusting test
Torres-ssf Jan 16, 2025
af5b9a8
fix test case
Torres-ssf Jan 16, 2025
4158f84
adjust test
Torres-ssf Jan 16, 2025
d550e44
fix test
Torres-ssf Jan 16, 2025
821ebdc
unset cached resources as soon as the TX is processed
Torres-ssf Jan 16, 2025
d2d176e
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 16, 2025
7701bad
document new expiration policy
Torres-ssf Jan 16, 2025
85a87bf
reverting breaking changes
Torres-ssf Jan 17, 2025
04c02f5
remove unused imports
Torres-ssf Jan 17, 2025
33902b8
add changeset
Torres-ssf Jan 17, 2025
ea88409
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 17, 2025
5590af0
adjusting errors messages from master
Torres-ssf Jan 17, 2025
a8885bf
implement gte helper for semver
Torres-ssf Jan 20, 2025
ee65f50
add features property to Provider class
Torres-ssf Jan 20, 2025
3256690
implement query getBalancesV2
Torres-ssf Jan 20, 2025
42135f5
add support for balance pagination
Torres-ssf Jan 20, 2025
e8e0f8e
implement query getBalanceV2
Torres-ssf Jan 20, 2025
34ae0cb
made getBalance return amount128 when supported by the node
Torres-ssf Jan 20, 2025
6428260
uncomment tests related to balance pagination
Torres-ssf Jan 20, 2025
de1679c
fix test
Torres-ssf Jan 20, 2025
01344d3
add more values to Features type
Torres-ssf Jan 20, 2025
23d82c4
ensure node supports getAssetDetails query
Torres-ssf Jan 20, 2025
f0649fd
ensure node supports daCompressedBlock query
Torres-ssf Jan 20, 2025
890a247
add more tests
Torres-ssf Jan 20, 2025
b370707
upgrade @fuels/vm-asm dep
Torres-ssf Jan 20, 2025
3d8e44e
update PANIC_REASONS const
Torres-ssf Jan 20, 2025
7b64418
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 20, 2025
3baa297
add TS DOCS
Torres-ssf Jan 21, 2025
8a8c773
add comments
Torres-ssf Jan 21, 2025
e85faa9
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 21, 2025
a08e7fe
comparing messages using regex instead of switch
Torres-ssf Jan 22, 2025
1321c22
update gql error message to match with any value
Torres-ssf Jan 22, 2025
4dd1f36
throwing error in proper place
Torres-ssf Jan 22, 2025
feba962
release PR
Torres-ssf Jan 22, 2025
aa2d70f
remove backwards compatibility for new features
Torres-ssf Jan 22, 2025
34cb7e6
remove TODO
Torres-ssf Jan 22, 2025
d2c55af
add test for u128 balances
Torres-ssf Jan 22, 2025
fa363cb
add test to validate getBalancesV1
Torres-ssf Jan 22, 2025
0b29a60
stop releasing PR
Torres-ssf Jan 22, 2025
438fa98
add test for daCompressedBlock
Torres-ssf Jan 22, 2025
dc94c51
add new props to GasCosts
Torres-ssf Jan 22, 2025
2980197
fix changeset
Torres-ssf Jan 22, 2025
3ecdae9
rename NOT_ENOUGH_FUNDS error and removed MAX_COINS_REACHED
Torres-ssf Jan 23, 2025
c3945ee
improving docs
Torres-ssf Jan 23, 2025
0f75513
fix changeset
Torres-ssf Jan 23, 2025
092aa06
fix link
Torres-ssf Jan 23, 2025
cedd2ee
Update apps/docs/src/guide/errors/index.md
Torres-ssf Jan 23, 2025
7df0184
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 23, 2025
24e2cb3
Update apps/docs/src/guide/errors/index.md
Torres-ssf Jan 23, 2025
48d1a1d
remove duplicated doc paragraph
Torres-ssf Jan 23, 2025
ede84bc
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 23, 2025
8c698d5
format forc project
Torres-ssf Jan 24, 2025
de249ef
fix BN variable
Torres-ssf Jan 24, 2025
e141e36
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 25, 2025
fbbf8c9
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 27, 2025
5861d88
chore: upgrade `fuel core` to `0.41.4` (#3628)
petertonysmith94 Jan 28, 2025
8a10deb
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Jan 30, 2025
d93a018
fix changeset
Torres-ssf Jan 30, 2025
8f34540
remove duplicated changeset
Torres-ssf Jan 30, 2025
c424a05
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 3, 2025
f352b58
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 4, 2025
68cc74e
upgrade fuel-core to 0.41.5
Torres-ssf Feb 4, 2025
92bccaf
fix changeset
Torres-ssf Feb 4, 2025
fa866c7
update fuel core graphql schema
Torres-ssf Feb 4, 2025
0059130
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 4, 2025
8c5e302
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 5, 2025
15c7b42
upgrade fuel-core to 0.41.6
Torres-ssf Feb 6, 2025
5865573
fix changeset
Torres-ssf Feb 6, 2025
9457de2
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 6, 2025
f8557f9
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 7, 2025
bef28e1
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 11, 2025
d5b35b5
made ResourceCache consider resource owner
Torres-ssf Feb 11, 2025
b970b6c
adjust resource cache unit tests
Torres-ssf Feb 11, 2025
e9d0353
adjust resource cache use on provider class
Torres-ssf Feb 11, 2025
3e6fd3e
Merge branch 'master' into st/chore/made-resource-cache-owner-specific
Torres-ssf Feb 11, 2025
7d6c3fe
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 12, 2025
15b4026
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 12, 2025
588de5c
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 13, 2025
400717a
update fuel core to 0.41.7
Torres-ssf Feb 13, 2025
59ecddc
fix changeset
Torres-ssf Feb 13, 2025
bc3f981
Merge branch 'master' into st/chore/made-resource-cache-owner-specific
Torres-ssf Feb 13, 2025
5aa2239
moving resources cache to same file
Torres-ssf Feb 15, 2025
4eaee56
rename some vars
Torres-ssf Feb 15, 2025
2e1fd8c
implement helper adjustResourcesToExclude
Torres-ssf Feb 15, 2025
f2bf5f8
adding tests
Torres-ssf Feb 15, 2025
948309a
remove unused imports
Torres-ssf Feb 16, 2025
5e7f755
make lint happy
Torres-ssf Feb 16, 2025
c8df01f
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 16, 2025
5f0f208
add changeset
Torres-ssf Feb 16, 2025
26ce04c
Merge branch 'master' into st/chore/made-resource-cache-owner-specific
Torres-ssf Feb 16, 2025
bb95ac5
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 17, 2025
3534f30
Merge branch 'master' into st/chore/made-resource-cache-owner-specific
Torres-ssf Feb 17, 2025
e1f0501
Merge branch 'st/chore/upgrade-fuel-core@0.41.0' into st/chore/made-r…
Torres-ssf Feb 18, 2025
f689858
adjusting tests
Torres-ssf Feb 18, 2025
27b0276
prioritize recent cached IDs
Torres-ssf Feb 18, 2025
686e49f
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 18, 2025
b36dbbf
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
arboleya Feb 19, 2025
246d8a2
lint fix
Torres-ssf Feb 19, 2025
ac299b3
Merge branch 'st/chore/upgrade-fuel-core@0.41.0' into st/chore/made-r…
Torres-ssf Feb 19, 2025
75d360a
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 20, 2025
7da6f62
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 21, 2025
a406830
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 24, 2025
fee5967
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
arboleya Feb 25, 2025
0c19354
Merge branch 'st/chore/upgrade-fuel-core@0.41.0' into st/chore/made-r…
Torres-ssf Feb 27, 2025
67fc4d9
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 27, 2025
2748a56
Merge branch 'master' into st/chore/upgrade-fuel-core@0.41.0
Torres-ssf Feb 27, 2025
b0be79f
Merge branch 'st/chore/upgrade-fuel-core@0.41.0' into st/chore/made-r…
Torres-ssf Feb 27, 2025
4007c47
Merge branch 'master' into st/chore/made-resource-cache-owner-specific
Torres-ssf Mar 5, 2025
82ea2b7
Merge branch 'master' into st/chore/made-resource-cache-owner-specific
Torres-ssf Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-candles-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": minor
---

chore!: made `ResourceCache` consider resource owner
265 changes: 0 additions & 265 deletions packages/account/src/providers/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,13 @@ import { mockIncompatibleVersions } from '../../test/utils/mockIncompabileVersio
import { setupTestProviderAndWallets, launchNode, TestMessage } from '../test-utils';

import type { GqlPageInfo } from './__generated__/operations';
import type { Coin } from './coin';
import type { Message } from './message';
import type { Block, ChainInfo, CursorPaginationArgs, NodeInfo } from './provider';
import Provider, {
BALANCES_PAGE_SIZE_LIMIT,
BLOCKS_PAGE_SIZE_LIMIT,
DEFAULT_RESOURCE_CACHE_TTL,
GAS_USED_MODIFIER,
RESOURCES_PAGE_SIZE_LIMIT,
} from './provider';
import type { ExcludeResourcesOption } from './resource';
import { isCoin } from './resource';
import type {
ChangeTransactionRequestOutput,
CoinTransactionRequestInput,
Expand Down Expand Up @@ -590,266 +585,6 @@ describe('Provider', () => {
expect(producedBlocks).toEqual(expectedBlocks);
});

it('can set cache ttl', async () => {
const ttl = 10000;
using launched = await setupTestProviderAndWallets({
providerOptions: {
resourceCacheTTL: ttl,
},
});
const { provider } = launched;

expect(provider.cache?.ttl).toEqual(ttl);
});

it('should use resource cache by default', async () => {
using launched = await setupTestProviderAndWallets();
const { provider } = launched;

expect(provider.cache?.ttl).toEqual(DEFAULT_RESOURCE_CACHE_TTL);
});

it('should validate resource cache value [invalid numerical]', async () => {
const { error } = await safeExec(async () => {
await setupTestProviderAndWallets({ providerOptions: { resourceCacheTTL: -500 } });
});
expect(error?.message).toMatch(/Invalid TTL: -500\. Use a value greater than zero/);
});

it('should be possible to disable the cache by using -1', async () => {
using launched = await setupTestProviderAndWallets({
providerOptions: {
resourceCacheTTL: -1,
},
});
const { provider } = launched;

expect(provider.cache).toBeUndefined();
});

it('should cache resources only when TX is successfully submitted', async () => {
const resourceAmount = 5_000;
const utxosAmount = 2;

const testMessage = new TestMessage({ amount: resourceAmount });

using launched = await setupTestProviderAndWallets({
nodeOptions: {
args: ['--poa-instant', 'false', '--poa-interval-period', '1s'],
},
// 3 resources with a total of 15_000
walletsConfig: {
coinsPerAsset: utxosAmount,
amountPerCoin: resourceAmount,
messages: [testMessage],
},
});
const {
provider,
wallets: [wallet, receiver],
} = launched;

const baseAssetId = await provider.getBaseAssetId();
const { coins } = await wallet.getCoins(baseAssetId);

expect(coins.length).toBe(utxosAmount);

// Tx will cost 10_000 for the transfer + 1 for fee. All resources will be used
const EXPECTED = {
utxos: coins.map((coin) => coin.id),
messages: [testMessage.nonce],
};

await wallet.transfer(receiver.address, 10_000);

const cachedResources = provider.cache?.getActiveData();
expect(new Set(cachedResources?.utxos)).toEqual(new Set(EXPECTED.utxos));
expect(new Set(cachedResources?.messages)).toEqual(new Set(EXPECTED.messages));
});

it('should NOT cache resources when TX submission fails', async () => {
const message = new TestMessage({ amount: 100_000 });

using launched = await setupTestProviderAndWallets({
nodeOptions: {
args: ['--poa-instant', 'false', '--poa-interval-period', '1s'],
},
walletsConfig: {
coinsPerAsset: 2,
amountPerCoin: 20_000,
messages: [message],
},
});
const {
provider,
wallets: [wallet, receiver],
} = launched;

const baseAssetId = await provider.getBaseAssetId();
const maxFee = 100_000;
const transferAmount = 10_000;

const { coins } = await wallet.getCoins(baseAssetId);
const utxos = coins.map((c) => c.id);
const messages = [message.nonce];

// No enough funds to pay for the TX fee
const resources = await wallet.getResourcesToSpend([[transferAmount, baseAssetId]]);

const request = new ScriptTransactionRequest({
maxFee,
});

request.addCoinOutput(receiver.address, transferAmount, baseAssetId);
request.addResources(resources);

// Forcing TX submission to fail at submission state
vi.spyOn(wallet.provider, 'sendTransaction').mockImplementationOnce(() =>
Promise.reject(new FuelError(ErrorCode.INVALID_REQUEST, 'Tx failed'))
);

await expectToThrowFuelError(
() => wallet.sendTransaction(request, { estimateTxDependencies: false }),
{ code: ErrorCode.INVALID_REQUEST }
);

// No resources were cached since the TX submission failed
[...utxos, ...messages].forEach((key) => {
expect(provider.cache?.isCached(key)).toBeFalsy();
});

vi.restoreAllMocks();
});

it('should unset cached resources when TX execution fails', async () => {
const message = new TestMessage({ amount: 100_000 });

using launched = await setupTestProviderAndWallets({
nodeOptions: {
args: ['--poa-instant', 'false', '--poa-interval-period', '1s'],
},
walletsConfig: {
coinsPerAsset: 1,
amountPerCoin: 100_000,
messages: [message],
},
});
const {
provider,
wallets: [wallet, receiver],
} = launched;

const baseAssetId = await provider.getBaseAssetId();
const maxFee = 100_000;
const transferAmount = 10_000;

const { coins } = await wallet.getCoins(baseAssetId);
const utxos = coins.map((c) => c.id);
const messages = [message.nonce];

// Should fetch resources enough to pay for the TX fee and transfer amount
const resources = await wallet.getResourcesToSpend([[maxFee + transferAmount, baseAssetId]]);

const request = new ScriptTransactionRequest({
maxFee,
// No enough gas to execute the TX
gasLimit: 0,
});

request.addCoinOutput(receiver.address, transferAmount, baseAssetId);
request.addResources(resources);

// TX submission will succeed
const submitted = await wallet.sendTransaction(request, { estimateTxDependencies: false });

// Resources were cached since the TX submission succeeded
[...utxos, ...messages].forEach((key) => {
expect(provider.cache?.isCached(key)).toBeTruthy();
});

// TX execution will fail
await expectToThrowFuelError(() => submitted.waitForResult(), {
code: ErrorCode.SCRIPT_REVERTED,
});

// Ensure user's resources were unset from the cache
[...utxos, ...messages].forEach((key) => {
expect(provider.cache?.isCached(key)).toBeFalsy();
});
});

it('should ensure cached resources are not being queried', async () => {
// Fund the wallet with 2 resources
const testMessage = new TestMessage({ amount: 100_000_000_000 });
using launched = await setupTestProviderAndWallets({
nodeOptions: {
args: ['--poa-instant', 'false', '--poa-interval-period', '1s'],
},
walletsConfig: {
coinsPerAsset: 1,
amountPerCoin: 100_000_000_000,
messages: [testMessage],
},
});

const {
provider,
wallets: [wallet, receiver],
} = launched;
const baseAssetId = await provider.getBaseAssetId();
const transferAmount = 10_000;

const {
coins: [coin],
} = await wallet.getCoins(baseAssetId);

const {
messages: [message],
} = await wallet.getMessages();

// One of the resources will be cached as the TX submission was successful
await wallet.transfer(receiver.address, transferAmount);

// Determine the used and unused resource
const cachedResource = provider.cache?.isCached(coin.id) ? coin : message;
const uncachedResource = provider.cache?.isCached(coin.id) ? message : coin;

expect(cachedResource).toBeDefined();
expect(uncachedResource).toBeDefined();

// Spy on the getCoinsToSpend method to ensure the cached resource is not being queried
const resourcesToSpendSpy = vi.spyOn(provider.operations, 'getCoinsToSpend');
const fetchedResources = await wallet.getResourcesToSpend([[transferAmount, baseAssetId]]);

// Only one resource is available as the other one was cached
expect(fetchedResources.length).toBe(1);

// Ensure the returned resource is the non-cached one
const excludedIds: Required<ExcludeResourcesOption> = { messages: [], utxos: [] };
if (isCoin(fetchedResources[0])) {
excludedIds.messages = expect.arrayContaining([(<Message>cachedResource).nonce]);
excludedIds.utxos = expect.arrayContaining([]);
expect(fetchedResources[0].id).toEqual((<Coin>uncachedResource).id);
} else {
excludedIds.utxos = expect.arrayContaining([(<Coin>cachedResource).id]);
excludedIds.messages = expect.arrayContaining([]);
expect(fetchedResources[0].nonce).toEqual((<Message>uncachedResource).nonce);
}

// Ensure the getCoinsToSpend query was called excluding the cached resource
expect(resourcesToSpendSpy).toHaveBeenCalledWith({
owner: wallet.address.toB256(),
queryPerAsset: [
{
assetId: baseAssetId,
amount: String(transferAmount),
max: undefined,
},
],
excludedIds,
});
});

it('should validate max number of inputs at sendTransaction method', async () => {
const maxInputs = 2;
using launched = await setupTestProviderAndWallets({
Expand Down
37 changes: 18 additions & 19 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors';
import type { BigNumberish, BN } from '@fuel-ts/math';
import { bn } from '@fuel-ts/math';
import type { Transaction } from '@fuel-ts/transactions';
import { InputType, InputMessageCoder, TransactionCoder } from '@fuel-ts/transactions';
import { InputMessageCoder, TransactionCoder } from '@fuel-ts/transactions';
import type { BytesLike } from '@fuel-ts/utils';
import { arrayify, hexlify, DateTime, isDefined } from '@fuel-ts/utils';
import { checkFuelCoreVersionCompatibility, gte, versions } from '@fuel-ts/versions';
Expand Down Expand Up @@ -66,6 +66,7 @@ import {
import type { RetryOptions } from './utils/auto-retry-fetch';
import { autoRetryFetch } from './utils/auto-retry-fetch';
import { assertGqlResponseHasNoErrors } from './utils/handle-gql-error-message';
import { adjustResourcesToExclude } from './utils/helpers';
import { validatePaginationArgs } from './utils/validate-pagination-args';

const MAX_RETRIES = 10;
Expand Down Expand Up @@ -885,19 +886,7 @@ export default class Provider {
return;
}

const inputsToCache = inputs.reduce(
(acc, input) => {
if (input.type === InputType.Coin) {
acc.utxos.push(input.id);
} else if (input.type === InputType.Message) {
acc.messages.push(input.nonce);
}
return acc;
},
{ utxos: [], messages: [] } as Required<ExcludeResourcesOption>
);

this.cache.set(transactionId, inputsToCache);
this.cache.set(transactionId, inputs);
}

/**
Expand Down Expand Up @@ -1561,15 +1550,25 @@ export default class Provider {
excludedIds?: ExcludeResourcesOption
): Promise<Resource[]> {
const ownerAddress = new Address(owner);
const excludeInput = {
let idsToExclude = {
messages: excludedIds?.messages?.map((nonce) => hexlify(nonce)) || [],
utxos: excludedIds?.utxos?.map((id) => hexlify(id)) || [],
};

if (this.cache) {
const cached = this.cache.getActiveData();
excludeInput.messages.push(...cached.messages);
excludeInput.utxos.push(...cached.utxos);
const cached = this.cache.getActiveData(ownerAddress.toB256());
if (cached.utxos.length || cached.messages.length) {
const {
consensusParameters: {
txParameters: { maxInputs },
},
} = await this.getChain();
idsToExclude = adjustResourcesToExclude({
userInput: idsToExclude,
cached,
maxInputs: maxInputs.toNumber(),
});
}
}

const coinsQuery = {
Expand All @@ -1581,7 +1580,7 @@ export default class Provider {
amount: amount.toString(10),
max: maxPerAsset ? maxPerAsset.toString(10) : undefined,
})),
excludedIds: excludeInput,
excludedIds: idsToExclude,
};

const result = await this.operations.getCoinsToSpend(coinsQuery);
Expand Down
Loading
Loading