Skip to content

Commit

Permalink
add: docker for 3 validators
Browse files Browse the repository at this point in the history
  • Loading branch information
Igx22 committed Aug 31, 2024
1 parent be99d53 commit bf26832
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 177 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:16.20.2
FROM node:20.6.1
WORKDIR /app
COPY . .
RUN yarn install
RUN yarn install --non-interactive --frozen-lockfile
EXPOSE 4001
EXPOSE 4002
EXPOSE 4003
Expand Down
72 changes: 0 additions & 72 deletions docker-compose-v01.yml

This file was deleted.

36 changes: 19 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
version: '3'
services:

redis:
image: 'redis:latest'

container_name: redis-main
restart: always
networks:
- main
push-shared-network:
aliases:
- redis.local
ports:
- 6379:6379
volumes:
- ./external/redis:/data

mysql:
image: mysql:5.7.32
container_name: db
platform: linux/amd64
image: mysql:8.0
container_name: mysql-main
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
Expand All @@ -24,12 +26,17 @@ services:
MYSQL_PASSWORD: ${DB_PASS}
ports:
- 3306:3306
# Change this to your local path
volumes:
- ./external/mysql:/var/lib/mysql/
- ./mysql-init:/docker-entrypoint-initdb.d/
networks:
push-shared-network:
aliases:
- mysql.local

phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin-main
depends_on:
- mysql
environment:
Expand All @@ -40,17 +47,12 @@ services:
restart: always
ports:
- 8183:80
networks:
push-shared-network:
aliases:
- phpmyadmin.local

ipfs:
image: ipfs/go-ipfs:latest
volumes:
- ./external/ipfs:/data
ports:
- '4001:4001'
- '127.0.0.1:8080:8080'
- '127.0.0.1:8081:8081'
- '127.0.0.1:5001:5001'

networks:
main:
driver: bridge
push-shared-network:
external: true
27 changes: 27 additions & 0 deletions mysql-init/create_databases.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

CREATE DATABASE vnode2 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode2.* TO '2roor'@'%';

CREATE DATABASE vnode3 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode3.* TO '2roor'@'%';

CREATE DATABASE vnode4 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode4.* TO '2roor'@'%';

CREATE DATABASE vnode5 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode5.* TO '2roor'@'%';

CREATE DATABASE vnode6 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode6.* TO '2roor'@'%';

CREATE DATABASE vnode7 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode7.* TO '2roor'@'%';

CREATE DATABASE vnode8 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode8.* TO '2roor'@'%';

CREATE DATABASE vnode9 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode9.* TO '2roor'@'%';

CREATE DATABASE vnode10 CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON vnode10.* TO '2roor'@'%';
85 changes: 85 additions & 0 deletions net.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
version: '3'
services:

hardhat:
image: hardhat-main
container_name: hardhat
networks:
push-shared-network:
aliases:
- hardhat.local
ports:
- "8545:8545"
restart: always

vnode1:
image: vnode-main
container_name: vnode1
networks:
push-shared-network:
aliases:
- vnode1.local
environment:
DB_NAME: vnode1
PORT: 4001
CONFIG_DIR: /config
LOG_DIR: /log
DB_HOST: mysql.local
REDIS_URL: redis://redis.local:6379
VALIDATOR_RPC_ENDPOINT: http://hardhat.local:8545
VALIDATOR_RPC_NETWORK: 1337
ports:
- "4001:4001"
volumes:
- ./push-docker/v01:/config
- ./push-docker/v01/log:/log


vnode2:
image: vnode-main
container_name: vnode2
networks:
push-shared-network:
aliases:
- vnode2.local
environment:
DB_NAME: vnode2
PORT: 4001
CONFIG_DIR: /config
LOG_DIR: /log
DB_HOST: mysql.local
REDIS_URL: redis://redis.local:6379
VALIDATOR_RPC_ENDPOINT: http://hardhat.local:8545
VALIDATOR_RPC_NETWORK: 1337
ports:
- "4002:4001"
volumes:
- ./push-docker/v02:/config
- ./push-docker/v02/log:/log


