Skip to content

Commit 6a135fb

Browse files
committed
Merge #15638: Move-only: Pull wallet code out of libbitcoin_server
4d074e8 [build] Move AnalyzePSBT from psbt.cpp to node/psbt.cpp (Russell Yanofsky) fd509bd [docs] Document src subdirectories and different libraries (John Newbery) 9eaeb7f [build] Move wallet load functions to wallet/load unit (John Newbery) 91a25d1 [build] Add several util units (John Newbery) 9951786 [build] Move several units into common libraries (John Newbery) 0509465 [build] Move rpc rawtransaction util functions to rpc/rawtransaction_util.cpp (John Newbery) 1acc61f [build] Move rpc utility methods to rpc/util (John Newbery) 4a75c9d [build] Move policy settings to new src/policy/settings unit (John Newbery) fdf8888 [build] Move CheckTransaction from lib_server to lib_consensus (John Newbery) Pull request description: This is a move-only commit. No code is changing and the moves can be easily verified with: ```sh git log -p -n1 --color-moved=dimmed_zebra ``` This commit moves functions and variables that wallet code depends on out of libbitcoin_server.a, so the bitcoin-wallet tool can be built without libbitcoin_server.a in #15639, and attempting to access server state from wallet code will result in link errors instead of silently broken code. List of moves: - `CheckTransaction` moves from `consensus/tx_verify.cpp` to `consensus/tx_check.cpp` - `urlDecode` moves from `httpserver.cpp` to `util/url.cpp` - `TransactionErrorString` moves from `node/transaction.cpp` to `util/error.cpp` - `StringForFeeReason` and `FeeModeFromString` move from `policy/fees.cpp` to `util/fees.cpp` - `incrementalRelayFee` `dustRelayFee` and `nBytesPerSigOp` move from `policy/policy.cpp` to `policy/settings.cpp` - `SignalsOptInRBF` moves from `policy/rbf.cpp` to `util/rbf.cpp` - `fIsBareMultisigStd` moves from `validation.cpp` to `policy/settings.cpp` - `ConstructTransaction` `TxInErrorToJSON` and `SignTransaction` move from `rpc/rawtransaction.cpp` to `rpc/rawtransaction_util.cpp` - `RPCTypeCheck` `RPCTypeCheckArgument` `RPCTypeCheckObj` `AmountFromValue` `ParseHashV``ParseHashO` `ParseHexV` `ParseHexO` `HelpExampleCli` and `HelpExampleRpc` move from `rpc/server.cpp` to `rpc/util.cpp` - `AmountHighWarn` and `AmountErrMsg` move from `ui_interface.cpp` to `util/error.cpp` - `FormatStateMessage` and `strMessageMagic` move from `validation.cpp` to `util/validation.cpp` - `VerifyWallets` `LoadWallets` `StartWallets` `FlushWallets` `StopWallets` and `UnloadWallets` move from `wallet/init.cpp` to `wallet/node.cpp` ACKs for commit 4d074e: jnewbery: utACK 4d074e8 (checked by doing the rebase myself and verifying no difference between my branch and 4d074e8) Tree-SHA512: 5e1604a9fb06475f2b96da0de0baa8330f4dda834dc20a0183ef11e1e4c27631d1d1bbb9abf0054efc03d56945fdf9920f63366b6a4f200f665b742a479ff75c
2 parents e3a0688 + 4d074e8 commit 6a135fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1228
-923
lines changed

build_msvc/libbitcoin_server/libbitcoin_server.vcxproj.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@
151151
</ItemDefinitionGroup>
152152
<ItemGroup>
153153
@SOURCE_FILES@
154+
<ClCompile Include="..\..\src\wallet\init.cpp">
155+
<ObjectFileName>$(IntDir)wallet_init.obj</ObjectFileName>
156+
</ClCompile>
154157
</ItemGroup>
155158
<ItemGroup>
156159
<None Include="packages.config" />

build_msvc/libbitcoinconsensus/libbitcoinconsensus.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<ItemGroup>
2323
<ClCompile Include="..\..\src\arith_uint256.cpp" />
2424
<ClCompile Include="..\..\src\consensus\merkle.cpp" />
25+
<ClCompile Include="..\..\src\consensus\tx_check.cpp" />
2526
<ClCompile Include="..\..\src\crypto\aes.cpp" />
2627
<ClCompile Include="..\..\src\crypto\chacha20.cpp" />
2728
<ClCompile Include="..\..\src\crypto\hmac_sha256.cpp" />

