Skip to content

Commit

Permalink
fix: get docker grpc target addr from env var
Browse files Browse the repository at this point in the history
Signed-off-by: Kostas Christopoulos <[email protected]>
  • Loading branch information
kchrist-rocketfueldev committed Oct 30, 2023
1 parent 589e250 commit 29c0250
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 95 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN yarn run build:binaries
# This build takes the production build from staging build

FROM node:slim AS runtime
ENV GRPC_URL=runtime:50051
WORKDIR /usr/src/app
COPY --from=appbuild /usr/src/app/common/docker/out/kyve* ./
CMD ["./kyve-linux-x64"]
2 changes: 1 addition & 1 deletion common/docker/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
type IConfig = string;

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

private grpcClient: RuntimeClient;

Expand Down
187 changes: 93 additions & 94 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 All @@ -9,25 +8,25 @@ type EmptyRequest = Record<string, never>;

export class TendermintServer {
async getRuntimeName(
call: grpc.ServerUnaryCall<EmptyRequest, { name: string }>,
callback: grpc.sendUnaryData<{ name: string }>
call: grpc.ServerUnaryCall<EmptyRequest, { name: string }>,
callback: grpc.sendUnaryData<{ name: string }>
) {
callback(null, { name });
}

async getRuntimeVersion(
call: grpc.ServerUnaryCall<EmptyRequest, { version: string }>,
callback: grpc.sendUnaryData<{ version: string }>
call: grpc.ServerUnaryCall<EmptyRequest, { version: string }>,
callback: grpc.sendUnaryData<{ version: string }>
) {
callback(null, { version });
}

async validateSetConfig(
call: grpc.ServerUnaryCall<
{ raw_config: string },
{ serialized_config: string }
>,
callback: grpc.sendUnaryData<{ serialized_config: string }>
call: grpc.ServerUnaryCall<
{ raw_config: string },
{ serialized_config: string }
>,
callback: grpc.sendUnaryData<{ serialized_config: string }>
) {
try {
const rawConfig = call.request.raw_config;
Expand Down Expand Up @@ -63,32 +62,30 @@ export class TendermintServer {
}

async getDataItem(
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; key: string },
{ data_item: DataItem }
>,
callback: grpc.sendUnaryData<{ data_item: DataItem }>
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; key: string },
{ data_item: DataItem }
>,
callback: grpc.sendUnaryData<{ data_item: DataItem }>
) {
try {
const config = JSON.parse(call.request.config.serialized_config);
const key = call.request.key;

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

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}`
`${config.rpc}/block_results?height=${key}`
);

const blockResults = blockResultsResponse.data.result;


// Construct the Value message
const value = {
block: block,
Expand All @@ -110,11 +107,11 @@ export class TendermintServer {
}
}
async prevalidateDataItem(
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; data_item: DataItem },
{ valid: boolean }
>,
callback: grpc.sendUnaryData<{ valid: boolean }>
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; data_item: DataItem },
{ valid: boolean }
>,
callback: grpc.sendUnaryData<{ valid: boolean }>
) {
try {
const config = JSON.parse(call.request.config.serialized_config);
Expand Down Expand Up @@ -160,11 +157,11 @@ export class TendermintServer {
}
}
async transformDataItem(
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; data_item: DataItem },
{ transformed_data_item: DataItem }
>,
callback: grpc.sendUnaryData<{ transformed_data_item: DataItem }>
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; data_item: DataItem },
{ transformed_data_item: DataItem }
>,
callback: grpc.sendUnaryData<{ transformed_data_item: DataItem }>
) {
try {
const request_item = call.request.data_item;
Expand All @@ -174,59 +171,59 @@ export class TendermintServer {
};

const compareEventAttribute = (a: any, b: any) =>
a.key.toLowerCase() > b.key.toLowerCase()
? 1
: b.key.toLowerCase() > a.key.toLowerCase()
? -1
: 0;
a.key.toLowerCase() > b.key.toLowerCase()
? 1
: b.key.toLowerCase() > a.key.toLowerCase()
? -1
: 0;

if (item.value.block_results.begin_block_events) {
item.value.block_results.begin_block_events =
item.value.block_results.begin_block_events.map((event: any) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: any) => attribute);
return event;
});
item.value.block_results.begin_block_events.map((event: any) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: any) => attribute);
return event;
});
}

if (item.value.block_results.end_block_events) {
item.value.block_results.end_block_events =
item.value.block_results.end_block_events.map((event: any) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: any) => attribute);
return event;
});
item.value.block_results.end_block_events.map((event: any) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: any) => attribute);
return event;
});
}

if (item.value.block_results.txs_results) {
item.value.block_results.txs_results =
item.value.block_results.txs_results.map((tx_result: any) => {
delete tx_result.log;

if (tx_result.events) {
tx_result.events = tx_result.events.map((event: any) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: any) => attribute);

if (event.type === 'fungible_token_packet') {
event.attributes = event.attributes.map((attribute: any) => {
if (attribute.key === 'YWNrbm93bGVkZ2VtZW50') {
attribute.value = '';
}

return attribute;
});
}

return event;
});
}

return tx_result;
});
item.value.block_results.txs_results.map((tx_result: any) => {
delete tx_result.log;

if (tx_result.events) {
tx_result.events = tx_result.events.map((event: any) => {
event.attributes = event.attributes
.sort(compareEventAttribute)
.map(({ index, ...attribute }: any) => attribute);

if (event.type === 'fungible_token_packet') {
event.attributes = event.attributes.map((attribute: any) => {
if (attribute.key === 'YWNrbm93bGVkZ2VtZW50') {
attribute.value = '';
}

return attribute;
});
}

return event;
});
}

return tx_result;
});
}

// Construct the data_item to return
Expand All @@ -245,15 +242,15 @@ export class TendermintServer {
}

async validateDataItem(
call: grpc.ServerUnaryCall<
{
config: { serialized_config: string };
proposed_data_item: DataItem;
validation_data_item: DataItem;
},
{ vote: number }
>,
callback: grpc.sendUnaryData<{ vote: number }>
call: grpc.ServerUnaryCall<
{
config: { serialized_config: string };
proposed_data_item: DataItem;
validation_data_item: DataItem;
},
{ vote: number }
>,
callback: grpc.sendUnaryData<{ vote: number }>
) {
try {
const request_proposed_data_item = call.request.proposed_data_item;
Expand All @@ -275,18 +272,20 @@ export class TendermintServer {
}

// 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 All @@ -300,11 +299,11 @@ export class TendermintServer {
}
}
async summarizeDataBundle(
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; bundle: Array<DataItem> },
{ summary: string }
>,
callback: grpc.sendUnaryData<{ summary: string }>
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; bundle: Array<DataItem> },
{ summary: string }
>,
callback: grpc.sendUnaryData<{ summary: string }>
) {
try {
const grpcBundle = call.request.bundle;
Expand All @@ -316,7 +315,7 @@ export class TendermintServer {

// Get the latest block height from the last item in the bundle
const latestBlockHeight =
bundle[bundle.length - 1]?.value?.block?.block?.header?.height || '';
bundle[bundle.length - 1]?.value?.block?.block?.header?.height || '';

callback(null, { summary: latestBlockHeight.toString() });
} catch (error: any) {
Expand All @@ -328,11 +327,11 @@ export class TendermintServer {
}

async nextKey(
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; key: string },
{ next_key: string }
>,
callback: grpc.sendUnaryData<{ next_key: string }>
call: grpc.ServerUnaryCall<
{ config: { serialized_config: string }; key: string },
{ next_key: string }
>,
callback: grpc.sendUnaryData<{ next_key: string }>
) {
try {
const key = call.request.key;
Expand Down

0 comments on commit 29c0250

Please sign in to comment.