Skip to content
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

Code cleanup #17

Merged
merged 3 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .env.example

This file was deleted.

5 changes: 4 additions & 1 deletion .github/scripts/check-data.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Download rosetta-cli
./.github/scripts/cli.sh

ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json ./bin/rosetta-cli check:data configs/optimism/goerli.json
# Run data tests
# echo "starting data tests..."
# ./bin/rosetta-cli check:data --configuration-file configs/config_goerli_eth.json
4 changes: 0 additions & 4 deletions .github/scripts/cli.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash

# downloading cli
echo "Downloading rosetta-cli..."
curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s
echo "rosetta-cli downloaded"
Expand All @@ -12,6 +11,3 @@ chmod +x ./rosetta-cli
source ./
rosetta-cli version
echo "Rosetta cli location: $(which rosetta-cli)"

# echo "start check:data"
# ./bin/rosetta-cli --configuration-file examples/ethereum/rosetta-cli-conf/devnet/config.json check:data --start-block 0
8 changes: 0 additions & 8 deletions .github/scripts/validate-goerli-config.sh

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/rosetta-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Rosetta Validation

# on: [push]


env:
go_version: 1.19
GO111MODULE: on
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
with:
go-version: ${{ env.go_version }}
- name: run unit tests
run: make unit-tests
run: make test
28 changes: 0 additions & 28 deletions .github/workflows/validate-configs.yaml

This file was deleted.

131 changes: 8 additions & 123 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,136 +1,21 @@
##############################################################
## Build golang
##############################################################
FROM ubuntu:20.04 as golang
FROM golang:1.18 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++ git
ENV GOLANG_VERSION 1.16.8
ENV GOLANG_DOWNLOAD_SHA256 f32501aeb8b7b723bc7215f6c373abb6981bbc7e1c7b44e9f07317e1a300dce2
ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz
ENV REPO=https://github.com/mdehoog/op-rosetta.git

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
RUN git clone $REPO src \
&& src \
&& make build

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"

##############################################################
## Build geth
##############################################################

# TODO:

##############################################################
## Build op-rosetta
##############################################################
FROM golang as rosetta

COPY . app
RUN cd app && go build

# TODO: Only copy necessary files split into various packages
# # Copy necessary files
# RUN mv src/* /app/op-rosetta \
# && mkdir /app/optimism \
# && mv utils/call_tracer.js /app/optimism/call_tracer.js \
# && mv geth.toml /app/optimism/geth.toml \
# && mv tokenList.json /app/tokenList.json \
# && rm -rf src

## Build Final Image
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates

# Construct owned directories
RUN mkdir -p /app \
&& chown -R nobody:nogroup /app \
&& mkdir -p /data \
&& chown -R nobody:nogroup /data

# Set the working directory
WORKDIR /app

