Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 2 additions & 85 deletions contrib/guix/libexec/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,13 @@
export LC_ALL=C
set -e -o pipefail

# Environment variables for determinism
export TAR_OPTIONS="--no-same-owner --owner=0 --group=0 --numeric-owner --mtime='@${SOURCE_DATE_EPOCH}' --sort=name"
export TZ=UTC

# Although Guix _does_ set umask when building its own packages (in our case,
# this is all packages in manifest.scm), it does not set it for `guix
# shell`. It does make sense for at least `guix shell --container`
# to set umask, so if that change gets merged upstream and we bump the
# time-machine to a commit which includes the aforementioned change, we can
# remove this line.
#
# This line should be placed before any commands which creates files.
umask 0022

if [ -n "$V" ]; then
# Print both unexpanded (-v) and expanded (-x) forms of commands as they are
# read from this file.
set -vx
# Set VERBOSE for CMake-based builds
export VERBOSE="$V"
fi

# Check that required environment variables are set
cat << EOF
Required environment variables as seen inside the container:
DIST_ARCHIVE_BASE: ${DIST_ARCHIVE_BASE:?not set}
DISTNAME: ${DISTNAME:?not set}
HOST: ${HOST:?not set}
SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH:?not set}
JOBS: ${JOBS:?not set}
DISTSRC: ${DISTSRC:?not set}
OUTDIR: ${OUTDIR:?not set}
EOF

ACTUAL_OUTDIR="${OUTDIR}"
OUTDIR="${DISTSRC}/output"

#####################
# Environment Setup #
#####################

# The depends folder also serves as a base-prefix for depends packages for
# $HOSTs after successfully building.
BASEPREFIX="${PWD}/depends"

# Given a package name and an output name, return the path of that output in our
# current guix environment
store_path() {
grep --extended-regexp "/[^-]{32}-${1}-[^-]+${2:+-${2}}" "${GUIX_ENVIRONMENT}/manifest" \
| head --lines=1 \
| sed --expression='s|\x29*$||' \
--expression='s|^[[:space:]]*"||' \
--expression='s|"[[:space:]]*$||'
}

# shellcheck source=setup.sh
source "$(dirname "${BASH_SOURCE[0]}")/setup.sh"

# Set environment variables to point the NATIVE toolchain to the right
# includes/libs
NATIVE_GCC="$(store_path gcc-toolchain)"

unset LIBRARY_PATH
unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset OBJCPLUS_INCLUDE_PATH

# Set native toolchain
build_CC="${NATIVE_GCC}/bin/gcc -isystem ${NATIVE_GCC}/include"
build_CXX="${NATIVE_GCC}/bin/g++ -isystem ${NATIVE_GCC}/include/c++ -isystem ${NATIVE_GCC}/include"
Expand Down Expand Up @@ -134,15 +74,6 @@ for p in "${PATHS[@]}"; do
fi
done

# Disable Guix ld auto-rpath behavior
export GUIX_LD_WRAPPER_DISABLE_RPATH=yes

# Make /usr/bin if it doesn't exist
[ -e /usr/bin ] || mkdir -p /usr/bin

# Symlink env to a conventional path
[ -e /usr/bin/env ] || ln -s --no-dereference "$(command -v env)" /usr/bin/env

# Determine the correct value for -Wl,--dynamic-linker for the current $HOST
case "$HOST" in
*linux*)
Expand Down Expand Up @@ -186,20 +117,6 @@ case "$HOST" in
;;
esac

###########################
# Source Tarball Building #
###########################

GIT_ARCHIVE="${DIST_ARCHIVE_BASE}/${DISTNAME}.tar.gz"

# Create the source tarball if not already there
if [ ! -e "$GIT_ARCHIVE" ]; then
mkdir -p "$(dirname "$GIT_ARCHIVE")"
git archive --prefix="${DISTNAME}/" --output="$GIT_ARCHIVE" HEAD
fi

mkdir -p "$OUTDIR"

###########################
# Binary Tarball Building #
###########################
Expand Down
91 changes: 91 additions & 0 deletions contrib/guix/libexec/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env bash
# Copyright (c) The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or https://opensource.org/license/mit.
export LC_ALL=C
set -e -o pipefail

# Environment variables for determinism
export TAR_OPTIONS="--no-same-owner --owner=0 --group=0 --numeric-owner --mtime='@${SOURCE_DATE_EPOCH}' --sort=name"
export TZ=UTC

# Although Guix _does_ set umask when building its own packages (in our case,
# this is all packages in manifest.scm), it does not set it for `guix
# shell`. It does make sense for at least `guix shell --container`
# to set umask, so if that change gets merged upstream and we bump the
# time-machine to a commit which includes the aforementioned change, we can
# remove this line.
#
# This line should be placed before any commands which creates files.
umask 0022

if [ -n "$V" ]; then
# Print both unexpanded (-v) and expanded (-x) forms of commands as they are
# read from this file.
set -vx
# Set VERBOSE for CMake-based builds
export VERBOSE="$V"
fi

