Skip to content

Commit 8b22af3

Browse files
committed
Replace bytes_serialized with bogosize
1 parent 7cc2c67 commit 8b22af3

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

doc/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ Low-level RPC changes
4242
- The `gettxoutsetinfo` RPC reports `hash_serialized_2` instead of `hash_serialized`,
4343
which does not commit to the transaction versions of unspent outputs, but does
4444
commit to the height and coinbase information.
45+
- The `gettxoutsetinfo` response now contains `disk_size` and `bogosize` instead of
46+
`bytes_serialized`. The first is a more accurate estimate of actual disk usage, but
47+
is not deterministic. The second is unrelated to disk usage, but is a
48+
database-independent metric of UTXO set size: it counts every UTXO entry as 50 + the
49+
length of its scriptPubKey.
4550
- The `getutxos` REST path no longer reports the `txvers` field in JSON format,
4651
and always reports 0 for transaction versions in the binary format
4752

53+
4854
- Error codes have been updated to be more accurate for the following error cases:
4955
- `getblock` now returns RPC_MISC_ERROR if the block can't be found on disk (for
5056
example if the block has been pruned). Previously returned RPC_INTERNAL_ERROR.

src/rpc/blockchain.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,12 @@ struct CCoinsStats
781781
uint256 hashBlock;
782782
uint64_t nTransactions;
783783
uint64_t nTransactionOutputs;
784+
uint64_t nBogoSize;
784785
uint256 hashSerialized;
785786
uint64_t nDiskSize;
786787
CAmount nTotalAmount;
787788

788-
CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nTotalAmount(0) {}
789+
CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nBogoSize(0), nDiskSize(0), nTotalAmount(0) {}
789790
};
790791

791792
static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
@@ -800,6 +801,8 @@ static void ApplyStats(CCoinsStats &stats, CHashWriter& ss, const uint256& hash,
800801
ss << VARINT(output.second.out.nValue);
801802
stats.nTransactionOutputs++;
802803
stats.nTotalAmount += output.second.out.nValue;
804+
stats.nBogoSize += 32 /* txid */ + 4 /* vout index */ + 4 /* height + coinbase */ + 8 /* amount */ +
805+
2 /* scriptPubKey len */ + output.second.out.scriptPubKey.size() /* scriptPubKey */;
803806
}
804807
ss << VARINT(0);
805808
}
@@ -904,7 +907,8 @@ UniValue gettxoutsetinfo(const JSONRPCRequest& request)
904907
" \"bestblock\": \"hex\", (string) the best block hash hex\n"
905908
" \"transactions\": n, (numeric) The number of transactions\n"
906909
" \"txouts\": n, (numeric) The number of output transactions\n"
907-
" \"hash_serialized\": \"hash\", (string) The serialized hash\n"
910+
" \"bogosize\": n, (numeric) A meaningless metric for UTXO set size\n"
911+
" \"hash_serialized_2\": \"hash\", (string) The serialized hash\n"
908912
" \"disk_size\": n, (numeric) The estimated size of the chainstate on disk\n"
909913
" \"total_amount\": x.xxx (numeric) The total amount\n"
910914
"}\n"
@@ -922,6 +926,7 @@ UniValue gettxoutsetinfo(const JSONRPCRequest& request)
922926
ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
923927
ret.push_back(Pair("transactions", (int64_t)stats.nTransactions));
924928
ret.push_back(Pair("txouts", (int64_t)stats.nTransactionOutputs));
929+
ret.push_back(Pair("bogosize", (int64_t)stats.nBogoSize));
925930
ret.push_back(Pair("hash_serialized_2", stats.hashSerialized.GetHex()));
926931
ret.push_back(Pair("disk_size", stats.nDiskSize));
927932
ret.push_back(Pair("total_amount", ValueFromAmount(stats.nTotalAmount)));

test/functional/blockchain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def _test_gettxoutsetinfo(self):
4949
assert_equal(res['transactions'], 200)
5050
assert_equal(res['height'], 200)
5151
assert_equal(res['txouts'], 200)
52+
assert_equal(res['bogosize'], 17000),
5253
assert_equal(res['bestblock'], node.getblockhash(200))
5354
size = res['disk_size']
5455
assert size > 6400
@@ -65,6 +66,7 @@ def _test_gettxoutsetinfo(self):
6566
assert_equal(res2['total_amount'], Decimal('0'))
6667
assert_equal(res2['height'], 0)
6768
assert_equal(res2['txouts'], 0)
69+
assert_equal(res2['bogosize'], 0),
6870
assert_equal(res2['bestblock'], node.getblockhash(0))
6971
assert_equal(len(res2['hash_serialized_2']), 64)
7072

@@ -76,6 +78,7 @@ def _test_gettxoutsetinfo(self):
7678
assert_equal(res['transactions'], res3['transactions'])
7779
assert_equal(res['height'], res3['height'])
7880
assert_equal(res['txouts'], res3['txouts'])
81+
assert_equal(res['bogosize'], res3['bogosize'])
7982
assert_equal(res['bestblock'], res3['bestblock'])
8083
assert_equal(res['hash_serialized_2'], res3['hash_serialized_2'])
8184

0 commit comments

Comments
 (0)