unchained-capital / caravan

Bitcoin multisig coordination software
https://unchained-capital.github.io/caravan/
MIT License
203 stars 177 forks source link

Configurable client #365

Closed bucko13 closed 8 months ago

bucko13 commented 9 months ago

Description

With a recent release adding mempool.space support (#347), a few issues came to light, which this PR seeks to address.

Problems

Rate Limiting in mempool.space

The biggest one noticed in #364 was that recent rate limiting implemented on mempool.space's main production endpoint caused significant performance degradation. Throttling was already an issue with blockstream for which we added a delay to avoid hitting the rate limit, but this may not be enough.

Hard to change client

Unfortunately the way to change the client had to come from unchained-bitcoin, which is really inconvenient and probably not the right long term place for this.

Clumsy API

Every api call had to pass in the network and client info even though once the wallet is setup, this doesn't change. Would be nice to just get this from the store and be done.

Mempool not a perfect drop-in replacement

One of the api calls (getFeeEstimates) was not quite a drop-in b/w mempool and blockstream. So this might've been broken as well

Hard to make changes

If there are any changes in the future (immediate example: mempool is going to have a websocket option for using as a wallet backend), it's not easy to update the client without backwards incompatible changes.

Solution

Does this PR introduce a breaking change?

Does this PR fix an open issue?

carlaiau commented 8 months ago

Is there an ETA of this getting merged into main?

carlaiau commented 8 months ago

Blockstream API broadcast accepts raw tx not JSON object. I am experiencing a CORS policy failure on preflight as well as the broadcast itself. Copying the HEX and posting it via CURL works successfully.

public async broadcastTransaction(rawTx: string): Promise<any> {
    try {
      if (this.type === ClientType.PRIVATE) {
        return bitcoindSendRawTransaction({
          hex: rawTx,
          ...this.bitcoindParams,
        });
      }
      return await this.Post(`/tx`, { tx: rawTx });
    } catch (error) {
      throw new Error(`Failed to broadcast transaction: ${error.message}`);
    }
  }
bucko13 commented 8 months ago

Added in the caravan monorepo now live as of d1d169