Skip to content

Commit

Permalink
Misc fixes (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
phearnot authored Oct 2, 2024
1 parent eb6f10c commit 78b2e15
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 49 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ name := "consensus-client"
maintainer := "Units Network Team"
resolvers ++= Resolver.sonatypeOssRepos("releases") ++ Resolver.sonatypeOssRepos("snapshots") ++ Seq(Resolver.mavenLocal)
libraryDependencies ++= Seq(
"com.wavesplatform" % "node-testkit" % "1.5.7-3964-SNAPSHOT" % "test",
"com.wavesplatform" % "node" % "1.5.7-3964-SNAPSHOT" % "provided",
"com.wavesplatform" % "node-testkit" % "1.5.8-SNAPSHOT" % "test",
"com.wavesplatform" % "node" % "1.5.8-SNAPSHOT" % "provided",
"com.softwaremill.sttp.client3" % "core_2.13" % "3.9.8",
"com.softwaremill.sttp.client3" %% "play-json" % "3.9.8",
"com.github.jwt-scala" %% "jwt-play-json" % "10.0.1"
Expand Down
24 changes: 13 additions & 11 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Units Network node consists of Waves blockchain node, Consensus Client extension

## Prerequisites
* Install [Docker Compose](https://docs.docker.com/compose/install/).
* Generate JWT secret and execution client keys by running `./gen-keys.sh`. This script requires `openssl` and `xxd`.
* Generate JWT secret and execution client keys by running `./gen-keys.sh`. This script requires `openssl`.
* Optional: get waves node [state](https://docs.waves.tech/en/waves-node/options-for-getting-actual-blockchain/state-downloading-and-applying) and place it inside the `./data/waves` directory.
* Optional: get execution client state.
* To run besu on Linux, you need to manually create data & log directories and set appropriate permissions:
```
install -d -o 1000 -g 1000 data/besu logs/besu
```

## Configuring Waves Node
* Create `./secrets.env` file with the base58-encoded [seed and password](https://docs.waves.tech/en/waves-node/how-to-work-with-node-wallet):
Expand All @@ -17,19 +21,17 @@ Units Network node consists of Waves blockchain node, Consensus Client extension
* Specify the proper declared addresses in the environment file (`testnet.env` for testnet, etc.). Make sure these declared addresses have distinct ports, otherwise your node will be banned from the network!

## Launching
To run besu on Linux, you need to manually create data & log directories and set appropriate permissions:
```
install -d -o 1000 -g 1000 data/besu logs/besu
```
There are two profiles in the compose file: `besu` and `geth`, each starting a respective execution client. You can choose which one to run by specifying either `--profile besu` or `--profile geth` on the command line.

Running, stopping and updating with besu in testnet:
```
docker compose --env-file=testnet.env up -d
docker compose --env-file=testnet.env down
docker compose --env-file=testnet.env pull
docker compose --profile besu --env-file=testnet.env up -d
docker compose --profile besu --env-file=testnet.env down
docker compose --profile besu --env-file=testnet.env pull
```
Running, stopping and updating with geth in testnet:
```
docker compose -f docker-compose-geth.yml --env-file=testnet.env up -d
docker compose -f docker-compose-geth.yml --env-file=testnet.env down
docker compose -f docker-compose-geth.yml --env-file=testnet.env pull
docker compose --profile geth --env-file=testnet.env up -d
docker compose --profile geth --env-file=testnet.env down
docker compose --profile geth --env-file=testnet.env pull
```
11 changes: 0 additions & 11 deletions docker/docker-compose-geth.yml

This file was deleted.

21 changes: 19 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
services:
besu:
profiles: [besu]
hostname: execution-client
extends:
file: ./services/besu.yml
service: besu

geth-init:
profiles: [geth]
extends:
file: ./services/geth.yml
service: geth-init

geth:
profiles: [geth]
hostname: execution-client
extends:
file: ./services/geth.yml
service: geth
depends_on:
geth-init:
condition: service_completed_successfully

waves-node:
extends:
file: ./services/waves-node.yml
service: waves-node
environment:
EXECUTION_CLIENT: besu
4 changes: 2 additions & 2 deletions docker/gen-keys.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
mkdir -p data/secrets
openssl rand 32 | xxd -p -c 32 > data/secrets/p2p-key
openssl rand 32 | xxd -p -c 32 > data/secrets/jwtsecret
openssl rand -hex 32 | tr -d "\n" > data/secrets/p2p-key
openssl rand -hex 32 | tr -d "\n" > data/secrets/jwtsecret
2 changes: 0 additions & 2 deletions docker/services/besu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ services:
- --rpc-http-api=ETH,NET,WEB3,TXPOOL,TRACE
- --rpc-http-cors-origins=all
- --rpc-ws-enabled
- --discovery-dns-url=enrtree://AIRIZFFZSCSIVHXTKA44WYZQJMR75FLTGWJ5TUNEW5IP7QKZDLBRK@${NETWORK}-nodes.unit0.dev
- --discovery-enabled=true
- --engine-rpc-enabled
- --engine-jwt-secret=/etc/secrets/jwtsecret
Expand All @@ -31,6 +30,5 @@ services:
ports:
- '30303:30303/tcp'
- '30303:30303/udp'
- '8545:8545'
environment:
- LOG4J_CONFIGURATION_FILE=/etc/besu/log4j2.xml
8 changes: 8 additions & 0 deletions docker/services/geth.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
services:
geth-init:
container_name: geth-init
image: ethereum/client-go:stable
entrypoint: /tmp/init-geth.sh
volumes:
- ../genesis-${NETWORK}.json:/tmp/genesis.json
- ../data/geth:/root/.ethereum
- ../init-geth.sh:/tmp/init-geth.sh
geth:
container_name: geth
image: ethereum/client-go:stable
Expand Down
6 changes: 3 additions & 3 deletions docker/testnet.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NETWORK=testnet
NETWORK_ID=88817
WAVES_NODE_TAG=L2-test
WAVES_DECLARED_ADDRESS=1.2.3.4:6868
UNITS_DECLARED_ADDRESS=1.2.3.4:6865
WAVES_NODE_TAG=testnet
#WAVES_DECLARED_ADDRESS=1.2.3.4:6868
#UNITS_DECLARED_ADDRESS=1.2.3.4:6865
5 changes: 3 additions & 2 deletions docker/waves-testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ waves {
}

l2 {
chain-contract = 3MsqKJ6o1ABE37676cHHBxJRs6huYTt72ch
execution-client-address = "http://${EXECUTION_CLIENT}:8551"
chain-contract = 3Msx4Aq69zWUKy4d1wyKnQ4ofzEDAfv5Ngf
execution-client-address = "http://execution-client:8551"
jwt-secret-file = /etc/secrets/jwtsecret

network {
port = 6865
declared-address = ${?UNITS_DECLARED_ADDRESS}
known-peers = [
"testnet-l2-htz-hel1-1.wavesnodes.com:6865"
"testnet-l2-htz-hel1-2.wavesnodes.com:6865"
"testnet-htz-nbg1-1.wavesnodes.com:6865"
]
Expand Down
11 changes: 4 additions & 7 deletions local-network/deploy/src/waves-txs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ export const ccMinerJoin1 = wt.invokeScript(
args: [
{
// Reward address
type: "binary",
// 0x7dbcf9c6c3583b76669100f9be3caf6d722bc9f9
value: "base64:fbz5xsNYO3ZmkQD5vjyvbXIryfk="
type: "string",
value: "0x7dbcf9c6c3583b76669100f9be3caf6d722bc9f9"
}
]
}
Expand All @@ -74,9 +73,8 @@ export const ccMinerJoin2 = wt.invokeScript(
args: [
{
// Reward address
type: "binary",
// 0xcf0b9e13fdd593f4ca26d36afcaa44dd3fdccbed
value: "base64:zwueE/3Vk/TKJtNq/KpE3T/cy+0="
type: "string",
value: "0xcf0b9e13fdd593f4ca26d36afcaa44dd3fdccbed"
}
]
}
Expand Down Expand Up @@ -131,4 +129,3 @@ export function mkE2CTransfer(senderPrivateKey: string, blockHash: string, merkl
{ privateKey: senderPrivateKey }
)
}

13 changes: 8 additions & 5 deletions src/test/resources/main.ride
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func appendBlock(
}

@Callable(i)
func join(rewardAddress: ByteVector) = {
func join(rewardAddressHex: String) = {
# EL miner must sign a Network block by own private key
func ensureNotOverrideOtherMinerPk(elAddressHex: String) = {
match getBinary(minerPkKey(elAddressHex)) {
Expand All @@ -500,6 +500,9 @@ func join(rewardAddress: ByteVector) = {
}
}

let parts = rewardAddressHex.split("0x")
let rewardAddress = parts[parts.size() - 1].fromBase16String()

if (!isContractSetup()) then
throw("The contract has not yet set up")
else if (i.originCaller.wavesBalance().generating < MIN_BALANCE) then
Expand All @@ -513,8 +516,8 @@ func join(rewardAddress: ByteVector) = {
then []
else {
let newMiner = i.originCaller.toString()
let rewardAddressHex = rewardAddress.toBase16String()
strict check = ensureNotOverrideOtherMinerPk(rewardAddressHex)
let lowercaseRewardAddress = rewardAddress.toBase16String()
strict check = ensureNotOverrideOtherMinerPk(lowercaseRewardAddress)

let newMiners =
if (allMiners.size() == 0)
Expand All @@ -531,8 +534,8 @@ func join(rewardAddress: ByteVector) = {
}
[
StringEntry(allMinersKey, newMiners),
StringEntry(minerRewardAddressKey(newMiner), "0x" + rewardAddressHex),
BinaryEntry(minerPkKey(rewardAddressHex), i.originCallerPublicKey)
StringEntry(minerRewardAddressKey(newMiner), "0x" + lowercaseRewardAddress),
BinaryEntry(minerPkKey(lowercaseRewardAddress), i.originCallerPublicKey)
] ++ deletePrevRewardAddressPk
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import units.client.L2BlockLike
import units.client.contract.HasConsensusLayerDappTxHelpers.*
import units.client.contract.HasConsensusLayerDappTxHelpers.defaultFees.chainContract.*
import units.eth.{EthAddress, EthereumConstants}
import units.util.HexBytesConverter

trait HasConsensusLayerDappTxHelpers {
def currentHitSource: ByteStr
Expand All @@ -38,7 +37,7 @@ trait HasConsensusLayerDappTxHelpers {
invoker = minerAccount,
dApp = chainContractAddress,
func = "join".some,
args = List(Terms.CONST_BYTESTR(ByteStr(HexBytesConverter.toBytes(elRewardAddress.hexNoPrefix))).explicitGet()),
args = List(Terms.CONST_STRING(elRewardAddress.hexNoPrefix).explicitGet()),
fee = joinFee
)

Expand Down

0 comments on commit 78b2e15

Please sign in to comment.