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

Revert "Estimate gas for RRP fulfillments" #1710

Merged
merged 2 commits into from
Apr 4, 2023
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
6 changes: 0 additions & 6 deletions .changeset/eighty-goats-provide.md

This file was deleted.

2 changes: 2 additions & 0 deletions .changeset/stupid-cups-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
1,216 changes: 351 additions & 865 deletions packages/airnode-node/src/evm/fulfillments/api-calls.test.ts

Large diffs are not rendered by default.

102 changes: 7 additions & 95 deletions packages/airnode-node/src/evm/fulfillments/api-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,6 @@ async function testFulfill(
return [[noticeLog], null, goRes.data];
}

async function estimateGasToFulfill(
airnodeRrp: AirnodeRrpV0,
request: Request<ApiCallWithResponse>
): Promise<LogsErrorData<ethers.BigNumber>> {
const noticeLog = logger.pend(
'DEBUG',
`Attempting to estimate gas for API call fulfillment for Request:${request.id}...`
);
if (!request.success) return [[], new Error('Only successful API can be submitted'), null];

const operation = (): Promise<ethers.BigNumber> =>
airnodeRrp.estimateGas.fulfill(
request.id,
request.airnodeAddress,
request.fulfillAddress,
request.fulfillFunctionId,
request.data.encodedValue,
request.data.signature
);
const goRes = await go(operation, { retries: 1, attemptTimeoutMs: BLOCKCHAIN_CALL_ATTEMPT_TIMEOUT });
if (!goRes.success) {
const errorLog = logger.pend(
'ERROR',
`Gas estimation for API call fulfillment failed for Request:${request.id} with ${goRes.error}`,
goRes.error
);
return [[noticeLog, errorLog], goRes.error, null];
}

return [[noticeLog], null, goRes.data];
}

