Skip to content

Commit

Permalink
Merge branch 'main' into chore/remove-rollup-table
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiam86 authored Dec 10, 2024
2 parents 4ec64e3 + 98216fe commit 73f9746
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 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
51 changes: 28 additions & 23 deletions backend/consensus/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,33 +569,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

0 comments on commit 73f9746

Please sign in to comment.