Skip to content

rpc: enforce BIP 145 SegWit rules in getblocktemplate#2569

Open
TechLateef wants to merge 1 commit into
btcsuite:masterfrom
TechLateef:fix-bip145-segwit-rules
Open

rpc: enforce BIP 145 SegWit rules in getblocktemplate#2569
TechLateef wants to merge 1 commit into
btcsuite:masterfrom
TechLateef:fix-bip145-segwit-rules

Conversation

@TechLateef

Copy link
Copy Markdown

Change Description

This PR addresses issue #1738 by enforcing BIP 145 SegWit rules within the getblocktemplate RPC response.

Specifically, this PR updates rpcserver.go to ensure that:

  • Client requests are rejected with ErrRPCInvalidParameter if SegWit is active but the client does not explicitly include the segwit rule in their request.
  • The rules array in the response conditionally includes !segwit if the generated block template contains transactions with witness data (indicating a witness commitment is required).
  • The rules array includes segwit (without the ! prefix) when SegWit is active but the template does not contain any witness transactions.

Steps to Test

  1. Run the RPC server integration tests using go test -v -tags=rpctest -run=TestRpcServer ./integration
  2. Ensure the newly added testGetBlockTemplateSegwitActiveNoRule, testGetBlockTemplateSegwitActiveWithRule, and testGetBlockTemplateResponseRules tests pass successfully.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

This commit updates the getblocktemplate RPC to enforce the SegWit
rules specified in BIP 145. Specifically, it ensures that:

- Client requests are rejected with ErrRPCInvalidParameter if SegWit
  is active but the client does not explicitly support the 'segwit' rule.
- The 'rules' array in the response conditionally includes '!segwit'
  if the generated block template contains transactions with witness
  data (indicating a witness commitment is required).
- The 'rules' array includes 'segwit' (without the '!' prefix) when
  SegWit is active but the template does not contain any witness
  transactions.

Additionally, integration tests have been added to verify that rule
signaling and SegWit activation behave correctly during block template
generation.
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.

1 participant