node icon indicating copy to clipboard operation
node copied to clipboard

feat: allow parsing Bitcoin deposit memo with inscription and add E2E test for parsing

Open bitSmiley opened this issue 1 year ago • 7 comments

Description

Adding e2e test for detecting memo from inscription.

The current btcutil does not have enough tapscript support, in this case, a nodejs sidecar to handle inscription txn generation is used instead. This is not intrusive and can be quickly removed once btcutil is upgraded.

How Has This Been Tested?

  • [ ] Tested CCTX in localnet
  • [ ] Tested in development environment
  • [ ] Go unit tests
  • [x] Go integration tests
  • [ ] Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Introduced a logging feature to enhance visibility of test executions.
    • Added a test case for extracting Bitcoin inscription memo names.
    • Implemented an Express.js server with endpoints for Bitcoin transaction handling.
    • Developed a ScriptBuilder for constructing tapscripts used in Bitcoin transactions.
    • Created a utility function for formatting public keys in Bitcoin transactions.
  • Bug Fixes

    • Improved transaction processing by updating methods to include witness data for better validation.
  • Documentation

    • Added configuration files like tsconfig.json for TypeScript setup.
  • Chores

    • Updated Docker configurations to include a new Bitcoin sidecar service in the setup.

bitSmiley avatar Aug 16 '24 03:08 bitSmiley

[!IMPORTANT]

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The recent changes introduce a robust suite of enhancements to the Bitcoin transaction handling system. Key updates include the addition of new test cases for better coverage, new Docker configurations for deployment, and the implementation of a Bitcoin Sidecar service that interacts with the Zetachain framework. Additionally, several methods have been refactored to improve flexibility and error handling, ultimately enhancing the overall functionality and maintainability of the codebase.

Changes

File Path Summary of Changes
cmd/zetae2e/local/bitcoin.go Added a logging statement in bitcoinTestRoutine for improved test visibility.
cmd/zetae2e/local/local.go Introduced a new test case, TestExtractBitcoinInscriptionMemoName, to enhance Bitcoin functionality testing.
contrib/localnet/bitcoin-sidecar/Dockerfile Created a multi-stage Dockerfile for the Bitcoin Sidecar, optimizing the build process for a Node.js application.
contrib/localnet/bitcoin-sidecar/js/package.json Added package.json for the zeta-btc-client, specifying dependencies and project metadata.
contrib/localnet/bitcoin-sidecar/js/src/client.ts Implemented the ZetaBtcClient class for interacting with the Zetachain blockchain, including methods for transaction handling.
contrib/localnet/bitcoin-sidecar/js/src/index.ts Established an Express.js server with endpoints for committing and revealing Bitcoin transactions.
contrib/localnet/bitcoin-sidecar/js/src/reveal.ts Introduced a script for testing Bitcoin interaction in regtest mode using ZetaBtcClient.
contrib/localnet/bitcoin-sidecar/js/src/script.ts Developed a ScriptBuilder class for constructing Bitcoin tapscripts.
contrib/localnet/bitcoin-sidecar/js/src/util.ts Added toXOnly, a utility function for handling public keys in Bitcoin transactions.
e2e/e2etests/e2etests.go Added new E2E test for extracting memos from Bitcoin inscriptions, improving test coverage.
e2e/e2etests/test_extract_bitcoin_inscription_memo.go Created an E2E test function to validate the extraction of memo data from Bitcoin inscriptions.
e2e/runner/bitcoin.go Enhanced E2ERunner with new methods for inscribing transactions with memos and improved error handling.
e2e/runner/inscription.go Introduced InscriptionBuilder for creating inscription transactions.
zetaclient/chains/bitcoin/observer/inbound.go Updated methods to process Bitcoin transactions using the GetBtcEventWithWitness for improved accuracy in event retrieval.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant Server as Express Server
    participant ZetaClient as ZetaBtcClient
    participant InscriptionBuilder as InscriptionBuilder

    Client->>Server: POST /commit
    Server->>ZetaClient: GenerateCommitAddress(memo)
    ZetaClient-->>Server: commitAddress
    Server-->>Client: { commitAddress }

    Client->>Server: POST /reveal
    Server->>ZetaClient: GenerateRevealTxn(to, txnHash, idx, amount)
    ZetaClient-->>Server: rawTxnHex
    Server-->>Client: { rawTxnHex }

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example: -- I pushed a fix in commit <commit_id>, please review it. -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples: -- @coderabbitai generate unit testing code for this file. -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -- @coderabbitai read src/utils.ts and generate unit testing code. -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Aug 16 '24 03:08 coderabbitai[bot]

⚠️ GitGuardian has uncovered 6 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard. Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
13392123 Triggered Generic High Entropy Secret 161d5433b29889a7b0ecb1358f314d37df2c1c21 zetaclient/chains/solana/signer/signer_test.go View secret
13392123 Triggered Generic High Entropy Secret e2414d83d9b1db7eb2373662a84b284b49f64ff6 zetaclient/chains/solana/signer/signer_test.go View secret
13340122 Triggered Generic High Entropy Secret e2414d83d9b1db7eb2373662a84b284b49f64ff6 zetaclient/chains/solana/signer/signer_test.go View secret
13340122 Triggered Generic High Entropy Secret 161d5433b29889a7b0ecb1358f314d37df2c1c21 zetaclient/chains/solana/signer/signer_test.go View secret
13340122 Triggered Generic High Entropy Secret e2414d83d9b1db7eb2373662a84b284b49f64ff6 zetaclient/chains/solana/signer/signer_test.go View secret
13340122 Triggered Generic High Entropy Secret 161d5433b29889a7b0ecb1358f314d37df2c1c21 zetaclient/chains/solana/signer/signer_test.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

gitguardian[bot] avatar Aug 16 '24 03:08 gitguardian[bot]

Thanks for the contribution!

FYI I renamed the PR, it is not a test change but a feature as we enable parsing inscription with this line: https://github.com/zeta-chain/node/pull/2727/files#diff-d1770566f9bb4e25361d8726f5c4eb18370d03316c9d52d886b4dc799cbade87R269

Another thing, can it be possible to add an entry in the changelog file: https://github.com/zeta-chain/node/blob/develop/changelog.md

lumtis avatar Aug 20 '24 12:08 lumtis

It seems it breaks the deposit BTC test: https://github.com/zeta-chain/node/actions/runs/10471358149/job/28998509065

Is the change supposed to be backward compatible

lumtis avatar Aug 21 '24 10:08 lumtis

@lumtis No, it should be backward compatible. There is an error fixed in https://github.com/zeta-chain/node/pull/2727/commits/b341832369fe9601a10341f5dc1a4975dcb7e7e1, which if OP_RETURN and inscription both cannot find the memo, then it should just return nil not error.

bitSmiley avatar Aug 21 '24 12:08 bitSmiley

@lumtis No, it should be backward compatible. There is an error fixed in b341832, which if OP_RETURN and inscription both cannot find the memo, then it should just return nil not error.

Ok, rerunning

lumtis avatar Aug 21 '24 14:08 lumtis

@lumtis sorry man, I just fixed the linting and change log, please help run the pipeline again.

bitSmiley avatar Aug 21 '24 15:08 bitSmiley

Opening back for develop for the next release

lumtis avatar Sep 14 '24 00:09 lumtis

Closing in favor of https://github.com/zeta-chain/node/pull/2957 as discussed on Slack

lumtis avatar Oct 02 '24 13:10 lumtis