src/Makefile.am

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ BITCOIN_CORE_H = \
124124
compat/sanity.h \
125125
compressor.h \
126126
consensus/consensus.h \
127+
consensus/tx_check.h \
127128
consensus/tx_verify.h \
128129
core_io.h \
129130
core_memusage.h \
@@ -155,6 +156,7 @@ BITCOIN_CORE_H = \
155156
netbase.h \
156157
netmessagemaker.h \
157158
node/coin.h \
159+
node/psbt.h \
158160
node/transaction.h \
159161
noui.h \
160162
optional.h \
@@ -163,6 +165,7 @@ BITCOIN_CORE_H = \
163165
policy/fees.h \
164166
policy/policy.h \
165167
policy/rbf.h \
168+
policy/settings.h \
166169
pow.h \
167170
protocol.h \
168171
psbt.h \
@@ -174,7 +177,7 @@ BITCOIN_CORE_H = \
174177
rpc/mining.h \
175178
rpc/protocol.h \
176179
rpc/server.h \
177-
rpc/rawtransaction.h \
180+
rpc/rawtransaction_util.h \
178181
rpc/register.h \
179182
rpc/util.h \
180183
scheduler.h \
@@ -201,10 +204,15 @@ BITCOIN_CORE_H = \
201204
undo.h \
202205
util/bip32.h \
203206
util/bytevectorhash.h \
207+
util/error.h \
208+
util/fees.h \
204209
util/system.h \
205210
util/memory.h \
206211
util/moneystr.h \
212+
util/rbf.h \
207213
util/time.h \
214+
util/url.h \
215+
util/validation.h \
208216
validation.h \
209217
validationinterface.h \
210218
versionbits.h \
@@ -215,6 +223,7 @@ BITCOIN_CORE_H = \
215223
wallet/db.h \
216224
wallet/feebumper.h \
217225
wallet/fees.h \
226+
wallet/load.h \
218227
wallet/psbtwallet.h \
219228
wallet/rpcwallet.h \
220229
wallet/wallet.h \
@@ -237,13 +246,15 @@ obj/build.h: FORCE
237246
libbitcoin_util_a-clientversion.$(OBJEXT): obj/build.h
238247

239248
# server: shared between bitcoind and bitcoin-qt
249+
# Contains code accessing mempool and chain state that is meant to be separated
250+
# from wallet and gui code (see node/README.md). Shared code should go in
251+
# libbitcoin_common or libbitcoin_util libraries, instead.
240252
libbitcoin_server_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
241253
libbitcoin_server_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
242254
libbitcoin_server_a_SOURCES = \
243255
addrdb.cpp \
244256
addrman.cpp \
245257
banman.cpp \
246-
bloom.cpp \
247258
blockencodings.cpp \
248259
blockfilter.cpp \
249260
chain.cpp \
@@ -255,21 +266,19 @@ libbitcoin_server_a_SOURCES = \
255266
index/base.cpp \
256267
index/txindex.cpp \
257268
interfaces/chain.cpp \
258-
interfaces/handler.cpp \
259269
interfaces/node.cpp \
260270
init.cpp \
261271
dbwrapper.cpp \
262-
merkleblock.cpp \
263272
miner.cpp \
264273
net.cpp \
265274
net_processing.cpp \
266275
node/coin.cpp \
276+
node/psbt.cpp \
267277
node/transaction.cpp \
268278
noui.cpp \
269-
outputtype.cpp \
270279
policy/fees.cpp \
271-
policy/policy.cpp \
272280
policy/rbf.cpp \
281+
policy/settings.cpp \
273282
pow.cpp \
274283
rest.cpp \
275284
rpc/blockchain.cpp \
@@ -278,7 +287,6 @@ libbitcoin_server_a_SOURCES = \
278287
rpc/net.cpp \
279288
rpc/rawtransaction.cpp \
280289
rpc/server.cpp \
281-
rpc/util.cpp \
282290
script/sigcache.cpp \
283291
shutdown.cpp \
284292
timedata.cpp \
@@ -291,6 +299,9 @@ libbitcoin_server_a_SOURCES = \
291299
versionbits.cpp \
292300
$(BITCOIN_CORE_H)
293301

