Skip to content

Commit 1088b02

Browse files
committed
Merge #10195: Switch chainstate db and cache to per-txout model
5898279 scripted-diff: various renames for per-utxo consistency (Pieter Wuille) a5e02bc Increase travis unit test timeout (Pieter Wuille) 73de2c1 Rename CCoinsCacheEntry::coins to coin (Pieter Wuille) 119e552 Merge CCoinsViewCache's GetOutputFor and AccessCoin (Pieter Wuille) 580b023 [MOVEONLY] Move old CCoins class to txdb.cpp (Pieter Wuille) 8b25d2c Upgrade from per-tx database to per-txout (Pieter Wuille) b2af357 Reduce reserved memory space for flushing (Pieter Wuille) 41aa5b7 Pack Coin more tightly (Pieter Wuille) 97072d6 Remove unused CCoins methods (Pieter Wuille) ce23efa Extend coins_tests (Pieter Wuille) 5083079 Switch CCoinsView and chainstate db from per-txid to per-txout (Pieter Wuille) 4ec0d9e Refactor GetUTXOStats in preparation for per-COutPoint iteration (Pieter Wuille) 13870b5 Replace CCoins-based CTxMemPool::pruneSpent with isSpent (Pieter Wuille) 05293f3 Remove ModifyCoins/ModifyNewCoins (Pieter Wuille) 961e483 Switch tests from ModifyCoins to AddCoin/SpendCoin (Pieter Wuille) 8b3868c Switch CScriptCheck to use Coin instead of CCoins (Pieter Wuille) c87b957 Only pass things committed to by tx's witness hash to CScriptCheck (Matt Corallo) f68cdfe Switch from per-tx to per-txout CCoinsViewCache methods in some places (Pieter Wuille) 0003911 Introduce new per-txout CCoinsViewCache functions (Pieter Wuille) bd83111 Optimization: Coin&& to ApplyTxInUndo (Pieter Wuille) cb2c7fd Replace CTxInUndo with Coin (Pieter Wuille) 422634e Introduce Coin, a single unspent output (Pieter Wuille) 7d991b5 Store/allow tx metadata in all undo records (Pieter Wuille) c3aa0c1 Report on-disk size in gettxoutsetinfo (Pieter Wuille) d342424 Remove/ignore tx version in utxo and undo (Pieter Wuille) 7e00322 Add specialization of SipHash for 256 + 32 bit data (Pieter Wuille) e484652 Introduce CHashVerifier to hash read data (Pieter Wuille) f54580e error() in disconnect for disk corruption, not inconsistency (Pieter Wuille) e66dbde Add SizeEstimate to CDBBatch (Pieter Wuille) Tree-SHA512: ce1fb1e40c77d38915cd02189fab7a8b125c7f44d425c85579d872c3bede3a437760997907c99d7b3017ced1c2de54b2ac7223d99d83a6658fe5ef61edef1de3
2 parents 39039b1 + 5898279 commit 1088b02

31 files changed

+1109
-1055
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ script:
6969
- ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false)
7070
- make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false )
7171
- export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib
72-
- if [ "$RUN_TESTS" = "true" ]; then make $MAKEJOBS check VERBOSE=1; fi
72+
- if [ "$RUN_TESTS" = "true" ]; then travis_wait 30 make $MAKEJOBS check VERBOSE=1; fi
7373
- if [ "$TRAVIS_EVENT_TYPE" = "cron" ]; then extended="--extended --exclude pruning"; fi
7474
- if [ "$RUN_TESTS" = "true" ]; then test/functional/test_runner.py --coverage --quiet ${extended}; fi
7575
after_script:

doc/release-notes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ Notable changes
3636
Low-level RPC changes
3737
---------------------
3838

39+
- The new database model no longer stores information about transaction
40+
versions of unspent outputs. This means that:
41+
- The `gettxout` RPC no longer has a `version` field in the response.
42+
- The `gettxoutsetinfo` RPC reports `hash_serialized_2` instead of `hash_serialized`,
43+
which does not commit to the transaction versions of unspent outputs, but does
44+
commit to the height and coinbase information.
45+
- The `getutxos` REST path no longer reports the `txvers` field in JSON format,
46+
and always reports 0 for transaction versions in the binary format
47+
3948
- Error codes have been updated to be more accurate for the following error cases:
4049
- `getblock` now returns RPC_MISC_ERROR if the block can't be found on disk (for
4150
example if the block has been pruned). Previously returned RPC_INTERNAL_ERROR.