# Check that required environment variables are set
cat << EOF
Required environment variables as seen inside the container:
DIST_ARCHIVE_BASE: ${DIST_ARCHIVE_BASE:?not set}
DISTNAME: ${DISTNAME:?not set}
HOST: ${HOST:?not set}
SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH:?not set}
JOBS: ${JOBS:?not set}
DISTSRC: ${DISTSRC:?not set}
OUTDIR: ${OUTDIR:?not set}
EOF

export ACTUAL_OUTDIR="${OUTDIR}"
export OUTDIR="${DISTSRC}/output"

#####################
# Environment Setup #
#####################

# The depends folder also serves as a base-prefix for depends packages for
# $HOSTs after successfully building.
export BASEPREFIX="${PWD}/depends"

# Given a package name and an output name, return the path of that output in our
# current guix environment
store_path() {
grep --extended-regexp "/[^-]{32}-${1}-[^-]+${2:+-${2}}" "${GUIX_ENVIRONMENT}/manifest" \
| head --lines=1 \
| sed --expression='s|\x29*$||' \
--expression='s|^[[:space:]]*"||' \
--expression='s|"[[:space:]]*$||'
}

# Disable Guix ld auto-rpath behavior
export GUIX_LD_WRAPPER_DISABLE_RPATH=yes

# Make /usr/bin if it doesn't exist
[ -e /usr/bin ] || mkdir -p /usr/bin

# Symlink env to a conventional path
[ -e /usr/bin/env ] || ln -s --no-dereference "$(command -v env)" /usr/bin/env

###########################
# Source Tarball Building #
###########################

GIT_ARCHIVE="${DIST_ARCHIVE_BASE}/${DISTNAME}.tar.gz"

# Create the source tarball if not already there
if [ ! -e "$GIT_ARCHIVE" ]; then
mkdir -p "$(dirname "$GIT_ARCHIVE")"
git archive --prefix="${DISTNAME}/" --output="$GIT_ARCHIVE" HEAD
fi

mkdir -p "$OUTDIR"

unset LIBRARY_PATH
unset CPATH
unset C_INCLUDE_PATH
unset CPLUS_INCLUDE_PATH
unset OBJC_INCLUDE_PATH
unset OBJCPLUS_INCLUDE_PATH
4 changes: 3 additions & 1 deletion src/bench/index_blockfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <span.h>
#include <sync.h>
#include <test/util/setup_common.h>
#include <test/util/time.h>
#include <uint256.h>
#include <util/strencodings.h>
#include <util/time.h>
Expand All @@ -37,9 +38,10 @@ static void BlockFilterIndexSync(benchmark::Bench& bench)
CPubKey pubkey{"02ed26169896db86ced4cbb7b3ecef9859b5952825adbeab998fb5b307e54949c9"_hex_u8};
CScript script = GetScriptForDestination(WitnessV0KeyHash(pubkey));
std::vector<CMutableTransaction> noTxns;
FakeNodeClock clock{};
for (int i = 0; i < CHAIN_SIZE - 100; i++) {
test_setup->CreateAndProcessBlock(noTxns, script);
SetMockTime(GetTime() + 1);
clock += 1s;
}
assert(WITH_LOCK(::cs_main, return test_setup->m_node.chainman->ActiveHeight() == CHAIN_SIZE));

Expand Down
2 changes: 1 addition & 1 deletion src/bench/util_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void BenchTimeDeprecated(benchmark::Bench& bench)

