Skip to content

Commit

Permalink
chore: dockerize kyve core
Browse files Browse the repository at this point in the history
Signed-off-by: Kostas Christopoulos <k.christopoulos@rocketfueldev.com>
  • Loading branch information
kchrist-rocketfueldev committed Oct 30, 2023
1 parent de2cbb2 commit 983ed5c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 49 deletions.
51 changes: 15 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
FROM node:lts

# Build Stage 1
# This build created a staging docker image
#
FROM node:lts AS appbuild
WORKDIR /usr/src/app
COPY . .
RUN yarn build:docker
RUN cd ./common/docker
RUN yarn run build:binaries

# install core
RUN mkdir -p common/types
RUN mkdir -p common/sdk
RUN mkdir -p common/protocol

COPY ./package.json ./
COPY ./tsconfig.json ./
COPY ./lerna.json ./
COPY ./nx.json ./

COPY ./common/types/package.json ./common/types/
COPY ./common/types/tsconfig.json ./common/types/
COPY ./common/types/scripts ./common/types/scripts
COPY ./common/types/src ./common/types/src

COPY ./common/sdk/package.json ./common/sdk/
COPY ./common/sdk/tsconfig.json ./common/sdk/
COPY ./common/sdk/src ./common/sdk/src

COPY ./common/protocol/package.json ./common/protocol/
COPY ./common/protocol/tsconfig.json ./common/protocol/
COPY ./common/protocol/src ./common/protocol/src
# Build Stage 2
# This build takes the production build from staging build

RUN mkdir -p integrations/tendermint

COPY ./integrations/tendermint/package.json ./integrations/tendermint/
COPY ./integrations/tendermint/tsconfig.json ./integrations/tendermint/
COPY ./integrations/tendermint/src ./integrations/tendermint/src

RUN yarn install
RUN yarn setup

# start core
WORKDIR /usr/src/app/integrations/tendermint
ENTRYPOINT ["yarn", "start"]
FROM node:slim AS runtime
ENV RUNTIME_SERVER_ADDR=runtime:50051
WORKDIR /usr/src/app
COPY --from=appbuild /usr/src/app/common/docker/out/kyve* ./
CMD ["./kyve-linux-x64"]
4 changes: 2 additions & 2 deletions common/docker/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
type IConfig = string;

export default class Docker implements IRuntime {
private static readonly GRPC_URL = 'localhost:50051';
private static readonly RUNTIME_SERVER_ADDR = process.env.RUNTIME_SERVER_ADDR || 'localhost:50051';

private grpcClient: RuntimeClient;

public config!: IConfig;

constructor() {
this.grpcClient = new RuntimeClient(
Docker.GRPC_URL,
Docker.RUNTIME_SERVER_ADDR,
grpc.credentials.createInsecure()
);
}
Expand Down
3 changes: 1 addition & 2 deletions docker-integrations/tendermint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"format": "prettier --write .",
"lint": "eslint . --ignore-path ./.eslintignore --ext ts --ext tsx --ext js --ext jsx",
"lint:fix": "eslint --fix . --ignore-path ./.eslintignore --ext ts --ext tsx --ext js --ext jsx",
"export-grpc-stubs": "protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=snakeToCamel=false --ts_proto_opt=outputServices=grpc-js --ts_proto_out=./src/proto --proto_path=./src/proto runtime.proto",
"test-build": "yarn build && rimraf out"
"export-grpc-stubs": "protoc --proto_path=../../common/protocol/src/types --plugin=../../node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=snakeToCamel=false --ts_proto_opt=outputServices=grpc-js --ts_proto_out=./src ../../common/protocol/src/types/protos/runtime.proto"
},
"bin": "./dist/src/index.js",
"pkg": {
Expand Down
13 changes: 6 additions & 7 deletions docker-integrations/tendermint/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import * as grpc from '@grpc/grpc-js';
import axios from 'axios';

Expand Down Expand Up @@ -80,15 +79,13 @@ export class TendermintServer {

const block = blockResponse.data.result;


// Fetch block results from rpc at the given block height
const blockResultsResponse = await axios.get(
`${config.rpc}/block_results?height=${key}`
);

const blockResults = blockResultsResponse.data.result;


// Construct the Value message
const value = {
block: block,
Expand Down Expand Up @@ -268,25 +265,27 @@ export class TendermintServer {
};

if (
JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem)
JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem)
) {
callback(null, { vote: VOTE.VALID });
return;
}

// prevent nondeterministic misbehaviour due to osmosis-1 specific problems
if (validationDataItem.value.block.block.header.chain_id === "osmosis-1") {
if (
validationDataItem.value.block.block.header.chain_id === 'osmosis-1'
) {
// remove nondeterministic begin_block_events to prevent incorrect invalid vote
delete validationDataItem.value.block_results.begin_block_events;
delete proposedDataItem.value.block_results.begin_block_events;

if (
JSON.stringify(proposedDataItem) === JSON.stringify(validationDataItem)
JSON.stringify(proposedDataItem) ===
JSON.stringify(validationDataItem)
) {
// vote abstain if begin_block_events are not equal
callback(null, { vote: VOTE.ABSTAIN });
return;

}
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"ts-proto": "^1.159.2"
},
"scripts": {
"setup": "lerna clean && yarn install && yarn export-grpc-stubs && lerna run build",
"setup": "lerna clean && yarn install && lerna run build",
"build:docker": "yarn nx reset && yarn install && lerna run build",
"graph": "yarn nx graph",
"build": "lerna run build",
"build:binaries": "lerna run build:binaries --concurrency 1",
Expand All @@ -43,6 +44,5 @@
"custom-version": "yarn lerna version --conventional-commits=false",
"export-grpc-stubs": "protoc --proto_path=./common/protocol/src/types --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=snakeToCamel=false --ts_proto_opt=outputServices=grpc-js --ts_proto_out=./common/docker/src common/protocol/src/types/protos/runtime.proto"
},

"version": "0.0.0"
}

0 comments on commit 983ed5c

Please sign in to comment.