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

[work-in-progress] improve manual relay #245

Merged
merged 11 commits into from
Feb 14, 2023
Merged

Conversation

canhtrinh
Copy link
Collaborator

@canhtrinh canhtrinh commented Feb 10, 2023

this PR fixes #175.

the issue was in the manualRelayToDestChain method, which was eagerly attempting to confirm every tx hash without first checking whether the tx has already been confirmed on the network.

the issue that comes up with cannot sign command comes up for transactions that were already confirmed but the batch has not been broadcasted to the destination chain.

this fix:

  • first checks to see whether the transaction was executed/approved/confirmed.
  • if already executed/approved, do nothing
  • if already confirmed, attempt to extract the commandId and query the batchedCommandID from the axelarscan API. then check if the commandID in that batched has not been executed, and execute if need be.
  • otherwise, do as before.

@canhtrinh canhtrinh changed the title Improve manual relay [work-in-progress] improve manual relay Feb 10, 2023
CHANGELOG.md Outdated Show resolved Hide resolved
@@ -97,6 +104,9 @@ export class AxelarGMPRecoveryAPI extends AxelarRecoveryApi {
signCommandTx,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused create pending transfer variable above

@@ -97,6 +104,9 @@ export class AxelarGMPRecoveryAPI extends AxelarRecoveryApi {
signCommandTx,
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused create pending transfer variable above

@@ -0,0 +1,15 @@
import { arrayify, keccak256 } from "ethers/lib/utils";

export function getCommandId(chainID: number, txHash: string, sourceEventIndex: number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a link to core for the derivation?

@@ -173,14 +181,15 @@ export function findContractEvent(
eventSignatures: string[],
abiInterface: Interface
): Nullable<EventLog> {
for (const log of receipt.logs) {
for (const [index, log] of receipt.logs.entries()) {
const eventIndex = eventSignatures.indexOf(log.topics[0]);
if (eventIndex > -1) {
const eventLog = abiInterface.parseLog(log);
return {
signature: eventSignatures[eventIndex],
eventLog,
logIndex: log.logIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logIndex is the event index, right?

const batchData = await this.fetchBatchData(commandId);
if (batchData) {
const command = batchData.commands.find((command) => command.id === commandId);
if (command && !command?.executed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not very readable, should encapsulate in a separate function, and return early on the failure condition for less nested ifs


if (!signEvent) return errorResponse(ApproveGatewayError.SIGN_COMMAND_FAILED);

await sleep(2);
const batchedCommandId = signEvent.attributes.find(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sign commands is racing axelarons here, so you will often not get the correct batch id to relay. The logic is also duplicated. I think this should be split across a few functions, and look something like:

  1. Add a method to check if tx hash is confirmed. Use the event query for this.
  2. If the event status is failed, abort.
  3. If not confirmed yet, check if tx is finalized (this could be skipped if axelarscan only shows the Approve button after src tx is finalized, to keep the logic here simpler, otherwise this method should check if latest block is x block confirmations over tx).
  4. And then call the confirm gateway tx method. Wait for 30s for votes to go through (can take 2-3 blocks) and signing/relaying to occur.
  5. Check if event is in completed status now. Fail if not.
  6. if event was in completed status, 2-5 can be skipped.
  7. If destination chain is not EVM, fail (with cosmos gmp this will change).
  8. Check if command is executed.
  9. If the batch itself wasn't found, then sign and wait 20s
  10. If the batch wasn't found OR command wasn't executed, submit batch to gateway using user's wallet, and wait for 20s.
  11. If command is still not executed, return an error.

@alanrsoares alanrsoares merged commit c8cc874 into v0.12.5 Feb 14, 2023
@alanrsoares alanrsoares deleted the improveManualRelay branch February 14, 2023 00:19
@canhtrinh canhtrinh mentioned this pull request Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants