diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 78ed2c6a..d5341b0a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to rosetta-bitcoin +# Contributing to mesh-bitcoin ## Code of Conduct @@ -10,11 +10,11 @@ You can contribute to this repository by asking questions, providing feedback, a ### Asking Questions -Submit your questions via the [Rosetta Community boards][13]. +Submit your questions via the [Mesh Community boards][13]. ### Providing Feedback -You can also use the [Rosetta Community boards][13] to provide feedback. +You can also use the [Mesh Community boards][13] to provide feedback. ### Reporting Issues @@ -70,11 +70,11 @@ All support requests must be made via [our support team][3]. **For security reasons, any communication referencing support tickets for Coinbase products will be ignored.** The request will have its content redacted and will be locked to prevent further discussion. -[1]: https://github.com/coinbase/rosetta-bitcoin/issues +[1]: https://github.com/coinbase/mesh-bitcoin/issues [2]: https://chris.beams.io/posts/git-commit/#seven-rules [3]: https://support.coinbase.com/customer/en/portal/articles/2288496-how-can-i-contact-coinbase-support [10]: https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/working-with-your-remote-repository-on-github-or-github-enterprise/creating-an-issue-or-pull-request#creating-an-issue [11]: https://docs.github.com/en/desktop/contributing-and-collaborating-using-github-desktop/working-with-your-remote-repository-on-github-or-github-enterprise/creating-an-issue-or-pull-request#creating-a-pull-request [12]: https://hackerone.com/coinbase -[13]: https://community.rosetta-api.org -[14]: https://github.com/coinbase/rosetta-bitcoin/security \ No newline at end of file +[13]: https://community.mesh-api.org +[14]: https://github.com/coinbase/mesh-bitcoin/security \ No newline at end of file diff --git a/README.md b/README.md index 33609dcc..c6a61d7e 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@

- - Rosetta + + Mesh

- Rosetta Bitcoin + Mesh Bitcoin

- - - - - + + + + +

@@ -21,16 +21,16 @@ USE AT YOUR OWN RISK.

