fix sync, remove sum from TxStore
Synchronization now seems to work well even with the rapid fire many inv-block messages that I'm seeing often on testnet3. I'm not 100% sure measuring the len() of a buffered channel is safe but it seems to work fine. Got rid of 'sum' in the TxStore; can be computed from GetAllUtxos() Might want to merge SCon and TxStore since there's not much going on in TxStore any more...
This commit is contained in:
parent
a9cf239ec3
commit
2f9fc87636
@ -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
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user