mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
7ff6515c88
9b2704777c
[doc] Include txindex changes in the release notes. (Jim Posen)ed77dd6b30
[test] Simple unit test for TxIndex. (Jim Posen)6d772a3d44
[rpc] Public interfaces to GetTransaction block until synced. (Jim Posen)a03f804f2a
[index] Move disk IO logic from GetTransaction to TxIndex::FindTx. (Jim Posen)e0a3b80033
[validation] Replace tx index code in validation code with TxIndex. (Jim Posen)8181db88f6
[init] Initialize and start TxIndex in init code. (Jim Posen)f90c3a62f5
[index] TxIndex method to wait until caught up. (Jim Posen)70d510d93c
[index] Allow TxIndex sync thread to be interrupted. (Jim Posen)94b4f8bbb9
[index] TxIndex initial sync thread. (Jim Posen)34d68bf3a3
[index] Create new TxIndex class. (Jim Posen)c88bcec93f
[db] Migration for txindex data to new, separate database. (Jim Posen)0cb8303241
[db] Create separate database for txindex. (Jim Posen) Pull request description: I'm re-opening #11857 as a new pull request because the last one stopped loading for people ------------------------------- This refactors the tx index code to be in it's own class and get built concurrently with validation code. The main benefit is decoupling and moving the txindex into a separate DB. The primary motivation is to lay the groundwork for other indexers that might be desired (such as the [compact filters](https://github.com/bitcoin/bips/pull/636)). The basic idea is that the TxIndex spins up its own thread, which first syncs the txindex to the current block index, then once in sync the BlockConnected ValidationInterface hook writes new blocks. ### DB changes At the suggestion of some other developers, the txindex has been split out into a separate database. A data migration runs at startup on any nodes with a legacy txindex. Currently the migration blocks node initialization until complete. ### Open questions - Should the migration of txindex data from the old DB to the new DB block in init or should it happen in a background thread? The downside to backgrounding it is that `getrawtransaction` would return an error message saying the txindex is syncing while the migration is running. ### Impact In a sample size n=1 test where I synced nodes from scratch, the average time [Index writing](https://github.com/bitcoin/bitcoin/blob/master/src/validation.cpp#L1903) was 3.36ms in master and 1.72ms in this branch. The average time between `UpdateTip` log lines for sequential blocks between 400,000 and IBD end on mainnet was 0.297204s in master and 0.286134s in this branch. Most likely this is just variance in IBD times, but I can try with some more trials if people want. Tree-SHA512: 451fd7d95df89dfafceaa723cdf0f7b137615b531cf5c5035cfb54e9ccc2026cec5ac85edbcf71b7f4e2f102e36e9202b8b3a667e1504a9e1a9976ab1f0079c4
72 lines
2.4 KiB
Python
Executable File
72 lines
2.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2014-2015 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#
|
|
# Test txindex generation and fetching
|
|
#
|
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import *
|
|
from test_framework.script import *
|
|
from test_framework.mininode import *
|
|
import binascii
|
|
|
|
class TxIndexTest(BitcoinTestFramework):
|
|
|
|
def set_test_params(self):
|
|
self.setup_clean_chain = True
|
|
self.num_nodes = 4
|
|
|
|
def setup_network(self):
|
|
self.add_nodes(self.num_nodes)
|
|
# Nodes 0/1 are "wallet" nodes
|
|
self.start_node(0)
|
|
self.start_node(1, ["-txindex"])
|
|
# Nodes 2/3 are used for testing
|
|
self.start_node(2, ["-txindex"])
|
|
self.start_node(3, ["-txindex"])
|
|
connect_nodes(self.nodes[0], 1)
|
|
connect_nodes(self.nodes[0], 2)
|
|
connect_nodes(self.nodes[0], 3)
|
|
|
|
self.is_network_split = False
|
|
self.sync_all()
|
|
|
|
def run_test(self):
|
|
self.log.info("Mining blocks...")
|
|
self.nodes[0].generate(105)
|
|
self.sync_all()
|
|
|
|
chain_height = self.nodes[1].getblockcount()
|
|
assert_equal(chain_height, 105)
|
|
|
|
self.log.info("Testing transaction index...")
|
|
|
|
addressHash = binascii.unhexlify("C5E4FB9171C22409809A3E8047A29C83886E325D")
|
|
scriptPubKey = CScript([OP_DUP, OP_HASH160, addressHash, OP_EQUALVERIFY, OP_CHECKSIG])
|
|
unspent = self.nodes[0].listunspent()
|
|
tx = CTransaction()
|
|
tx_fee_sat = 1000
|
|
amount = int(unspent[0]["amount"] * 100000000) - tx_fee_sat
|
|
tx.vin = [CTxIn(COutPoint(int(unspent[0]["txid"], 16), unspent[0]["vout"]))]
|
|
tx.vout = [CTxOut(amount, scriptPubKey)]
|
|
tx.rehash()
|
|
|
|
signed_tx = self.nodes[0].signrawtransactionwithwallet(binascii.hexlify(tx.serialize()).decode("utf-8"))
|
|
txid = self.nodes[0].sendrawtransaction(signed_tx["hex"], True)
|
|
self.nodes[0].generate(1)
|
|
self.sync_all()
|
|
|
|
# Check verbose raw transaction results
|
|
verbose = self.nodes[3].getrawtransaction(txid, 1)
|
|
assert_equal(verbose["vout"][0]["valueSat"], 50000000000 - tx_fee_sat)
|
|
assert_equal(verbose["vout"][0]["value"] * 100000000, 50000000000 - tx_fee_sat)
|
|
|
|
self.log.info("Passed")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
TxIndexTest().main()
|