## Overview -The `rosetta-bitcoin` repository provides a reference implementation of the Rosetta API for Bitcoin in Golang. This repository was created for developers of Bitcoin-like (a.k.a., UTXO) blockchains, who may find it easier to fork this reference implementation than write one from scratch. +The `mesh-bitcoin` repository provides a reference implementation of the Mesh API for Bitcoin in Golang. This repository was created for developers of Bitcoin-like (a.k.a., UTXO) blockchains, who may find it easier to fork this reference implementation than write one from scratch. -[Rosetta](https://www.rosetta-api.org/docs/welcome.html) is an open-source specification and set of tools that makes integrating with blockchains simpler, faster, and more reliable. The Rosetta API is specified in the [OpenAPI 3.0 format](https://www.openapis.org). +[Mesh](https://www.mesh-api.org/docs/welcome.html) is an open-source specification and set of tools that makes integrating with blockchains simpler, faster, and more reliable. The Mesh API is specified in the [OpenAPI 3.0 format](https://www.openapis.org). Requests and responses can be crafted with auto-generated code using [Swagger Codegen](https://swagger.io/tools/swagger-codegen) or [OpenAPI Generator](https://openapi-generator.tech), are human-readable (easy to debug and understand), and can be used in servers and browsers. ## Features -* Rosetta API implementation (both Data API and Construction API) -* UTXO cache for all accounts (accessible using the Rosetta `/account/balance` API) +* Mesh API implementation (both Data API and Construction API) +* UTXO cache for all accounts (accessible using the Mesh `/account/balance` API) * Stateless, offline, curve-based transaction construction from any SegWit-Bech32 Address * Automatically prune bitcoind while indexing blocks * Reduce sync time with concurrent block indexing @@ -38,7 +38,7 @@ Requests and responses can be crafted with auto-generated code using [Swagger Co ## System Requirements -The `rosetta-bitcoin` implementation has been tested on an [AWS c5.2xlarge instance](https://aws.amazon.com/ec2/instance-types/c5). This instance type has 8 vCPU and 16 GB of RAM. +The `mesh-bitcoin` implementation has been tested on an [AWS c5.2xlarge instance](https://aws.amazon.com/ec2/instance-types/c5). This instance type has 8 vCPU and 16 GB of RAM. ## Getting Started @@ -48,7 +48,7 @@ The `rosetta-bitcoin` implementation has been tested on an [AWS c5.2xlarge insta ### Network Settings -To increase the load that `rosetta-bitcoin` can handle, we recommend tunning your OS settings to allow for more connections. On a linux-based OS, you can run these commands ([source](http://www.tweaked.io/guide/kernel)): +To increase the load that `mesh-bitcoin` can handle, we recommend tunning your OS settings to allow for more connections. On a linux-based OS, you can run these commands ([source](http://www.tweaked.io/guide/kernel)): ```text sysctl -w net.ipv4.tcp_tw_reuse=1 @@ -58,13 +58,13 @@ sysctl -w net.ipv4.tcp_max_syn_backlog=10000 sysctl -w net.core.somaxconn=10000 sysctl -p (when done) ``` -_We have not tested `rosetta-bitcoin` with `net.ipv4.tcp_tw_recycle` and do not recommend enabling it._ +_We have not tested `mesh-bitcoin` with `net.ipv4.tcp_tw_recycle` and do not recommend enabling it._ You should also modify your open file settings to `100000`. This can be done on a linux-based OS with the command: `ulimit -n 100000`. ### Memory-Mapped Files -`rosetta-bitcoin` uses [memory-mapped files](https://en.wikipedia.org/wiki/Memory-mapped_file) to persist data in the `indexer`. As a result, you **must** run `rosetta-bitcoin` on a 64-bit architecture (the virtual address space easily exceeds 100s of GBs). +`mesh-bitcoin` uses [memory-mapped files](https://en.wikipedia.org/wiki/Memory-mapped_file) to persist data in the `indexer`. As a result, you **must** run `mesh-bitcoin` on a 64-bit architecture (the virtual address space easily exceeds 100s of GBs). If you receive a kernel OOM, you may need to increase the allocated size of swap space on your OS. There is a great tutorial for how to do this on Linux [here](https://linuxize.com/post/create-a-linux-swap-file/). @@ -81,22 +81,22 @@ While working on improvements to this repository, we recommend that you use thes ### Deployment -As specified in the [Rosetta API Principles](https://www.rosetta-api.org/docs/automated_deployment.html), all Rosetta implementations must be deployable via Docker and support running via either an [`online` or `offline` mode](https://www.rosetta-api.org/docs/node_deployment.html#multiple-modes). +As specified in the [Mesh API Principles](https://www.mesh-api.org/docs/automated_deployment.html), all Mesh implementations must be deployable via Docker and support running via either an [`online` or `offline` mode](https://www.mesh-api.org/docs/node_deployment.html#multiple-modes). **YOU MUST [INSTALL DOCKER](https://www.docker.com/get-started) FOR THESE INSTRUCTIONS TO WORK.** #### Image Installation -Running these commands will create a Docker image called `rosetta-bitcoin:latest`. +Running these commands will create a Docker image called `mesh-bitcoin:latest`. ##### Installing from GitHub To download the pre-built Docker image from the latest release, run: ```text -curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-bitcoin/master/install.sh | sh -s +curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-bitcoin/master/install.sh | sh -s ``` -_Do not try to install rosetta-bitcoin using GitHub Packages!_ +_Do not try to install mesh-bitcoin using GitHub Packages!_ ##### Installing from Source @@ -108,11 +108,11 @@ make build-local #### Run Docker -Running these commands will start a Docker container in [detached mode](https://docs.docker.com/engine/reference/run/#detached--d) with a data directory at `/bitcoin-data` and the Rosetta API accessible at port `8080`. +Running these commands will start a Docker container in [detached mode](https://docs.docker.com/engine/reference/run/#detached--d) with a data directory at `/bitcoin-data` and the Mesh API accessible at port `8080`. ##### Required Arguments -**`MODE`** - Determines whether Rosetta can make outbound connections. +**`MODE`** - Determines whether Mesh can make outbound connections. - **Type:** `String` - **Options:** `ONLINE`, `OFFLINE` - **Default:** None @@ -122,7 +122,7 @@ Running these commands will start a Docker container in [detached mode](https:// - **Options:** `MAINNET`, `ROPSTEN`, `RINKEBY`, `GOERLI` or `TESTNET` - **Default:** `ROPSTEN`, but only for backwards compatibility if you use `TESTNET` -**`PORT`** - The port to use for Rosetta. +**`PORT`** - The port to use for Mesh. - **Type:** `Integer` - **Options:** `8080`, any compatible port number. - **Default:** None @@ -135,7 +135,7 @@ You can run these commands from the command line. If you cloned the repository, Uncloned repo: ```text -docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 8333:8333 rosetta-bitcoin:latest +docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 8333:8333 mesh-bitcoin:latest ``` Cloned repo: ```text @@ -146,7 +146,7 @@ make run-mainnet-online Uncloned repo: ```text -docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest +docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 mesh-bitcoin:latest ``` Cloned repo: ```text @@ -157,7 +157,7 @@ make run-mainnet-offline Uncloned repo: ```text -docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 18333:18333 rosetta-bitcoin:latest +docker run -d --rm --ulimit "nofile=100000:100000" -v "$(pwd)/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 18333:18333 mesh-bitcoin:latest ``` Cloned repo: @@ -169,7 +169,7 @@ make run-testnet-online Uncloned repo: ```text -docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest +docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 mesh-bitcoin:latest ``` Cloned repo: @@ -179,37 +179,37 @@ make run-testnet-offline ## Architecture -`rosetta-bitcoin` uses the `syncer`, `storage`, `parser`, and `server` package from [`rosetta-sdk-go`](https://github.com/coinbase/rosetta-sdk-go) instead of a new Bitcoin-specific implementation of packages of similar functionality. Below you can find an overview of how everything fits together: +`mesh-bitcoin` uses the `syncer`, `storage`, `parser`, and `server` package from [`mesh-sdk-go`](https://github.com/coinbase/mesh-sdk-go) instead of a new Bitcoin-specific implementation of packages of similar functionality. Below you can find an overview of how everything fits together:

