Skip to content

Commit

Permalink
Move safety store to rust (#982)
Browse files Browse the repository at this point in the history
## Summary

This PR moves Address Book and Safety Store to RocksDB (i.e. at Rust
side of the Node code). The migration is of the existing stores is
performed automatically at startup.
  • Loading branch information
siy authored Sep 13, 2024
2 parents 2dc7c1a + 4f621f7 commit d9d5c66
Show file tree
Hide file tree
Showing 133 changed files with 6,414 additions and 884 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ concurrency:

on:
pull_request:
# Runs on all PRs
# Runs on all PRs
push:
branches:
- develop
Expand Down Expand Up @@ -209,7 +209,8 @@ jobs:
restore-keys: ${{ runner.os }}-gradle
- name: Run steady-state integration tests
env:
RADIXDLT_LOG_LEVEL: warn
# Might be set to warn for debugging purposes. Warning, log file will be huge.
RADIXDLT_LOG_LEVEL: error
run: ./gradlew clean runSteadyStateIntegrationTests --info --refresh-dependencies
targeted-integration:
name: Targeted integration tests
Expand All @@ -229,7 +230,8 @@ jobs:
restore-keys: ${{ runner.os }}-gradle
- name: Run targeted integration tests
env:
RADIXDLT_LOG_LEVEL: warn
# Might be set to warn for debugging purposes. Warning, log file will be huge.
RADIXDLT_LOG_LEVEL: error
run: ./gradlew clean runTargetedIntegrationTests --info --refresh-dependencies --parallel
cross-xwin:
name: Cross compile to Windows
Expand Down
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ ENV VERSION_LAST_TAG=$VERSION_LAST_TAG
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
docker.io=20.10.24+dfsg1-1+b3 \
libssl-dev=3.0.13-1~deb12u1 \
libssl-dev=3.0.14-1~deb12u2 \
pkg-config=1.8.1-1 \
unzip=6.0-28 \
wget=${WGET_VERSION} \
software-properties-common=0.99.30-4.1~deb12u1 \
&& apt-get install -y --no-install-recommends \
openjdk-17-jdk=17.0.11+9-1~deb12u1 \
openjdk-17-jdk=17.0.12+7-2~deb12u1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -126,12 +126,12 @@ RUN apt-get update \
ca-certificates \
build-essential=12.9 \
# https://security-tracker.debian.org/tracker/CVE-2023-38545
curl=7.88.1-10+deb12u6 \
curl=7.88.1-10+deb12u7 \
g++-aarch64-linux-gnu \
g++-x86-64-linux-gnu \
libc6-dev-arm64-cross=2.36-8cross1 \
libclang-dev=1:14.0-55.7~deb12u1 \
libssl-dev=3.0.13-1~deb12u1 \
libssl-dev=3.0.14-1~deb12u2 \
pkg-config=1.8.1-1 \
&& rm -rf /var/lib/apt/lists/*

Expand Down Expand Up @@ -177,18 +177,21 @@ RUN USER=root "$HOME/.cargo/bin/cargo" init --lib --name dummy --vcs none . \
&& mkdir -p ./jni-export/src \
&& mkdir -p ./node-common/src \
&& mkdir -p ./state-manager/src \
&& mkdir -p ./p2p/src \
&& touch ./core-api-server/src/lib.rs \
&& touch ./engine-state-api-server/src/lib.rs \
&& touch ./jni-export/src/lib.rs \
&& touch ./node-common/src/lib.rs \
&& touch ./state-manager/src/lib.rs
&& touch ./state-manager/src/lib.rs \
&& touch ./p2p/src/lib.rs
COPY core-rust/Cargo.toml ./
COPY core-rust/Cargo.lock ./
COPY core-rust/core-api-server/Cargo.toml ./core-api-server
COPY core-rust/engine-state-api-server/Cargo.toml ./engine-state-api-server
COPY core-rust/jni-export/Cargo.toml ./jni-export
COPY core-rust/node-common/Cargo.toml ./node-common
COPY core-rust/state-manager/Cargo.toml ./state-manager
COPY core-rust/p2p/Cargo.toml ./p2p

COPY docker/build_scripts/cargo_build_by_platform.sh /opt/radixdlt/cargo_build_by_platform.sh

Expand Down Expand Up @@ -256,9 +259,9 @@ LABEL org.opencontainers.image.authors="[email protected]"
# - https://packages.debian.org/bookworm/libc6
RUN apt-get update -y \
&& apt-get -y --no-install-recommends install \
openjdk-17-jre-headless=17.0.11+9-1~deb12u1 \
openjdk-17-jre-headless=17.0.12+7-2~deb12u1 \
# https://security-tracker.debian.org/tracker/CVE-2023-38545
curl=7.88.1-10+deb12u6 \
curl=7.88.1-10+deb12u7 \
gettext-base=0.21-12 \
daemontools=1:0.76-8.1 \
# https://security-tracker.debian.org/tracker/CVE-2023-4911
Expand Down
2 changes: 1 addition & 1 deletion cli-tools/src/main/java/com/radixdlt/shell/RadixShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public Node build() throws Exception {
dataDir = new File(Files.createTempDirectory("radix-shell-node-").toString());
}

customProperties.build().forEach((k, v) -> properties.set(k, v));
customProperties.build().forEach(properties::set);

properties.set("db.location", dataDir.toString());

Expand Down
10 changes: 10 additions & 0 deletions common/src/main/java/com/radixdlt/lang/Option.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ default T or(T replacement) {
return fold(Functions::id, () -> replacement);
}

/**
* Return current value stored in current instance if current instance is present. If current
* instance is empty then return {@code null}.
*
* @return either value stored in current instance or {@code null} if current instance is empty
*/
default T toNullable() {
return fold(Functions::id, () -> null);
}

/**
* Return current value stored in current instance if current instance is present. If current
* instance is empty then return value returned by provided supplier. If current instance is not
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands).
*
* Licensed under the Radix License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
*
* radixfoundation.org/licenses/LICENSE-v1
*
* The Licensor hereby grants permission for the Canonical version of the Work to be
* published, distributed and used under or by reference to the Licensor’s trademark
* Radix ® and use of any unregistered trade names, logos or get-up.
*
* The Licensor provides the Work (and each Contributor provides its Contributions) on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
*
* Whilst the Work is capable of being deployed, used and adopted (instantiated) to create
* a distributed ledger it is your responsibility to test and validate the code, together
* with all logic and performance of that code under all foreseeable scenarios.
*
* The Licensor does not make or purport to make and hereby excludes liability for all
* and any representation, warranty or undertaking in any form whatsoever, whether express
* or implied, to any entity or person, including any representation, warranty or
* undertaking, as to the functionality security use, value or other characteristics of
* any distributed ledger nor in respect the functioning or value of any tokens which may
* be created stored or transferred using the Work. The Licensor does not warrant that the
* Work or any use of the Work complies with any law or regulation in any territory where
* it may be implemented or used or that it will be appropriate for any specific purpose.
*
* Neither the licensor nor any current or former employees, officers, directors, partners,
* trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor
* shall be liable for any direct or indirect, special, incidental, consequential or other
* losses of any kind, in tort, contract or otherwise (including but not limited to loss
* of revenue, income or profits, or loss of use or data, or loss of reputation, or loss
* of any economic or other opportunity of whatsoever nature or howsoever arising), arising
* out of or in connection with (without limitation of any use, misuse, of any ledger system
* or use made or its functionality or any performance or operation of any code or protocol
* caused by bugs or programming or logic errors or otherwise);
*
* A. any offer, purchase, holding, use, sale, exchange or transmission of any
* cryptographic keys, tokens or assets created, exchanged, stored or arising from any
* interaction with the Work;
*
* B. any failure in a transmission or loss of any token or assets keys or other digital
* artefacts due to errors in transmission;
*
* C. bugs, hacks, logic errors or faults in the Work or any communication;
*
* D. system software or apparatus including but not limited to losses caused by errors
* in holding or transmitting tokens by any third-party;
*
* E. breaches or failure of security including hacker attacks, loss or disclosure of
* password, loss of private key, unauthorised use or misuse of such passwords or keys;
*
* F. any losses including loss of anticipated savings or other benefits resulting from
* use of the Work or any changes to the Work (however implemented).
*
* You are solely responsible for; testing, validating and evaluation of all operation
* logic, functionality, security and appropriateness of using the Work for any commercial
* or non-commercial purpose and for any reproduction or redistribution by You of the
* Work. You assume all risks associated with Your use of the Work and the exercise of
* permissions under this License.
*/

package com.radixdlt.p2p;

import com.radixdlt.lang.Option;
import com.radixdlt.sbor.codec.CodecMap;
import com.radixdlt.sbor.codec.StructCodec;
import java.util.Set;

public record AddressBookEntryDTO(
NodeIdDTO nodeId, Option<Long> bannedUntil, Set<PeerAddressEntryDTO> knownAddresses) {
public static void registerCodec(CodecMap codecMap) {
codecMap.register(
AddressBookEntryDTO.class,
codecs -> StructCodec.fromRecordComponents(AddressBookEntryDTO.class, codecs));
}
}
76 changes: 76 additions & 0 deletions core-rust-bridge/src/main/java/com/radixdlt/p2p/NodeIdDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands).
*
* Licensed under the Radix License, Version 1.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
*
* radixfoundation.org/licenses/LICENSE-v1
*
* The Licensor hereby grants permission for the Canonical version of the Work to be
* published, distributed and used under or by reference to the Licensor’s trademark
* Radix ® and use of any unregistered trade names, logos or get-up.
*
* The Licensor provides the Work (and each Contributor provides its Contributions) on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
* MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
*
* Whilst the Work is capable of being deployed, used and adopted (instantiated) to create
* a distributed ledger it is your responsibility to test and validate the code, together
* with all logic and performance of that code under all foreseeable scenarios.
*
* The Licensor does not make or purport to make and hereby excludes liability for all
* and any representation, warranty or undertaking in any form whatsoever, whether express
* or implied, to any entity or person, including any representation, warranty or
* undertaking, as to the functionality security use, value or other characteristics of
* any distributed ledger nor in respect the functioning or value of any tokens which may
* be created stored or transferred using the Work. The Licensor does not warrant that the
* Work or any use of the Work complies with any law or regulation in any territory where
* it may be implemented or used or that it will be appropriate for any specific purpose.
*
* Neither the licensor nor any current or former employees, officers, directors, partners,
* trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor
* shall be liable for any direct or indirect, special, incidental, consequential or other
* losses of any kind, in tort, contract or otherwise (including but not limited to loss
* of revenue, income or profits, or loss of use or data, or loss of reputation, or loss
* of any economic or other opportunity of whatsoever nature or howsoever arising), arising
* out of or in connection with (without limitation of any use, misuse, of any ledger system
* or use made or its functionality or any performance or operation of any code or protocol
* caused by bugs or programming or logic errors or otherwise);
*
* A. any offer, purchase, holding, use, sale, exchange or transmission of any
* cryptographic keys, tokens or assets created, exchanged, stored or arising from any
* interaction with the Work;
*
* B. any failure in a transmission or loss of any token or assets keys or other digital
* artefacts due to errors in transmission;
*
* C. bugs, hacks, logic errors or faults in the Work or any communication;
*
* D. system software or apparatus including but not limited to losses caused by errors
* in holding or transmitting tokens by any third-party;
*
* E. breaches or failure of security including hacker attacks, loss or disclosure of
* password, loss of private key, unauthorised use or misuse of such passwords or keys;
*
* F. any losses including loss of anticipated savings or other benefits resulting from
* use of the Work or any changes to the Work (however implemented).
*
* You are solely responsible for; testing, validating and evaluation of all operation
* logic, functionality, security and appropriateness of using the Work for any commercial
* or non-commercial purpose and for any reproduction or redistribution by You of the
* Work. You assume all risks associated with Your use of the Work and the exercise of
* permissions under this License.
*/

package com.radixdlt.p2p;

import com.radixdlt.crypto.ECDSASecp256k1PublicKey;
import com.radixdlt.sbor.codec.CodecMap;
import com.radixdlt.sbor.codec.StructCodec;

public record NodeIdDTO(ECDSASecp256k1PublicKey publicKey) {
public static void registerCodec(CodecMap codecMap) {
codecMap.register(
NodeIdDTO.class, codecs -> StructCodec.fromRecordComponents(NodeIdDTO.class, codecs));
}
}
Loading

0 comments on commit d9d5c66

Please sign in to comment.