Skip to content

Commit

Permalink
Merge pull request #1 from push-protocol/basic-rpc
Browse files Browse the repository at this point in the history
Basic rpc
  • Loading branch information
Igx22 authored Aug 31, 2024
2 parents 2b2be32 + 5037a5e commit 75e8f7d
Show file tree
Hide file tree
Showing 36 changed files with 1,091 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"plugins": ["@typescript-eslint", "unused-imports", "simple-import-sort"],
"rules": {
"unused-imports/no-unused-imports": "error",
"prefer-const": "error",
"prefer-const": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"no-var": "error"
Expand Down
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
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ For the nodes to function correctly, you need to set up three separate databases
curl --location 'http://localhost:4001/apis/v1/messaging/settings/eip155:11155111:0xD8634C39BBFd4033c0d3289C4515275102423681/ETH_TEST_SEPOLIA'
```
## Contributing
We welcome contributions from the community! To contribute, please follow these steps:
Expand All @@ -262,3 +263,146 @@ Please ensure your code adheres to our coding standards and includes appropriate
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Docker (local testing)
Assumptions:
- default dir is /Users/w/chain where all push git repos are located (you can use any)
- /Users/w/chain/push-node-smart-contracts
- /Users/w/chain/push-vnode
- /Users/w/chain/push-snode
- /Users/w/chain/push-anode
- docker and docker-compose are installed
- docker desktop case: Allow full docker image access to /Users/w/chain in Preferences->Resources->File sharing
- recommended docker version could look like this (no specific version is needed; )
- naming conventions:
- docker images: hardhat-main, validator-main, ...
- docker containers: vnode1, vnode2, ...
- docker dns: vnode1.local, redis.local, hardhat.local, ....
```shell
docker --version
Docker version 20.10.21, build baeda1f
docker-compose --version
Docker Compose version v2.13.0
```
Setup docker images for smart-contracts & vnodes
```bash
## create docker network
docker network create push-shared-network
## prepare image for hardhat
cd /Users/w/chain/push-node-smart-contracts
docker build . -t hardhat-main
## prepare image for V
cd /Users/w/chain/push-vnode
docker build . -t vnode-main
```
Run (2 shell tabs recommended)
```bash
## run mysql + redis + phpmyadmin (shell1)
## add up -d for background
export DB_PASS=s1mpl3
export DB_NAME=vnode1
export DB_USER=2roor
cd /Users/w/chain/push-vnode
docker-compose up
## run hardhat + vnode1 + vnode2 + vnode3 (shell2)
## add up -d for background
export DB_PASS=s1mpl3
export DB_USER=2roor
cd /Users/w/push-vnode
docker-compose -f net.yml up
```
Check that all docker DNS is online (OPTIONAL)
```bash
docker exec redis-main bash -c " getent hosts redis.local "
docker exec redis-main bash -c " getent hosts mysql.local "
docker exec redis-main bash -c " getent hosts phpmyadmin.local "
docker exec redis-main bash -c " getent hosts hardhat.local "
docker exec redis-main bash -c " getent hosts vnode1.local "
docker exec redis-main bash -c " getent hosts vnode2.local "
docker exec redis-main bash -c " getent hosts vnode3.local "
```
Test
```shell
## vnode1, vnode2, vnode3 are online and visible from the host machine
curl --location 'http://localhost:4001/api/v1/rpc/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "push_listening",
"params": [],
"id": 1
}'
echo ------------
curl --location 'http://localhost:4002/api/v1/rpc/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "push_listening",
"params": [],
"id": 2
}'
echo ------------
curl --location 'http://localhost:4003/api/v1/rpc/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "push_listening",
"params": [],
"id": 3
}'
echo ------------
```
Smoke-test validator api
```shell
### get api token
curl --location 'http://localhost:4001/api/v1/rpc/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "push_getApiToken",
"params": [],
"id": 1
}'
echo ------------
### send a test transaction (DUMMY DATA)
curl --location 'http://localhost:4001/api/v1/rpc/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "push_sendTransaction",
"params": ["1208494e49545f4449441a0d6569703135353a313a30784141220d6569703135353a313a30784242220d6569703135353a313a307843432a1a0a043078414112043078424218012204307843432a04307844443210d8555d2a5c474fa0a5f588563d50b2873ab40b7b226e6f646573223a5b7b226e6f64654964223a22307838653132644531324333356541426633356235366230344535334334453436386534363732374538222c2274734d696c6c6973223a313732343637333234303033302c2272616e646f6d486578223a2266376266376266303366656130613732353135363965303564653635363832646235353935353765222c2270696e67526573756c7473223a5b7b226e6f64654964223a22307866444145616637616643466262346534643136444336366244323033396664363030344346636538222c2274734d696c6c6973223a313732343637333234303032302c22737461747573223a317d2c7b226e6f64654964223a22307839384639443931304165663942334239413435313337616631434137363735654439306135333535222c2274734d696c6c6973223a313732343637333234303031392c22737461747573223a317d5d2c227369676e6174757265223a22307862333333636331623731633434633430386439366237626662363338353439336366313637636232626432353532376437383664333866376239383065616433303132663736636137386533616231613337653661316363666432306236393364656664303039633837313163666338396630353262333933363866316365383162227d2c7b226e6f64654964223a22307866444145616637616643466262346534643136444336366244323033396664363030344346636538222c2274734d696c6c6973223a313732343637333234303032352c2272616e646f6d486578223a2239323136383734646630653134383539376639643434643064666661656465393538343464643137222c2270696e67526573756c7473223a5b7b226e6f64654964223a22307838653132644531324333356541426633356235366230344535334334453436386534363732374538222c2274734d696c6c6973223a313732343637333232343635302c22737461747573223a317d2c7b226e6f64654964223a22307839384639443931304165663942334239413435313337616631434137363735654439306135333535222c2274734d696c6c6973223a313732343637333232343635352c22737461747573223a317d5d2c227369676e6174757265223a22307837626663343432343464633431376132383463313038353064613335313663353035613036326662323262623538353438383661613239393739653032663139376565633263393664356439343864306131643635306563323334646130356330663933626535653230393136316563326363626331653963396537343238623162227d2c7b226e6f64654964223a22307839384639443931304165663942334239413435313337616631434137363735654439306135333535222c2274734d696c6c6973223a313732343637333234303032342c2272616e646f6d486578223a2230643961313661383939636164306566633838336633343564306638306237666131356136353666222c2270696e67526573756c7473223a5b7b226e6f64654964223a22307838653132644531324333356541426633356235366230344535334334453436386534363732374538222c2274734d696c6c6973223a313732343637333232363934332c22737461747573223a317d2c7b226e6f64654964223a22307866444145616637616643466262346534643136444336366244323033396664363030344346636538222c2274734d696c6c6973223a313732343637333232363934372c22737461747573223a317d5d2c227369676e6174757265223a22307862613632393639366565653830343864313639303730336166656361663866626333663834333139643439316164623363663364663333313131396530303239303531373732303237393137313335333332653430666233323639333963626137663634373636663262363933343065366534663066623336333639386663393162227d5d7d4201ee4a0131"],
"id": 1
}'
echo ------------
### read transaction queue size
curl --location 'http://localhost:4001/api/v1/rpc/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "push_readBlockQueueSize",
"params": [],
"id": 1
}'
### read transaction queue
curl --location 'http://localhost:4001/api/v1/rpc/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "push_readBlockQueue",
"params": ["0"],
"id": 1
}'
```
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'@'%';
Loading

0 comments on commit 75e8f7d

Please sign in to comment.