@clonegod/ttd-sol-common 2.0.84 → 2.0.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,6 +9,7 @@ export declare class SolTransactionBuilder {
|
|
|
9
9
|
recentBlockheight: number;
|
|
10
10
|
constructor(appConfig: SolanaTradeAppConfig);
|
|
11
11
|
init(): Promise<void>;
|
|
12
|
+
private warmupSigner;
|
|
12
13
|
private handleBlockUpdateEvent;
|
|
13
14
|
private getPreInstructions;
|
|
14
15
|
private createComputeUnitLimitWithJitoDontFront;
|
package/dist/trade/tx_builder.js
CHANGED
|
@@ -56,6 +56,24 @@ class SolTransactionBuilder {
|
|
|
56
56
|
}
|
|
57
57
|
async init() {
|
|
58
58
|
this.appConfig.arb_event_subscriber.subscribe_new_block(dist_1.CHAIN_ID.SOLANA, this.handleBlockUpdateEvent.bind(this));
|
|
59
|
+
this.warmupSigner();
|
|
60
|
+
}
|
|
61
|
+
warmupSigner() {
|
|
62
|
+
try {
|
|
63
|
+
for (let i = 0; i < 2; i++) {
|
|
64
|
+
const tx = new web3_js_1.Transaction();
|
|
65
|
+
tx.add(web3_js_1.SystemProgram.transfer({
|
|
66
|
+
fromPubkey: this.keypair.publicKey,
|
|
67
|
+
toPubkey: this.keypair.publicKey,
|
|
68
|
+
lamports: 0,
|
|
69
|
+
}));
|
|
70
|
+
tx.recentBlockhash = '11111111111111111111111111111111';
|
|
71
|
+
tx.feePayer = this.keypair.publicKey;
|
|
72
|
+
tx.sign(this.keypair);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
}
|
|
59
77
|
}
|
|
60
78
|
async handleBlockUpdateEvent(eventData) {
|
|
61
79
|
let blockUpdateEvent = JSON.parse(eventData);
|
package/package.json
CHANGED
package/src/trade/tx_builder.ts
CHANGED
|
@@ -83,6 +83,29 @@ export class SolTransactionBuilder {
|
|
|
83
83
|
public async init(): Promise<void> {
|
|
84
84
|
// 订阅区块更新事件
|
|
85
85
|
this.appConfig.arb_event_subscriber.subscribe_new_block(CHAIN_ID.SOLANA, this.handleBlockUpdateEvent.bind(this));
|
|
86
|
+
// 预热签名路径:web3.js 1.98 用 @noble/curves/ed25519,首次 sign 要懒构建 base-point wNAF 表
|
|
87
|
+
// + V8 JIT 整条 compileMessage/serialize 路径,冷启动 ~34ms。在 init 跑几笔 dummy sign
|
|
88
|
+
// 把这 ~30ms 从「第一笔真实交易的关键路径」挪到进程启动期(实测首笔 34ms→~5ms)。
|
|
89
|
+
this.warmupSigner()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 进程启动期预热 ed25519 签名 + 序列化热路径,消除第一笔交易的冷启动尖刺 */
|
|
93
|
+
private warmupSigner(): void {
|
|
94
|
+
try {
|
|
95
|
+
for (let i = 0; i < 2; i++) {
|
|
96
|
+
const tx = new Transaction()
|
|
97
|
+
tx.add(SystemProgram.transfer({
|
|
98
|
+
fromPubkey: this.keypair.publicKey,
|
|
99
|
+
toPubkey: this.keypair.publicKey,
|
|
100
|
+
lamports: 0,
|
|
101
|
+
}))
|
|
102
|
+
tx.recentBlockhash = '11111111111111111111111111111111' // 仅预热用,不广播
|
|
103
|
+
tx.feePayer = this.keypair.publicKey
|
|
104
|
+
tx.sign(this.keypair)
|
|
105
|
+
}
|
|
106
|
+
} catch {
|
|
107
|
+
// 预热失败不影响主流程(首笔退化为冷签名)
|
|
108
|
+
}
|
|
86
109
|
}
|
|
87
110
|
|
|
88
111
|
private async handleBlockUpdateEvent(eventData: string): Promise<void> {
|
|
@@ -196,7 +219,7 @@ export class SolTransactionBuilder {
|
|
|
196
219
|
swapTx.instructions.push(tip_instruction)
|
|
197
220
|
|
|
198
221
|
const _t1 = Date.now()
|
|
199
|
-
swapTx.sign(this.keypair) // = compileMessage(serialize) + ed25519
|
|
222
|
+
swapTx.sign(this.keypair) // = compileMessage(serialize) + @noble/curves ed25519 签名(已在 init 预热)
|
|
200
223
|
const _t2 = Date.now()
|
|
201
224
|
// 耗时拆分(debug 级,不刷屏):assemble=组装指令+设字段;sign=编译消息+ed25519 签名
|
|
202
225
|
log_debug(`[txBuilder] build breakdown: assemble=${_t1 - _t0}ms sign=${_t2 - _t1}ms total=${_t2 - _t0}ms`)
|