Skip to content

Commit dc5714f

Browse files
docs: clarify batch optimizer preview status and limitations
Address CodeRabbit review feedback by clearly documenting that: - Gas estimation uses average values (71k/tx) not actual estimateGas calls - Execute endpoint provides cost estimates only, does not queue transactions - Status endpoint returns placeholder data pending queue integration Changes: - Add prominent "Preview Status" warning section to BATCH_OPTIMIZER.md - Update execute endpoint to return "estimated" status with clear warning message - Update status endpoint to indicate "estimated" state with limitation notice - Add warning field to batchStatusSchema for API transparency - Add detailed TODO comments explaining integration needs This makes it crystal clear to users that this is a demonstration/preview feature showing the API design and cost analysis capabilities, while actual transaction execution requires integration with SendTransactionQueue. Addresses CodeRabbit issues: placeholder gas estimation, non-functional execute endpoint, and placeholder status tracking
1 parent 2cd0f8b commit dc5714f

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

docs/BATCH_OPTIMIZER.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
11
# Smart Transaction Batch Optimizer 🚀
22

3+
## ⚠️ Preview Status
4+
5+
**This feature is currently in PREVIEW mode for demonstration and testing purposes.**
6+
7+
**Current Limitations:**
8+
- ✅ Gas price analysis and cost estimation - **WORKING**
9+
- ✅ Batch metadata caching and tracking - **WORKING**
10+
- ⚠️ **Gas estimation uses average values (71k gas/tx) instead of actual estimateGas calls**
11+
- ⚠️ **Execute endpoint does NOT actually queue transactions to blockchain**
12+
- ⚠️ **Status endpoint returns placeholder data only**
13+
14+
**Use this feature to:**
15+
- Explore the batch optimizer API design
16+
- Test cost estimation and gas price analysis
17+
- Evaluate potential gas savings for your use case
18+
19+
**Production Integration Required:**
20+
- Integration with `SendTransactionQueue` for actual execution
21+
- Real `eth_estimateGas` calls for accurate gas estimates
22+
- Database/queue polling for transaction status tracking
23+
24+
See "Future Enhancements" section for full production roadmap.
25+
26+
---
27+
328
## Overview
429

5-
A game-changing feature that helps users **save 15-30% on gas costs** while giving thirdweb Engine unprecedented scalability through intelligent transaction batching and cost optimization.
30+
A feature designed to help users **save 15-30% on gas costs** while giving thirdweb Engine unprecedented scalability through intelligent transaction batching and cost optimization.
631

732
## Why This Matters
833

src/server/routes/transaction/batch-optimizer.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const executeBatchRequestSchema = Type.Object({
119119
const batchStatusSchema = Type.Object({
120120
batchId: Type.String(),
121121
status: Type.Literal("pending")
122+
.Or(Type.Literal("estimated"))
122123
.Or(Type.Literal("queued"))
123124
.Or(Type.Literal("processing"))
124125
.Or(Type.Literal("completed"))
@@ -133,6 +134,7 @@ const batchStatusSchema = Type.Object({
133134
transactionHash: Type.Optional(Type.String()),
134135
}),
135136
),
137+
warning: Type.Optional(Type.String()),
136138
});
137139

138140
// Helper to generate batch ID
@@ -151,12 +153,17 @@ const getBatchData = async (batchId: string) => {
151153
};
152154

153155
// Estimate gas for transactions
156+
// NOTE: This is a simplified estimation using average gas values.
157+
// TODO: Replace with actual estimateGas calls for production accuracy.
158+
// Current implementation provides conservative estimates but may not reflect
159+
// actual gas costs for complex contract interactions.
154160
const estimateGasForBatch = async (
155161
chainId: number,
156162
transactions: any[],
157163
): Promise<bigint> => {
158-
// Simplified estimation - in production, would call estimateGas for each
159-
const avgGasPerTx = 21000n + 50000n; // Base + avg contract interaction
164+
// Using average gas: 21k (base transfer) + 50k (avg contract call)
165+
// Real implementation should call eth_estimateGas for each transaction
166+
const avgGasPerTx = 21000n + 50000n;
160167
return BigInt(transactions.length) * avgGasPerTx;
161168
};
162169

@@ -374,25 +381,27 @@ export async function executeBatchTransactions(fastify: FastifyInstance) {
374381

375382
const { fromAddress, chainId, transactions, optimization } = batchData;
376383

377-
// TODO: Integrate with actual transaction queue
378-
// For now, return success with placeholder queue IDs
384+
// IMPORTANT: This is a placeholder implementation
385+
// TODO: Integrate with SendTransactionQueue to actually queue transactions
386+
// Current implementation only estimates and caches batch data for demonstration
379387
const queueIds = transactions.map(
380388
(_: any, i: number) => `${batchId}_tx_${i}`,
381389
);
382390

383391
// Update batch status in Redis
384392
await cacheBatchData(batchId, {
385393
...batchData,
386-
status: "queued",
394+
status: "estimated", // Changed from "queued" to reflect actual state
387395
queueIds,
388-
executedAt: Date.now(),
396+
estimatedAt: Date.now(),
389397
});
390398

391399
reply.status(StatusCodes.OK).send({
392400
batchId,
393-
status: "queued",
394-
message: `Batch of ${transactions.length} transactions queued for execution with ${optimization} optimization`,
401+
status: "estimated",
402+
message: `Batch of ${transactions.length} transactions estimated. Note: Actual execution integration pending - this endpoint currently provides cost estimates only.`,
395403
queueIds,
404+
warning: "Batch optimizer is in preview mode. Transactions are not actually queued for execution yet.",
396405
});
397406
},
398407
);
@@ -430,20 +439,23 @@ export async function getBatchStatus(fastify: FastifyInstance) {
430439

431440
const { transactions, queueIds = [] } = batchData;
432441

433-
// TODO: Get actual transaction statuses from queue
442+
// IMPORTANT: Placeholder status implementation
443+
// TODO: Query actual transaction statuses from SendTransactionQueue/database
444+
// Current implementation only returns cached estimation data
434445
const txStatuses = queueIds.map((queueId: string, i: number) => ({
435446
queueId,
436-
status: "pending",
447+
status: "estimated", // Reflects that transactions are not actually queued
437448
transactionHash: undefined,
438449
}));
439450

440451
const response = {
441452
batchId,
442-
status: batchData.status || "pending",
453+
status: batchData.status || "estimated",
443454
transactionCount: transactions.length,
444455
completedCount: 0,
445456
failedCount: 0,
446457
transactions: txStatuses,
458+
warning: "Batch optimizer is in preview mode. Status tracking not yet implemented.",
447459
} satisfies Static<typeof batchStatusSchema>;
448460

449461
reply.status(StatusCodes.OK).send(response);

0 commit comments

Comments
 (0)