Skip to content

Commit a80f99a

Browse files
authored
Merge pull request #39 from stakewise/fix-keeper
Fix keeper submitting validator vote
2 parents 91574f8 + 05fd246 commit a80f99a

File tree

11 files changed

+95
-143
lines changed

11 files changed

+95
-143
lines changed

deploy/docker-compose.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ volumes:
2121
services:
2222
oracle:
2323
container_name: oracle
24-
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0-rc.4
24+
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0
2525
restart: always
2626
entrypoint: ["python"]
2727
command: ["oracle/oracle/main.py"]
@@ -30,7 +30,7 @@ services:
3030

3131
keeper:
3232
container_name: keeper
33-
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0-rc.4
33+
image: europe-west4-docker.pkg.dev/stakewiselabs/public/oracle:v2.0.0
3434
restart: always
3535
entrypoint: ["python"]
3636
command: ["oracle/keeper/main.py"]
@@ -77,7 +77,7 @@ services:
7777

7878
subgraphs:
7979
container_name: subgraphs
80-
image: europe-west4-docker.pkg.dev/stakewiselabs/public/subgraphs:v1.0.2
80+
image: europe-west4-docker.pkg.dev/stakewiselabs/public/subgraphs:v1.0.4
8181
command: >
8282
/bin/sh -c "until nc -vz graph-node 8020; do echo 'Waiting graph-node'; sleep 2; done
8383
&& yarn prepare:${NETWORK}

oracle/keeper/contracts.py

