Fixed some bugs. Still more to fix!
This commit is contained in:
parent
2b352c966d
commit
b42c527b1c
1 changed files with 23 additions and 18 deletions
|
@ -1006,7 +1006,7 @@ func (b *blockManager) handleHeadersMsg(hmsg *headersMsg) {
|
||||||
// that is already in the database and is only used to ensure
|
// that is already in the database and is only used to ensure
|
||||||
// the next header links properly, it must be removed before
|
// the next header links properly, it must be removed before
|
||||||
// fetching the blocks.
|
// fetching the blocks.
|
||||||
b.headerList.Remove(b.headerList.Front())
|
// b.headerList.Remove(b.headerList.Front())
|
||||||
//log.Infof("Received %v block headers: Fetching blocks",
|
//log.Infof("Received %v block headers: Fetching blocks",
|
||||||
// b.headerList.Len())
|
// b.headerList.Len())
|
||||||
//b.progressLogger.SetLastLogTime(time.Now())
|
//b.progressLogger.SetLastLogTime(time.Now())
|
||||||
|
@ -1069,6 +1069,23 @@ func (b *blockManager) QueueCFHeaders(cfheaders *wire.MsgCFHeaders,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ignore messages with 0 headers.
|
||||||
|
if len(cfheaders.HeaderHashes) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that the count is correct. This works even when the map lookup
|
||||||
|
// fails as it returns 0 in that case.
|
||||||
|
if sp.requestedCFHeaders[cfhRequest{
|
||||||
|
extended: cfheaders.Extended,
|
||||||
|
stopHash: cfheaders.StopHash,
|
||||||
|
}] != len(cfheaders.HeaderHashes) {
|
||||||
|
log.Warnf("Received cfheaders message doesn't match any "+
|
||||||
|
"getcfheaders request. Peer %s is probably on a "+
|
||||||
|
"different chain -- ignoring", sp.Addr())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Track number of pending cfheaders messsages for both basic and
|
// Track number of pending cfheaders messsages for both basic and
|
||||||
// extended filters.
|
// extended filters.
|
||||||
pendingMsgs := &b.numBasicCFHeadersMsgs
|
pendingMsgs := &b.numBasicCFHeadersMsgs
|
||||||
|
@ -1095,20 +1112,9 @@ func (b *blockManager) handleCFHeadersMsg(cfhmsg *cfheadersMsg) {
|
||||||
pendingMsgs = &b.numExtCFHeadersMsgs
|
pendingMsgs = &b.numExtCFHeadersMsgs
|
||||||
}
|
}
|
||||||
defer delete(cfhmsg.peer.requestedCFHeaders, req)
|
defer delete(cfhmsg.peer.requestedCFHeaders, req)
|
||||||
defer atomic.AddInt32(pendingMsgs, -1)
|
atomic.AddInt32(pendingMsgs, -1)
|
||||||
// Check that the count is correct. This works even when the map lookup
|
|
||||||
// fails as it returns 0 in that case.
|
|
||||||
headerList := cfhmsg.cfheaders.HeaderHashes
|
headerList := cfhmsg.cfheaders.HeaderHashes
|
||||||
respLen := len(headerList)
|
respLen := len(headerList)
|
||||||
if cfhmsg.peer.requestedCFHeaders[req] != respLen {
|
|
||||||
log.Warnf("Received cfheaders message doesn't match any "+
|
|
||||||
"getcfheaders request. Peer %s is probably on a "+
|
|
||||||
"different chain -- ignoring", cfhmsg.peer.Addr())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if respLen == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Find the block header matching the last filter header, if any.
|
// Find the block header matching the last filter header, if any.
|
||||||
el := b.headerList.Back()
|
el := b.headerList.Back()
|
||||||
for el != nil {
|
for el != nil {
|
||||||
|
@ -1132,6 +1138,7 @@ func (b *blockManager) handleCFHeadersMsg(cfhmsg *cfheadersMsg) {
|
||||||
hash = node.header.BlockHash()
|
hash = node.header.BlockHash()
|
||||||
b.mapMutex.Lock()
|
b.mapMutex.Lock()
|
||||||
if _, ok := headerMap[hash]; !ok {
|
if _, ok := headerMap[hash]; !ok {
|
||||||
|
b.mapMutex.Unlock()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Process this header and set up the next iteration.
|
// Process this header and set up the next iteration.
|
||||||
|
@ -1146,9 +1153,9 @@ func (b *blockManager) handleCFHeadersMsg(cfhmsg *cfheadersMsg) {
|
||||||
stopHash: req.stopHash,
|
stopHash: req.stopHash,
|
||||||
extended: req.extended,
|
extended: req.extended,
|
||||||
}
|
}
|
||||||
log.Tracef("Processed cfheaders starting at %s, ending at %s, from "+
|
log.Tracef("Processed cfheaders starting at %d(%s), ending at %s, from"+
|
||||||
"peer %s, extended: %t", node.header.BlockHash(), req.stopHash,
|
" peer %s, extended: %t", node.height, node.header.BlockHash(),
|
||||||
cfhmsg.peer.Addr(), req.extended)
|
req.stopHash, cfhmsg.peer.Addr(), req.extended)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleProcessCFHeadersMsg checks to see if we have enough cfheaders to make
|
// handleProcessCFHeadersMsg checks to see if we have enough cfheaders to make
|
||||||
|
@ -1196,8 +1203,6 @@ func (b *blockManager) handleProcessCFHeadersMsg(msg *processCFHeadersMsg) {
|
||||||
// iterate through all of those headers, looking for conflicts. If we
|
// iterate through all of those headers, looking for conflicts. If we
|
||||||
// find a conflict, we have to do additional checks; otherwise, we write
|
// find a conflict, we have to do additional checks; otherwise, we write
|
||||||
// the filter header to the database.
|
// the filter header to the database.
|
||||||
log.Tracef("Begin processing cfheaders messages starting at %d (%s)",
|
|
||||||
msg.earliestNode.height, msg.earliestNode.header.BlockHash())
|
|
||||||
el := b.headerList.Front()
|
el := b.headerList.Front()
|
||||||
for el != nil {
|
for el != nil {
|
||||||
node := el.Value.(*headerNode)
|
node := el.Value.(*headerNode)
|
||||||
|
|
Loading…
Reference in a new issue