Skip to content

Commit

Permalink
chore(deps): update dependency @vue/eslint-config-prettier to v10 (#697)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency @vue/eslint-config-prettier to v10

* fix: adding Hardhat Dockerfile in GitHub Workflow (#693)

* fix(hardhat): prevent race conditions in contract deployment (#704)

* fix(hardhat): Add contract deployment and healthcheck to prevent race conditions

- Added healthcheck to hardhat service in docker-compose.yml
- Modified Dockerfile.hardhat to deploy contracts after node is ready
- Added proper service dependency in docker-compose.yml to ensure jsonrpc waits for hardhat

This fixes the race condition where jsonrpc would try to access hardhat accounts before they were available, causing the finality window to crash.

* fix: use named volume for hardhat artifacts to fix permissions issue

- Changed hardhat artifacts from bind mount to named volume
- This ensures correct permissions are maintained
- Fixes CI/CD pipeline issues with hardhat compilation

* chore(docker): add curl to Dockerfile.hardhat and update healthcheck method

* chore(docker): merge RUN instructions and sort package names in Dockerfile

* fix: change health check command to nc instead of curl

* fix: healthcheck trying curl with increased retries

---------

Co-authored-by: kstroobants <[email protected]>

* fix: catch exception to keep loop running (#705)

Co-authored-by: Cristiam Da Silva <[email protected]>

* fix: add BACKEND_BUILD_TARGET used in docker compose file in .env.example to run in debug (#707)

Co-authored-by: Cristiam Da Silva <[email protected]>

* chore: Update reviewers for renovate (#694)

Co-authored-by: Cristiam Da Silva <[email protected]>

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Edinaldo Pereira da Silva Junior <[email protected]>
Co-authored-by: Miguel Paya <[email protected]>
Co-authored-by: kstroobants <[email protected]>
Co-authored-by: kstroobants <[email protected]>
Co-authored-by: Cristiam Da Silva <[email protected]>
Co-authored-by: Agustín Díaz <[email protected]>
  • Loading branch information
7 people authored Dec 10, 2024
1 parent d46aa3f commit 7eb7ee8
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 79 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/docker-build-and-push-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
51 changes: 28 additions & 23 deletions backend/consensus/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 12 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:

20 changes: 13 additions & 7 deletions docker/Dockerfile.hardhat
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ FROM node:20.11-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
Expand Down
65 changes: 20 additions & 45 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"npm": {
"minimumReleaseAge": "3 days"
},
"reviewers": ["denishacquin", "AgustinRamiroDiaz"]
}
"reviewers": ["denishacquin", "mpaya5", "kstroobants", "epsjunior"]
}

0 comments on commit 7eb7ee8

Please sign in to comment.