# Copy app files from rosetta
COPY --from=rosetta /app/* /app/*

# TODO: Only copy necessary files
# COPY --from=rosetta /app/rosetta-ethereum /app/rosetta-ethereum
# COPY --from=rosetta /app/tokenList.json /app/tokenList.json

# Set permissions for everything added to /app
RUN chmod -R 755 /app/*

# Run the op-rosetta binary
CMD ["/app/op-rosetta", "run"]














# Compile geth
FROM golang-builder as geth-builder

# VERSION: go-ethereum v.1.10.16
RUN git clone https://github.com/ethereum/go-ethereum \
&& cd go-ethereum \
&& git checkout 20356e57b119b4e70ce47665a71964434e15200d

RUN cd go-ethereum \
&& make geth

RUN mv go-ethereum/build/bin/geth /app/geth \
&& rm -rf go-ethereum

# Compile rosetta-ethereum
FROM golang-builder as rosetta-builder

# Copy binary from geth-builder
COPY --from=geth-builder /app/geth /app/geth

# Use native remote build context to build in any directory
COPY . src

RUN mv src/geth.toml /app/geth.toml \
&& mv src/entrypoint.sh /app/entrypoint.sh \
&& rm -rf src

## Build Final Image
FROM ubuntu:20.04

RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates

RUN mkdir -p /app \
&& chown -R nobody:nogroup /app \
&& mkdir -p /data \
&& chown -R nobody:nogroup /data

WORKDIR /app

# Copy binary from geth-builder
COPY --from=geth-builder /app/geth /app/geth

# Copy binary from rosetta-builder
COPY --from=rosetta-builder /app /app

# Set permissions for everything added to /app
RUN chmod -R 755 /app/*

EXPOSE 8545 8546 30303 30303/udp
COPY --from=rosetta-builder /app/bin/op-rosetta /app/op-rosetta

ENTRYPOINT ["/app/entrypoint.sh"]
EXPOSE 8080

ENTRYPOINT ["/app/op-rosetta"]
106 changes: 16 additions & 90 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,12 @@ LINT_SETTINGS=golint,misspell,gocyclo,gocritic,whitespace,goconst,gocognit,bodyc
GOLINES_INSTALL=go install github.com/segmentio/golines@latest
GOLINES_CMD=golines

# Run the full pipeline
all: clean tidy format build test lint
.PHONY: \
test \
tests \
format \
lint \
build \
clean
.PHONY: clean format lint build run test

# Clean up built binaries
# Clean up Rosetta Server binary
clean:
rm -rf bin/op-rosetta

# Tidy the go mod
tidy:
go mod tidy

# Formatting with gofmt
format:
gofmt -s -w -l .
Expand All @@ -43,85 +31,23 @@ format:
lint:
golangci-lint run -E asciicheck,goimports,misspell ./...

# Build the `op-rosetta` binary
# Build Rosetta Server binary
build:
env GO111MODULE=on go build -o bin/op-rosetta ./cmd

# Comprehensive tests
test: tests
tests: unit-tests integration-tests
unit-tests:
go test -v ./...
integration-tests: config-validation
config-validation: run-optimism-mainnet-validate-config run-optimism-goerli-validate-config

# TODO: Add the `check:construction` command to the pipeline
check-construction: run-optimism-mainnet-construction-check run-optimism-goerli-construction-check

# TODO: Add the `check:data` command to the pipeline
# TODO: Requires node env var configuration in the github repository for the actions to run tests successfully
check-data: run-optimism-mainnet-data-check run-optimism-goerli-data-check


##################################################################################
## GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI ##
##################################################################################

# Runs rosetta-cli configuration:validate against the optimism goerli configuration
run-optimism-goerli-validate-config:
ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli configuration:validate configs/optimism/goerli.json

# Runs the rosetta-cli check:data command with the optimism goerli configuration
run-optimism-goerli-data-check:
ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli check:data configs/optimism/goerli.json

# Runs the rosetta-cli check:construction command with the optimism goerli configuration
run-optimism-goerli-construction-check:
ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli check:construction configs/optimism/goerli.json

# Runs an instance of `op-rosetta` configured for Optimism Goerli
# For the transition (aka "genesis") block hash, see:
# https://github.com/ethereum-optimism/optimism/blob/5e8bc3d5b4f36f0192b22b032e25b09f23cd0985/op-node/chaincfg/chains.go#L49
run-optimism-goerli:
CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' \
MODE=ONLINE \
PORT=8080 \
BLOCKCHAIN=Optimism \
NETWORK=Goerli \
GETH=${OPTIMISM_GOERLI_NODE} \
ENABLE_TRACE_CACHE=true \
ENABLE_GETH_TRACER=true \
TRANSITION_BLOCK_HASH=${OPTIMISM_GOERLI_TRANSITION_BLOCK_HASH} \
# Run Rosetta Server
run:
MODE=${MODE} \
PORT=${PORT} \
BLOCKCHAIN=${BLOCKCHAIN} \
NETWORK=${NETWORK} \
FILTER=${FILTER} \
GENESIS_BLOCK_HASH=${GENESIS_BLOCK_HASH} \
GETH=${GETH} \
CHAIN_CONFIG=${CHAIN_CONFIG} \
bin/op-rosetta

#####################################################################################
## MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET ##
#####################################################################################

# Runs rosetta-cli configuration:validate against the optimism mainnet configuration
run-optimism-mainnet-validate-config:
ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli configuration:validate configs/optimism/mainnet.json

# Runs the rosetta-cli check:data command with the optimism mainnet configuration
run-optimism-mainnet-data-check:
ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli check:data configs/optimism/mainnet.json

# Runs the rosetta-cli check:construction command with the optimism mainnet configuration
run-optimism-mainnet-construction-check:
ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli check:construction configs/optimism/mainnet.json

# Runs an instance of `op-rosetta` configured for Optimism Mainnet
# For the transition (aka "genesis") block hash, see:
# https://github.com/ethereum-optimism/optimism/blob/5e8bc3d5b4f36f0192b22b032e25b09f23cd0985/op-node/chaincfg/chains.go
run-optimism-mainnet:
CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' \
MODE=ONLINE \
PORT=8080 \
BLOCKCHAIN=Optimism \
NETWORK=Mainnet \
ENABLE_TRACE_CACHE=true \
ENABLE_GETH_TRACER=true \
GETH=${OPTIMISM_MAINNET_NODE} \
TRANSITION_BLOCK_HASH=${OPTIMISM_MAINNET_TRANSITION_BLOCK_HASH} \
bin/op-rosetta
# Run tests
test:
go test -v ./...

Loading