src/bench/ccoins_caching.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
3535
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
3636
dummyTransactions[0].vout[1].nValue = 50 * CENT;
3737
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
38-
coinsRet.ModifyCoins(dummyTransactions[0].GetHash())->FromTx(dummyTransactions[0], 0);
38+
AddCoins(coinsRet, dummyTransactions[0], 0);
3939

4040
dummyTransactions[1].vout.resize(2);
4141
dummyTransactions[1].vout[0].nValue = 21 * CENT;
4242
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(key[2].GetPubKey().GetID());
4343
dummyTransactions[1].vout[1].nValue = 22 * CENT;
4444
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(key[3].GetPubKey().GetID());
45-
coinsRet.ModifyCoins(dummyTransactions[1].GetHash())->FromTx(dummyTransactions[1], 0);
45+
AddCoins(coinsRet, dummyTransactions[1], 0);
4646

4747
return dummyTransactions;
4848
}

src/bitcoin-tx.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -556,24 +556,26 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
556556
if (nOut < 0)
557557
throw std::runtime_error("vout must be positive");
558558

559+
COutPoint out(txid, nOut);
559560
std::vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));
560561
CScript scriptPubKey(pkData.begin(), pkData.end());
561562

562563
{
563-
CCoinsModifier coins = view.ModifyCoins(txid);
564-
if (coins->IsAvailable(nOut) && coins->vout[nOut].scriptPubKey != scriptPubKey) {
564+
const Coin& coin = view.AccessCoin(out);
565+
if (!coin.IsSpent() && coin.out.scriptPubKey != scriptPubKey) {
565566
std::string err("Previous output scriptPubKey mismatch:\n");
566-
err = err + ScriptToAsmStr(coins->vout[nOut].scriptPubKey) + "\nvs:\n"+
567+
err = err + ScriptToAsmStr(coin.out.scriptPubKey) + "\nvs:\n"+
567568
ScriptToAsmStr(scriptPubKey);
568569
throw std::runtime_error(err);
569570
}
570-
if ((unsigned int)nOut >= coins->vout.size())
571-
coins->vout.resize(nOut+1);
572-
coins->vout[nOut].scriptPubKey = scriptPubKey;
573-
coins->vout[nOut].nValue = 0;
571+
Coin newcoin;
572+
newcoin.out.scriptPubKey = scriptPubKey;
573+
newcoin.out.nValue = 0;
574574
if (prevOut.exists("amount")) {
575-
coins->vout[nOut].nValue = AmountFromValue(prevOut["amount"]);
575+
newcoin.out.nValue = AmountFromValue(prevOut["amount"]);
576576
}
577+
newcoin.nHeight = 1;
578+
view.AddCoin(out, std::move(newcoin), true);
577579
}
578580

579581
// if redeemScript given and private keys given,
@@ -595,13 +597,13 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
595597
// Sign what we can:
596598
for (unsigned int i = 0; i < mergedTx.vin.size(); i++) {
597599
CTxIn& txin = mergedTx.vin[i];
598-
const CCoins* coins = view.AccessCoins(txin.prevout.hash);
599-
if (!coins || !coins->IsAvailable(txin.prevout.n)) {
600+
const Coin& coin = view.AccessCoin(txin.prevout);
601+
if (coin.IsSpent()) {
600602
fComplete = false;
601603
continue;
602604
}
603-
const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey;
604-
const CAmount& amount = coins->vout[txin.prevout.n].nValue;
605+
const CScript& prevPubKey = coin.out.scriptPubKey;
606+
const CAmount& amount = coin.out.nValue;
605607

606608
SignatureData sigdata;
607609
// Only sign SIGHASH_SINGLE if there's a corresponding output:

0 commit comments

Comments
 (0)