diff --git a/.env.example b/.env.example index 2c136da4..bc397ce4 100644 --- a/.env.example +++ b/.env.example @@ -53,6 +53,9 @@ VITE_IS_HOSTED = 'false' FRONTEND_BUILD_TARGET = 'final' # change to 'dev' to run in dev mode +# Backend Configuration +BACKEND_BUILD_TARGET = 'debug' # change to 'prod' or remove to run in prod mode + # Hardhat port HARDHAT_URL = 'http://hardhat' HARDHAT_PORT = '8545' diff --git a/.github/workflows/docker-build-and-push-all.yml b/.github/workflows/docker-build-and-push-all.yml index 0ac527c8..790a3bf3 100644 --- a/.github/workflows/docker-build-and-push-all.yml +++ b/.github/workflows/docker-build-and-push-all.yml @@ -50,3 +50,13 @@ jobs: dockerhub_username: ${{ vars.DOCKERHUB_USERNAME }} secrets: dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} + + hardhat: + uses: ./.github/workflows/docker-build-and-push-image.yml + with: + docker_build_context: . + dockerfile: docker/Dockerfile.hardhat + dockerhub_repo: yeagerai/simulator-hardhat + dockerhub_username: ${{ vars.DOCKERHUB_USERNAME }} + secrets: + dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/unit-tests-pr.yml b/.github/workflows/unit-tests-pr.yml index a599a0b8..a1df7e1d 100644 --- a/.github/workflows/unit-tests-pr.yml +++ b/.github/workflows/unit-tests-pr.yml @@ -34,6 +34,6 @@ jobs: - run: pip install pytest-cov - run: pytest tests/unit --cov=backend --cov-report=xml --cov-branch - name: SonarCloud Scan - uses: sonarsource/sonarcloud-github-action@v3.0.0 + uses: sonarsource/sonarcloud-github-action@v4.0.0 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/backend/consensus/base.py b/backend/consensus/base.py index e47569d9..31d359f3 100644 --- a/backend/consensus/base.py +++ b/backend/consensus/base.py @@ -573,33 +573,38 @@ async def _appeal_window(self): FINALITY_WINDOW = int(os.getenv("FINALITY_WINDOW")) print(" ~ ~ ~ ~ ~ FINALITY WINDOW: ", FINALITY_WINDOW) while True: - with self.get_session() as session: - chain_snapshot = ChainSnapshot(session) - transactions_processor = TransactionsProcessor(session) - accepted_transactions = chain_snapshot.get_accepted_transactions() - for transaction in accepted_transactions: - transaction = transaction_from_dict(transaction) - if not transaction.appealed: - if ( - int(time.time()) - transaction.timestamp_accepted - ) > FINALITY_WINDOW: - self.finalize_transaction( + try: + with self.get_session() as session: + chain_snapshot = ChainSnapshot(session) + transactions_processor = TransactionsProcessor(session) + accepted_transactions = chain_snapshot.get_accepted_transactions() + for transaction in accepted_transactions: + transaction = transaction_from_dict(transaction) + if not transaction.appealed: + if ( + int(time.time()) - transaction.timestamp_accepted + ) > FINALITY_WINDOW: + self.finalize_transaction( + transaction, + transactions_processor, + ) + session.commit() + else: + transactions_processor.set_transaction_appeal( + transaction.hash, False + ) + self.commit_reveal_accept_transaction( transaction, transactions_processor, + lambda contract_address: contract_snapshot_factory( + contract_address, session, transaction + ), ) session.commit() - else: - transactions_processor.set_transaction_appeal( - transaction.hash, False - ) - self.commit_reveal_accept_transaction( - transaction, - transactions_processor, - lambda contract_address: contract_snapshot_factory( - contract_address, session, transaction - ), - ) - session.commit() + + except Exception as e: + print("Error running consensus", e) + print(traceback.format_exc()) await asyncio.sleep(1) diff --git a/docker-compose.yml b/docker-compose.yml index a9fcda34..e32845af 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -80,6 +80,8 @@ services: - ./backend:/app/backend - ./hardhat/artifacts:/app/hardhat/artifacts depends_on: + hardhat: + condition: service_healthy database-migration: condition: service_completed_successfully webrequest: @@ -199,7 +201,16 @@ services: - ./hardhat/scripts:/app/scripts - ./hardhat/test:/app/test - ./hardhat/hardhat.config.js:/app/hardhat.config.js - - ./hardhat/artifacts:/app/artifacts + - hardhat_artifacts:/app/artifacts environment: - HARDHAT_NETWORK=hardhat + healthcheck: + test: ["CMD", "curl", "-X", "POST", "-H", "Content-Type: application/json", "--fail", "http://localhost:8545", "-d", '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}'] + interval: 10s + timeout: 5s + retries: 10 + start_period: 10s + +volumes: + hardhat_artifacts: diff --git a/docker/Dockerfile.hardhat b/docker/Dockerfile.hardhat index ce901aa4..8383eab9 100644 --- a/docker/Dockerfile.hardhat +++ b/docker/Dockerfile.hardhat @@ -4,22 +4,28 @@ FROM node:22.12-alpine3.19 RUN addgroup -S hardhat-group && adduser -S hardhat-user -G hardhat-group WORKDIR /app -RUN apk add --no-cache g++ make netcat-openbsd python3 +# Install necessary packages and set up the environment +RUN apk add --no-cache curl g++ make netcat-openbsd python3 && \ + # Copy and install npm packages + mkdir -p /app && \ + chown -R hardhat-user:hardhat-group /app COPY ./hardhat/package*.json ./ RUN npm install --ignore-scripts COPY ./hardhat . -# Change ownership of the app directory to the non-root user -RUN chown -R hardhat-user:hardhat-group /app +# Set up directories and permissions +RUN mkdir -p /app/artifacts/build-info && \ + mkdir -p /app/artifacts/contracts && \ + chown -R hardhat-user:hardhat-group /app && \ + chmod -R 755 /app/artifacts && \ + # Create start script + echo -e '#!/bin/sh\necho "Compiling contracts..."\nnpx hardhat compile --force\necho "Starting Hardhat node..."\nexec ./node_modules/.bin/hardhat node --network hardhat' > /app/start.sh && \ + chmod +x /app/start.sh ENV PATH="/app/node_modules/.bin:${PATH}" -RUN echo -e '#!/bin/sh\necho "Compiling contracts..."\nnpx hardhat compile --force\necho "Starting Hardhat node..."\nexec ./node_modules/.bin/hardhat node --network hardhat' > /app/start.sh && \ - chmod +x /app/start.sh && \ - ls -la /app/start.sh - EXPOSE 8545 # Switch to non-root user diff --git a/frontend/package-lock.json b/frontend/package-lock.json index f4e4d5a2..7ea4ed3b 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -62,7 +62,7 @@ "@vitejs/plugin-vue-jsx": "^3.1.0", "@vitest/coverage-v8": "^1.6.0", "@vitest/ui": "^1.6.0", - "@vue/eslint-config-prettier": "^9.0.0", + "@vue/eslint-config-prettier": "^10.0.0", "@vue/eslint-config-typescript": "^13.0.0", "@vue/test-utils": "^2.4.5", "@vue/tsconfig": "^0.5.1", @@ -1538,6 +1538,7 @@ "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", "dev": true, + "license": "MIT", "engines": { "node": "^12.20.0 || ^14.18.0 || >=16.0.0" }, @@ -2920,16 +2921,17 @@ } }, "node_modules/@vue/eslint-config-prettier": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/@vue/eslint-config-prettier/-/eslint-config-prettier-9.0.0.tgz", - "integrity": "sha512-z1ZIAAUS9pKzo/ANEfd2sO+v2IUalz7cM/cTLOZ7vRFOPk5/xuRKQteOu1DErFLAh/lYGXMVZ0IfYKlyInuDVg==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/@vue/eslint-config-prettier/-/eslint-config-prettier-10.1.0.tgz", + "integrity": "sha512-J6wV91y2pXc0Phha01k0WOHBTPsoSTf4xlmMjoKaeSxBpAdsgTppGF5RZRdOHM7OA74zAXD+VLANrtYXpiPKkQ==", "dev": true, + "license": "MIT", "dependencies": { - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-prettier": "^5.0.0" + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1" }, "peerDependencies": { - "eslint": ">= 8.0.0", + "eslint": ">= 8.21.0", "prettier": ">= 3.0.0" } }, @@ -4953,13 +4955,14 @@ } }, "node_modules/eslint-plugin-prettier": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz", - "integrity": "sha512-C9GCVAs4Eq7ZC/XFQHITLiHJxQngdtraXaM+LoUFoFp/lHNl2Zn8f3WQbe9HvTBBQ9YnKFB0/2Ajdqwo5D1EAw==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", + "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", "dev": true, + "license": "MIT", "dependencies": { "prettier-linter-helpers": "^1.0.0", - "synckit": "^0.8.6" + "synckit": "^0.9.1" }, "engines": { "node": "^14.18.0 || >=16.0.0" @@ -9610,10 +9613,11 @@ "dev": true }, "node_modules/synckit": { - "version": "0.8.8", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.8.tgz", - "integrity": "sha512-HwOKAP7Wc5aRGYdKH+dw0PRRpbO841v2DENBtjnR5HFWoiNByAl7vrx3p0G/rCyYXQsrxqtX48TImFtPcIHSpQ==", + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", + "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", "dev": true, + "license": "MIT", "dependencies": { "@pkgr/core": "^0.1.0", "tslib": "^2.6.2" diff --git a/frontend/package.json b/frontend/package.json index 0d1a1616..270d52e2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -74,7 +74,7 @@ "@vitejs/plugin-vue-jsx": "^3.1.0", "@vitest/coverage-v8": "^1.6.0", "@vitest/ui": "^1.6.0", - "@vue/eslint-config-prettier": "^9.0.0", + "@vue/eslint-config-prettier": "^10.0.0", "@vue/eslint-config-typescript": "^13.0.0", "@vue/test-utils": "^2.4.5", "@vue/tsconfig": "^0.5.1", diff --git a/frontend/src/hooks/useGenlayer.ts b/frontend/src/hooks/useGenlayer.ts index 996ccf72..e9812c10 100644 --- a/frontend/src/hooks/useGenlayer.ts +++ b/frontend/src/hooks/useGenlayer.ts @@ -23,6 +23,7 @@ export function useGenlayer() { function initClient() { client = createClient({ chain: simulator, + endpoint: import.meta.env.VITE_JSON_RPC_SERVER_URL, account: createAccount(accountsStore.currentPrivateKey || undefined), }); } diff --git a/renovate.json b/renovate.json index cf9f476d..81be0e85 100644 --- a/renovate.json +++ b/renovate.json @@ -20,5 +20,5 @@ "npm": { "minimumReleaseAge": "3 days" }, - "reviewers": ["denishacquin", "AgustinRamiroDiaz"] -} \ No newline at end of file + "reviewers": ["denishacquin", "mpaya5", "kstroobants", "epsjunior"] +}