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
2 changes: 2 additions & 0 deletions builds/gnu/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 = \
Expand Down
2 changes: 2 additions & 0 deletions builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<ClCompile Include="..\..\..\..\src\sessions\session_manual.cpp" />
<ClCompile Include="..\..\..\..\src\sessions\session_outbound.cpp" />
<ClCompile Include="..\..\..\..\src\settings.cpp" />
<ClCompile Include="..\..\..\..\src\validate.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\builds\msvc\resource.h" />
Expand Down Expand Up @@ -219,6 +220,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_peer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\sessions.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\validate.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\version.hpp" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@
<ClCompile Include="..\..\..\..\src\settings.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\validate.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\builds\msvc\resource.h">
Expand Down Expand Up @@ -353,6 +356,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\validate.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\version.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
Expand Down
2 changes: 2 additions & 0 deletions builds/msvc/vs2026/libbitcoin-node/libbitcoin-node.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<ClCompile Include="..\..\..\..\src\sessions\session_manual.cpp" />
<ClCompile Include="..\..\..\..\src\sessions\session_outbound.cpp" />
<ClCompile Include="..\..\..\..\src\settings.cpp" />
<ClCompile Include="..\..\..\..\src\validate.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\builds\msvc\resource.h" />
Expand Down Expand Up @@ -219,6 +220,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\session_peer.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\sessions\sessions.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\validate.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\node\version.hpp" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@
<ClCompile Include="..\..\..\..\src\settings.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\validate.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\builds\msvc\resource.h">
Expand Down Expand Up @@ -353,6 +356,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\node\settings.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\validate.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\node\version.hpp">
<Filter>include\bitcoin\node</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <bitcoin/node/events.hpp>
#include <bitcoin/node/full_node.hpp>
#include <bitcoin/node/settings.hpp>
#include <bitcoin/node/validate.hpp>
#include <bitcoin/node/version.hpp>
#include <bitcoin/node/channels/channel.hpp>
#include <bitcoin/node/channels/channel_peer.hpp>
Expand Down
40 changes: 40 additions & 0 deletions include/bitcoin/node/validate.hpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef LIBBITCOIN_NODE_VALIDATE_HPP
#define LIBBITCOIN_NODE_VALIDATE_HPP

#include <bitcoin/node/define.hpp>
#include <bitcoin/node/full_node.hpp>

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
50 changes: 50 additions & 0 deletions src/validate.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <bitcoin/node/validate.hpp>

#include <bitcoin/node/define.hpp>

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
Loading