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

Implement RBF and CPFP with new fees package and add pending transactions view in @caravan/coordinator #116

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Legend101Zz
Copy link
Contributor

This commit lays foundation of introduction of significant enhancements to be done to the transaction management capabilities of caravan/coordinator, focusing on Replace-By-Fee (RBF) and Child-Pays-For-Parent (CPFP) functionalities, along with a new pending transactions view.

Key changes Expected:

  1. Pending Transactions View:

    • Add new component 'PendingTransactionsView' in src/components/Wallet/
    • Implement basic layout showing transaction ID, amount, recipient, and timestamp
    • Integrate view into main Wallet dashboard
  2. Enhanced Transaction Information:

    • Add 'TransactionDetails' component to display comprehensive tx info
    • Implement time-pending calculation and display
    • Add current fee rate vs market rate comparison
    • Include estimated blocks until confirmation based on current mempool state
  3. Fee Bumping Possibility Indicators:

    • Add RBF status indicator to transaction details
    • Implement change output detection and display
    • Calculate and show estimated cost for potential fee bump
  4. UI Support for Manual RBF:

    • Modify existing transaction creation flow to support RBF
    • Add RBF toggle in transaction creation form (OutputsForm.jsx)
    • Implement logic to replace existing transaction when RBF is selected
  5. Fee Bumping Interfaces:

    • Add 'CancelTransaction' button and associated logic
    • Implement 'AccelerateTransaction' functionality
    • Create 'DownloadPSBT' option for RBF/CPFP transactions
    • Modify transaction authoring page to support pre-filled RBF/CPFP data
  6. Integration with new fees package:

    • Import and utilize functions from @caravan/fees for fee calculations
    • Implement FeeManager class to handle fee-related operations
  7. State Management Updates:

    • Add new reducers for managing pending transactions and fee bump operations
    • Implement new actions for RBF and CPFP operations
    • Update selectors to support new state structure

…ions view in @caravan/coordinator

This commit introduces significant enhancements to the transaction management
capabilities of caravan/coordinator, focusing on Replace-By-Fee (RBF) and
Child-Pays-For-Parent (CPFP) functionalities, along with a new pending
transactions view.

Key changes Expected:

1. Pending Transactions View:
   - Add new component 'PendingTransactionsView' in src/components/Wallet/
   - Implement basic layout showing transaction ID, amount, recipient, and timestamp
   - Integrate view into main Wallet dashboard

2. Enhanced Transaction Information:
   - Add 'TransactionDetails' component to display comprehensive tx info
   - Implement time-pending calculation and display
   - Add current fee rate vs market rate comparison
   - Include estimated blocks until confirmation based on current mempool state

3. Fee Bumping Possibility Indicators:
   - Add RBF status indicator to transaction details
   - Implement change output detection and display
   - Calculate and show estimated cost for potential fee bump

4. UI Support for Manual RBF:
   - Modify existing transaction creation flow to support RBF
   - Add RBF toggle in transaction creation form (OutputsForm.jsx)
   - Implement logic to replace existing transaction when RBF is selected

5. Fee Bumping Interfaces:
   - Add 'CancelTransaction' button and associated logic
   - Implement 'AccelerateTransaction' functionality
   - Create 'DownloadPSBT' option for RBF/CPFP transactions
   - Modify transaction authoring page to support pre-filled RBF/CPFP data

6. Integration with new fees package:
   - Import and utilize functions from @caravan/fees for fee calculations
   - Implement FeeManager class to handle fee-related operations

7. State Management Updates:
   - Add new reducers for managing pending transactions and fee bump operations
   - Implement new actions for RBF and CPFP operations
   - Update selectors to support new state structure
Copy link

vercel bot commented Aug 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
caravan-coordinator ❌ Failed (Inspect) Sep 7, 2024 9:18pm

@Legend101Zz
Copy link
Contributor Author

Added RBF toggle to transaction creation (Step 1 of RBF/CPFP implementation) .... :)
Screenshot 2024-08-07 at 03 48 18

…transactions view in @caravan/coordinator"

This reverts commit 2781e95.
Copy link

changeset-bot bot commented Aug 26, 2024

⚠️ No Changeset found

Latest commit: bd4842d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Add a new 'Pending Transactions' tab to the Wallet component, enabling users to easily view and manage pending transactions. This update helps users perform fee bumping actions (RBF, CPFP) when necessary.
@Legend101Zz
Copy link
Contributor Author

Screen Recording 2024-08-28 at 02 35 43 (1)

This is how the functional Pending Tx Tab looks like ...

Copy link
Contributor

@bucko13 bucko13 left a comment

Choose a reason for hiding this comment

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

Looking good so far! Excited to see this hooked up with the fees package.

One additional comment I wanted to add was that it would be nice if the RBF option(s) allowed for an override to fee bump even if the pending tx is not signaling. full-rbf is going to be the default in core soon and there is already a decent chance that fee bumping even without opt-in signaling will work. So maybe you can have a little chip indicating if it's signaling and then allow an option to override with a warning that it might be rejected or not propagate.

Comment on lines 33 to 64
const walletSlices = useSelector((state: RootState) => [
...Object.values(state.wallet.deposits.nodes),
...Object.values(state.wallet.change.nodes),
]);
const blockchainClient = useGetClient();

useEffect(() => {
fetchPendingTransactions();
}, [network, walletSlices, blockchainClient]);

const fetchPendingTransactions = async () => {
try {
const pendingTxs = walletSlices
.flatMap((slice) => slice.utxos)
.filter((utxo) => !utxo.confirmed);

const currentNetworkFeeRate = await getCurrentNetworkFeeRate();

const analyzedTransactions = await Promise.all(
pendingTxs.map(async (utxo) =>
analyzeTransaction(utxo, currentNetworkFeeRate),
),
);

setPendingTransactions(analyzedTransactions);
} catch (error) {
console.error("Error fetching pending transactions:", error);
setError("Failed to fetch pending transactions. Please try again later.");
} finally {
setIsLoading(false);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this could all be pulled out as a hook, something like useGetPendingTransactions. We'd need some way to set an error from inside the hook though.

@@ -0,0 +1,37 @@
import { Network } from "@caravan/bitcoin";

export interface UTXO {
Copy link
Contributor

Choose a reason for hiding this comment

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

these are ultimately going to come from the fees package right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes ... unless I need a custom type to handle some changes

utxos: UTXO[];
}

export interface RootState {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move this closer to the actual root store file?

import { satoshisToBitcoins } from "@caravan/bitcoin";

export const calculateTimeElapsed = (timestamp: number): string => {
const now = Date.now();
Copy link
Contributor

Choose a reason for hiding this comment

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

the coordinator already has momentjs installed so you could probably use that to do time comparisons a little more easily.

inputs: state.inputs.map(convertLegacyInput),
inputs: state.inputs.map((input) => ({
...convertLegacyInput(input),
sequence: rbfSequence,
Copy link
Contributor

Choose a reason for hiding this comment

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

So I can see an implementation for the sequence field has been added in the fees package which works with PSBT V2. But as this PR stands, I think the sequence is not persisting in the inputs
image
inputData logging is coming from packages/caravan-psbt/src/psbtv0/psbt.ts:L90

Working with testnet v4 (merged in #131)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback .... I shall move on to resolving this issue and completing the fees package integration, once I am done with completing the last round of reviews on the fees package and getting it merged :)

}

if (!parentTx) {
const parentTxDetails = await blockchainClient.getTransaction(
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that this depends on #134

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