Skip to content

Commit

Permalink
[wip] temp fix for timeout on getblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ihavenoface committed May 5, 2023
1 parent 34e4674 commit 79eefe7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 1 addition & 5 deletions blockchain/ppc.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ func (b *BlockChain) getLastBlockIndex(pindex *blockNode, fProofOfStake bool) (b
}

func (b *BlockChain) GetLastBlockIndex(hash *chainhash.Hash, fProofOfStake bool) chainhash.Hash {
pindex := b.index.LookupNode(hash)
for pindex != nil && pindex.parent != nil && pindex.isProofOfStake() != fProofOfStake {
pindex = pindex.parent
}
return pindex.hash
return b.getLastBlockIndex(b.index.LookupNode(hash), fProofOfStake).hash
}

// calcNextRequiredDifficulty calculates the required difficulty for the block
Expand Down
10 changes: 10 additions & 0 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,11 @@ func (p *Peer) PushAddrV2Msg(addrs []*wire.NetAddressV2) (
//
// This function is safe for concurrent access.
func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chainhash.Hash) error {
// todo ppc this gets rid of the forced timeout -> dc when requesting blocks because otherwise we'd just be ignored
// it's not clear to me just yet if we should be sending getblocks in the first place
if len(locator) > 0 {
locator = locator[1:]
}
// Extract the begin hash from the block locator, if one was specified,
// to use for filtering duplicate getblocks requests.
var beginHash *chainhash.Hash
Expand All @@ -931,6 +936,8 @@ func (p *Peer) PushGetBlocksMsg(locator blockchain.BlockLocator, stopHash *chain
}

// Construct the getblocks request and queue it to be sent.
// todo ppc this is producing something the endpoint can't or wont handle at the moment
// which in turn causes the message to stall
msg := wire.NewMsgGetBlocks(stopHash)
for _, hash := range locator {
err := msg.AddBlockLocatorHash(hash)
Expand Down Expand Up @@ -1211,7 +1218,9 @@ func (p *Peer) maybeAddDeadline(pendingResponses map[string]time.Time, msgCmd st

case wire.CmdGetBlocks:
// Expects an inv message.
// todo ppc we appear to be missing some info so we could just udp these until fixed
pendingResponses[wire.CmdInv] = deadline
log.Debugf("%s, %v", msgCmd, deadline)

case wire.CmdGetData:
// Expects a block, merkleblock, tx, or notfound message.
Expand Down Expand Up @@ -1344,6 +1353,7 @@ out:
continue
}

log.Debugf("%s, %v", command, deadline)
log.Debugf("Peer %s appears to be stalled or "+
"misbehaving, %s timeout -- "+
"disconnecting", p, command)
Expand Down
11 changes: 6 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,7 @@ func (sp *serverPeer) OnGetBlocks(_ *peer.Peer, msg *wire.MsgGetBlocks) {
// is not a reference into the inventory slice which
// would prevent the entire slice from being eligible
// for GC as soon as it's sent.
// peercoin: send latest proof-of-work block to allow the
// download node to accept as orphan (proof-of-stake
// block might be rejected by stake connection check)
continueHash := chain.GetLastBlockIndex(&invMsg.InvList[invListLen-1].Hash, false)
continueHash := invMsg.InvList[invListLen-1].Hash
sp.continueHash = &continueHash
}
sp.QueueMessage(invMsg, nil)
Expand Down Expand Up @@ -1616,10 +1613,14 @@ func (s *server) pushBlockMsg(sp *serverPeer, hash *chainhash.Hash, doneChan cha
// would fit into a single message, send it a new inventory message
// to trigger it to issue another getblocks message for the next
// batch of inventory.
// peercoin: send latest proof-of-work block to allow the
// download node to accept as orphan (proof-of-stake
// block might be rejected by stake connection check)
if sendInv {
best := sp.server.chain.BestSnapshot()
bestHash := sp.server.chain.GetLastBlockIndex(&best.Hash, false)
invMsg := wire.NewMsgInvSizeHint(1)
iv := wire.NewInvVect(wire.InvTypeBlock, &best.Hash)
iv := wire.NewInvVect(wire.InvTypeBlock, &bestHash)
invMsg.AddInvVect(iv)
sp.QueueMessage(invMsg, doneChan)
sp.continueHash = nil
Expand Down

0 comments on commit 79eefe7

Please sign in to comment.