Giter Club home page Giter Club logo

alt-integration-cpp's Introduction

Quality Gate Status CI codecov loc

This repository contains a C++11 veriblock-pop-cpp library - an implementation of VeriBlock Proof-of-Proof ("POP") consensus protocol for prevention of 51% attacks.

POP overall consists of 2 protocols:

  • POP Fork Resolution - given set of POP publications sent to Altchain from 2 chains, select best chain among these two, based on timeliness of publications in VBK tree, number of publications and other factors.
  • POP Rewards - an economic incentive for POP miners to send endorsing VBK transactions in VBK blockchain, and sending back proofs to Altchain. POP Rewards are paid in Altchain coins.

See https://veriblock.github.io/alt-integration-cpp/ for details.

alt-integration-cpp's People

Contributors

bernatcarbo avatar black0rwhite avatar blackyblack avatar enfipy avatar eu321 avatar memekas avatar mr-leshiy avatar nviktorov avatar overcookedpanda avatar skemba avatar wahidtanner avatar warchant avatar xagau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

alt-integration-cpp's Issues

Fuzz e2e failed

==10867== ERROR: libFuzzer: deadly signal
[288](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:288)
    #0 0x4ceea0 in __sanitizer_print_stack_trace (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x4ceea0)
[289](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:289)
    #1 0x47a7f8 in fuzzer::PrintStackTrace() (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x47a7f8)
[290](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:290)
    #2 0x460833 in fuzzer::Fuzzer::CrashCallback() (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x460833)
[291](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:291)
    #3 0x7f3e4e0ef3bf  (/lib/x86_64-linux-gnu/libpthread.so.0+0x153bf)
[292](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:292)
    #4 0x7f3e4df0018a in raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618a)
[293](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:293)
    #5 0x7f3e4dedf858 in abort (/lib/x86_64-linux-gnu/libc.so.6+0x25858)
[294](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:294)
    #6 0x7f3e4e2ea910  (/lib/x86_64-linux-gnu/libstdc++.so.6+0x9e910)
[295](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:295)
    #7 0x7f3e4e2f638b  (/lib/x86_64-linux-gnu/libstdc++.so.6+0xaa38b)
[296](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:296)
    #8 0x7f3e4e2f63f6 in std::terminate() (/lib/x86_64-linux-gnu/libstdc++.so.6+0xaa3f6)
[297](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:297)
    #9 0x7f3e4e2f7154 in __cxa_pure_virtual (/lib/x86_64-linux-gnu/libstdc++.so.6+0xab154)
[298](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:298)
    #10 0x599032 in unsigned int altintegration::getNextWorkRequired<altintegration::VbkBlock, altintegration::VbkChainParams>(altintegration::BlockIndex<altintegration::VbkBlock> const&, altintegration::VbkBlock const&, altintegration::VbkChainParams const&) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x599032)
[299](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:299)
    #11 0x5988ac in altintegration::Miner<altintegration::VbkBlock, altintegration::VbkChainParams>::getBlockTemplate(altintegration::BlockIndex<altintegration::VbkBlock> const&, altintegration::Blob<16ul> const&) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x5988ac)
[300](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:300)
    #12 0x52a5d1 in altintegration::Miner<altintegration::VbkBlock, altintegration::VbkChainParams>::createNextBlock(altintegration::BlockIndex<altintegration::VbkBlock> const&) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x52a5d1)
[301](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:301)
    #13 0x527157 in altintegration::MockMiner::mineBlock(altintegration::BlockIndex<altintegration::VbkBlock> const&, std::vector<altintegration::VbkTx, std::allocator<altintegration::VbkTx> > const&) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x527157)
[302](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:302)
    #14 0x52985a in altintegration::BlockIndex<altintegration::VbkBlock>* altintegration::MockMiner::mineBlocks<altintegration::VbkBlock, altintegration::VbkTx>(unsigned long, altintegration::BlockIndex<altintegration::VbkBlock> const&, std::vector<altintegration::VbkTx, std::allocator<altintegration::VbkTx> > const&) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x52985a)