302+
if ENABLE_WALLET
303+
libbitcoin_server_a_SOURCES += wallet/init.cpp
304+
endif
294305
if !ENABLE_WALLET
295306
libbitcoin_server_a_SOURCES += dummywallet.cpp
296307
endif
@@ -317,7 +328,7 @@ libbitcoin_wallet_a_SOURCES = \
317328
wallet/db.cpp \
318329
wallet/feebumper.cpp \
319330
wallet/fees.cpp \
320-
wallet/init.cpp \
331+
wallet/load.cpp \
321332
wallet/psbtwallet.cpp \
322333
wallet/rpcdump.cpp \
323334
wallet/rpcwallet.cpp \
@@ -391,6 +402,7 @@ libbitcoin_consensus_a_SOURCES = \
391402
consensus/merkle.cpp \
392403
consensus/merkle.h \
393404
consensus/params.h \
405+
consensus/tx_check.cpp \
394406
consensus/validation.h \
395407
hash.cpp \
396408
hash.h \
@@ -423,6 +435,7 @@ libbitcoin_common_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
423435
libbitcoin_common_a_SOURCES = \
424436
base58.cpp \
425437
bech32.cpp \
438+
bloom.cpp \
426439
chainparams.cpp \
427440
coins.cpp \
428441
compressor.cpp \
@@ -431,11 +444,16 @@ libbitcoin_common_a_SOURCES = \
431444
key.cpp \
432445
key_io.cpp \
433446
keystore.cpp \
447+
merkleblock.cpp \
434448
netaddress.cpp \
435449
netbase.cpp \
450+
outputtype.cpp \
436451
policy/feerate.cpp \
452+
policy/policy.cpp \
437453
protocol.cpp \
438454
psbt.cpp \
455+
rpc/rawtransaction_util.cpp \
456+
rpc/util.cpp \
439457
scheduler.cpp \
440458
script/descriptor.cpp \
441459
script/ismine.cpp \
@@ -458,6 +476,7 @@ libbitcoin_util_a_SOURCES = \
458476
compat/glibcxx_sanity.cpp \
459477
compat/strnlen.cpp \
460478
fs.cpp \
479+
interfaces/handler.cpp \
461480
logging.cpp \
462481
random.cpp \
463482
rpc/protocol.cpp \
@@ -466,10 +485,15 @@ libbitcoin_util_a_SOURCES = \
466485
threadinterrupt.cpp \
467486
util/bip32.cpp \
468487
util/bytevectorhash.cpp \
488+
util/error.cpp \
489+
util/fees.cpp \
469490
util/system.cpp \
470491
util/moneystr.cpp \
492+
util/rbf.cpp \
471493
util/strencodings.cpp \
472494
util/time.cpp \
495+
util/url.cpp \
496+
util/validation.cpp \
473497
$(BITCOIN_CORE_H)
474498

475499
if GLIBC_BACK_COMPAT

src/bitcoin-tx.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <script/script.h>
1919
#include <script/sign.h>
2020
#include <univalue.h>
21+
#include <util/rbf.h>
2122
#include <util/system.h>
2223
#include <util/moneystr.h>
2324
#include <util/strencodings.h>

src/consensus/tx_check.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright (c) 2017-2018 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <consensus/tx_check.h>
6+
7+
#include <primitives/transaction.h>
8+
#include <consensus/validation.h>
9+
10+
bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs)
11+
{
12+
// Basic checks that don't depend on any context
13+
if (tx.vin.empty())
14+
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty");
15+
if (tx.vout.empty())
16+
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty");
17+
// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
18+
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
19+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");
20+
21+
// Check for negative or overflow output values
22+
CAmount nValueOut = 0;
23+
for (const auto& txout : tx.vout)
24+
{
25+
if (txout.nValue < 0)
26+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-negative");
27+
if (txout.nValue > MAX_MONEY)
28+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-toolarge");
29+
nValueOut += txout.nValue;
30+
if (!MoneyRange(nValueOut))
31+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
32+
}
33+
34+
// Check for duplicate inputs - note that this check is slow so we skip it in CheckBlock
35+
if (fCheckDuplicateInputs) {
36+
std::set<COutPoint> vInOutPoints;
37+
for (const auto& txin : tx.vin)
38+
{
39+
if (!vInOutPoints.insert(txin.prevout).second)
40+
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate");
41+
}
42+
}
43+
44+
if (tx.IsCoinBase())
45+
{
46+
if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
47+
return state.DoS(100, false, REJECT_INVALID, "bad-cb-length");
48+
}
49+
else
50+
{
51+
for (const auto& txin : tx.vin)
52+
if (txin.prevout.IsNull())
53+
return state.DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null");
54+
}
55+
56+
return true;
57+
}