async function submitFulfill(
airnodeRrp: AirnodeRrpV0,
request: Request<ApiCallWithResponse>,
Expand Down Expand Up @@ -140,11 +108,16 @@ async function submitFulfill(
return [[noticeLog], null, applyTransactionResult(request, goRes.data)];
}

export async function testAndSubmitFulfill(
async function testAndSubmitFulfill(
airnodeRrp: AirnodeRrpV0,
request: Request<ApiCallWithResponse>,
options: TransactionOptions
): Promise<LogsErrorData<Request<ApiCallWithResponse>>> {
const errorMessage = requests.getErrorMessage(request);
if (errorMessage) {
return submitFail(airnodeRrp, request, errorMessage, options);
}

// Should not throw
const [testLogs, testErr, testData] = await testFulfill(airnodeRrp, request, options);

Expand Down Expand Up @@ -178,60 +151,6 @@ export async function testAndSubmitFulfill(
return [[...testLogs, errorLog], testErr, null];
}

export async function estimateGasAndSubmitFulfill(
airnodeRrp: AirnodeRrpV0,
request: Request<ApiCallWithResponse>,
options: TransactionOptions
): Promise<LogsErrorData<Request<ApiCallWithResponse>>> {
// Should not throw
const [estimateGasLogs, estimateGasErr, estimateGasData] = await estimateGasToFulfill(airnodeRrp, request);

if (estimateGasErr || !estimateGasData) {
// Make static test call to get revert string
const [testLogs, testErr, testData] = await testFulfill(airnodeRrp, request, options);

if (testErr || !testData || !testData.callSuccess) {
const updatedRequest: Request<ApiCallWithResponse> = {
...request,
errorMessage: testErr
? `${RequestErrorMessage.FulfillTransactionFailed} with error: ${testErr.message}`
: RequestErrorMessage.FulfillTransactionFailed,
};
const [submitLogs, submitErr, submittedRequest] = await submitFail(
airnodeRrp,
updatedRequest,
testErr?.message ?? decodeRevertString(testData?.callData || '0x'),
options
);
return [[...estimateGasLogs, ...testLogs, ...submitLogs], submitErr, submittedRequest];
}

// If static test call is successful even though gas estimation failure,
// it'll be caused by an RPC issue, so submit specific reason to chain
const updatedRequest: Request<ApiCallWithResponse> = {
...request,
errorMessage: estimateGasErr
? `${RequestErrorMessage.GasEstimationFailed} with error: ${estimateGasErr.message}`
: RequestErrorMessage.GasEstimationFailed,
};
const [submitLogs, submitErr, submittedRequest] = await submitFail(
airnodeRrp,
updatedRequest,
estimateGasErr?.message ?? RequestErrorMessage.GasEstimationFailed,
options
);
return [[...estimateGasLogs, ...testLogs, ...submitLogs], submitErr, submittedRequest];
}

// If gas estimation is success, submit fulfillment without making static test call
const gasLimitNoticeLog = logger.pend('INFO', `Gas limit is set to ${estimateGasData} for Request:${request.id}.`);
const [submitLogs, submitErr, submitData] = await submitFulfill(airnodeRrp, request, {
...options,
gasTarget: { ...options.gasTarget, gasLimit: estimateGasData },
});
return [[...estimateGasLogs, gasLimitNoticeLog, ...submitLogs], submitErr, submitData];
}

// =================================================================
// Failures
// =================================================================
Expand Down Expand Up @@ -284,13 +203,6 @@ export const submitApiCall: SubmitRequest<ApiCallWithResponse> = (airnodeRrp, re
return Promise.resolve([[log], null, null]);
}

const errorMessage = requests.getErrorMessage(request);
if (errorMessage) {
return submitFail(airnodeRrp, request, errorMessage, options);
}

// Should not throw
if (options.gasTarget.gasLimit) return testAndSubmitFulfill(airnodeRrp, request, options);

return estimateGasAndSubmitFulfill(airnodeRrp, request, options);
return testAndSubmitFulfill(airnodeRrp, request, options);
};
4 changes: 1 addition & 3 deletions packages/airnode-node/src/evm/fulfillments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ const failMock = jest.fn();
const fulfillMock = jest.fn();
const fulfillWithdrawalMock = jest.fn();
const staticFulfillMock = jest.fn();
const estimateFulfillMock = jest.fn();
mockEthers({
airnodeRrpMocks: {
callStatic: {
fulfill: staticFulfillMock,
},
estimateGas: { fulfill: estimateFulfillMock, fulfillWithdrawal: estimateWithdrawalGasMock },
estimateGas: { fulfillWithdrawal: estimateWithdrawalGasMock },
fail: failMock,
fulfill: fulfillMock,
fulfillWithdrawal: fulfillWithdrawalMock,
Expand Down Expand Up @@ -58,7 +57,6 @@ describe('submit', () => {
const provider = new ethers.providers.JsonRpcProvider();
const state = providerState.update(mutableInitialState, { gasTarget, provider, requests });

estimateFulfillMock.mockResolvedValue(73804);
staticFulfillMock.mockResolvedValue({ callSuccess: true });
fulfillMock.mockResolvedValueOnce({ hash: '0xapicall_tx1' });
fulfillMock.mockResolvedValueOnce({ hash: '0xapicall_tx2' });
Expand Down
1 change: 0 additions & 1 deletion packages/airnode-node/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export enum RequestErrorMessage {
ApiCallFailed = 'API call failed',
ReservedParametersInvalid = 'Reserved parameters are invalid',
FulfillTransactionFailed = 'Fulfill transaction failed',
GasEstimationFailed = 'Gas estimation failed',
SponsorRequestLimitExceeded = 'Sponsor request limit exceeded',
}

Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-validator/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const gasPriceOracleSchema = z

export const chainOptionsSchema = z
.object({
fulfillmentGasLimit: z.number().int().optional(),
fulfillmentGasLimit: z.number().int(),
withdrawalRemainder: amountSchema.optional(),
gasPriceOracle: gasPriceOracleSchema,
})
Expand Down