pocketnetteam / pocketnet.core

Decentralized social network based on the blockchain
https://pocketnet.app
Apache License 2.0
114 stars 28 forks source link

Segmentation Fault 20.12, PocketTx #100

Closed tawmaz closed 2 years ago

tawmaz commented 2 years ago

I hit a segmentation fault while attempting to sync 20.12 built from commit 78fb244cd0a8775287b9ed7a1c0f535e9d80c67f and including recent update to checkpoints/main.sqllite described in the SocialConsensus issue. The issue occurs on my setup after social consensus validation of block 1016945.

The segmentation fault occurs when Transaction::GetType() is called when object "this" is null and uninitialized.

Faulting code is this: https://github.com/pocketnetteam/pocketnet.core/blob/feature/sqlite/src/pocketdb/models/base/Transaction.cpp#L45 called from this: https://github.com/pocketnetteam/pocketnet.core/blob/feature/sqlite/src/pocketdb/consensus/Helper.cpp#L216

Call stack:

PocketTx::Transaction::GetType(const PocketTx::Transaction * const this) (/media/shawn/data/src/pocketnet.core.sqlite/src/pocketdb/models/base/Transaction.cpp:45)
PocketConsensus::PostConsensus::Validate(PocketConsensus::PostConsensus * const this,  tx, const PocketConsensus::PostRef & ptx,  block) (/usr/include/c++/9/bits/shared_ptr_base.h:1020)
PocketConsensus::SocialConsensusHelper::validate(const CTransactionRef & tx, const PocketHelpers::PTransactionRef & ptx, const PocketHelpers::PocketBlockRef & pBlock, int height) (/usr/include/c++/9/ext/atomicity.h:96)
PocketConsensus::SocialConsensusHelper::Validate(const CBlock & block, const PocketHelpers::PocketBlockRef & pBlock, int height) (/media/shawn/data/src/pocketnet.core.sqlite/src/pocketdb/consensus/Helper.cpp:38)
CChainState::ConnectBlock(CChainState * const this,  block, const PocketHelpers::PocketBlockRef & pocketBlock, CValidationState & state, CBlockIndex * pindex, CCoinsViewCache & view, const CChainParams & chainparams, bool fJustCheck) (/media/shawn/data/src/pocketnet.core.sqlite/src/validation.cpp:2540)
CChainState::ConnectTip(CChainState * const this, CValidationState & state, const CChainParams & chainparams, CBlockIndex * pindexNew,  pblock,  pocketBlockPart, ConnectTrace & connectTrace, DisconnectedBlockTransactions & disconnectpool) (/media/shawn/data/src/pocketnet.core.sqlite/src/validation.cpp:3060)
CChainState::ActivateBestChainStep(CChainState * const this, CValidationState & state, const CChainParams & chainparams, CBlockIndex * pindexMostWork, const std::shared_ptr<CBlock const> & pblock, const std::shared_ptr<std::vector<std::shared_ptr<PocketTx::Transaction>, std::allocator<std::shared_ptr<PocketTx::Transaction> > > > & pocketBlock, bool & fInvalidFound,  connectTrace) (/usr/include/c++/9/bits/shared_ptr_base.h:616)
CChainState::ActivateBestChain(CChainState * const this,  state,  chainparams, std::shared_ptr<CBlock const> pblock, const std::shared_ptr<std::vector<std::shared_ptr<PocketTx::Transaction>, std::allocator<std::shared_ptr<PocketTx::Transaction> > > > pocketBlock) (/media/shawn/data/src/pocketnet.core.sqlite/src/uint256.h:47)
ProcessNewBlock(CValidationState & state, const CChainParams & chainparams, const std::shared_ptr<CBlock const> & pblock, const PocketHelpers::PocketBlockRef & pocketBlock, bool fForceProcessing, bool fReceived, bool * fNewBlock) (/usr/include/c++/9/ext/atomicity.h:96)
ProcessMessage(CNode * pfrom,  strCommand,  vRecv, int64_t nTimeReceived, const CChainParams & chainparams, CConnman * connman, const std::atomic<bool> & interruptMsgProc, bool enable_bip61) (/usr/include/c++/9/bits/shared_ptr.h:246)
PeerLogicValidation::ProcessMessages(PeerLogicValidation * const this, CNode * pfrom, std::atomic<bool> & interruptMsgProc) (/media/shawn/data/src/pocketnet.core.sqlite/src/net_processing.cpp:3207)
CConnman::ThreadMessageHandler(CConnman * const this) (/media/shawn/data/src/pocketnet.core.sqlite/src/net.cpp:2142)
std::function<void ()>::operator()() const(const std::function<void()> * const this) (/usr/include/c++/9/bits/std_function.h:683)
TraceThread<std::function<void ()> >(char const*, std::function<void ()>)(const char * name, std::function<void()> func) (/media/shawn/data/src/pocketnet.core.sqlite/src/util.h:329)
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) (/usr/include/c++/9/bits/move.h:182)
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) (/usr/include/c++/9/bits/invoke.h:95)
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>)(std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void()>), char const*, std::function<void()> > > * const this) (/usr/include/c++/9/thread:244)
std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void ()>), char const*, std::function<void ()> > >::operator()()(std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void()>), char const*, std::function<void()> > > * const this) (/usr/include/c++/9/thread:251)
std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void ()>), char const*, std::function<void ()> > > >::_M_run()(std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(char const*, std::function<void()>), char const*, std::function<void()> > > > * const this) (/usr/include/c++/9/thread:195)
libstdc++.so.6![Unknown/Just-In-Time compiled code] (Unknown Source:0)
tawmaz commented 2 years ago

