Rescan works and tests pass.
This commit is contained in:
parent
bebe29012e
commit
e7bae84662
2 changed files with 25 additions and 9 deletions
|
@ -292,6 +292,9 @@ func (s *ChainService) GetCFilter(blockHash chainhash.Hash,
|
||||||
if err == nil && filter != nil {
|
if err == nil && filter != nil {
|
||||||
return filter
|
return filter
|
||||||
}
|
}
|
||||||
|
// We didn't get the filter from the DB, so we'll set it to nil and try
|
||||||
|
// to get it from the network.
|
||||||
|
filter = nil
|
||||||
block, _, err := s.GetBlockByHash(blockHash)
|
block, _, err := s.GetBlockByHash(blockHash)
|
||||||
if err != nil || block.BlockHash() != blockHash {
|
if err != nil || block.BlockHash() != blockHash {
|
||||||
return nil
|
return nil
|
||||||
|
@ -314,6 +317,12 @@ func (s *ChainService) GetCFilter(blockHash chainhash.Hash,
|
||||||
switch response := resp.(type) {
|
switch response := resp.(type) {
|
||||||
// We're only interested in "cfilter" messages.
|
// We're only interested in "cfilter" messages.
|
||||||
case *wire.MsgCFilter:
|
case *wire.MsgCFilter:
|
||||||
|
// Only keep this going if we haven't already
|
||||||
|
// found a filter, or we risk closing an already
|
||||||
|
// closed channel.
|
||||||
|
if filter != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
if len(response.Data) < 4 {
|
if len(response.Data) < 4 {
|
||||||
// Filter data is too short.
|
// Filter data is too short.
|
||||||
// Ignore this message.
|
// Ignore this message.
|
||||||
|
@ -324,17 +333,15 @@ func (s *ChainService) GetCFilter(blockHash chainhash.Hash,
|
||||||
// request. Ignore this message.
|
// request. Ignore this message.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gotFilter, err :=
|
gotFilter, err := gcs.FromNBytes(
|
||||||
gcs.FromNBytes(builder.DefaultP,
|
builder.DefaultP, response.Data)
|
||||||
response.Data)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Malformed filter data. We
|
// Malformed filter data. We
|
||||||
// can ignore this message.
|
// can ignore this message.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if builder.MakeHeaderForFilter(gotFilter,
|
if builder.MakeHeaderForFilter(gotFilter,
|
||||||
*prevHeader) !=
|
*prevHeader) != *curHeader {
|
||||||
*curHeader {
|
|
||||||
// Filter data doesn't match
|
// Filter data doesn't match
|
||||||
// the headers we know about.
|
// the headers we know about.
|
||||||
// Ignore this response.
|
// Ignore this response.
|
||||||
|
@ -386,9 +393,14 @@ func (s *ChainService) GetBlockFromNetwork(
|
||||||
switch response := resp.(type) {
|
switch response := resp.(type) {
|
||||||
// We're only interested in "block" messages.
|
// We're only interested in "block" messages.
|
||||||
case *wire.MsgBlock:
|
case *wire.MsgBlock:
|
||||||
|
// Only keep this going if we haven't already
|
||||||
|
// found a block, or we risk closing an already
|
||||||
|
// closed channel.
|
||||||
|
if foundBlock != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
// If this isn't our block, ignore it.
|
// If this isn't our block, ignore it.
|
||||||
if response.BlockHash() !=
|
if response.BlockHash() != blockHash {
|
||||||
blockHash {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
block := btcutil.NewBlock(response)
|
block := btcutil.NewBlock(response)
|
||||||
|
@ -396,8 +408,7 @@ func (s *ChainService) GetBlockFromNetwork(
|
||||||
// automagically put one in.
|
// automagically put one in.
|
||||||
if block.Height() ==
|
if block.Height() ==
|
||||||
btcutil.BlockHeightUnknown {
|
btcutil.BlockHeightUnknown {
|
||||||
block.SetHeight(
|
block.SetHeight(int32(height))
|
||||||
int32(height))
|
|
||||||
}
|
}
|
||||||
// If this claims our block but doesn't
|
// If this claims our block but doesn't
|
||||||
// pass the sanity check, the peer is
|
// pass the sanity check, the peer is
|
||||||
|
|
|
@ -32,6 +32,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Try btclog.InfoLvl for output like you'd see in normal operation, or
|
||||||
|
// btclog.TraceLvl to help debug code. Anything but btclog.Off turns on
|
||||||
|
// log messages from the tests themselves as well. Keep in mind some
|
||||||
|
// log messages may not appear in order due to use of multiple query
|
||||||
|
// goroutines in the tests.
|
||||||
logLevel = btclog.Off
|
logLevel = btclog.Off
|
||||||
syncTimeout = 30 * time.Second
|
syncTimeout = 30 * time.Second
|
||||||
syncUpdate = time.Second
|
syncUpdate = time.Second
|
||||||
|
|
Loading…
Reference in a new issue