Skip to content
Open
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
16 changes: 8 additions & 8 deletions cln-rpc/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,13 @@ macro_rules! amount {
self.$field
}

fn checked_add(self, rhs: Self) -> Option<Self> {
/// Adds two amounts, returning `None` if the result overflows.
pub fn checked_add(self, rhs: Self) -> Option<Self> {
self.$field.checked_add(rhs.$field).map($name::$from_fn)
}

fn checked_sub(self, rhs: Self) -> Option<Self> {
/// Subtracts two amounts, returning `None` if the result underflows.
pub fn checked_sub(self, rhs: Self) -> Option<Self> {
self.$field.checked_sub(rhs.$field).map($name::$from_fn)
}
}
Expand All @@ -202,19 +204,17 @@ macro_rules! amount {
type Output = Self;

fn add(self, rhs: Self) -> Self {
Self {
$field: self.$field + rhs.$field,
}
self.checked_add(rhs)
.expect("attempt to add with overflow")
}
}

impl std::ops::Sub for $name {
type Output = Self;

fn sub(self, rhs: Self) -> Self::Output {
Self {
$field: self.$field - rhs.$field,
}
self.checked_sub(rhs)
.expect("attempt to subtract with overflow")
}
}

Expand Down
12 changes: 12 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ default_python()
echo "$p"
return
fi
# uv may be unavailable or unable to reach the network
# (offline/sandboxed builds); fall back to the interpreter itself.
if $p --version 2>&1 | grep -q "Python 3."; then
echo "$p"
return
fi
fi
done
}
Expand Down Expand Up @@ -345,6 +351,12 @@ done
# Now fill in any unset vars.
set_defaults

if [ -z "$PYTHON" ]; then
echo "configure: no Python 3 interpreter found." >&2
echo "Install python3, or set it explicitly: ./configure PYTHON=/path/to/python3" >&2
exit 1
fi

if [ "$ASAN" = "1" ]; then
if [ "$VALGRIND" = "1" ]; then
echo "Address sanitizer (ASAN) and valgrind cannot be enabled at the same time"
Expand Down
20 changes: 14 additions & 6 deletions nix/pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ let
p.grpcio-tools
p.mako
]);
# lowdown uses sandbox_init(3) on Darwin, which fails when invoked from
# within Nix's existing build sandbox. Disable the redundant inner sandbox
# for this build-only lowdown dependency.
lowdownForBuild =
if stdenv.isDarwin then
lowdown.overrideAttrs (old: {
postPatch = (old.postPatch or "") + ''
substituteInPlace main.c \
--replace-fail '#elif HAVE_SANDBOX_INIT' '#elif 0 /* Already sandboxed by Nix. */'
'';
})
else
lowdown;
in
stdenv.mkDerivation {
name = "cln";
Expand All @@ -33,7 +46,7 @@ stdenv.mkDerivation {
gettext
gitMinimal
libtool
lowdown
lowdownForBuild
pkgconf
py3
unzip
Expand Down Expand Up @@ -77,11 +90,6 @@ stdenv.mkDerivation {

configureFlags = [ "--disable-valgrind" ];

# ./configure detects Python via `uv` (configure:default_python), which is not
# part of this derivation. Point it at the python3 we already provide so the
# codegen steps that call $(PYTHON) (e.g. devtools/blockreplace.py) work.
preConfigure = "export PYTHON=python3";

enableParallelBuilding = true;

# workaround for build issue, happens only x86_64-darwin, not aarch64-darwin
Expand Down
Loading