Skip to content

Commit d4ce7a6

Browse files
authored
Merge pull request #44 from chainstacklabs/dev
Add block range for eth_getLogs
2 parents 97258fb + 55e1acb commit d4ce7a6

File tree

6 files changed

+57
-18
lines changed

6 files changed

+57
-18
lines changed

config/defaults.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class MetricsServiceConfig:
3333

3434
# Block offset configuration (N blocks back from latest)
3535
BLOCK_OFFSET_RANGES = { # noqa: RUF012
36-
"ethereum": (7200, 14400),
37-
"base": (7200, 14400),
36+
"ethereum": (7200, 10000),
37+
"base": (7200, 10000),
3838
"solana": (432000, 648000),
3939
"ton": (1555200, 1572480),
40-
"arbitrum": (7200, 14400),
41-
"bnb": (7200, 14400),
40+
"arbitrum": (7200, 10000),
41+
"bnb": (7200, 10000),
4242
}
4343

4444

metrics/arbitrum.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,23 @@ class HTTPGetLogsLatencyMetric(HttpCallLatencyMetricBase):
109109
def method(self) -> str:
110110
return "eth_getLogs"
111111

112+
@staticmethod
113+
def validate_state(state_data: dict) -> bool:
114+
"""Validates that required old block number exists in state data."""
115+
return bool(state_data and state_data.get("block"))
116+
112117
@staticmethod
113118
def get_params_from_state(state_data: dict) -> list:
114-
"""Get parameters for USDC transfer logs from latest block."""
119+
"""Get parameters for USDC transfer logs from recent block range."""
120+
from_block_hex = state_data["old_block"]
121+
from_block_int = int(from_block_hex, 16)
122+
to_block_int: int = max(0, from_block_int + 100)
123+
to_block_hex: str = hex(to_block_int)
124+
115125
return [
116126
{
117-
"fromBlock": "latest",
127+
"fromBlock": from_block_hex,
128+
"toBlock": to_block_hex,
118129
"address": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", # USDC on Arbitrum
119130
"topics": [
120131
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" # Transfer event

metrics/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,16 @@ def method(self) -> str:
111111

112112
@staticmethod
113113
def get_params_from_state(state_data: dict) -> list:
114-
"""Get parameters for USDC transfer logs from latest block."""
114+
"""Get parameters for USDC transfer logs from recent block range."""
115+
from_block_hex = state_data["old_block"]
116+
from_block_int = int(from_block_hex, 16)
117+
to_block_int: int = max(0, from_block_int + 100)
118+
to_block_hex: str = hex(to_block_int)
119+
115120
return [
116121
{
117-
"fromBlock": "latest",
122+
"fromBlock": from_block_hex,
123+
"toBlock": to_block_hex,
118124
"address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913", # USDC on Base
119125
"topics": [
120126
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" # Transfer event

metrics/bnbsc.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,23 @@ class HTTPGetLogsLatencyMetric(HttpCallLatencyMetricBase):
109109
def method(self) -> str:
110110
return "eth_getLogs"
111111

112+
@staticmethod
113+
def validate_state(state_data: dict) -> bool:
114+
"""Validates that required old block number exists in state data."""
115+
return bool(state_data and state_data.get("block"))
116+
112117
@staticmethod
113118
def get_params_from_state(state_data: dict) -> list:
114-
"""Get parameters for Wrapped BNB transfer logs from latest block."""
119+
"""Get parameters for Wrapped BNB transfer logs from recent block range."""
120+
from_block_hex = state_data["old_block"]
121+
from_block_int = int(from_block_hex, 16)
122+
to_block_int: int = max(0, from_block_int + 100)
123+
to_block_hex: str = hex(to_block_int)
124+
115125
return [
116126
{
117-
"fromBlock": "latest",
127+
"fromBlock": from_block_hex,
128+
"toBlock": to_block_hex,
118129
"address": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c", # Wrapped BNB on BSC
119130
"topics": [
120131
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" # Transfer event

metrics/ethereum.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,23 @@ class HTTPGetLogsLatencyMetric(HttpCallLatencyMetricBase):
117117
def method(self) -> str:
118118
return "eth_getLogs"
119119

120+
@staticmethod
121+
def validate_state(state_data: dict) -> bool:
122+
"""Validates that required block number exists in state data."""
123+
return bool(state_data and state_data.get("old_block"))
124+
120125
@staticmethod
121126
def get_params_from_state(state_data: dict) -> list:
122-
"""Get parameters for USDC transfer logs from latest block."""
127+
"""Get parameters for USDC transfer logs from recent block range."""
128+
from_block_hex = state_data["old_block"]
129+
from_block_int = int(from_block_hex, 16)
130+
to_block_int: int = max(0, from_block_int + 100)
131+
to_block_hex: str = hex(to_block_int)
132+
123133
return [
124134
{
125-
"fromBlock": "latest",
135+
"fromBlock": from_block_hex,
136+
"toBlock": to_block_hex,
126137
"address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", # USDC
127138
"topics": [
128139
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" # Transfer event

vercel.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"functions": {
33
"api/read/ethereum.py": {
4-
"memory": 300,
4+
"memory": 400,
55
"maxDuration": 59
66
},
77
"api/read/base.py": {
8-
"memory": 320,
8+
"memory": 400,
99
"maxDuration": 59
1010
},
1111
"api/read/solana.py": {
@@ -17,11 +17,11 @@
1717
"maxDuration": 59
1818
},
1919
"api/read/arbitrum.py": {
20-
"memory": 300,
20+
"memory": 400,
2121
"maxDuration": 59
2222
},
2323
"api/read/bnbsc.py": {
24-
"memory": 300,
24+
"memory": 400,
2525
"maxDuration": 59
2626
},
2727
"api/read/test_blockchain.py": {
@@ -72,7 +72,7 @@
7272
},
7373
{
7474
"path": "/api/support/update_state",
75-
"schedule": "*/30 * * * *"
75+
"schedule": "*/15 * * * *"
7676
}
7777
]
78-
}
78+
}

0 commit comments

Comments
 (0)