Skip to content

Commit

Permalink
optimise tx confirmation (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaStreamflow authored Mar 26, 2024
1 parent cba5f39 commit 37ccf37
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
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

0 comments on commit 37ccf37

Please sign in to comment.