[303](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:303)
    #15 0x4d1e4c in handle(FuzzedDataProvider&, FuzzState&) /home/runner/work/alt-integration-cpp/alt-integration-cpp/fuzz/e2e/fuzzer.cpp:123:27
[304](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:304)
    #16 0x4d8aaa in LLVMFuzzerTestOneInput /home/runner/work/alt-integration-cpp/alt-integration-cpp/fuzz/e2e/fuzzer.cpp:326:23
[305](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:305)
    #17 0x461d91 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x461d91)
[306](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:306)
    #18 0x4614d5 in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x4614d5)
[307](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:307)
    #19 0x462f00 in fuzzer::Fuzzer::MutateAndTestOne() (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x462f00)
[308](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:308)
    #20 0x463975 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x463975)
[309](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:309)
    #21 0x453385 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x453385)
[310](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:310)
    #22 0x47afd2 in main (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x47afd2)
[311](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:311)
    #23 0x7f3e4dee10b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
[312](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:312)
    #24 0x427bad in _start (/home/runner/work/alt-integration-cpp/alt-integration-cpp/build/bin/e2e_fuzz+0x427bad)
[313](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:313)

[314](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:314)
NOTE: libFuzzer has rudimentary signal handlers.
[315](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:315)
      Combine libFuzzer with AddressSanitizer or similar for better crash reports.
