-
Notifications
You must be signed in to change notification settings - Fork 127
Addressing issue #41 - maxSyncConcurrency environment variable #63
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
fd5cd81
99913d3
cb96a31
b8a3f21
76e5c89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| rosetta-bitcoin | ||
| bitcoin-data | ||
| cli-data | ||
| .DS_Store | ||
| rosetta-sdk-go |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,7 @@ ENV GOLANG_VERSION 1.15.5 | |
| ENV GOLANG_DOWNLOAD_SHA256 9a58494e8da722c3aef248c9227b0e9c528c7318309827780f16220998180a0d | ||
| ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz | ||
|
|
||
|
|
||
| RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ | ||
| && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ | ||
| && tar -C /usr/local -xzf golang.tar.gz \ | ||
|
|
@@ -85,7 +86,6 @@ COPY --from=bitcoind-builder /app/bitcoind /app/bitcoind | |
|
|
||
| # Copy binary from rosetta-builder | ||
| COPY --from=rosetta-builder /app/* /app/ | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: removed line unnecessarily
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added back in. |
||
| # Set permissions for everything added to /app | ||
| RUN chmod -R 755 /app/* | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Copyright 2020 Coinbase, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Build bitcoind | ||
| FROM ubuntu:18.04 as bitcoind-builder | ||
|
|
||
| RUN mkdir -p /app \ | ||
| && chown -R nobody:nogroup /app | ||
| WORKDIR /app | ||
|
|
||
| # Copy the local sdk to your container | ||
| COPY ./rosetta-sdk-go/* /app/ | ||
|
|
||
| # Source: https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md#ubuntu--debian | ||
| RUN apt-get update && apt-get install -y make gcc g++ autoconf autotools-dev bsdmainutils build-essential git libboost-all-dev \ | ||
| libcurl4-openssl-dev libdb++-dev libevent-dev libssl-dev libtool pkg-config python python-pip libzmq3-dev wget | ||
|
|
||
| # VERSION: Bitcoin Core 0.20.1 | ||
| RUN git clone https://github.com/bitcoin/bitcoin \ | ||
| && cd bitcoin \ | ||
| && git checkout 7ff64311bee570874c4f0dfa18f518552188df08 | ||
|
|
||
| RUN cd bitcoin \ | ||
| && ./autogen.sh \ | ||
| && ./configure --disable-tests --without-miniupnpc --without-gui --with-incompatible-bdb --disable-hardening --disable-zmq --disable-bench --disable-wallet \ | ||
| && make | ||
|
|
||
| RUN mv bitcoin/src/bitcoind /app/bitcoind \ | ||
| && rm -rf bitcoin | ||
|
|
||
| # Build Rosetta Server Components | ||
| FROM ubuntu:18.04 as rosetta-builder | ||
|
|
||
| RUN mkdir -p /app \ | ||
| && chown -R nobody:nogroup /app | ||
| WORKDIR /app | ||
|
|
||
| RUN apt-get update && apt-get install -y curl make gcc g++ | ||
| ENV GOLANG_VERSION 1.15.5 | ||
| ENV GOLANG_DOWNLOAD_SHA256 9a58494e8da722c3aef248c9227b0e9c528c7318309827780f16220998180a0d | ||
| ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz | ||
|
|
||
|
|
||
| RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ | ||
| && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ | ||
| && tar -C /usr/local -xzf golang.tar.gz \ | ||
| && rm golang.tar.gz | ||
|
|
||
| ENV GOPATH /go | ||
| ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH | ||
| RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" | ||
|
|
||
| # Use native remote build context to build in any directory | ||
| COPY . src | ||
| RUN cd src \ | ||
| && go build \ | ||
| && cd .. \ | ||
| && mv src/rosetta-bitcoin /app/rosetta-bitcoin \ | ||
| && mv src/assets/* /app \ | ||
| && rm -rf src | ||
|
|
||
| ## Build Final Image | ||
| FROM ubuntu:18.04 | ||
|
|
||
| RUN apt-get update && \ | ||
| apt-get install --no-install-recommends -y libevent-dev libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev && \ | ||
| apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
|
||
| RUN mkdir -p /app \ | ||
| && chown -R nobody:nogroup /app \ | ||
| && mkdir -p /data \ | ||
| && chown -R nobody:nogroup /data | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy binary from bitcoind-builder | ||
| COPY --from=bitcoind-builder /app/bitcoind /app/bitcoind | ||
|
|
||
| # Copy binary from rosetta-builder | ||
| COPY --from=rosetta-builder /app/* /app/ | ||
| # Set permissions for everything added to /app | ||
| RUN chmod -R 755 /app/* | ||
|
|
||
| CMD ["/app/rosetta-bitcoin"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,16 @@ After cloning this repository, run: | |
| ```text | ||
| make build-local | ||
| ``` | ||
| #### From Source and Developing Locally | ||
| After cloning this repository, run: | ||
| ```text | ||
| make build-local-dev | ||
| ``` | ||
| Note: The purpose of this command is to build rosetta-bitcoin using a local sdk - this means you must have a local copy of rosetta-sdk-go in the same folder as the Dockefile and you must add the following to the bottom of your go.mod | ||
|
|
||
| ```text | ||
| replace github.com/coinbase/rosetta-sdk-go v0.6.5 => ./rosetta-sdk-go | ||
| ``` | ||
| ### Run | ||
| Running the following commands will start a Docker container in | ||
| [detached mode](https://docs.docker.com/engine/reference/run/#detached--d) with | ||
|
|
@@ -61,25 +70,25 @@ at port `8080`. | |
|
|
||
| #### Mainnet:Online | ||
| ```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 "MAXSYNC"="256" -e "MODE=ONLINE" -e "NETWORK=MAINNET" -e "PORT=8080" -p 8080:8080 -p 8333:8333 rosetta-bitcoin:latest | ||
|
||
| ``` | ||
| _If you cloned the repository, you can run `make run-mainnet-online`._ | ||
|
|
||
| #### Mainnet:Offline | ||
| ```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 "MAXSYNC"="256" -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest | ||
| ``` | ||
| _If you cloned the repository, you can run `make run-mainnet-offline`._ | ||
|
|
||
| #### Testnet:Online | ||
| ```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 "MAXSYNC"="256" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 18333:18333 rosetta-bitcoin:latest | ||
| ``` | ||
| _If you cloned the repository, you can run `make run-testnet-online`._ | ||
|
|
||
| #### Testnet:Offline | ||
| ```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 "MAXSYNC"="256" -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest | ||
| ``` | ||
| _If you cloned the repository, you can run `make run-testnet-offline`._ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,8 @@ import ( | |
| "strconv" | ||
| "time" | ||
|
|
||
| "github.com/coinbase/rosetta-sdk-go/syncer" | ||
|
|
||
| "github.com/coinbase/rosetta-bitcoin/bitcoin" | ||
|
|
||
| "github.com/btcsuite/btcd/chaincfg" | ||
|
|
@@ -90,6 +92,10 @@ const ( | |
| // to determine mode. | ||
| ModeEnv = "MODE" | ||
|
|
||
| // MaxSyncConcurrency is an environment variable | ||
| // used to cap the syncer concurrency | ||
| MaxSyncConcurrency = "MAXSYNC" | ||
|
|
||
| // NetworkEnv is the environment variable | ||
| // read to determine network. | ||
| NetworkEnv = "NETWORK" | ||
|
|
@@ -122,6 +128,7 @@ type Configuration struct { | |
| IndexerPath string | ||
| BitcoindPath string | ||
| Compressors []*encoder.CompressorEntry | ||
| MaxSyncConcurrency int64 | ||
| } | ||
|
|
||
| // LoadConfiguration attempts to create a new Configuration | ||
|
|
@@ -133,7 +140,15 @@ func LoadConfiguration(baseDirectory string) (*Configuration, error) { | |
| Depth: pruneDepth, | ||
| MinHeight: minPruneHeight, | ||
| } | ||
|
|
||
| maxSyncValue := os.Getenv(MaxSyncConcurrency) | ||
| switch maxSyncValue { | ||
| case "": | ||
| config.MaxSyncConcurrency = syncer.DefaultMaxConcurrency | ||
| case "0": | ||
| return nil, errors.New("syncer concurrency must be greater than zero") | ||
| default: | ||
| config.MaxSyncConcurrency, _ = strconv.ParseInt(maxSyncValue, 10, 64) | ||
|
||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The expression on line 148 is equivalent to: !(err == nil || defaultMaxSync) if we want to change. |
||
| modeValue := Mode(os.Getenv(ModeEnv)) | ||
| switch modeValue { | ||
| case Online: | ||
|
|
@@ -180,6 +195,7 @@ func LoadConfiguration(baseDirectory string) (*Configuration, error) { | |
| } | ||
| config.GenesisBlockIdentifier = bitcoin.TestnetGenesisBlockIdentifier | ||
| config.Params = bitcoin.TestnetParams | ||
|
|
||
|
||
| config.Currency = bitcoin.TestnetCurrency | ||
| config.ConfigPath = testnetConfigPath | ||
| config.RPCPort = testnetRPCPort | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,7 @@ require ( | |
| golang.org/x/tools v0.0.0-20200904185747-39188db58858 // indirect | ||
| honnef.co/go/tools v0.0.1-2020.1.5 // indirect | ||
| ) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed