-
Notifications
You must be signed in to change notification settings - Fork 830
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
feat: Added dry run feature for default tx executor and logs file #96
Open
nikola43
wants to merge
4
commits into
warp-id:master
Choose a base branch
from
nikola43:feat/simulate-tx
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
BlockhashWithExpiryBlockHeight, | ||
Keypair, | ||
VersionedTransaction | ||
} from '@solana/web3.js'; | ||
import { AxiosError } from 'axios'; | ||
|
||
import { TransactionExecutor } from './transaction-executor.interface'; | ||
import { load, DataType, open, close } from 'ffi-rs'; | ||
import bs58 from 'bs58'; | ||
import { logger } from '../helpers'; | ||
|
||
export class TpuTransactionExecutor implements TransactionExecutor { | ||
|
||
constructor() { } | ||
|
||
public async executeAndConfirm( | ||
transaction: VersionedTransaction, | ||
payer: Keypair, | ||
latestBlockhash: BlockhashWithExpiryBlockHeight, | ||
simulate: boolean | ||
): Promise<{ confirmed: boolean; signature?: string }> { | ||
const serializedTransaction = transaction.serialize(); | ||
const signatureBase58 = bs58.encode(transaction.signatures[0]); | ||
let result = false | ||
try { | ||
open({ | ||
library: 'tpu_client', // key | ||
path: "/Users/kasiopea/dev/rust/tpu-sol-test/target/aarch64-apple-darwin/release/libtpu_client.dylib" // path | ||
}) | ||
const RPC_ENDPOINT="http://127.0.0.1:8899" | ||
const RPC_WEBSOCKET_ENDPOINT="ws://127.0.0.1:8900" | ||
|
||
|
||
result = load({ | ||
library: "tpu_client", // path to the dynamic library file | ||
funcName: 'send_tpu_tx', // the name of the function to call | ||
retType: DataType.Boolean, // the return value type | ||
paramsType: [DataType.String, DataType.String, DataType.U8Array, DataType.I32], // the parameter types | ||
paramsValue: [RPC_ENDPOINT, RPC_WEBSOCKET_ENDPOINT, serializedTransaction, serializedTransaction.length] // the actual parameter values | ||
}) | ||
console.log({ | ||
result | ||
}) | ||
} catch (error) { | ||
logger.error(error, "executeAndConfirm"); | ||
if (error instanceof AxiosError) { | ||
logger.trace({ error: error.response?.data }, 'Failed to execute warp transaction'); | ||
} | ||
} finally { | ||
close('tpu_client') | ||
} | ||
|
||
return { confirmed: result, signature: signatureBase58 }; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been researching how to call the TPU as people say transactions are faster, I've tried using
https://github.com/lmvdz/tpu-client but it doesn't work because solana migrated to quic, so the only way I've had to use it from TS is creating a mini library in rust and doing binding to ts using ffi-rs, this is the code
https://github.com/nikola43/tpu_client
So i serialize tx and send it to tpu_client for release it
I forgot add compiled library to project and leave my local path, my idea is build for mac, windows and linux for bot be compatible with any OS.
Refereces:
https://solana.stackexchange.com/questions/5971/tpu-client-sometimes-the-transaction-doesnt-go-through-0-5-sol-bounty
https://solana.stackexchange.com/questions/9502/optimal-transaction-execution-speed
https://solana.stackexchange.com/questions/10003/solana-tpu-client-and-sending-versioned-transactions