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

RFC: Local Transaction Mempool #4035

Open
fuxingloh opened this issue Sep 13, 2023 · 3 comments
Open

RFC: Local Transaction Mempool #4035

fuxingloh opened this issue Sep 13, 2023 · 3 comments
Labels
kind/feature New feature request needs/area Needs area label(s) needs/priority Needs a priority label needs/triage Waiting for triage to be accepted

Comments

@fuxingloh
Copy link
Contributor

fuxingloh commented Sep 13, 2023

What would you like to be added and why is this needed:

Currently, the wallet only supports one transaction at a time. If a user tries to send a second transaction while the first transaction is still pending, the second transaction will fail. This is because the wallet is not able to handle multiple transactions at the same time since no "mempool" is implemented on the wallet.

Transaction confirmation can take up to 10 minutes and being bottleneck by a single transaction is not ideal. This RFC proposes a local transaction mempool that will allow the wallet to handle multiple transactions at the same time.

How this can be implemented:

By editing this piece of code:

const accountProvider = new WhaleWalletAccountProvider(
client,
getJellyfishNetwork(network)
);
return new JellyfishWallet(provider, accountProvider);

By design, JellyfishSDK uses a provider pattern for UTXO to allow the user to choose which UTXO provider they want to use. The default UTXO provider is the WhalePrevoutProvider which is a remote only provider. This means that the wallet will only be able to spent on confirmed UTXOs.

Instead of using the default WhaleWalletAccountProvider, we could extend the implementation.

Below is a pseudo code of how this could be implemented. This is not a complete implementation.

interface LocalMempool {
  tx: Transaction;
  spend: boolean;
}

export class LocalWhalePrevoutProvider extends WhalePrevoutProvider {
  mempool: LocalMempool[] = []; // this should be stored in sqlite?

  async add(tx: Transaction): Promise<void> {
    this.mempool.push({
      tx: tx,
      spend: false,
    });
    this.mempool.forEach(prev => {
      // Loop mempool and set `spend: true` if `vin` is spent
    });
  }

  async sync(): Promise<void> {
    // Advanced feature.
    // Sync all local mempool into Whale, esp when there is rollback or unconfirmed that got lost.
  }

  async all(): Promise<Prevout[]> {
    const remote = super.all();
    return [
      ...remote.filter(), // Remove prevout is spent based on mempool comparision
      ...this.mempool.filter(m => !m.spend)
        .flatMap(m => m.tx.vout),
    ];
  }
}

Create custom WhaleWalletAccountProvider that uses the local mempool:

export class LocalWhaleAccount extends WhaleWalletAccount {
  constructor(client: WhaleApiClient, walletEllipticPair: WalletEllipticPair, network: Network) {
    super(walletEllipticPair, network);
    this.prevoutProvider = new LocalWhalePrevoutProvider(this, prevoutSize);
  }
}

export class LocalWhaleWalletAccountProvider implements WalletAccountProvider<LocalWhaleAccount> {
  provide(walletEllipticPair: WalletEllipticPair): LocalWhaleAccount {
    return new LocalWhaleAccount(this.client, walletEllipticPair, this.network);
  }
}

Other concerns?

We should have a UI to show the Mempool transactions and allow the user to:

  1. look at pending transaction
  2. cancel the transaction (tx might be stuck, this allow them to reset)
  3. resubmit all transactions (syncing mempool)
  4. resubmit with higher fee (advanced feature)
  5. clear mempool
@fuxingloh fuxingloh added the kind/feature New feature request label Sep 13, 2023
@github-actions github-actions bot added the needs/triage Waiting for triage to be accepted label Sep 13, 2023
@github-actions
Copy link
Contributor

@fuxingloh: Thanks for opening an issue, it is currently awaiting triage.

The triage/accepted label can be added by foundation members by writing /triage accepted in a comment.

Details

I am a bot created to help the BirthdayResearch developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@github-actions
Copy link
Contributor

@fuxingloh: There are no 'area' labels on this issue. Adding an appropriate label will greatly expedite the process for us. You can add as many area as you see fit. If you are unsure what to do you can ignore this!

You can add area labels by leaving a /area comment.

Details

I am a bot created to help the BirthdayResearch developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

@github-actions github-actions bot added needs/area Needs area label(s) needs/priority Needs a priority label labels Sep 13, 2023
@github-actions
Copy link
Contributor

@fuxingloh: Thanks for opening an issue, an appropriate priority will be added soon.

The priority labels can be added by foundation members by writing /priority [type] in a comment.

Details

I am a bot created to help the BirthdayResearch developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature request needs/area Needs area label(s) needs/priority Needs a priority label needs/triage Waiting for triage to be accepted
Projects
None yet
Development

No branches or pull requests

1 participant