Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove calldata from frontend, stabilize eth_call, make tests less flaky #805

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion backend/node/genvm/origin/base_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ async def wait_all_timeout():

if not coro_loop.done():
coro_loop.cancel()
await coro_loop

try:
await coro_loop
except Exception as e:
errors.append(e)

if not handler.has_result():
if (
Expand Down
15 changes: 9 additions & 6 deletions backend/protocol_rpc/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# rpc/endpoints.py
import random
import json
import eth_utils
from functools import partial
from typing import Any
from flask_jsonrpc import JSONRPC
from flask_jsonrpc.exceptions import JSONRPCError
from sqlalchemy import Table
from sqlalchemy.orm import Session

import backend.node.genvm.origin.calldata as genvm_calldata

from backend.database_handler.contract_snapshot import ContractSnapshot
Expand Down Expand Up @@ -36,6 +36,7 @@
decode_signed_transaction,
transaction_has_valid_signature,
decode_method_call_data,
decode_method_send_data,
decode_deployment_data,
)
from backend.errors.errors import InvalidAddressError, InvalidTransactionError
Expand Down Expand Up @@ -331,7 +332,7 @@ async def get_contract_schema(


async def get_contract_schema_for_code(
msg_handler: MessageHandler, contract_code: str
msg_handler: MessageHandler, contract_code_hex: str
) -> dict:
node = Node( # Mock node just to get the data from the GenVM
contract_snapshot=None,
Expand All @@ -351,7 +352,9 @@ async def get_contract_schema_for_code(
msg_handler=msg_handler.with_client_session(get_client_session_id()),
contract_snapshot_factory=None,
)
schema = await node.get_contract_schema(contract_code.encode("utf-8"))
schema = await node.get_contract_schema(
eth_utils.hexadecimal.decode_hex(contract_code_hex)
)
return json.loads(schema)


Expand All @@ -368,7 +371,7 @@ def get_balance(


def get_transaction_count(
transactions_processor: TransactionsProcessor, address: str
transactions_processor: TransactionsProcessor, address: str, block: str = "latest"
) -> int:
return transactions_processor.get_transaction_count(address)

Expand Down Expand Up @@ -425,7 +428,7 @@ async def call(
raise JSONRPCError(
message="running contract failed", data={"receipt": receipt.to_dict()}
)
return base64.b64encode(receipt.result[1:]).decode("ascii")
return eth_utils.hexadecimal.encode_hex(receipt.result[1:])


def send_raw_transaction(
Expand Down Expand Up @@ -488,7 +491,7 @@ def send_raw_transaction(
raise InvalidAddressError(
to_address, f"Invalid address to_address: {to_address}"
)
decoded_data = decode_method_call_data(decoded_transaction.data)
decoded_data = decode_method_send_data(decoded_transaction.data)
transaction_data = {"calldata": decoded_data.calldata}
transaction_type = TransactionType.RUN_CONTRACT
leader_only = decoded_data.leader_only
Expand Down
18 changes: 12 additions & 6 deletions backend/protocol_rpc/transactions_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
from eth_account import Account
from eth_account._utils.legacy_transactions import Transaction, vrs_from
from eth_account._utils.signing import hash_of_signed_transaction
import eth_utils
from eth_utils import to_checksum_address
from hexbytes import HexBytes

from backend.protocol_rpc.types import (
DecodedDeploymentData,
DecodedMethodCallData,
DecodedMethodSendData,
DecodedTransaction,
)

Expand Down Expand Up @@ -93,23 +95,27 @@ def transaction_has_valid_signature(
return recovered_address == decoded_tx.from_address


def decode_method_call_data(data: str) -> DecodedMethodCallData:
def decode_method_send_data(data: str) -> DecodedMethodSendData:
data_bytes = HexBytes(data)

try:
data_decoded = rlp.decode(data_bytes, MethodCallTransactionPayload)
data_decoded = rlp.decode(data_bytes, MethodSendTransactionPayload)
except rlp.exceptions.DeserializationError as e:
print("WARN | falling back to default decode method call data:", e)
data_decoded = rlp.decode(data_bytes, MethodCallTransactionPayloadDefault)
data_decoded = rlp.decode(data_bytes, MethodSendTransactionPayloadDefault)

leader_only = getattr(data_decoded, "leader_only", False)

return DecodedMethodCallData(
return DecodedMethodSendData(
calldata=data_decoded["calldata"],
leader_only=leader_only,
)


def decode_method_call_data(data: str) -> DecodedMethodCallData:
return DecodedMethodCallData(eth_utils.hexadecimal.decode_hex(data))


def decode_deployment_data(data: str) -> DecodedDeploymentData:
data_bytes = HexBytes(data)

Expand Down Expand Up @@ -145,14 +151,14 @@ class DeploymentContractTransactionPayloadDefault(rlp.Serializable):
]


class MethodCallTransactionPayload(rlp.Serializable):
class MethodSendTransactionPayload(rlp.Serializable):
fields = [
("calldata", binary),
("leader_only", boolean),
]


class MethodCallTransactionPayloadDefault(rlp.Serializable):
class MethodSendTransactionPayloadDefault(rlp.Serializable):
fields = [
("calldata", binary),
]
5 changes: 5 additions & 0 deletions backend/protocol_rpc/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ class DecodedTransaction:
@dataclass
class DecodedMethodCallData:
calldata: bytes


@dataclass
class DecodedMethodSendData:
calldata: bytes
leader_only: bool = False


Expand Down
5 changes: 4 additions & 1 deletion docker/Dockerfile.webrequest
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ RUN mkdir -p "${base}/${path}" && \
cd "${base}/${selpath}" && \
wget -q https://storage.googleapis.com/chrome-for-testing-public/128.0.6613.119/linux64/chrome-linux64.zip && \
wget -q https://storage.googleapis.com/chrome-for-testing-public/128.0.6613.119/linux64/chromedriver-linux64.zip && \
unzip chromedriver-linux64.zip && \
unzip chrome-linux64.zip && \
rm chromedriver-linux64.zip chrome-linux64.zip && \
wget -q https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.24.0/selenium-server-4.24.0.jar && \
true

ENV PYTHONPATH="${base}/${path}"
ENV PATH=":${PATH}"
ENV PATH="${PATH}:${base}:${base}/${selpath}/chromedriver-linux64/:${base}/${selpath}/chrome-linux64/"
RUN chown -R appuser:appuser $base

USER appuser
Expand Down
8 changes: 4 additions & 4 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 @@ -35,7 +35,7 @@
"defu": "^6.1.4",
"dexie": "^4.0.4",
"floating-vue": "^5.2.2",
"genlayer-js": "^0.4.6",
"genlayer-js": "^0.6.1",
"hash-sum": "^2.0.0",
"jump.js": "^1.0.2",
"lodash-es": "^4.17.21",
Expand Down
14 changes: 0 additions & 14 deletions frontend/src/calldata/consts.ts

This file was deleted.

88 changes: 0 additions & 88 deletions frontend/src/calldata/decoder.ts

This file was deleted.

Loading
Loading