Skip to content

Commit

Permalink
Merge pull request #2243 from Chia-Network/paninaro.mempool_conflict_…
Browse files Browse the repository at this point in the history
…message

Special handling for MEMPOOL_CONFLICT txn status
  • Loading branch information
seeden authored Dec 20, 2023
2 parents e6f0cce + 73ac1d8 commit 5033e71
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
11 changes: 9 additions & 2 deletions packages/core/src/utils/getTransactionResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ export default function getTransactionResult(transaction): {

// At least one node has accepted our transaction as pending
const pendingNodeResponse = transaction.sentTo.find((item) => item[1] === mempoolInclusionStatus.PENDING);
if (pendingNodeResponse) {

// Note: A refactoring of this is probably warranted, especially if additional mempool statuses need special handling
//
// For now, MEMPOOL_CONFLICT will be treated as a failure, but we'll display an error explaining that the full node
// will retry to include the txn if the conflicts are resolved.
const ignoredMempoolStatuses = ['MEMPOOL_CONFLICT'];

if (pendingNodeResponse && !ignoredMempoolStatuses.includes(pendingNodeResponse[2])) {
return {
message: t`Transaction has sent to a full node and is pending inclusion into the mempool. ${pendingNodeResponse[2]}`,
message: t`Transaction has been sent to a full node and is pending inclusion into the mempool. ${pendingNodeResponse[2]}`,
success: true,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AlertDialog, Flex } from '@chia-network/core';
import { Trans } from '@lingui/macro';
import { Trans, t } from '@lingui/macro';
import React from 'react';

type WalletSendTransactionResultDialogProps = {
Expand All @@ -12,6 +12,10 @@ function WalletSendTransactionResultDialogTitle(success: boolean, message: strin
return <Trans>Success</Trans>;
}

if (message === 'MEMPOOL_CONFLICT') {
return <Trans>Mempool Conflict</Trans>;
}

if (message === 'INVALID_FEE_TOO_CLOSE_TO_ZERO' || message === 'INVALID_FEE_LOW_FEE') {
return <Trans>Mempool Full</Trans>;
}
Expand All @@ -27,22 +31,28 @@ function WalletSendTransactionResultDialogContent(
return message ?? <Trans>Transaction has successfully been sent to a full node and included in the mempool.</Trans>;
}

let message1;
let message2;

if (message === 'MEMPOOL_CONFLICT') {
message1 = t`The transaction is pending inclusion in the mempool because it conflicts with one or more other transactions
already in the mempool. The transaction will be retried periodically, and may be included in the mempool if
the conflicting transactions are removed.`;
}

if (message === 'INVALID_FEE_TOO_CLOSE_TO_ZERO' || message === 'INVALID_FEE_LOW_FEE') {
message1 = t`The transaction could not be immediately included in the mempool because the specified fee is too low. The
transaction will be retried periodically, and may be included in the mempool once fees are lower, or if
space becomes available.`;
message2 = t`If you would like to speed up the transaction, please delete unconfirmed transactions and retry with a
higher fee.`;
}

if (message1) {
return (
<Flex flexDirection="column" gap={3}>
<Flex>
<Trans>
The transaction could not be immediately included in the mempool because the specified fee is too low. The
transaction will be retried periodically, and may be included in the mempool once fees are lower, or if
space becomes available.
</Trans>
</Flex>
<Flex>
<Trans>
If you would like to speed up the transaction, please delete unconfirmed transactions and retry with a
higher fee.
</Trans>
</Flex>
<Flex>{message1}</Flex>
{message2 && <Flex>{message2}</Flex>}
</Flex>
);
}
Expand Down

0 comments on commit 5033e71

Please sign in to comment.