+53-98
Original file line numberDiff line numberDiff line change
@@ -62,73 +62,76 @@ def get_oracles_contract() -> Contract:
6262
"stateMutability": "view",
6363
"type": "function",
6464
},
65+
{
66+
"inputs": [
67+
{"internalType": "bytes32", "name": "role", "type": "bytes32"}
68+
],
69+
"name": "getRoleMemberCount",
70+
"outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
71+
"stateMutability": "view",
72+
"type": "function",
73+
},
74+
{
75+
"inputs": [
76+
{"internalType": "bytes32", "name": "role", "type": "bytes32"},
77+
{"internalType": "uint256", "name": "index", "type": "uint256"},
78+
],
79+
"name": "getRoleMember",
80+
"outputs": [{"internalType": "address", "name": "", "type": "address"}],
81+
"stateMutability": "view",
82+
"type": "function",
83+
},
84+
{
85+
"inputs": [],
86+
"name": "paused",
87+
"outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
88+
"stateMutability": "view",
89+
"type": "function",
90+
},
6591
{
6692
"inputs": [
6793
{
68-
"components": [
69-
{
70-
"internalType": "address",
71-
"name": "operator",
72-
"type": "address",
73-
},
74-
{
75-
"internalType": "bytes32",
76-
"name": "withdrawalCredentials",
77-
"type": "bytes32",
78-
},
79-
{
80-
"internalType": "bytes32",
81-
"name": "depositDataRoot",
82-
"type": "bytes32",
83-
},
84-
{
85-
"internalType": "bytes",
86-
"name": "publicKey",
87-
"type": "bytes",
88-
},
89-
{
90-
"internalType": "bytes",
91-
"name": "signature",
92-
"type": "bytes",
93-
},
94-
],
95-
"internalType": "struct IPoolValidators.DepositData",
96-
"name": "depositData",
97-
"type": "tuple",
94+
"internalType": "bytes32",
95+
"name": "merkleRoot",
96+
"type": "bytes32",
9897
},
9998
{
100-
"internalType": "bytes32[]",
101-
"name": "merkleProof",
102-
"type": "bytes32[]",
99+
"internalType": "string",
100+
"name": "merkleProofs",
101+
"type": "string",
103102
},
104103
{
105104
"internalType": "bytes[]",
106105
"name": "signatures",
107106
"type": "bytes[]",
108107
},
109108
],
110-
"name": "finalizeValidator",
109+
"name": "submitMerkleRoot",
111110
"outputs": [],
112111
"stateMutability": "nonpayable",
113112
"type": "function",
114113
},
115114
{
116115
"inputs": [
117-
{"internalType": "bytes32", "name": "role", "type": "bytes32"}
118-
],
119-
"name": "getRoleMemberCount",
120-
"outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
121-
"stateMutability": "view",
122-
"type": "function",
123-
},
124-
{
125-
"inputs": [
126-
{"internalType": "bytes32", "name": "role", "type": "bytes32"},
127-
{"internalType": "uint256", "name": "index", "type": "uint256"},
116+
{
117+
"internalType": "uint256",
118+
"name": "totalRewards",
119+
"type": "uint256",
120+
},
121+
{
122+
"internalType": "uint256",
123+
"name": "activatedValidators",
124+
"type": "uint256",
125+
},
126+
{
127+
"internalType": "bytes[]",
128+
"name": "signatures",
129+
"type": "bytes[]",
130+
},
128131
],
129-
"name": "getRoleMember",
130-
"outputs": [{"internalType": "address", "name": "", "type": "address"}],
131-
"stateMutability": "view",
132+
"name": "submitRewards",
133+
"outputs": [],
134+
"stateMutability": "nonpayable",
132135
"type": "function",
133136
},
134137
{
@@ -170,66 +173,18 @@ def get_oracles_contract() -> Contract:
170173
"name": "merkleProof",
171174
"type": "bytes32[]",
172175
},
173-
{
174-
"internalType": "bytes[]",
175-
"name": "signatures",
176-
"type": "bytes[]",
177-
},
178-
],
179-
"name": "initializeValidator",
180-
"outputs": [],
181-
"stateMutability": "nonpayable",
182-
"type": "function",
183-
},
184-
{
185-
"inputs": [],
186-
"name": "paused",
187-
"outputs": [{"internalType": "bool", "name": "", "type": "bool"}],
188-
"stateMutability": "view",
189-
"type": "function",
190-
},
191-
{
192-
"inputs": [
193176
{
194177
"internalType": "bytes32",
195-
"name": "merkleRoot",
178+
"name": "validatorsDepositRoot",
196179
"type": "bytes32",
197180
},
198-
{
199-
"internalType": "string",
200-
"name": "merkleProofs",
201-
"type": "string",
202-
},
203-
{
204-
"internalType": "bytes[]",
205-
"name": "signatures",
206-
"type": "bytes[]",
207-
},
208-
],
209-
"name": "submitMerkleRoot",
210-
"outputs": [],
211-
"stateMutability": "nonpayable",
212-
"type": "function",
213-
},
214-
{
215-
"inputs": [
216-
{
217-
"internalType": "uint256",
218-
"name": "totalRewards",
219-
"type": "uint256",
220-
},
221-
{
222-
"internalType": "uint256",
223-
"name": "activatedValidators",
224-
"type": "uint256",
225-
},
226181
{
227182
"internalType": "bytes[]",
228183
"name": "signatures",
229184
"type": "bytes[]",
230185
},
231186
],
232-
"name": "submitRewards",
187+
"name": "registerValidator",
233188
"outputs": [],
234189
"stateMutability": "nonpayable",
235190
"type": "function",

oracle/keeper/main.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import time
55
from typing import Any
66

7+
import backoff
8+
79
from oracle.common.health_server import create_health_server_runner, start_health_server
810
from oracle.common.settings import ENABLE_HEALTH_SERVER, LOG_LEVEL
911
from oracle.keeper.health_server import keeper_routes
@@ -38,6 +40,7 @@ def exit_gracefully(self, signum: int, frame: Any) -> None:
3840
self.exit = True
3941

4042

43+
@backoff.on_exception(backoff.expo, Exception, max_time=900)
4144
def main() -> None:
4245
# wait for interrupt
4346
interrupt_handler = InterruptHandler()

oracle/keeper/settings.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
ORACLE_PRIVATE_KEY = config("ORACLE_PRIVATE_KEY")
99

10-
KEEPER_PROCESS_INTERVAL = config("KEEPER_PROCESS_INTERVAL", default=30, cast=int)
10+
KEEPER_PROCESS_INTERVAL = config("KEEPER_PROCESS_INTERVAL", default=10, cast=int)
1111

1212
KEEPER_MIN_BALANCE_WEI = config(
1313
"KEEPER_MIN_BALANCE_WEI", default=Web3.toWei(0.1, "ether"), cast=int
@@ -17,14 +17,14 @@
1717

1818
if NETWORK == MAINNET:
1919
ORACLES_CONTRACT_ADDRESS = Web3.toChecksumAddress(
20-
"0xE949060ACE386D5e277De217703B17A2547f24C0"
20+
"0x8a887282E67ff41d36C0b7537eAB035291461AcD"
2121
)
2222
MULTICALL_CONTRACT_ADDRESS = Web3.toChecksumAddress(
2323
"0xeefBa1e63905eF1D7ACbA5a8513c70307C1cE441"
2424
)
2525
elif NETWORK == GOERLI:
2626
ORACLES_CONTRACT_ADDRESS = Web3.toChecksumAddress(
27-
"0x4bBaA17eFd71683dCb9C769DD38E7674994FE38d"
27+
"0x531b9D9cb268E88D53A87890699bbe31326A6f08"
2828
)
2929
MULTICALL_CONTRACT_ADDRESS = Web3.toChecksumAddress(
3030
"0x77dCa2C955b15e9dE4dbBCf1246B4B85b651e50e"

oracle/keeper/utils.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def check_validator_vote(vote: ValidatorVote, oracle: ChecksumAddress) -> bool:
145145
int(vote["nonce"]),
146146
vote["public_key"],
147147
vote["operator"],
148-
vote["validators_count"],
148+
vote["validators_deposit_root"],
149149
],
150150
)
151151
return validate_vote_signature(encoded_data, oracle, vote["signature"])
@@ -239,7 +239,6 @@ def get_transaction_params() -> TxParams:
239239
)
240240

