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

optimise tx confirmation #149

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"packages": [
"packages/*"
],
"version": "5.11.3",
"version": "5.11.4",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion packages/stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@streamflow/stream",
"version": "5.11.3",
"version": "5.11.4",
"description": "JavaScript SDK to interact with Streamflow protocol.",
"homepage": "https://github.com/streamflow-finance/js-sdk/",
"main": "dist/index.js",
Expand Down
24 changes: 9 additions & 15 deletions packages/stream/solana/StreamClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ export default class SolanaStreamClient extends BaseStreamClient {
this.connection,
ixs,
extParams.sender.publicKey,
this.getCommitment(),
undefined,

metadata
);
const signature = await signAndExecuteTransaction(this.connection, extParams.sender, tx, hash);
Expand Down Expand Up @@ -288,7 +289,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
this.connection,
ixs,
extParams.sender.publicKey,
this.getCommitment(),
undefined,
metadata
);
const signature = await signAndExecuteTransaction(this.connection, extParams.sender, tx, hash);
Expand Down Expand Up @@ -457,9 +458,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
instructionsBatch.push({ ixs, metadata, recipient: recipientData.recipient });
}

const commitment =
typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
const hash = await this.connection.getLatestBlockhash(commitment);
const hash = await this.connection.getLatestBlockhash();

for (const { ixs, metadata, recipient } of instructionsBatch) {
const tx = new Transaction({
Expand Down Expand Up @@ -554,8 +553,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
const { tx, hash } = await prepareTransaction(
this.connection,
ixs,
extParams.invoker.publicKey,
this.getCommitment()
extParams.invoker.publicKey
);
const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash);

Expand Down Expand Up @@ -619,8 +617,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
const { tx, hash } = await prepareTransaction(
this.connection,
ixs,
extParams.invoker.publicKey,
this.getCommitment()
extParams.invoker.publicKey
);
const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash);

Expand Down Expand Up @@ -691,8 +688,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
const { tx, hash } = await prepareTransaction(
this.connection,
ixs,
extParams.invoker.publicKey,
this.getCommitment()
extParams.invoker.publicKey
);
const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash);

Expand Down Expand Up @@ -756,8 +752,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
const { tx, hash } = await prepareTransaction(
this.connection,
ixs,
extParams.invoker.publicKey,
this.getCommitment()
extParams.invoker.publicKey
);
const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash);

Expand Down Expand Up @@ -884,8 +879,7 @@ export default class SolanaStreamClient extends BaseStreamClient {
const { tx, hash } = await prepareTransaction(
this.connection,
ixs,
extParams.invoker.publicKey,
this.getCommitment()
extParams.invoker.publicKey
);
const signature = await signAndExecuteTransaction(this.connection, extParams.invoker, tx, hash);

Expand Down
8 changes: 7 additions & 1 deletion packages/stream/solana/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ export function isSignerKeypair(
}

/**
* Creates a Transaction with given instructions and optionally signs it
* Creates a Transaction with given instructions and optionally signs it.
* Be careful when passing `commitment` as for `confirmed` blockhash it always returns blockheight + 300 in `lastValidBlockHeight`
* And if you use this blockheight to confirm the transaction it could happen so that transaction is successfully executed
* But because `confirmTransaction` waits for only a minute it considers tx as expired as it could be that 300 blocks won't pass in a minute
* https://solana.stackexchange.com/questions/6238/why-is-lastvalidblockheight-300-blocks-ahead-than-current-blockheight-if-hashes
* https://solana.com/docs/core/transactions/retry
* It might be better to rely on `commitment` level that you pass to `Connection` instance of Solana client as it will be used when fetching blockheight on transaction confirmation
* @param connection - Solana client connection
* @param ixs - Instructions to add to the Transaction
* @param payer - PublicKey of payer
Expand Down
Loading