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

Hardhat/anvil for Bitcoin local development #54

Open
nud3l opened this issue Oct 23, 2023 · 5 comments
Open

Hardhat/anvil for Bitcoin local development #54

nud3l opened this issue Oct 23, 2023 · 5 comments
Labels
enhancement New feature or request prio:low nice to have question Further information is requested

Comments

@nud3l
Copy link
Contributor

nud3l commented Oct 23, 2023

Is your feature request related to a problem? Please describe.
Local development/regtest is difficult and often impractical, especially when a local Bitcoin node is required. It requires good knowledge of Bitcoin core (which is good to have) but:

  1. There's an overwhelming number of options to start a Bitcoin node
  2. It's not possible to fork Bitcoin mainnet or testnet into a local devnet for testing
  3. Interacting with regtest is not very ergonomical via bitcoin-cli

Describe the solution you'd like
We need an easy-to-use tool similar to bitcoind -regtest with additional functionality. It does not need to provide consensus compatibility, but should make it easier to replicate Bitcoin "quirks" for testing. For example with regtest we cannot emulate chain forks to test light client (SPV) logic, it is also cumbersome to auto-mine blocks and bitcoind does not allow us to "fork" from some pre-existing state. The tool should be similar to anvil from the Foundry suite and should provide Bitcoin RPC compatibility so we can re-use existing tools such as Electrs.

Describe alternatives you've considered
We have been using regtest for quite some time, right now nothing exists which satisfies these requirements.

Additional context
We should use rust-bitcoin and existing Bitcoin libraries as much as possible. We may need to provide additional tooling to support forking since we need to load state over HTTP(S), it may be possible with Electrs but requires further experimentation.

@nud3l nud3l added the enhancement New feature or request label Oct 23, 2023
@nud3l nud3l added this to Backlog Oct 23, 2023
@github-project-automation github-project-automation bot moved this to New 🆕 in Backlog Oct 23, 2023
@gregdhill
Copy link
Contributor

Here are some of the advantages of working with Anvil on Ethereum, I've extracted those which could also make sense for Bitcoin.

The toolkit is quite configurable and has several options for startup:

  • Test accounts generated and pre-funded
  • Configurable dev account balances
  • Can enable and configure interval mining (otherwise on demand)
  • Change mempool sorting logic
  • Set timestamp of genesis block
  • Use a specific hard fork or load state from a remote URL (and block number)
  • Configure gas limit, price, etc.

It also provides a compatible ETH RPC interface and some additional methods:

  • Impersonate accounts (force send transactions from an externally owned account)
  • Drop transactions from the mempool
  • Set balances and gas prices
  • Dump or load chain state
  • Revert to an earlier height (or reset completely)

The docs here list many more configurations and methods.

@gregdhill
Copy link
Contributor

The Bitcoin Dev Kit (BDK) provides a variety of tooling, for instance we can integrate the wallet functionality - signing and coin selection.

@nud3l
Copy link
Contributor Author

nud3l commented Oct 26, 2023

Instead of writing our own tool from scratch we want to:

  1. Use https://github.com/vulpemventures/nigiri/ for bitcoin regtest setup
  2. Fork electrs to add ordinals and brc20 functions, see Unified REST APIs for working with Bitcoin #55
  3. Add our electrs fork to nigiri
  4. Create a hackathon/simple starter template that consists of nigiri and foundry as toolchains and includes an automatic deployment of BOB smart contracts to be used in local test environments

@nud3l
Copy link
Contributor Author

nud3l commented Oct 26, 2023

@gregdhill do you think we should close this issue and create a new one?

@gregdhill
Copy link
Contributor

I would be inclined to leave this open for now and get feedback from teams working directly with regtest so we can get a better idea of the pain points to determine if a more grandiose tool is required. We can open a separate issue to track the setup tooling you described above.

@nud3l nud3l moved this from New 🆕 to Research 🔬 in Backlog Nov 6, 2023
@nud3l nud3l added prio:low nice to have question Further information is requested labels Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request prio:low nice to have question Further information is requested
Projects
Status: Research 🔬
Development

No branches or pull requests

2 participants