MCPcopy Create free account
hub / github.com/citp/BlockSci / addNewBlocks

Method addNewBlocks

tools/parser/block_processor.cpp:836–958  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

834
835template <typename ParseTag>
836std::vector<blocksci::RawBlock> BlockProcessor::addNewBlocks(const ParserConfiguration<ParseTag> &config, std::vector<BlockInfo<ParseTag>> blocks, UTXOState &utxoState, UTXOAddressState &utxoAddressState, AddressState &addressState, UTXOScriptState &utxoScriptState) {
837
838 AddressWriter addressWriter{config};
839 IndexedFileWriter<1> txFile(blocksci::ChainAccess::txFilePath(config.dataConfig.chainDirectory()));
840 FixedSizeFileWriter<OutputLinkData> linkDataFile(config.txUpdatesFilePath());
841 FixedSizeFileWriter<blocksci::uint256> txHashFile{blocksci::ChainAccess::txHashesFilePath(config.dataConfig.chainDirectory())};
842
843 auto discardFunc = [](RawTransaction &) { return false; };
844
845 auto progressBar = blocksci::makeProgressBar(totalTxCount, [=](RawTransaction &tx) {
846 std::cout << ", Block " << tx.blockHeight << "/" << maxBlockHeight;
847 });
848
849 /* Advance function of the last step
850 * Optimization: Only push tx to finished_transaction_queue if it meets certain conditions, otherwise de-allocate it */
851
852 auto serializeAddressDiscardFunc = [&](RawTransaction &tx) {
853 progressBar.update(tx.txNum - startingTxCount, tx);
854 return tx.realSize >= 800;
855 };
856
857 // Definition of all ProcessStep objects for the processing pipeline
858 ProcessStepQueue processQueue;
859
860 // 0. Step: Calculate hash of transaction and write it to the hash file (chain/tx_hashes.dat)
861 processQueue.addStep(makeStandardProcessStep(std::make_unique<CalculateTxHashStep>(txHashFile), discardFunc, discardFunc));
862
863 // 1. Step: Parse the output scripts (into CScriptView) of the transaction in order to identify address types and extract relevant information.
864 processQueue.addStep(makeStandardProcessStep(std::make_unique<GenerateScriptOutputsStep>(), discardFunc, discardFunc));
865
866 // 2. Step: Store information about the spent output with each input of the transaction. Then store information about each output for future lookup.
867 processQueue.addStep(makeStandardProcessStep(std::make_unique<ConnectUTXOsStep>(utxoState), discardFunc, discardFunc));
868
869 /* 3. Step: Parse the input script of each input based information about the associated output script.
870 * Then store information about each output address for future lookup. */
871 processQueue.addStep(makeStandardProcessStep(std::make_unique<GenerateScriptInputStep>(utxoAddressState), discardFunc, discardFunc));
872
873 /* 4. Step: Attach a scriptNum to each script in the transaction. For address types which are
874 deduplicated (Pubkey, ScriptHash, Multisig and their varients) use the previously allocated
875 scriptNum if the address was seen before. Increment the scriptNum counter for newly seen addresses. */
876 processQueue.addStep(makeStandardProcessStep(std::make_unique<ProcessAddressesStep>(addressState), discardFunc, discardFunc));
877
878 /* 5. Step: Record the scriptNum for each output for later reference. Assign each spent input with
879 the scriptNum of the output its spending */
880 processQueue.addStep(makeStandardProcessStep(std::make_unique<RecordAddressesStep>(utxoScriptState), discardFunc, discardFunc));
881
882 // 6. Step: Serialize transaction data, inputs, and outputs and write them to the txFile
883 processQueue.addStep(makeStandardProcessStep(std::make_unique<SerializeTransactionStep>(txFile, linkDataFile), discardFunc, discardFunc));
884
885 // 7. Step: Save address data into files for the analysis library
886 processQueue.addStep(makeStandardProcessStep(std::make_unique<SerializeAddressesStep>(addressWriter), discardFunc, serializeAddressDiscardFunc, false, true));
887
888 // Two hold stages for ATOR
889 processQueue.addStep(makeHoldTxStep()); // 8
890 processQueue.addStep(makeHoldTxStep()); // 9
891
892 processQueue.setStepOrder({
893 {0, 0}, // calculate tx hash

Callers 1

updateChainFunction · 0.80

Calls 15

makeProgressBarFunction · 0.85
makeStandardProcessStepFunction · 0.85
makeHoldTxStepFunction · 0.85
readNewBlockFunction · 0.85
chainDirectoryMethod · 0.80
txUpdatesFilePathMethod · 0.80
addStepMethod · 0.80
setStepOrderMethod · 0.80
pushMethod · 0.80
isRunningMethod · 0.80
waitForCompleteMethod · 0.80

Tested by

no test coverage detected