[316](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:316)
SUMMARY: libFuzzer: deadly signal
[317](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:317)
MS: 1 ChangeBit-; base unit: 1e4c7f8019dba90d204f50a8fa9611660f49f484
[318](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:318)
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x0,0x0,0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x44,0x44,0x0,0x20,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
[319](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:319)
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00DD\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
[320](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:320)
artifact_prefix='./'; Test unit written to ./crash-3a1a6bb70c5453bf6ad907f0f5a7a44dbbe2cb56
[321](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:321)
Base64: AAAAAAAAAAAAAAAAAAAAAgAAAAAAAQAAAAAAAAAAAABERAAgAAAAAAAAAAAAAAA=
[322](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:322)
stat::number_of_executed_units: 25
[323](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:323)
stat::average_exec_per_sec:     12
[324](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:324)
stat::new_units_added:          8
[325](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:325)
stat::slowest_unit_time_sec:    0
[326](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:326)
stat::peak_rss_mb:              92
[327](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:327)
INFO: exiting: 77 time: 2612s
[328](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:328)
make[3]: *** [fuzz/CMakeFiles/run_e2e_fuzz.dir/build.make:70: fuzz/CMakeFiles/run_e2e_fuzz] Error 77
[329](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:329)
make[2]: *** [CMakeFiles/Makefile2:1284: fuzz/CMakeFiles/run_e2e_fuzz.dir/all] Error 2
[330](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:330)
make[1]: *** [CMakeFiles/Makefile2:1135: fuzz/CMakeFiles/fuzz.dir/rule] Error 2
[331](https://github.com/VeriBlock/alt-integration-cpp/runs/5421824517?check_suite_focus=true#step:7:331)
make: *** [Makefile:507: fuzz] Error 2

Reproduce:

Base64: AAAAAAAAAAAAAAAAAAAAAgAAAAAAAQAAAAAAAAAAAABERAAgAAAAAAAAAAAAAAA=

Add serde for BTC data types

  • Add serialization from bitcoin for bitcoin types: Full Block, Header (use BtcBlock), Tx, p2p messages (Inv, Addr...)
  • For each type add test

Test for pop mempool inclusion order

Mempool returns PopData in this order:

  1. Payloads with earlier VBK block will be earlier. VBK = use itself, ATV=block of proof, VTB=containing.
  2. Payloads with VBK block on active chain will be earlier.
  3. ATVs with same VBK block will be compared by ATV VBK tx fee. Higher fee - more chances that ATV will be picked.

Write a test that will check current logic against this ^.

VbkBlock finalization check

For VbkBlock need to add some kind of canFinalized() method which will return to us either can we finalize this block or not.

  • update VbkBlockAddon, add MerkleTree struct for the VbkPopTxs and fill it with the any new related transaction.
  • update VbkBlockAddon, add validation method which will be checked if all possible VbkPopTxs have been already added into the MerkleTree
  • update VbkBlockTree, payloads procedure with the filling this new MerkleTree field for the VbkBlockAddond
  • update VbkBlockTree finalization procedure with the usage of the new VbkBlockAddond validation method

Linux: SEGFAULT during sync (vBTC incentivized testnet)

Observed during vBTC incentivized testnet testing:
When syncing the blockchain vbitcoind would eventually crash with a SEGFAULT, presumably because of the stack getting too deep due to the recursion in AltBlockTree::connectBlock This was true for both debug and release builds of vbitcoind.

Stack Trace
Obtained from debug build of vbitcoind:

(gdb) where
#0  0x000056544951f972 in __gnu_cxx::new_allocator<unsigned char>::_M_max_size (this=0x0) at /usr/include/c++/10.3.1/ext/new_allocator.h:185
#1  0x000056544951ec0b in __gnu_cxx::new_allocator<unsigned char>::allocate (this=0x7ff0995d0230, __n=32) at /usr/include/c++/10.3.1/ext/new_allocator.h:105
#2  0x000056544951dde3 in std::allocator_traits<std::allocator<unsigned char> >::allocate (__a=..., __n=32) at /usr/include/c++/10.3.1/bits/alloc_traits.h:460
#3  0x000056544951c489 in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_allocate (this=0x7ff0995d0230, __n=32) at /usr/include/c++/10.3.1/bits/stl_vector.h:346
#4  0x000056544951c3b8 in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_M_create_storage (this=0x7ff0995d0230, __n=32) at /usr/include/c++/10.3.1/bits/stl_vector.h:361
#5  0x000056544951a768 in std::_Vector_base<unsigned char, std::allocator<unsigned char> >::_Vector_base (this=0x7ff0995d0230, __n=32, __a=...) at /usr/include/c++/10.3.1/bits/stl_vector.h:305
#6  0x00005654495a893b in std::vector<unsigned char, std::allocator<unsigned char> >::vector (this=0x7ff0995d0230, __x=std::vector of length 32, capacity 32 = {...}) at /usr/include/c++/10.3.1/bits/stl_vector.h:555
#7  0x00005654499314dd in altintegration::AltBlock::AltBlock (this=0x7ff0995d0230) at /usr/local/include/veriblock/pop/entities/altblock.hpp:28
#8  0x0000565449b6d3b0 in VeriBlock::AltChainParamsVBTC::getBootstrapBlock (this=0x7ff0a3ff30e0) at vbk/params.hpp:75
#9  0x0000565449f0b951 in altintegration::AltBlockTree::BlockPayloadMutator::BlockPayloadMutator (this=0x7ff0995d0460, tree=..., block=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:398
#10 0x0000565449f0c775 in altintegration::AltBlockTree::makeConnectedLeafPayloadMutator (this=this@entry=0x7ff0a3ef3550, block=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:499
#11 0x0000565449f0c830 in altintegration::AltBlockTree::connectBlock (this=0x7ff0a3ef3550, index=..., state=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:195
#12 0x0000565449f0d680 in altintegration::AltBlockTree::connectBlock (this=0x7ff0a3ef3550, index=..., state=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:211
#13 0x0000565449f0d680 in altintegration::AltBlockTree::connectBlock (this=0x7ff0a3ef3550, index=..., state=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:211
[... frame repeats until ...]
#315 0x0000565449f0d680 in altintegration::AltBlockTree::connectBlock (this=0x7ff0a3ef3550, index=..., state=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:211
#316 0x0000565449f0d680 in altintegration::AltBlockTree::connectBlock (this=this@entry=0x7ff0a3ef3550, index=..., state=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:211
#317 0x0000565449f0dc06 in altintegration::AltBlockTree::acceptBlock (this=this@entry=0x7ff0a3ef3550, index=..., payloads=..., state=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:110
#318 0x0000565449f0dca7 in altintegration::AltBlockTree::acceptBlock (this=this@entry=0x7ff0a3ef3550, index=..., payloads=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:101
#319 0x0000565449f0e18b in altintegration::AltBlockTree::acceptBlock (this=0x7ff0a3ef3550, block=std::vector of length 32, capacity 32 = {...}, payloads=...) at /opt/alt-integration-cpp-03e5d066369030c36d5dd22c2628817b829f0218/src/pop/blockchain/alt_block_tree.cpp:93
#320 0x0000565449911a62 in VeriBlock::addAllBlockPayloads (block=..., state=...) at vbk/pop_service.cpp:114
#321 0x000056544985692d in CChainState::AcceptBlock (this=0x7ff0a40c4960, pblock=std::shared_ptr<const CBlock> (use count 2, weak count 0) = {...}, state=..., chainparams=..., ppindex=0x7ff0995ed788, fRequested=true, dbp=0x0, fNewBlock=0x7ff0995ed96f) at validation.cpp:3894
#322 0x0000565449856f89 in ProcessNewBlock (chainparams=..., pblock=std::shared_ptr<const CBlock> (use count 2, weak count 0) = {...}, fForceProcessing=true, fNewBlock=0x7ff0995ed96f) at validation.cpp:3945
#323 0x00005654495877a2 in ProcessMessage (pfrom=0x7ff0995a9520, strCommand="block", vRecv=..., nTimeReceived=1631627288765281, chainparams=..., connman=0x7ff09c3c6300, banman=0x7ff0a3ef2580, interruptMsgProc=...) at net_processing.cpp:3027
#324 0x000056544958a801 in PeerLogicValidation::ProcessMessages (this=0x7ff0a4087e60, pfrom=0x7ff0995a9520, interruptMsgProc=...) at net_processing.cpp:3403
#325 0x000056544952a66c in CConnman::ThreadMessageHandler (this=0x7ff09c3c6300) at net.cpp:2023
#326 0x0000565449574754 in std::__invoke_impl<void, void (CConnman::*&)(), CConnman*&> (__f=@0x7ff099740640: (void (CConnman::*)(CConnman * const)) 0x56544952a46c <CConnman::ThreadMessageHandler()>, __t=@0x7ff099740650: 0x7ff09c3c6300) at /usr/include/c++/10.3.1/bits/invoke.h:73
#327 0x0000565449572501 in std::__invoke<void (CConnman::*&)(), CConnman*&> (__fn=@0x7ff099740640: (void (CConnman::*)(CConnman * const)) 0x56544952a46c <CConnman::ThreadMessageHandler()>) at /usr/include/c++/10.3.1/bits/invoke.h:95
#328 0x000056544956f285 in std::_Bind<void (CConnman::*(CConnman*))()>::__call<void, , 0ul>(std::tuple<>&&, std::_Index_tuple<0ul>) (this=0x7ff099740640, __args=...) at /usr/include/c++/10.3.1/functional:416
#329 0x000056544956a4e3 in std::_Bind<void (CConnman::*(CConnman*))()>::operator()<, void>() (this=0x7ff099740640) at /usr/include/c++/10.3.1/functional:499
#330 0x00005654495642c9 in std::__invoke_impl<void, std::_Bind<void (CConnman::*(CConnman*))()>&>(std::__invoke_other, std::_Bind<void (CConnman::*(CConnman*))()>&) (__f=...) at /usr/include/c++/10.3.1/bits/invoke.h:60
#331 0x000056544955a91d in std::__invoke_r<void, std::_Bind<void (CConnman::*(CConnman*))()>&>(std::_Bind<void (CConnman::*(CConnman*))()>&) (__fn=...) at /usr/include/c++/10.3.1/bits/invoke.h:153
#332 0x000056544954d4c4 in std::_Function_handler<void (), std::_Bind<void (CConnman::*(CConnman*))()> >::_M_invoke(std::_Any_data const&) (__functor=...) at /usr/include/c++/10.3.1/bits/std_function.h:291
#333 0x00005654494abf6b in std::function<void ()>::operator()() const (this=0x7ff0995f06b0) at /usr/include/c++/10.3.1/bits/std_function.h:622
#334 0x00005654494b2075 in TraceThread<std::function<void ()> >(char const*, std::function<void ()>) (name=0x56544a10387c "msghand", func=...) at ./util/system.h:365
#335 0x0000565449576632 in std::__invoke_impl<void, void (*)(char const*, std::function<void ()>), char const*, std::function<void ()> >(std::__invoke_other, void (*&&)(char const*, std::function<void ()>), char const*&&, std::function<void ()>&&) (
    __f=@0x7ff099734170: 0x5654494b1fef <TraceThread<std::function<void ()> >(char const*, std::function<void ()>)>) at /usr/include/c++/10.3.1/bits/invoke.h:60
