diff --git a/uspv/eight333.go b/uspv/eight333.go index eb2bbd85..26dd0a96 100644 --- a/uspv/eight333.go +++ b/uspv/eight333.go @@ -138,7 +138,7 @@ func OpenSPV(remoteNode string, hfn, tsfn string, go s.outgoingMessageHandler() s.mBlockQueue = make(chan HashAndHeight, 32) // queue depth 32 is a thing s.fPositives = make(chan int32, 4000) // a block full, approx - s.inWaitState = make(chan bool) + s.inWaitState = make(chan bool, 1) go s.fPositiveHandler() return s, nil @@ -308,7 +308,18 @@ func (s *SPVCon) IngestMerkleBlock(m *wire.MsgMerkleBlock) error { if err != nil { return err } - hah := <-s.mBlockQueue // pop height off mblock queue + var hah HashAndHeight + select { + case hah = <-s.mBlockQueue: // pop height off mblock queue + // not super comfortable with this but it seems to work. + if len(s.mBlockQueue) == 0 { // done and fully sync'd + s.inWaitState <- true + } + break + default: + return fmt.Errorf("Unrequested merkle block") + } + // this verifies order, and also that the returned header fits // into our SPV header file newMerkBlockSha := m.Header.BlockSha() @@ -328,10 +339,6 @@ func (s *SPVCon) IngestMerkleBlock(m *wire.MsgMerkleBlock) error { return err } - // not super comfortable with this but it seems to work. - if len(s.mBlockQueue) == 0 { // done and fully sync'd - s.inWaitState <- true - } return nil } diff --git a/uspv/msghandler.go b/uspv/msghandler.go index 8c6ecfbe..5b648e0a 100644 --- a/uspv/msghandler.go +++ b/uspv/msghandler.go @@ -148,8 +148,8 @@ func (s *SPVCon) TxHandler(m *wire.MsgTx) { m.TxSha().String()) s.fPositives <- 1 // add one false positive to chan } else { - log.Printf("tx %s ingested and matches utxo/adrs. sum %d", - m.TxSha().String(), s.TS.Sum) + log.Printf("tx %s ingested and matches %d utxo/adrs.", + m.TxSha().String(), hits) } } @@ -167,10 +167,13 @@ func (s *SPVCon) InvHandler(m *wire.MsgInv) { case <-s.inWaitState: // start getting headers fmt.Printf("asking for headers due to inv block\n") - s.AskForHeaders() + err := s.AskForHeaders() + if err != nil { + log.Printf("AskForHeaders error: %s", err.Error()) + } default: // drop it as if its component particles had high thermal energies - fmt.Printf("inv block but ignoring, not synched\n") + fmt.Printf("inv block but ignoring; not synched\n") } } } diff --git a/uspv/txstore.go b/uspv/txstore.go index 5937bc85..505586ff 100644 --- a/uspv/txstore.go +++ b/uspv/txstore.go @@ -18,7 +18,6 @@ import ( type TxStore struct { OKTxids map[wire.ShaHash]int32 // known good txids and their heights - Sum int64 // racks on racks Adrs []MyAdr // endeavouring to acquire capital StateDB *bolt.DB // place to write all this down // this is redundant with the SPVCon param... ugly and should be taken out diff --git a/uspv/utxodb.go b/uspv/utxodb.go index 07f3ee82..28475470 100644 --- a/uspv/utxodb.go +++ b/uspv/utxodb.go @@ -289,7 +289,6 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx) (uint32, error) { return hits, err } nUtxoBytes = append(nUtxoBytes, b) - ts.Sum += newu.Value hits++ break // only one match } @@ -318,7 +317,6 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx) (uint32, error) { if err != nil { return err } - ts.Sum -= lostTxo.Value hits++ // then delete the utxo from duf, save to old err = duf.Delete(k)