Skip to content

Commit

Permalink
final fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaele-oplabs committed Nov 4, 2024
1 parent 62192f7 commit 99a4d65
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# .env
L1_GETH_URL="https://l1-geth.rpc"
L2_OP_NODE_URL="https://op-node.rpc"
L2_OP_GETH_URL="https://op-geth.rpc"
mainnet_geth_url="https://l1-geth.rpc"
mainnet_op_geth_url="https://op-geth.rpc"
mainnet_op_node_url="https://op-node.rpc"
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ ui-tests/.pnp.*
local_data
local_data/*

.env
.env
nodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import urllib3
import os
import requests
from pprint import pprint
# Disable warnings for insecure HTTPS requests
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Expand Down Expand Up @@ -130,7 +131,8 @@ def get_block_timestamp(self, blockNumber: int):
"formatted_timestamp": f"{datetime.fromtimestamp(timestamp, tz=timezone.utc).strftime('%Y-%m-%d %H:%M:%S')}",
}
return ret



def get_game_data(self,withDrawalHash:str ,proofSubmitter:str):
if type(withDrawalHash) is str:
withDrawalHash = bytes.fromhex(withDrawalHash)
Expand All @@ -140,9 +142,13 @@ def get_game_data(self,withDrawalHash:str ,proofSubmitter:str):
rootClaim=game.functions.rootClaim().call()

sentMessages=self.L2ToL1MessagePasser.functions.sentMessages(withDrawalHash).call()

optimism_outputAtBlock=self.optimism_output_at_block(l2BlockNumber)


try:
optimism_outputAtBlock=self.optimism_output_at_block(l2BlockNumber)
except Exception as e:
print(f"Error: {str(e)}")
optimism_outputAtBlock=None

return {"gameProxyAddress":gameProxyAddress,"timestamp":timestamp,"l2BlockNumber":l2BlockNumber,"rootClaim":f"0x{rootClaim.hex()}","sentMessages":sentMessages,"optimism_outputAtBlock":optimism_outputAtBlock}


Expand All @@ -163,9 +169,16 @@ def optimism_output_at_block(self,blockNumber:int):

# Send the POST request
response = requests.post(url, headers=headers, data=json.dumps(data),verify=not self.ignore_certificate)

# Check if the request was successful
if response.status_code == 200:
return response.json()["result"]["outputRoot"]
else:
raise Exception(f"Error: {response.status_code} - {response.text}")
raise Exception(f"Error: {response.status_code} - {response.text}")

def getL2Block(self,blockNumber:int):
try:
block=self.l2_op_geth.eth.get_block(blockNumber)
return block
except Exception as e:
print(f"Error: {str(e)}")
return None
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ python-dotenv
requests
toml
web3
urllib3
urllib3
ipywidgets
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "46adf20d-5de6-4f88-8c65-24e2c11f4ea6",
"metadata": {},
"outputs": [],
Expand All @@ -29,21 +29,14 @@
"from lib.web3 import *\n",
"from pprint import pprint\n",
"from datetime import datetime, timedelta\n",
"from IPython.display import Javascript, display\n",
"import yaml\n",
"\n",
"\n",
"#parameters setup (there should be no need to change the one below)\n",
"abi_folder_path=\"abi\"\n",
"\n",
"env_file = \".env\"\n",
"if os.path.exists(env_file):\n",
" load_dotenv(env_file)\n",
" print(\"Environment variables loaded from .env file.\")\n",
"else:\n",
" print(\"No .env file found. Using system environment variables. Make sure to set them up. An example .env file is provided insite the automated folder .env.example\")\n",
"\n",
"L1_GETH_URL = os.getenv('L1_GETH_URL')\n",
"L2_OP_NODE_URL = os.getenv('L2_OP_NODE_URL')\n",
"L2_OP_GETH_URL = os.getenv('L2_OP_GETH_URL')"
"env_file = \".env\"\n"
]
},
{
Expand All @@ -58,7 +51,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 2,
"id": "1f8a7d7e",
"metadata": {},
"outputs": [],
Expand All @@ -68,33 +61,85 @@
"\n",
"#set cahin you need to monitor\n",
"l1_chain_name=\"mainnet\"\n",
"l2_chain_name=\"op\"\n"
"l2_chain_name=\"base\"\n",
"\n",
"#set the chain URL to use as trusted node explicitly or set in .env file\n",
"L1_GETH_URL = \"\"\n",
"L2_NODE_URL = \"\"\n",
"L2_GETH_URL = \"\" "
]
},
{
"cell_type": "markdown",
"id": "c103440d",
"metadata": {},
"source": [
"## Loading local values and superchain regsitry values"
"## Loading local values and superchain regsitry values\n",
"You can either set the values manually temporarly\n",
"```\n",
"L1_GETH_URL = \"\"\n",
"L2_NODE_URL = \"\"\n",
"L2_GETH_URL = \"\" \n",
"```\n",
"Or you can set into .env for a more permanent use of this runbooks.\n",
"Make sure to use the correct name convention as shown below.\n",
"```\n",
"mainnet_geth_url=\"https://l1-geth.rpc\"\n",
"<l1>_geth_url=\"https://l1-geth.rpc\"\n",
"\n",
"mainnet_op_geth_url=\n",
"<l1>_<l2>_get_url=\"https://op-geth.rpc\"\n",
"\n",
"mainnet_op_node_url=\"https://op-node.rpc\"\n",
"<l1>_<l2>_node_url=\"https://op-geth.rpc\"\n",
"```\n",
"\n",
"\n",
"If you are part of OP you have access to the internal repository with internal nodes to call. You can save [https://github.com/ethereum-optimism/internal-data/blob/main/automated-runbooks/.env](https://github.com/ethereum-optimism/internal-data/blob/main/automated-runbooks/.env) whitin the same folder."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "d8621fe4",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"OptimismPortal2 address: https://etherscan.io/address/0x49048044D57e1C92A77f79988d21Fa8fAF74E97e#readProxyContract\n"
]
}
],
"source": [
"if L1_GETH_URL == \"\" or L2_NODE_URL == \"\" or L2_GETH_URL == \"\":\n",
" env_file = \".env\"\n",
" if os.path.exists(env_file):\n",
" load_dotenv(env_file)\n",
" L1_GETH_URL = os.getenv((f\"{l1_chain_name}_geth_url\"))\n",
" L2_OP_NODE_URL = os.getenv((f\"{l1_chain_name}_{l2_chain_name}_node_url\"))\n",
" L2_OP_GETH_URL = os.getenv((f\"{l1_chain_name}_{l2_chain_name}_geth_url\"))\n",
" else:\n",
" print(\"No .env file found. Using system environment variables. Make sure to set them up. An example .env file is provided insite the automated folder .env.example\")\n",
" print(\"If you have access to private nodes in OP Labs you can download the .env file from https://github.com/ethereum-optimism/internal-data/blob/main/automated-runbooks/.env\")\n",
" \n",
"if L1_GETH_URL is None or L2_NODE_URL is None or L2_GETH_URL is None:\n",
" print(\"Please set the environment variables for the chains you want to monitor\")\n",
" exit()\n",
" \n",
"superchain=get_superchain_file(l1_chain_name, l2_chain_name)\n",
"\n",
"eth_scan_url=\"https://etherscan.io\"\n",
"\n",
"if l1_chain_name==\"sepolia\":\n",
" eth_scan_url=\"https://sepolia.etherscan.io\"\n",
" \n",
"superchain=get_superchain_file(l1_chain_name, l2_chain_name)\n",
"\n",
"l2_eth_scan_url=superchain[\"explorer\"]\n",
"\n",
"OptimismPortalProxy=superchain[\"addresses\"][\"OptimismPortalProxy\"]\n",
"\n",
"print(f\"OptimismPortal2 address:{eth_scan_url}/address/{OptimismPortalProxy}#readProxyContract\")\n",
"print(f\"OptimismPortal2 address: {eth_scan_url}/address/{OptimismPortalProxy}#readProxyContract\")\n",
"\n",
"web3_utility=Web3Utility(L1_GETH_URL, L2_OP_GETH_URL,L2_OP_NODE_URL,abi_folder_path, OptimismPortalProxy, ignore_certificate=ignore_url_certificate)"
]
Expand All @@ -112,10 +157,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "e32fd923-03ef-41d5-94af-7212ca36bbb9",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Last withdrawal event:\n",
"timestamp: 1730746475 \n",
"timestamp: 2024-11-04 18:54:35\n",
"\n",
"Last withdrawal happened: \n",
"at block: https://etherscan.io/block/21116207 \n",
"with transaction hash: https://etherscan.io/tx/0xfeeff7830dd809724133295504cf130f4c7011c2795269d4855ef97937e5d4d9\n",
"Logs can be found at: https://etherscan.io/address/0x49048044D57e1C92A77f79988d21Fa8fAF74E97e#events using filter:0x798f9f13695f8f045aa5f80ed8efebb695f3c7fe65da381969f2f28bf3c60b97\n",
"\n",
"WARNING: Last withdrawal event happened less than 24 hours ago. The monitoring may be stalled\n"
]
}
],
"source": [
"result=web3_utility.find_latest_withdrawal_event()\n",
"\n",
Expand Down
Loading

0 comments on commit 99a4d65

Please sign in to comment.