#336 0x0000565449576452 in std::__invoke<void (*)(char const*, std::function<void ()>), char const*, std::function<void ()> >(void (*&&)(char const*, std::function<void ()>), char const*&&, std::function<void ()>&&) (
    __fn=@0x7ff099734170: 0x5654494b1fef <TraceThread<std::function<void ()> >(char const*, std::function<void ()>)>) at /usr/include/c++/10.3.1/bits/invoke.h:95
#337 0x00005654495762d2 in std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void ()>), char const*, std::function<void ()> > >::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) (this=0x7ff099734148) at /usr/include/c++/10.3.1/thread:264
#338 0x000056544957624d in std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void ()>), char const*, std::function<void ()> > >::operator()() (this=0x7ff099734148) at /usr/include/c++/10.3.1/thread:271
#339 0x000056544957620f in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void ()>), char const*, std::function<void ()> > > >::_M_run() (this=0x7ff099734140) at /usr/include/c++/10.3.1/thread:215
#340 0x00007ff0a4489713 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::swap(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&) () from /usr/lib/libstdc++.so.6

Environment
Running inside Alpine Linux container built from Dockerfile in vbk-ri-btc.
container host: Fedora Linux 33, kernel 5.13.12-100.fc33.x86_64

ulimits (container host):

$ ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 514782
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 514782
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

