diff --git a/builds/gnu/Makefile.am b/builds/gnu/Makefile.am index 09d1811b..da9fe3c7 100644 --- a/builds/gnu/Makefile.am +++ b/builds/gnu/Makefile.am @@ -57,6 +57,7 @@ src_libbitcoin_node_la_SOURCES = \ ${srcdir}/../../src/estimator.cpp \ ${srcdir}/../../src/full_node.cpp \ ${srcdir}/../../src/settings.cpp \ + ${srcdir}/../../src/validate.cpp \ ${srcdir}/../../src/channels/channel_peer.cpp \ ${srcdir}/../../src/chasers/chaser.cpp \ ${srcdir}/../../src/chasers/chaser_block.cpp \ @@ -114,6 +115,7 @@ include_bitcoin_node_HEADERS = \ ${srcdir}/../../include/bitcoin/node/events.hpp \ ${srcdir}/../../include/bitcoin/node/full_node.hpp \ ${srcdir}/../../include/bitcoin/node/settings.hpp \ + ${srcdir}/../../include/bitcoin/node/validate.hpp \ ${srcdir}/../../include/bitcoin/node/version.hpp include_bitcoin_node_channelsdir = \ diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj index b9353557..c9de9cbf 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj @@ -164,6 +164,7 @@ + @@ -219,6 +220,7 @@ + diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters index d03ee456..ada1ec44 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters @@ -192,6 +192,9 @@ src + + src + @@ -353,6 +356,9 @@ include\bitcoin\node + + include\bitcoin\node + include\bitcoin\node diff --git a/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj index 833b0cbf..b8169764 100644 --- a/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj +++ b/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj @@ -164,6 +164,7 @@ + @@ -219,6 +220,7 @@ + diff --git a/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj.filters index d03ee456..ada1ec44 100644 --- a/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj.filters +++ b/builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj.filters @@ -192,6 +192,9 @@ src + + src + @@ -353,6 +356,9 @@ include\bitcoin\node + + include\bitcoin\node + include\bitcoin\node diff --git a/include/bitcoin/node.hpp b/include/bitcoin/node.hpp index 2befa366..1b8f31b1 100644 --- a/include/bitcoin/node.hpp +++ b/include/bitcoin/node.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/include/bitcoin/node/validate.hpp b/include/bitcoin/node/validate.hpp new file mode 100644 index 00000000..306192ed --- /dev/null +++ b/include/bitcoin/node/validate.hpp @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2011-2026 libbitcoin developers + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef LIBBITCOIN_NODE_VALIDATE_HPP +#define LIBBITCOIN_NODE_VALIDATE_HPP + +#include +#include + +namespace libbitcoin { +namespace node { + +/// Transaction validation against the confirmed chain, for services that +/// accept transactions from clients (there is no tx pool until v5). Shared +/// by the server protocols, which obtain the context of the next block. + +/// Validate tx in the given context, populating its prevout metadata. +/// Includes the block-rule guards, a DoS guard for standalone validation. +BCN_API code validate_transaction(const system::chain::transaction& tx, + const query& query, const system::chain::context& pool) NOEXCEPT; + +} // namespace node +} // namespace libbitcoin + +#endif diff --git a/src/validate.cpp b/src/validate.cpp new file mode 100644 index 00000000..e84ba92e --- /dev/null +++ b/src/validate.cpp @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2011-2026 libbitcoin developers + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#include + +#include + +namespace libbitcoin { +namespace node { + +using namespace system; + +code validate_transaction(const chain::transaction& tx, const query& query, + const chain::context& pool) NOEXCEPT +{ + code ec{}; + + // Ensure tx does not violate tx consensus rules. + if (!ec) ec = tx.check(); + if (!ec) ec = tx.check(pool); + if (!ec) query.populate_with_metadata(tx, true); + if (!ec) ec = tx.accept(pool); + if (!ec) ec = tx.confirm(pool); + if (!ec) ec = tx.connect(pool); + + // Ensure tx does not violate presumed block consensus rules. + // This is a DoS guard when validating a tx outside of a block. + if (!ec) ec = tx.check_guard(); + if (!ec) ec = tx.check_guard(pool); + if (!ec) ec = tx.accept_guard(pool); + return ec; +} + +} // namespace node +} // namespace libbitcoin