241241

242-
@backoff.on_exception(backoff.expo, Exception, max_time=900)
243242
def submit_update(function_call: ContractFunction) -> None:
244243
tx_params = get_transaction_params()
245244
estimated_gas = function_call.estimateGas(tx_params)
@@ -317,40 +316,40 @@ def submit_votes(votes: OraclesVotes, total_oracles: int) -> None:
317316

318317
counter = Counter(
319318
[
320-
(vote["public_key"], vote["operator"], vote["validators_count"])
319+
(vote["public_key"], vote["operator"], vote["validators_deposit_root"])
321320
for vote in votes.validator
322321
]
323322
)
324323
most_voted = counter.most_common(1)
325324
if most_voted and can_submit(most_voted[0][1], total_oracles):
326-
public_key, operator, validators_count = most_voted[0][0]
325+
public_key, operator, validators_deposit_root = most_voted[0][0]
327326
signatures = []
328327
i = 0
329328
while not can_submit(len(signatures), total_oracles):
330329
vote = votes.validator[i]
331-
if (public_key, operator, validators_count) == (
330+
if (public_key, operator, validators_deposit_root) == (
332331
vote["public_key"],
333332
vote["operator"],
334-
vote["validators_count"],
333+
vote["validators_deposit_root"],
335334
):
336335
signatures.append(vote["signature"])
337336
i += 1
338337

339338
validator_vote: ValidatorVote = next(
340339
vote
341340
for vote in votes.validator
342-
if (public_key, operator, validators_count)
341+
if (public_key, operator, validators_deposit_root)
343342
== (
344343
vote["public_key"],
345344
vote["operator"],
346-
vote["validators_count"],
345+
vote["validators_deposit_root"],
347346
)
348347
)
349348
logger.info(
350349
f"Submitting validator registration: "
351350
f"operator={operator}, "
352351
f"public key={public_key}, "
353-
f"validator count={validators_count}"
352+
f"validator deposit root={validators_deposit_root}"
354353
)
355354
submit_update(
356355
oracles_contract.functions.registerValidator(
@@ -362,7 +361,7 @@ def submit_votes(votes: OraclesVotes, total_oracles: int) -> None:
362361
signature=validator_vote["deposit_data_signature"],
363362
),
364363
validator_vote["proof"],
365-
validators_count,
364+
validators_deposit_root,
366365
signatures,
367366
),
368367
)

oracle/oracle/distributor/eth1.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,14 @@ async def get_operators_rewards(
318318
if total_validators <= 0:
319319
return {}, total_reward
320320

321-
operators_reward = (total_reward * total_points) // (
322-
total_validators * 10000 * (to_block - from_block)
321+
operators_reward = Wei(
322+
(total_reward * total_points)
323+
// (total_validators * 10000 * (to_block - from_block))
323324
)
324325
if operators_reward <= 0:
325326
return {}, total_reward
326327

328+
operators_reward = min(total_reward, operators_reward)
327329
rewards = calculate_points_based_rewards(
328330
total_reward=operators_reward,
329331
points=points,
@@ -378,12 +380,14 @@ async def get_partners_rewards(
378380
if total_contributed <= 0:
379381
return {}, total_reward
380382

381-
partners_reward = (total_reward * total_points) // (
382-
total_contributed * 10000 * (to_block - from_block)
383+
partners_reward = Wei(
384+
(total_reward * total_points)
385+
// (total_contributed * 10000 * (to_block - from_block))
383386
)
384387
if partners_reward <= 0:
385388
return {}, total_reward
386389

390+
partners_reward = min(total_reward, partners_reward)
387391
rewards = calculate_points_based_rewards(
388392
total_reward=partners_reward,
389393
points=points,

oracle/oracle/graphql_queries.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@
383383
query getValidatorRegistrations($block_number: Int, $public_key: Bytes) {
384384
validatorRegistrations(
385385
block: { number: $block_number }
386-
where: { id: $public_key }
386+
where: { publicKey: $public_key }
387387
) {
388-
id
388+
publicKey
389389
}
390390
}
391391
"""
@@ -400,7 +400,7 @@
400400
orderBy: createdAtBlock
401401
orderDirection: desc
402402
) {
403-
index
403+
validatorsDepositRoot
404404
}
405405
}
406406
"""

0 commit comments

Comments
 (0)