src/consensus/tx_check.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2017-2018 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_CONSENSUS_TX_CHECK_H
6+
#define BITCOIN_CONSENSUS_TX_CHECK_H
7+
8+
/**
9+
* Context-independent transaction checking code that can be called outside the
10+
* bitcoin server and doesn't depend on chain or mempool state. Transaction
11+
* verification code that does call server functions or depend on server state
12+
* belongs in tx_verify.h/cpp instead.
13+
*/
14+
15+
class CTransaction;
16+
class CValidationState;
17+
18+
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true);
19+
20+
#endif // BITCOIN_CONSENSUS_TX_CHECK_H

src/consensus/tx_verify.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -156,55 +156,6 @@ int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& i
156156
return nSigOps;
157157
}
158158

159-
bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs)
160-
{
161-
// Basic checks that don't depend on any context
162-
if (tx.vin.empty())
163-
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty");
164-
if (tx.vout.empty())
165-
return state.DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty");
166-
// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
167-
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
168-
return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");
169-
170-
// Check for negative or overflow output values
171-
CAmount nValueOut = 0;
172-
for (const auto& txout : tx.vout)
173-
{
174-
if (txout.nValue < 0)
175-
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-negative");
176-
if (txout.nValue > MAX_MONEY)
177-
return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-toolarge");
178-
nValueOut += txout.nValue;
179-
if (!MoneyRange(nValueOut))
180-
return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
181-
}
182-
183-
// Check for duplicate inputs - note that this check is slow so we skip it in CheckBlock
184-
if (fCheckDuplicateInputs) {
185-
std::set<COutPoint> vInOutPoints;
186-
for (const auto& txin : tx.vin)
187-
{
188-
if (!vInOutPoints.insert(txin.prevout).second)
189-
return state.DoS(100, false, REJECT_INVALID, "bad-txns-inputs-duplicate");
190-
}
191-
}
192-
193-
if (tx.IsCoinBase())
194-
{
195-
if (tx.vin[0].scriptSig.size() < 2 || tx.vin[0].scriptSig.size() > 100)
196-
return state.DoS(100, false, REJECT_INVALID, "bad-cb-length");
197-
}
198-
else
199-
{
200-
for (const auto& txin : tx.vin)
201-
if (txin.prevout.IsNull())
202-
return state.DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null");
203-
}
204-
205-
return true;
206-
}
207-
208159
bool Consensus::CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight, CAmount& txfee)
209160
{
210161
// are the actual inputs available?

src/consensus/tx_verify.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class CValidationState;
1717

1818
/** Transaction validation functions */
1919

20-
/** Context-independent validity checks */
21-
bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true);
22-
2320
namespace Consensus {
2421
/**
2522
* Check whether all inputs of this transaction are valid (no double spends and amounts)

src/httpserver.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,3 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
655655
pathHandlers.erase(i);
656656
}
657657
}
658-
659-
std::string urlDecode(const std::string &urlEncoded) {
660-
std::string res;
661-
if (!urlEncoded.empty()) {
662-
char *decoded = evhttp_uridecode(urlEncoded.c_str(), false, nullptr);
663-
if (decoded) {
664-
res = std::string(decoded);
665-
free(decoded);
666-
}
667-
}
668-
return res;
669-
}

src/httpserver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,4 @@ class HTTPEvent
148148
struct event* ev;
149149
};
150150

151-
std::string urlDecode(const std::string &urlEncoded);
152-
153151
#endif // BITCOIN_HTTPSERVER_H

0 commit comments

Comments
 (0)