ulimits (inside container):

~/.vbitcoin $ ulimit -a
core file size (blocks)         (-c) unlimited
data seg size (kb)              (-d) unlimited
scheduling priority             (-e) 0
file size (blocks)              (-f) unlimited
pending signals                 (-i) 514782
max locked memory (kb)          (-l) 64
max memory size (kb)            (-m) unlimited
open files                      (-n) 1048576
POSIX message queues (bytes)    (-q) 819200
real-time priority              (-r) 0
stack size (kb)                 (-s) 8192
cpu time (seconds)              (-t) unlimited
max user processes              (-u) unlimited
virtual memory (kb)             (-v) unlimited
file locks                      (-x) unlimited

Workaround
Replacing the recursion with e.g. a regular loop + stack to avoid the deep call stack seems to resolve the issue:

---
 src/pop/blockchain/alt_block_tree.cpp | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/pop/blockchain/alt_block_tree.cpp b/src/pop/blockchain/alt_block_tree.cpp
index 14ae9ef3..f31f8201 100644
--- a/src/pop/blockchain/alt_block_tree.cpp
+++ b/src/pop/blockchain/alt_block_tree.cpp
@@ -108,6 +108,26 @@ void AltBlockTree::acceptBlock(index_t& index,
 
   if (index.pprev->isConnected()) {
     connectBlock(index, state);
+    // connect the descendants
+    std::stack<altintegration::BlockIndex<altintegration::AltBlock>*> stack;
+    for(auto pos = index.pnext.rbegin(); pos != index.pnext.rend(); pos++) {
+      auto* next = *pos;
+      stack.push(next);
+    }
+
+    while(!stack.empty()) {
+      auto* toProcess = stack.top();
+      stack.pop();
+      if (toProcess->hasFlags(BLOCK_HAS_PAYLOADS)) {
+        ValidationState dummy;
+        connectBlock(*toProcess, dummy);
+        // fill stack
+        for(auto pos = toProcess->pnext.rbegin(); pos != toProcess->pnext.rend(); pos++) {
+          auto* next = *pos;
+          stack.push(next);
+        }
+      }
+    }
   }
 }
 