static void BenchTimeMock(benchmark::Bench& bench)
{
NodeClockContext clock_ctx{111s};
FakeNodeClock clock{111s};
bench.run([&] {
(void)GetTime<std::chrono::seconds>();
});
Expand Down
2 changes: 1 addition & 1 deletion src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b

// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
// The reason is 'generatetoaddress', which creates a chain with deterministic timestamps in the past.
NodeClockContext clock_ctx{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
{
LOCK(wallet.cs_wallet);
Expand Down
4 changes: 2 additions & 2 deletions src/bench/wallet_create_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();

// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
NodeClockContext clock_ctx{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
{
LOCK(wallet.cs_wallet);
Expand Down Expand Up @@ -173,7 +173,7 @@ static void AvailableCoins(benchmark::Bench& bench, const std::vector<OutputType
{
const auto test_setup = MakeNoLogFileContext<const TestingSetup>();
// Set clock to genesis block, so the descriptors/keys creation time don't interfere with the blocks scanning process.
NodeClockContext clock_ctx{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
FakeNodeClock clock{test_setup->m_node.chainman->GetParams().GenesisBlock().Time()};
CWallet wallet{test_setup->m_node.chain.get(), "", CreateMockableWalletDatabase()};
{
LOCK(wallet.cs_wallet);
Expand Down
3 changes: 2 additions & 1 deletion src/bench/wallet_encrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <random.h>
#include <support/allocators/secure.h>
#include <test/util/setup_common.h>
#include <test/util/time.h>
#include <util/time.h>
#include <wallet/context.h>
#include <wallet/test/util.h>
Expand Down Expand Up @@ -44,7 +45,7 @@ static void WalletEncrypt(benchmark::Bench& bench, unsigned int key_count)

// Setting a mock time is necessary to force default derive iteration count during
// wallet encryption.
SetMockTime(1);
FakeNodeClock clock{1s};

std::unique_ptr<WalletDatabase> database;
std::shared_ptr<CWallet> wallet;
Expand Down
11 changes: 5 additions & 6 deletions src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ BOOST_AUTO_TEST_CASE(addrman_simple)

BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures)
{
auto now = Now<NodeSeconds>();
SetMockTime(now - (ADDRMAN_MIN_FAIL + 24h));
FakeNodeClock clock{};

auto addrman{std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node))};

Expand All @@ -109,7 +108,7 @@ BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures)
BOOST_CHECK(addrman->Add({addr}, source));
BOOST_CHECK(addrman->Good(addr));

SetMockTime(now);
clock += ADDRMAN_MIN_FAIL + 24h;

CAddress addr_helper{CAddress(ResolveService("251.252.2.3", 8333), NODE_NONE)};
addr_helper.nTime = Now<NodeSeconds>();
Expand All @@ -132,7 +131,7 @@ BOOST_AUTO_TEST_CASE(addrman_terrible_many_failures)

BOOST_AUTO_TEST_CASE(addrman_penalty_self_announcement)
{
SetMockTime(Now<NodeSeconds>());
FakeNodeClock clock{};
auto addrman = std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node));

const auto base_time{Now<NodeSeconds>() - 10000s};
Expand Down Expand Up @@ -1031,8 +1030,8 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
BOOST_CHECK_EQUAL(addrman->SelectTriedCollision().first.ToStringAddrPort(), "250.1.1.36:0");

// Eviction is also successful if too much time has passed since last try
NodeClockContext clock_ctx{};
clock_ctx += 4h;
FakeNodeClock clock{};
clock += 4h;
addrman->ResolveCollisions();
BOOST_CHECK(addrman->SelectTriedCollision().first.ToStringAddrPort() == "[::]:0");
//Now 19 is in tried again, and 36 back to new
Expand Down
2 changes: 1 addition & 1 deletion src/test/banman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ BOOST_FIXTURE_TEST_SUITE(banman_tests, BasicTestingSetup)

BOOST_AUTO_TEST_CASE(file)
{
NodeClockContext clock_ctx{777s};
FakeNodeClock clock{777s};
const fs::path banlist_path{m_args.GetDataDirBase() / "banlist_test"};
{
const std::string entries_write{
Expand Down
9 changes: 5 additions & 4 deletions src/test/chainstate_write_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ BOOST_FIXTURE_TEST_CASE(chainstate_write_interval, TestingSetup)
m_node.validation_signals->RegisterSharedValidationInterface(sub);
auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()};
BlockValidationState state_dummy{};
NodeClockContext clock_ctx{};
FakeNodeClock clock{};

// The first periodic flush sets m_next_write and does not flush
chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
m_node.validation_signals->SyncWithValidationInterfaceQueue();
BOOST_CHECK(!sub->m_did_flush);

// The periodic flush interval is between 50 and 70 minutes (inclusive)
clock_ctx += DATABASE_WRITE_INTERVAL_MIN - 1min;
clock += DATABASE_WRITE_INTERVAL_MIN - 1min;
chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
m_node.validation_signals->SyncWithValidationInterfaceQueue();
BOOST_CHECK(!sub->m_did_flush);

clock_ctx += DATABASE_WRITE_INTERVAL_MAX;
clock += DATABASE_WRITE_INTERVAL_MAX;
chainstate.FlushStateToDisk(state_dummy, FlushStateMode::PERIODIC);
m_node.validation_signals->SyncWithValidationInterfaceQueue();
BOOST_CHECK(sub->m_did_flush);
Expand All @@ -70,6 +70,7 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup)

auto& chainstate{Assert(m_node.chainman)->ActiveChainstate()};
BlockValidationState state_dummy{};
FakeNodeClock clock{};

// Pop two blocks from the tip
const CBlockIndex* tip{chainstate.m_chain.Tip()};
Expand All @@ -88,7 +89,7 @@ BOOST_FIXTURE_TEST_CASE(write_during_multiblock_activation, TestChain100Setup)
m_node.validation_signals->SyncWithValidationInterfaceQueue();
// The periodic flush interval is between 50 and 70 minutes (inclusive)
// The next call to a PERIODIC write will flush
SetMockTime(GetMockTime() + DATABASE_WRITE_INTERVAL_MAX);
clock += DATABASE_WRITE_INTERVAL_MAX;

const auto sub{std::make_shared<TestSubscriber>()};
m_node.validation_signals->RegisterSharedValidationInterface(sub);
Expand Down
Loading
Loading