- - Architecture + + Architecture

### Concurrent Block Syncing -To speed up indexing, `rosetta-bitcoin` uses concurrent block processing with a "wait free" design (using [the channels function](https://golangdocs.com/channels-in-golang) instead of [the sleep function](https://pkg.go.dev/time#Sleep) to signal which threads are unblocked). This allows `rosetta-bitcoin` to fetch multiple inputs from disk while it waits for inputs that appeared in recently processed blocks to save to disk. +To speed up indexing, `mesh-bitcoin` uses concurrent block processing with a "wait free" design (using [the channels function](https://golangdocs.com/channels-in-golang) instead of [the sleep function](https://pkg.go.dev/time#Sleep) to signal which threads are unblocked). This allows `mesh-bitcoin` to fetch multiple inputs from disk while it waits for inputs that appeared in recently processed blocks to save to disk.

- - Concurrent Block Syncing + + Concurrent Block Syncing

-## Test the Implementation with the rosetta-cli Tool +## Test the Implementation with the mesh-cli Tool -To validate `rosetta-bitcoin`, [install `rosetta-cli`](https://github.com/coinbase/rosetta-cli#install) and run one of these commands: +To validate `mesh-bitcoin`, [install `mesh-cli`](https://github.com/coinbase/mesh-cli#install) and run one of these commands: -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates that the Data API information in the `testnet` network is correct. It also ensures that the implementation does not miss any balance-changing operations. -* `rosetta-cli check:construction --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates the blockchain’s construction, signing, and broadcasting. -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/mainnet/config.json` - This command validates that the Data API information in the `mainnet` network is correct. It also ensures that the implementation does not miss any balance-changing operations. +* `mesh-cli check:data --configuration-file mesh-cli-conf/testnet/config.json` - This command validates that the Data API information in the `testnet` network is correct. It also ensures that the implementation does not miss any balance-changing operations. +* `mesh-cli check:construction --configuration-file mesh-cli-conf/testnet/config.json` - This command validates the blockchain’s construction, signing, and broadcasting. +* `mesh-cli check:data --configuration-file mesh-cli-conf/mainnet/config.json` - This command validates that the Data API information in the `mainnet` network is correct. It also ensures that the implementation does not miss any balance-changing operations. -Read the [How to Test your Rosetta Implementation](https://www.rosetta-api.org/docs/rosetta_test.html) documentation for additional details. +Read the [How to Test your Mesh Implementation](https://www.mesh-api.org/docs/mesh_test.html) documentation for additional details. ## Contributing -You may contribute to the `rosetta-bitcoin` project in various ways: +You may contribute to the `mesh-bitcoin` project in various ways: * [Asking Questions](CONTRIBUTING.md/#asking-questions) * [Providing Feedback](CONTRIBUTING.md/#providing-feedback) @@ -217,34 +217,34 @@ You may contribute to the `rosetta-bitcoin` project in various ways: Read our [Contributing](CONTRIBUTING.MD) documentation for more information. -When you've finished an implementation for a blockchain, share your work in the [ecosystem category of the community site](https://community.rosetta-api.org/c/ecosystem). Platforms looking for implementations for certain blockchains will be monitoring this section of the website for high-quality implementations they can use for integration. Make sure that your implementation meets the [expectations](https://www.rosetta-api.org/docs/node_deployment.html) of any implementation. +When you've finished an implementation for a blockchain, share your work in the [ecosystem category of the community site](https://community.mesh-api.org/c/ecosystem). Platforms looking for implementations for certain blockchains will be monitoring this section of the website for high-quality implementations they can use for integration. Make sure that your implementation meets the [expectations](https://www.mesh-api.org/docs/node_deployment.html) of any implementation. -You can also find community implementations for a variety of blockchains in the [rosetta-ecosystem](https://github.com/coinbase/rosetta-ecosystem) repository. +You can also find community implementations for a variety of blockchains in the [mesh-ecosystem](https://github.com/coinbase/mesh-ecosystem) repository. ## Documentation -You can find the Rosetta API documentation at [rosetta-api.org](https://www.rosetta-api.org/docs/welcome.html). +You can find the Mesh API documentation at [mesh-api.org](https://www.mesh-api.org/docs/welcome.html). -Check out the [Getting Started](https://www.rosetta-api.org/docs/getting_started.html) section to start diving into Rosetta. +Check out the [Getting Started](https://www.mesh-api.org/docs/getting_started.html) section to start diving into Mesh. Our documentation is divided into the following sections: -* [Product Overview](https://www.rosetta-api.org/docs/welcome.html) -* [Getting Started](https://www.rosetta-api.org/docs/getting_started.html) -* [Rosetta API Spec](https://www.rosetta-api.org/docs/Reference.html) -* [Testing](https://www.rosetta-api.org/docs/rosetta_cli.html) -* [Best Practices](https://www.rosetta-api.org/docs/node_deployment.html) -* [Repositories](https://www.rosetta-api.org/docs/rosetta_specifications.html) +* [Product Overview](https://www.mesh-api.org/docs/welcome.html) +* [Getting Started](https://www.mesh-api.org/docs/getting_started.html) +* [Mesh API Spec](https://www.mesh-api.org/docs/Reference.html) +* [Testing](https://www.mesh-api.org/docs/mesh_cli.html) +* [Best Practices](https://www.mesh-api.org/docs/node_deployment.html) +* [Repositories](https://www.mesh-api.org/docs/mesh_specifications.html) ## Related Projects -* [rosetta-sdk-go](https://github.com/coinbase/rosetta-sdk-go) — The `rosetta-sdk-go` SDK provides a collection of packages used for interaction with the Rosetta API specification. -* [rosetta-specifications](https://github.com/coinbase/rosetta-specifications) — Much of the SDK code is generated from this repository. -* [rosetta-cli](https://github.com/coinbase/rosetta-ecosystem) — Use the `rosetta-cli` tool to test your Rosetta API implementation. The tool also provides the ability to look up block contents and account balances. +* [mesh-sdk-go](https://github.com/coinbase/mesh-sdk-go) — The `mesh-sdk-go` SDK provides a collection of packages used for interaction with the Mesh API specification. +* [mesh-specifications](https://github.com/coinbase/mesh-specifications) — Much of the SDK code is generated from this repository. +* [mesh-cli](https://github.com/coinbase/mesh-ecosystem) — Use the `mesh-cli` tool to test your Mesh API implementation. The tool also provides the ability to look up block contents and account balances. ### Sample Implementations -You can find community implementations for a variety of blockchains in the [rosetta-ecosystem](https://github.com/coinbase/rosetta-ecosystem) repository, and in the [ecosystem category](https://community.rosetta-api.org/c/ecosystem) of our community site. +You can find community implementations for a variety of blockchains in the [mesh-ecosystem](https://github.com/coinbase/mesh-ecosystem) repository, and in the [ecosystem category](https://community.mesh-api.org/c/ecosystem) of our community site. ## License This project is available open source under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0). diff --git a/bitcoin/client.go b/bitcoin/client.go index c6f0d9e4..3966eb91 100644 --- a/bitcoin/client.go +++ b/bitcoin/client.go @@ -20,7 +20,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net" "net/http" "strconv" @@ -835,11 +835,15 @@ func (b *Client) post( if err != nil { return fmt.Errorf("%w: error posting to rpc-api", err) } - defer res.Body.Close() - + defer func() { + if cerr := res.Body.Close(); cerr != nil { + // Log or handle the error + fmt.Printf("Failed to close response body: %v", cerr) + } + }() // We expect JSON-RPC responses to return `200 OK` statuses if res.StatusCode != http.StatusOK { - val, _ := ioutil.ReadAll(res.Body) + val, _ := io.ReadAll(res.Body) return fmt.Errorf("invalid response: %s %s", res.Status, string(val)) }