Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
cyc60 committed Dec 1, 2023
2 parents c25aa0b + 8fe024c commit 3e0f207
Show file tree
Hide file tree
Showing 8 changed files with 522 additions and 327 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ docker build --pull -t stakewiselabs/v3-operator .
or pull existing one:
```sh
docker pull europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.1
docker pull europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.3
```
You have to mount keystores and deposit data folders into docker container.
Expand All @@ -221,7 +221,7 @@ Start the container with the following command:
```sh
docker run --restart on-failure:10 \
-v ~/.stakewise/:/data \
europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.1 \
europe-west4-docker.pkg.dev/stakewiselabs/public/v3-operator:v1.0.3 \
src/main.py start \
--vault=0x3320a...68 \
--data-dir=/data \
Expand Down
641 changes: 322 additions & 319 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "v3-operator"
version = "v1.0.1"
version = "v1.0.3"
description = "StakeWise operator service for registering vault validators"
authors = ["StakeWise Labs <info@stakewise.io>"]

Expand All @@ -20,6 +20,7 @@ eciespy = "==0.4.0"
prometheus-client = "==0.17.1"
psycopg2 = "==2.9.9"
pyyaml = "==6.0.1"
aiohttp = "==3.9.1"

[tool.poetry.group.dev.dependencies]
pylint = "==3.0.1"
Expand Down
144 changes: 144 additions & 0 deletions src/common/abi/IV2PoolEscrow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_owner",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferApplied",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "currentOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "futureOwner",
"type": "address"
}
],
"name": "OwnershipTransferCommitted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "sender",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "payee",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Withdrawn",
"type": "event"
},
{
"inputs": [],
"name": "applyOwnershipTransfer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "commitOwnershipTransfer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "futureOwner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address payable",
"name": "payee",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
2 changes: 1 addition & 1 deletion src/common/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ async def _get_max_fee_per_gas() -> Wei:
priority_fee = await _calculate_median_priority_fee()
latest_block = await execution_client.eth.get_block('latest')
base_fee = latest_block['baseFeePerGas']
max_fee_per_gas = priority_fee + 2 * base_fee
max_fee_per_gas = priority_fee + base_fee
return Wei(max_fee_per_gas)


Expand Down
8 changes: 8 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import click

import src
from src.commands.create_keys import create_keys
from src.commands.create_wallet import create_wallet
from src.commands.get_validators_root import get_validators_root
Expand All @@ -15,9 +16,16 @@
from src.commands.remote_signer_setup import remote_signer_setup
from src.commands.start import start
from src.commands.validators_exit import validators_exit
from src.common.utils import get_build_version
from src.remote_db.commands import remote_db_group

build = get_build_version()
version = src.__version__
if build:
version += f'-{build}'


@click.version_option(version=version, prog_name='Stakewise v3 operator service')
@click.group()
def cli() -> None:
pass
Expand Down
19 changes: 16 additions & 3 deletions src/remote_db/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ def setup_validator(
raise click.ClickException('No keypairs found in the remote db.')

public_keys_count = len(keypairs)
keys_per_validator = public_keys_count // total_validators
start_index = keys_per_validator * validator_index
end_index = min(start_index + keys_per_validator, public_keys_count)
start_index, end_index = _get_key_indexes(
public_keys_count=public_keys_count,
validator_index=validator_index,
total_validators=total_validators,
)
if not 0 <= start_index < end_index <= public_keys_count:
raise click.ClickException('Invalid validator index')

Expand Down Expand Up @@ -348,3 +350,14 @@ def _generate_proposer_config(
}
with open(filepath, 'w', encoding='utf-8') as f:
json.dump(config, f, ensure_ascii=False, indent=4)


def _get_key_indexes(
public_keys_count: int,
total_validators: int,
validator_index: int,
) -> tuple[int, int]:
keys_per_validator = (public_keys_count - 1) // total_validators + 1
start_index = keys_per_validator * validator_index
end_index = min(start_index + keys_per_validator, public_keys_count)
return start_index, end_index
28 changes: 27 additions & 1 deletion src/remote_db/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from src.common.typings import Oracles
from src.remote_db.commands import remote_db_group
from src.remote_db.database import ConfigsCrud, KeyPairsCrud
from src.remote_db.tasks import _encrypt_private_key
from src.remote_db.tasks import _encrypt_private_key, _get_key_indexes
from src.remote_db.typings import RemoteDatabaseKeyPair
from src.validators.signing.key_shares import private_key_to_private_key_shares
from src.validators.typings import BLSPrivkey
Expand Down Expand Up @@ -395,3 +395,29 @@ def test_setup_operator(
result = runner.invoke(remote_db_group, args)
output = 'Successfully created operator configuration file.\n'
assert output.strip() in result.output.strip()


def test_get_key_indexes():
assert _get_key_indexes(1, 1, 0) == (0, 1)

assert _get_key_indexes(2, 1, 0) == (0, 2)

assert _get_key_indexes(2, 2, 0) == (0, 1)
assert _get_key_indexes(2, 2, 1) == (1, 2)

assert _get_key_indexes(27, 2, 0) == (0, 14)
assert _get_key_indexes(27, 2, 1) == (14, 27)

assert _get_key_indexes(150, 3, 0) == (0, 50)
assert _get_key_indexes(150, 3, 1) == (50, 100)
assert _get_key_indexes(150, 3, 2) == (100, 150)

total = 50
count = 0
for i in range(total):
if i == 49:
assert _get_key_indexes(199, total, i) == (196, 199)
else:
assert _get_key_indexes(199, total, i) == (i * 4, i * 4 + 4)
count += _get_key_indexes(199, total, i)[1] - _get_key_indexes(199, total, i)[0]
assert count == 199

0 comments on commit 3e0f207

Please sign in to comment.