was requesting an already known block, fixed that

This commit is contained in:
Tadge Dryja 2016-02-26 12:30:15 -08:00
parent d2d37ce1ab
commit 623d67234d
2 changed files with 8 additions and 8 deletions

@ -349,7 +349,7 @@ func (s *SPVCon) AskForBlocks() error {
return nil return nil
} }
fmt.Printf("will request blocks %d to %d\n", dbTip, headerTip) fmt.Printf("will request blocks %d to %d\n", dbTip+1, headerTip)
if !s.HardMode { // don't send this in hardmode! that's the whole point if !s.HardMode { // don't send this in hardmode! that's the whole point
// create initial filter // create initial filter
@ -362,9 +362,10 @@ func (s *SPVCon) AskForBlocks() error {
fmt.Printf("sent filter %x\n", filt.MsgFilterLoad().Filter) fmt.Printf("sent filter %x\n", filt.MsgFilterLoad().Filter)
} }
// loop through all heights where we want merkleblocks. // loop through all heights where we want merkleblocks.
for dbTip <= headerTip { for dbTip < headerTip {
// load header from file dbTip++ // we're requesting the next header
// load header from file
s.headerMutex.Lock() // seek to header we need s.headerMutex.Lock() // seek to header we need
_, err = s.headerFile.Seek(int64((dbTip)*80), os.SEEK_SET) _, err = s.headerFile.Seek(int64((dbTip)*80), os.SEEK_SET)
if err != nil { if err != nil {
@ -392,6 +393,7 @@ func (s *SPVCon) AskForBlocks() error {
if err != nil { if err != nil {
return err return err
} }
hah := NewRootAndHeight(hdr.BlockSha(), dbTip) hah := NewRootAndHeight(hdr.BlockSha(), dbTip)
if dbTip == headerTip { // if this is the last block, indicate finality if dbTip == headerTip { // if this is the last block, indicate finality
hah.final = true hah.final = true
@ -399,8 +401,6 @@ func (s *SPVCon) AskForBlocks() error {
// waits here most of the time for the queue to empty out // waits here most of the time for the queue to empty out
s.blockQueue <- hah // push height and mroot of requested block on queue s.blockQueue <- hah // push height and mroot of requested block on queue
s.outMsgQueue <- gdataMsg s.outMsgQueue <- gdataMsg
dbTip++
} }
return nil return nil
} }

@ -179,7 +179,7 @@ func (s *SPVCon) IngestBlock(m *wire.MsgBlock) {
// iterate through all txs in the block, looking for matches. // iterate through all txs in the block, looking for matches.
// use a local bloom filter to ignore txs that don't affect us // use a local bloom filter to ignore txs that don't affect us
for i, tx := range m.Transactions { for _, tx := range m.Transactions {
utilTx := btcutil.NewTx(tx) utilTx := btcutil.NewTx(tx)
if s.TS.localFilter.MatchTxAndUpdate(utilTx) { if s.TS.localFilter.MatchTxAndUpdate(utilTx) {
hits, err := s.TS.Ingest(tx, hah.height) hits, err := s.TS.Ingest(tx, hah.height)
@ -188,8 +188,8 @@ func (s *SPVCon) IngestBlock(m *wire.MsgBlock) {
return return
} }
if hits > 0 { if hits > 0 {
log.Printf("block %d tx %d %s ingested and matches %d utxo/adrs.", // log.Printf("block %d tx %d %s ingested and matches %d utxo/adrs.",
hah.height, i, tx.TxSha().String(), hits) // hah.height, i, tx.TxSha().String(), hits)
} else { } else {
fPositive++ // matched filter but no hits fPositive++ // matched filter but no hits
} }