Skip to content

Make mining more flexible in bdk_testenv#2100

Merged
evanlinjin merged 1 commit intobitcoindevkit:masterfrom
evanlinjin:feature/testenv-mine-with-timestamp
Mar 5, 2026
Merged

Make mining more flexible in bdk_testenv#2100
evanlinjin merged 1 commit intobitcoindevkit:masterfrom
evanlinjin:feature/testenv-mine-with-timestamp

Conversation

@evanlinjin
Copy link
Member

@evanlinjin evanlinjin commented Jan 24, 2026

Description

Add mine_block to bdk_testenv::Env with custom timestamp and coinbase address. This allows us to test timelocked transactions.

Changelog notice

Added
- `mine_block` method to `bdk_testenv::Env` with custom `MineParams`. Blocks can be mined with no transactions, contain custom timestamp and custom coinbase address.
- `min_time_for_next_block` and `get_block_template` helper methods.

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch 2 times, most recently from 46db014 to b91363e Compare January 24, 2026 12:49
@oleonardolima
Copy link
Collaborator

@evanlinjin I'd suggest you start working on this on top of #1826, as we're migrating to corepc library/API.

@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch from b91363e to 70bca59 Compare January 24, 2026 13:30
@evanlinjin evanlinjin self-assigned this Jan 25, 2026
@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch from 70bca59 to 8a31d1f Compare January 25, 2026 09:48
@evanlinjin
Copy link
Member Author

@evanlinjin I'd suggest you start working on this on top of #1826, as we're migrating to corepc library/API.

Good point. I'll do so once that PR is merged. I would like to test this against bdk-tx right now and that's using the old bdk_testenv (for testing MTP).

@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch 5 times, most recently from f776d50 to 9d7f859 Compare January 28, 2026 14:57
@evanlinjin evanlinjin marked this pull request as ready for review January 28, 2026 14:58
@oleonardolima oleonardolima self-requested a review January 31, 2026 02:50
@oleonardolima oleonardolima moved this to Needs Review in BDK Chain Jan 31, 2026
@oleonardolima oleonardolima added this to the Chain 0.24.0 milestone Jan 31, 2026
Copy link
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

utACK 9d7f859

Overall looks good. I left a few comments that might help with removing some decoding done here, didn't tried the changes yet though.

@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch from 9d7f859 to 2d3b817 Compare February 4, 2026 15:16
@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch from 2d3b817 to 9620a7d Compare February 6, 2026 06:44
Copy link
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

utACK 9620a7d

I don't mean to keep bikeshedding on the review, all the comments can be addressed in a follow-up. I didn't test it, though as the fns are already been used in existing tests, I think it looks fine.

@notmandatory
Copy link
Member

This will need a rebase since I merged #2123.

@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch from 9620a7d to 0cb3ef8 Compare March 5, 2026 06:38
…dress

Refactor block mining in `TestEnv` to use `getblocktemplate` RPC properly:

- Add `MineParams` struct to configure mining (empty blocks, custom
  timestamp, custom coinbase address)
- Add `mine_block()` method that builds blocks from the template with
  proper BIP34 coinbase scriptSig, witness commitment, and merkle root
- Add `min_time_for_next_block()` and `get_block_template()` helpers
- Refactor `mine_empty_block()` to use the new `mine_block()` API
- Include mempool transactions when `empty: false`
@evanlinjin evanlinjin force-pushed the feature/testenv-mine-with-timestamp branch from 0cb3ef8 to 9b1111f Compare March 5, 2026 06:53
Copy link
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

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

ACK 9b1111f

It looks good! Thanks for addressing the comments above.

I didn't do any fancy local test though, as it's being used throughout multiple existing tests (through the bdk_testenv).

@evanlinjin evanlinjin merged commit 91db0f2 into bitcoindevkit:master Mar 5, 2026
17 checks passed
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Chain Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants