Skip to content

Commit 1f5f58b

Browse files
authored
Revert "feat: adding hardhat and solve migrations (#674)" (#675)
This reverts commit b48a417.
1 parent b48a417 commit 1f5f58b

35 files changed

+55
-1609
lines changed

.dockerignore

-9
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,3 @@ frontend/vite.config.ts.timestamp-*
2727
# Byte-compiled / optimized / DLL files
2828
**/__pycache__/
2929
**/*.py[cod]
30-
31-
# Hardhat files
32-
hardhat/cache/
33-
hardhat/artifacts/
34-
hardhat/node_modules/
35-
hardhat/coverage/
36-
hardhat/.env
37-
hardhat/coverage.json
38-
hardhat/typechain-types/

.env.example

-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ VITE_PROXY_JSON_RPC_SERVER_URL = 'http://jsonrpc:4000'
5151
VITE_PROXY_WS_SERVER_URL = 'ws://jsonrpc:4000'
5252
VITE_IS_HOSTED = 'false'
5353

54-
FRONTEND_BUILD_TARGET = 'final' # change to 'dev' to run in dev mode
55-
56-
# Hardhat port
57-
HARDHAT_URL = 'http://hardhat'
58-
HARDHATPORT = '8545'
59-
HARDHAT_PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
6054
# LLM Providers Configuration
6155
# If you want to use OpenAI LLMs, add your key here
6256
OPENAIKEY = '<add_your_openai_api_key_here>'

.github/workflows/backend_integration_tests_pr.yml

-25
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,3 @@ jobs:
140140
uses: ./.github/workflows/load-test-oha.yml
141141
with:
142142
oha-version: "v1.4.5"
143-
144-
hardhat-test:
145-
needs: triggers
146-
if: ${{ needs.triggers.outputs.is_pull_request_opened == 'true' || needs.triggers.outputs.is_pull_request_review_approved == 'true' || needs.triggers.outputs.is_pull_request_labeled_with_run_tests == 'true' }}
147-
148-
runs-on: ubuntu-latest
149-
150-
steps:
151-
- name: Checkout code
152-
uses: actions/checkout@v4
153-
154-
- name: Set up Docker Buildx
155-
uses: docker/setup-buildx-action@v3
156-
157-
- name: Cache Docker layers
158-
uses: actions/cache@v4
159-
with:
160-
path: /tmp/.buildx-cache
161-
key: ${{ runner.os }}-buildx-${{ github.sha }}
162-
restore-keys: |
163-
${{ runner.os }}-buildx-
164-
165-
- name: Run Docker Compose
166-
run: docker compose -f tests/hardhat/docker-compose.yml --project-directory . up tests --build --force-recreate --always-recreate-deps
167-

.gitignore

+1-10
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,8 @@ consensus/nodes/nodes.json
147147
# npm
148148
node_modules/
149149
package-lock.json
150-
/package.json
150+
package.json
151151

152152
# Nginx TLS certificates and keys
153153
nginx/ssl/*.key
154154
nginx/ssl/*.crt
155-
156-
# Hardhat files
157-
hardhat/cache
158-
hardhat/artifacts
159-
hardhat/.openzeppelin
160-
hardhat/coverage
161-
hardhat/coverage.json
162-
hardhat/typechain
163-
hardhat/typechain-types

backend/consensus/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,6 @@ def finalize_transaction(
420420
"data": {
421421
"state": leader_receipt["contract_state"],
422422
"code": transaction.data["contract_code"],
423-
"ghost_contract_address": transaction.ghost_contract_address,
424423
},
425424
}
426425
leaders_contract_snapshot.register_contract(new_contract)

backend/database_handler/contract_snapshot.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,10 @@ def __init__(self, contract_address: str | None, session: Session):
2626
self.contract_data = contract_account.data
2727
self.contract_code = self.contract_data["code"]
2828
self.encoded_state = self.contract_data["state"]
29-
self.ghost_contract_address = (
30-
self.contract_data["ghost_contract_address"]
31-
if "ghost_contract_address" in self.contract_data
32-
else None
33-
)
3429

3530
def _load_contract_account(self) -> CurrentState:
3631
"""Load and return the current state of the contract from the database."""
32+
3733
result = (
3834
self.session.query(CurrentState)
3935
.filter(CurrentState.id == self.contract_address)

backend/database_handler/migration/versions/cb34b6b353ed_add_ghost_contract_address_column.py

-30
This file was deleted.

backend/database_handler/models.py

+32-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class Transactions(Base):
9494
r: Mapped[Optional[int]] = mapped_column(Integer)
9595
s: Mapped[Optional[int]] = mapped_column(Integer)
9696
v: Mapped[Optional[int]] = mapped_column(Integer)
97-
ghost_contract_address: Mapped[Optional[str]] = mapped_column(String(255))
9897

9998
# Relationship for triggered transactions
10099
triggered_by_hash: Mapped[Optional[str]] = mapped_column(
@@ -118,6 +117,38 @@ class Transactions(Base):
118117
timestamp_accepted: Mapped[Optional[int]] = mapped_column(BigInteger, default=None)
119118

120119

120+
class RollupTransactions(Base):
121+
__tablename__ = "rollup_transactions"
122+
__table_args__ = (
123+
PrimaryKeyConstraint("transaction_hash", name="rollup_transactions_pkey"),
124+
)
125+
126+
transaction_hash: Mapped[str] = mapped_column(
127+
String(66), primary_key=True, unique=True
128+
)
129+
from_: Mapped[str] = mapped_column(
130+
String(255),
131+
)
132+
to_: Mapped[Optional[dict]] = mapped_column(
133+
String(255),
134+
)
135+
gas: Mapped[int] = mapped_column(
136+
Integer,
137+
)
138+
gas_price: Mapped[int] = mapped_column(
139+
Integer,
140+
)
141+
value: Mapped[Optional[int]] = mapped_column(
142+
Integer,
143+
)
144+
input: Mapped[str] = mapped_column(
145+
Text,
146+
)
147+
nonce: Mapped[int] = mapped_column(
148+
BigInteger,
149+
)
150+
151+
121152
class Validators(Base):
122153
__tablename__ = "validators"
123154
__table_args__ = (

backend/database_handler/transactions_processor.py

+21-106
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
import rlp
44

5-
from .models import Transactions
5+
from .models import Transactions, RollupTransactions
66
from sqlalchemy.orm import Session
77
from sqlalchemy import or_, and_
88

@@ -11,10 +11,6 @@
1111
import json
1212
import base64
1313
import time
14-
from backend.domain.types import TransactionType
15-
from web3 import Web3
16-
from backend.database_handler.contract_snapshot import ContractSnapshot
17-
import os
1814

1915

2016
class TransactionAddressFilter(Enum):
@@ -30,12 +26,6 @@ def __init__(
3026
):
3127
self.session = session
3228

33-
# Connect to Hardhat Network
34-
port = os.environ.get("HARDHAT_PORT")
35-
url = os.environ.get("HARDHAT_URL")
36-
hardhat_url = f"{url}:{port}"
37-
self.web3 = Web3(Web3.HTTPProvider(hardhat_url))
38-
3929
@staticmethod
4030
def _parse_transaction_data(transaction_data: Transactions) -> dict:
4131
return {
@@ -59,7 +49,6 @@ def _parse_transaction_data(transaction_data: Transactions) -> dict:
5949
transaction.hash
6050
for transaction in transaction_data.triggered_transactions
6151
],
62-
"ghost_contract_address": transaction_data.ghost_contract_address,
6352
"appealed": transaction_data.appealed,
6453
"timestamp_accepted": transaction_data.timestamp_accepted,
6554
}
@@ -141,64 +130,6 @@ def insert_transaction(
141130
from_address, to_address, data, value, type, nonce
142131
)
143132

144-
if type == TransactionType.DEPLOY_CONTRACT.value:
145-
# Hardhat account
146-
account = self.web3.eth.accounts[0]
147-
private_key = os.environ.get("HARDHAT_PRIVATE_KEY")
148-
149-
# Ghost contract
150-
# Read contract ABI and bytecode from compiled contract
151-
contract_file = os.path.join(
152-
os.getcwd(),
153-
"hardhat/artifacts/contracts/GhostContract.sol/GhostContract.json",
154-
)
155-
156-
with open(contract_file, "r") as f:
157-
contract_json = json.loads(f.read())
158-
abi = contract_json["abi"]
159-
bytecode = contract_json["bytecode"]
160-
161-
# Create the contract instance
162-
contract = self.web3.eth.contract(abi=abi, bytecode=bytecode)
163-
164-
# Build the transaction
165-
gas_estimate = self.web3.eth.estimate_gas(
166-
contract.constructor().build_transaction(
167-
{
168-
"from": account,
169-
"nonce": self.web3.eth.get_transaction_count(account),
170-
"gasPrice": 0,
171-
}
172-
)
173-
)
174-
transaction = contract.constructor().build_transaction(
175-
{
176-
"from": account,
177-
"nonce": self.web3.eth.get_transaction_count(account),
178-
"gas": gas_estimate,
179-
"gasPrice": 0,
180-
}
181-
)
182-
183-
# Sign the transaction
184-
signed_tx = self.web3.eth.account.sign_transaction(
185-
transaction, private_key=private_key
186-
)
187-
188-
# Send the transaction
189-
tx_hash = self.web3.eth.send_raw_transaction(signed_tx.raw_transaction)
190-
191-
# Wait for the transaction receipt
192-
receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash)
193-
ghost_contract_address = receipt.contractAddress
194-
195-
elif type == TransactionType.RUN_CONTRACT.value:
196-
genlayer_contract_address = to_address
197-
contract_snapshot = ContractSnapshot(
198-
genlayer_contract_address, self.session
199-
)
200-
ghost_contract_address = contract_snapshot.ghost_contract_address
201-
202133
new_transaction = Transactions(
203134
hash=transaction_hash,
204135
from_address=from_address,
@@ -221,7 +152,6 @@ def insert_transaction(
221152
if triggered_by_hash
222153
else None
223154
),
224-
ghost_contract_address=ghost_contract_address,
225155
appealed=False,
226156
timestamp_accepted=None,
227157
)
@@ -265,44 +195,29 @@ def create_rollup_transaction(self, transaction_hash: str):
265195
transaction = (
266196
self.session.query(Transactions).filter_by(hash=transaction_hash).one()
267197
)
268-
rollup_input_data = json.dumps(
198+
rollup_input_data = self._transaction_data_to_str(
269199
self._parse_transaction_data(transaction)
270-
).encode("utf-8")
271-
272-
# Hardhat transaction
273-
account = self.web3.eth.accounts[0]
274-
private_key = os.environ.get("HARDHAT_PRIVATE_KEY")
275-
276-
gas_estimate = self.web3.eth.estimate_gas(
277-
{
278-
"from": account,
279-
"to": transaction.ghost_contract_address,
280-
"value": transaction.value,
281-
"data": rollup_input_data,
282-
}
283200
)
284-
285-
transaction = {
286-
"from": account,
287-
"to": transaction.ghost_contract_address,
288-
"value": transaction.value,
289-
"data": rollup_input_data,
290-
"nonce": self.web3.eth.get_transaction_count(account),
291-
"gas": gas_estimate,
292-
"gasPrice": 0,
293-
}
294-
295-
# Sign and send the transaction
296-
signed_tx = self.web3.eth.account.sign_transaction(
297-
transaction, private_key=private_key
201+
rollup_nonce = int(time.time() * 1000)
202+
rollup_transaction_hash = self._generate_transaction_hash(
203+
transaction.from_address,
204+
transaction.to_address,
205+
rollup_input_data,
206+
transaction.value,
207+
0,
208+
rollup_nonce,
298209
)
299-
tx_hash = self.web3.eth.send_raw_transaction(signed_tx.raw_transaction)
300-
301-
# Wait for transaction to be actually mined and get the receipt
302-
receipt = self.web3.eth.wait_for_transaction_receipt(tx_hash)
303-
304-
# Get full transaction details including input data
305-
transaction = self.web3.eth.get_transaction(tx_hash)
210+
rollup_transaction_record = RollupTransactions(
211+
transaction_hash=rollup_transaction_hash,
212+
from_=transaction.from_address,
213+
to_=transaction.to_address,
214+
gas=0,
215+
gas_price=0,
216+
value=transaction.value,
217+
input=rollup_input_data,
218+
nonce=rollup_nonce,
219+
)
220+
self.session.add(rollup_transaction_record)
306221

307222
def get_transaction_count(self, address: str) -> int:
308223
count = (

backend/domain/types.py

-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class Transaction:
7979
leader_only: bool = (
8080
False # Flag to indicate if this transaction should be processed only by the leader. Used for fast and cheap execution of transactions.
8181
)
82-
ghost_contract_address: str | None = None
8382
appealed: bool = False
8483
timestamp_accepted: int | None = None
8584

@@ -100,7 +99,6 @@ def to_dict(self):
10099
"s": self.s,
101100
"v": self.v,
102101
"leader_only": self.leader_only,
103-
"ghost_contract_address": self.ghost_contract_address,
104102
"appealed": self.appealed,
105103
"timestamp_accepted": self.timestamp_accepted,
106104
}
@@ -123,7 +121,6 @@ def transaction_from_dict(input: dict) -> Transaction:
123121
s=input.get("s"),
124122
v=input.get("v"),
125123
leader_only=input.get("leader_only", False),
126-
ghost_contract_address=input.get("ghost_contract_address"),
127124
appealed=input.get("appealed"),
128125
timestamp_accepted=input.get("timestamp_accepted"),
129126
)

backend/protocol_rpc/requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ Flask-SQLAlchemy==3.1.1
2121
jsf==0.11.2
2222
jsonschema==4.23.0
2323
loguru==0.7.2
24-
web3==7.5.0

0 commit comments

Comments
 (0)