@@ -204,13 +224,6 @@ bool AltBlockTree::connectBlock(index_t& index, ValidationState& state) {
 
   if (index.isValid()) {
     onBlockConnected.emit(index);
-    // connect the descendants
-    for (auto* successor : index.pnext) {
-      if (successor->hasFlags(BLOCK_HAS_PAYLOADS)) {
-        ValidationState dummy;
-        connectBlock(*successor, dummy);
-      }
-    }
   } else {
     onInvalidBlockConnected.emit(index, state);
   };
-- 
2.31.1

Assertion failed at /opt/alt-integration-cpp-x/src/pop/base58.cpp:160 inside AssertDecodeBase58

2022-03-07T06:22:42Z [alt-cpp] [debug] overrideTip: ALT:56714:e218cd87f640e053ff02e0e6a5dec32023f102614549b0d97c03000000000000 VBK:3007905:00000000022cf637ff6e344cecc5db2da830eff38d19a3ac BTC:726123:00000000000000000003e2b0974c08fe61c8d21846cfa4056c2390e331dda6e5
2022-03-07T06:22:42Z     - Verify 0 txins: 91.59ms (0.000ms/txin) [3.54s (35.39ms/blk)]
2022-03-07T06:22:42Z     - Index writing: 0.04ms [0.00s (0.04ms/blk)]
2022-03-07T06:22:42Z     - Callbacks: 0.01ms [0.00s (0.01ms/blk)]
2022-03-07T06:22:42Z   - Connect total: 91.70ms [3.93s (39.29ms/blk)]
2022-03-07T06:22:42Z   - Flush: 0.01ms [0.00s (0.01ms/blk)]
2022-03-07T06:22:42Z   - Writing chainstate: 0.01ms [0.00s (0.01ms/blk)]
2022-03-07T06:22:42Z Blockpolicy estimates updated by 0 of 0 block txs, since last block 0 of 0 tracked, mempool map size 0, max target 0 from current
2022-03-07T06:22:42Z [alt-cpp] [critical] AssertDecodeBase58: Assertion failed at /opt/alt-integration-cpp-1beffc9d12147caa221e2cc0c440ea7c1fd675a8/src/pop/base58.cpp:160 inside AssertDecodeBase58:
status
Invalid input: �h���\x7f\x00\x00JzYhAVCx6vYvvKnWoDFq4Q

Assertion failed at /opt/alt-integration-cpp-1beffc9d12147caa221e2cc0c440ea7c1fd675a8/src/pop/base58.cpp:160 inside AssertDecodeBase58:
status
Invalid input: �h���JzYhAVCx6vYvvKnWoDFq4Q
terminate called without an active exception

finalizeBlockImpl assertion failed

2022-03-02T09:16:28Z [alt-cpp] [critical] finalizeBlockImpl: Assertion failed at /opt/alt-integration-cpp-b7765fdc477ef1f22e6ee3a62dda500b6c7f6ff1/include/veriblock/pop/blockchain/base_block_tree.hpp:882 inside finaliz$
appliedBlockCount == activeChain_.blocksCount()

Add long-running e2e benchmark

Requirements:

  • Deterministically (based on size_t seed) generate series of "commands" (atomic actions) in e2e setup.
  • Input is a vector of bytes.
    • interface for strategies: fuzz strategy, seed strategy
  • Define a list of actions (enum):
    • Mine BTC, VBK, ALT block. When block is mined, take entire (corresponding) mempool content and include in next block.
    • Create BTC TX, VBK TX, VBK POP TX. Creates a tx and stores in corresponding mempool.
    • Submit ATV, VTB, VBK, ALL. Submit corresponding payload (first, random, all in candidates).
  • At the end return a struct of "statistics" (metrics).

Mempool cleanup bugs

  1. When new block arrived fully valid connecting VTB has been removed from the mempool. New block did not contain this VTB.
  2. For some reason VBK statefully duplicate blocks remain in mempool (should be removed).

Assert failed inside loadBlockInner

2021-12-15T08:59:15Z [alt-cpp] [warn] loadTree: Loading 2016 BTC blocks with tip 0000000000000000000c57d98837a8c297accb8cee7f5c3c3cb751a8ec74aba8
2021-12-15T08:59:15Z [alt-cpp] [critical] loadBlockInner: Assertion failed at /home/runner/work/vbk-ri-btc/vbk-ri-btc/depends/work/build/x86_64-w64-mingw32/veriblock-pop-cpp/0ad18f53e7778c30ef56696ea507c7cc2a0f9cf3-f28c264663d/include/veriblock/pop/blockchain/base_block_tree.hpp:636 inside loadBlockInner:
index.height >= root.getHeight()
Blocks can be forward connected after root only. index.height: 708156, root.height: 711392

Create library `veriblock-abfi-cpp`

  • Create library
  • Add install step
  • Add link dependency on veriblock-pop-cpp
  • Separate tests: abfi tests should link veriblock-abfi-cpp library, pop tests should link only veriblock-pop-cpp

BtcTx empty data bug

It is possible to send BtcTx with the empty data which lead to the SegFault corruption
How to trigger:
Update BtcTx with the empty data:

struct BtcTx {
  using hash_t = uint256;
  std::vector<uint8_t> tx{};

  BtcTx() = default;
  BtcTx(std::vector<uint8_t>) : tx({}) {}
  BtcTx(Slice<const uint8_t>) : tx({}) {}
  ...
}

Test project /home/leshiy/Work/alt-integration-cpp/build
      Start 38: vbk_blockchain_test
 1/78 Test #38: vbk_blockchain_test ..............   Passed    9.46 sec
      Start 12: mempool_test_vtbs_contextgap
 2/78 Test #12: mempool_test_vtbs_contextgap .....***Exception: SegFault153.70 sec
      Start 42: blockchain_test
 3/78 Test #42: blockchain_test ..................   Passed   73.04 sec
      Start 13: mempool_getpop_test
 4/78 Test #13: mempool_getpop_test ..............***Exception: SegFault  3.56 sec
      Start 71: progpow_test
 5/78 Test #71: progpow_test .....................   Passed   21.33 sec
      Start 58: poprewards_test
 6/78 Test #58: poprewards_test ..................   Passed   11.76 sec
      Start 29: pop_payouts_e2e_test
 7/78 Test #29: pop_payouts_e2e_test .............   Passed   10.85 sec
      Start 39: vbk_getblockproof_test
 8/78 Test #39: vbk_getblockproof_test ...........   Passed    0.01 sec
      Start 11: mempool_test
 9/78 Test #11: mempool_test .....................***Exception: SegFault  3.20 sec
      Start 26: scenario_8_test
10/78 Test #26: scenario_8_test ..................***Exception: SegFault  8.50 sec

New type of context gap

When only VBK blocks are added but not VTBs, we may end up in a situation when we no longer can advance BTC context, due to all VTBs added into "finalized" (tip-2000) VBK blocks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.