vnode3:
image: vnode-main
container_name: vnode3
networks:
push-shared-network:
aliases:
- vnode3.local
environment:
DB_NAME: vnode3
PORT: 4001
CONFIG_DIR: /config
LOG_DIR: /log
DB_HOST: mysql.local
REDIS_URL: redis://redis.local:6379
VALIDATOR_RPC_ENDPOINT: http://hardhat.local:8545
VALIDATOR_RPC_NETWORK: 1337
ports:
- "4003:4001"
volumes:
- ./push-docker/v03:/config
- ./push-docker/v03/log:/log

networks:
push-shared-network:
external: true
91 changes: 5 additions & 86 deletions src/services/messaging/QueueManager.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,13 @@
/*
This is a distributed set, which has the same contents on every node.
Every node syncs with every other node - reads it's [queue],
downloads all items starting from latest offset,
and saves them into [queue] and [set]
example:
1) initial state:
node1 <---> node2
(a,b) (c)
2) replicates to:
node1 <---> node2
(a,b,c) (c,a,b)
3) node 2 adds new item e
node1 <---> node2
(a,b,c) (c,a,b, e)
4) node1 reads new item from the node2 queue, and appends it to local set
node1 <---> node2
(a,b,c, e) (c,a,b, e)
every server: adds only new items
*/

import { Inject, Service } from 'typedi'
import { MySqlUtil } from '../../utilz/mySqlUtil'
import { Logger } from 'winston'
import ChannelsService from '../channelsService'
import schedule from 'node-schedule'
import { ValidatorContractState } from '../messaging-common/validatorContractState'
import { WinstonUtil } from '../../utilz/winstonUtil'
import { QueueServer } from '../messaging-dset/queueServer'
import { QueueClient } from '../messaging-dset/queueClient'
import { QueueClientHelper } from '../messaging-common/queueClientHelper'

/*
The data flow:
comm contract (via HistoryFetcher)
rest endpoint
|
|
V
ChannelsService
1.addExternalSubscribers ----> SubscribersService -----> QueueInitializerValidator
1.removeExternalSubscribers ----> | 3. Append to Queue
V
2.validate,
tryAdd to db
SubscribersService <------ 1. QueueClient
| |
V |
2.validate, |
tryAdd to db V
3. Append to Queue
*/



@Service()
export class QueueManager {
public log: Logger = WinstonUtil.newLog(QueueManager)
Expand All @@ -81,8 +27,7 @@ export class QueueManager {
private static QUEUE_REPLY_PAGE_SIZE = 10
private static CLIENT_REQUEST_PER_SCHEDULED_JOB = 10

private subscribersQueue: QueueServer
private subscribersQueueClient: QueueClient

private mBlockQueue: QueueServer
private queueMap = new Map<string, QueueServer>()

Expand All @@ -92,35 +37,9 @@ export class QueueManager {

public async postConstruct() {
this.log.debug('postConstruct()')
const qv = QueueManager

// setup queues that serve data to the outside world
this.subscribersQueue = new QueueServer(
qv.QUEUE_SUBSCRIBERS,
qv.QUEUE_REPLY_PAGE_SIZE,
this.channelService
)
await this.startQueue(this.subscribersQueue)

this.mBlockQueue = new QueueServer(qv.QUEUE_MBLOCK, 10, null)
this.mBlockQueue = new QueueServer(QueueManager.QUEUE_MBLOCK, 10, null)
await this.startQueue(this.mBlockQueue)

// setup client that fetches data from remote queues
this.subscribersQueueClient = new QueueClient(this.subscribersQueue, qv.QUEUE_SUBSCRIBERS)
await QueueClientHelper.initClientForEveryQueueForEveryValidator(this.contractState, [
qv.QUEUE_SUBSCIRBERS
])
const qs = this
schedule.scheduleJob(this.CLIENT_READ_SCHEDULE, async function () {
const taskName = 'Client Read Scheduled'
try {
await qs.subscribersQueueClient.pollRemoteQueue(qv.CLIENT_REQUEST_PER_SCHEDULED_JOB)
qs.log.info(`Cron Task Completed -- ${taskName}`)
} catch (err) {
qs.log.error(`Cron Task Failed -- ${taskName}`)
qs.log.error(`Error Object: %o`, err)
}
})
}

private async startQueue(queue: QueueServer) {
Expand Down

0 comments on commit bf26832

Please sign in to comment.