From 79eefe7211709f0fb5f3601f643cf574f35fb9bf Mon Sep 17 00:00:00 2001 From: noface Date: Fri, 5 May 2023 06:12:31 +0200 Subject: [PATCH] [wip] temp fix for timeout on getblocks --- blockchain/ppc.go | 6 +----- peer/peer.go | 10 ++++++++++ server.go | 11 ++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/blockchain/ppc.go b/blockchain/ppc.go index f2a49a3136f..000f18368dc 100644 --- a/blockchain/ppc.go +++ b/blockchain/ppc.go @@ -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 diff --git a/peer/peer.go b/peer/peer.go index 09cbfabedf8..f4307e870ee 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -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 @@ -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) @@ -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. @@ -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) diff --git a/server.go b/server.go index c1d6f2f44f5..e3fef4191df 100644 --- a/server.go +++ b/server.go @@ -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) @@ -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