Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 8f30527

Browse files
committed
Fix segfault during sync bug
Segfault is occurring when a peer reconnects while its disconnect is still pending, which results in a live Session but no entry in EthereumCapability::m_peers. EthereumCapability::interpretCapabilityPacket directly accesses m_peers via node ID rather than using a lookup function, which is causing the segfault.
1 parent fa45a92 commit 8f30527

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

libethereum/EthereumCapability.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ void EthereumCapability::onDisconnect(NodeID const& _peerID)
629629
bool EthereumCapability::interpretCapabilityPacket(
630630
NodeID const& _peerID, unsigned _id, RLP const& _r)
631631
{
632-
auto& peer = m_peers[_peerID];
633-
peer.setLastAsk(std::chrono::system_clock::to_time_t(chrono::system_clock::now()));
632+
auto& remotePeer = peer(_peerID);
633+
remotePeer.setLastAsk(std::chrono::system_clock::to_time_t(chrono::system_clock::now()));
634634

635635
try
636636
{
@@ -648,10 +648,10 @@ bool EthereumCapability::interpretCapabilityPacket(
648648
<< networkId << " / " << genesisHash << ", TD: " << totalDifficulty
649649
<< " = " << latestHash;
650650

651-
peer.setStatus(
651+
remotePeer.setStatus(
652652
peerProtocolVersion, networkId, totalDifficulty, latestHash, genesisHash);
653653
setIdle(_peerID);
654-
m_peerObserver->onPeerStatus(peer);
654+
m_peerObserver->onPeerStatus(remotePeer);
655655
break;
656656
}
657657
case TransactionsPacket:
@@ -691,7 +691,7 @@ bool EthereumCapability::interpretCapabilityPacket(
691691
}
692692
case BlockHeadersPacket:
693693
{
694-
if (peer.asking() != Asking::BlockHeaders)
694+
if (remotePeer.asking() != Asking::BlockHeaders)
695695
LOG(m_loggerImpolite) << "Peer " << _peerID
696696
<< " giving us block headers when we didn't ask for them.";
697697
else
@@ -724,7 +724,7 @@ bool EthereumCapability::interpretCapabilityPacket(
724724
}
725725
case BlockBodiesPacket:
726726
{
727-
if (peer.asking() != Asking::BlockBodies)
727+
if (remotePeer.asking() != Asking::BlockBodies)
728728
LOG(m_loggerImpolite)
729729
<< "Peer " << _peerID << " giving us block bodies when we didn't ask for them.";
730730
else
@@ -803,7 +803,7 @@ bool EthereumCapability::interpretCapabilityPacket(
803803
}
804804
case NodeDataPacket:
805805
{
806-
if (peer.asking() != Asking::NodeData)
806+
if (remotePeer.asking() != Asking::NodeData)
807807
LOG(m_loggerImpolite)
808808
<< "Peer " << _peerID << " giving us node data when we didn't ask for them.";
809809
else
@@ -815,7 +815,7 @@ bool EthereumCapability::interpretCapabilityPacket(
815815
}
816816
case ReceiptsPacket:
817817
{
818-
if (peer.asking() != Asking::Receipts)
818+
if (remotePeer.asking() != Asking::Receipts)
819819
LOG(m_loggerImpolite)
820820
<< "Peer " << _peerID << " giving us receipts when we didn't ask for them.";
821821
else

libethereum/EthereumPeer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace eth
1717
class EthereumPeer
1818
{
1919
public:
20-
EthereumPeer() = default;
20+
EthereumPeer() = delete;
2121
EthereumPeer(std::shared_ptr<p2p::CapabilityHostFace> _host, NodeID const& _peerID,
2222
u256 const& /*_capabilityVersion*/)
2323
: m_host(std::move(_host)), m_id(_peerID)

0 commit comments

Comments
 (0)