Last lines of debug.log

2021-12-05T22:17:43Z init message: Loading banlist...
2021-12-05T22:17:43Z init message: Starting network threads...
2021-12-05T22:17:43Z net thread start
2021-12-05T22:17:43Z dnsseed thread start
2021-12-05T22:17:43Z addcon thread start
2021-12-05T22:17:43Z opencon thread start
2021-12-05T22:17:43Z msghand thread start
2021-12-05T22:17:43Z init message: Done loading
2021-12-05T22:17:43Z New outbound peer connected: version: 70015, blocks=1469802, peer=1
2021-12-05T22:17:54Z Loading addresses from DNS seeds (could take a while)
2021-12-05T22:17:54Z 0 addresses found from DNS seeds
2021-12-05T22:17:54Z dnsseed thread exit
2021-12-05T22:17:55Z New outbound peer connected: version: 70015, blocks=1469803, peer=2
2021-12-05T22:18:00Z New outbound peer connected: version: 70015, blocks=1469802, peer=3
2021-12-05T22:18:03Z New outbound peer connected: version: 70015, blocks=1469803, peer=4
2021-12-05T22:18:04Z New outbound peer connected: version: 70015, blocks=1469803, peer=6
2021-12-05T22:18:05Z New outbound peer connected: version: 70015, blocks=1469803, peer=7
2021-12-05T22:18:06Z New outbound peer connected: version: 70015, blocks=1469803, peer=8
2021-12-05T22:18:09Z New outbound peer connected: version: 70015, blocks=1469802, peer=5
2021-12-05T22:18:36Z New outbound peer connected: version: 70015, blocks=1469698, peer=0
2021-12-05T22:32:23Z Imported mempool transactions from disk: 0 succeeded, 0 failed, 0 expired, 0 already there
2021-12-05T22:32:23Z Staker thread started for 
2021-12-05T22:36:53Z New outbound peer connected: version: 70015, blocks=1469824, peer=9
2021-12-05T22:37:23Z Timeout downloading block adeb8e970780cf937b88b99492d58c952b92960c169f6c29b99d63c1d37359ef from peer=0, disconnecting
2021-12-05T22:38:51Z --- Block validated: 1016945 BH: 6113c937e8e567b1130d9041946c2efc4751bcbb33b18fbf40e7211a6b30b4cf
tawmaz commented 2 years ago

At block height 1016946 it appears there is a social consensus checkpoint of TX 97e3df91e7632820735931453616ed5257da21a97c85a0bc38554e706b8ba098. Immediately after we attempt to access relayTx->GetType, however relayTx is NULL causing the segmentation fault.

https://github.com/pocketnetteam/pocketnet.core/blob/feature/sqlite/src/pocketdb/consensus/social/Post.hpp#L39

Testing a fix where we check relayOk before dereferencing relayTx