db optimizations
This commit is contained in:
parent
f9a740d392
commit
caf56aaff0
@ -141,22 +141,22 @@ func (s *SPVCon) TxHandler(m *wire.MsgTx) {
|
||||
}
|
||||
|
||||
// check for double spends
|
||||
allTxs, err := s.TS.GetAllTxs()
|
||||
if err != nil {
|
||||
log.Printf("Can't get txs from db: %s", err.Error())
|
||||
return
|
||||
}
|
||||
dubs, err := CheckDoubleSpends(m, allTxs)
|
||||
if err != nil {
|
||||
log.Printf("CheckDoubleSpends error: %s", err.Error())
|
||||
return
|
||||
}
|
||||
if len(dubs) > 0 {
|
||||
for i, dub := range dubs {
|
||||
fmt.Printf("dub %d known tx %s and new tx %s are exclusive!!!\n",
|
||||
i, dub.String(), m.TxSha().String())
|
||||
}
|
||||
}
|
||||
// allTxs, err := s.TS.GetAllTxs()
|
||||
// if err != nil {
|
||||
// log.Printf("Can't get txs from db: %s", err.Error())
|
||||
// return
|
||||
// }
|
||||
// dubs, err := CheckDoubleSpends(m, allTxs)
|
||||
// if err != nil {
|
||||
// log.Printf("CheckDoubleSpends error: %s", err.Error())
|
||||
// return
|
||||
// }
|
||||
// if len(dubs) > 0 {
|
||||
// for i, dub := range dubs {
|
||||
// fmt.Printf("dub %d known tx %s and new tx %s are exclusive!!!\n",
|
||||
// i, dub.String(), m.TxSha().String())
|
||||
// }
|
||||
// }
|
||||
hits, err := s.TS.Ingest(m, height)
|
||||
if err != nil {
|
||||
log.Printf("Incoming Tx error: %s\n", err.Error())
|
||||
|
@ -76,10 +76,10 @@ func (s SortableUtxoSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// height 0 means your lesser
|
||||
func (s SortableUtxoSlice) Less(i, j int) bool {
|
||||
if s[i].AtHeight == 0 {
|
||||
if s[i].AtHeight == 0 && s[j].AtHeight > 0 {
|
||||
return true
|
||||
}
|
||||
if s[j].AtHeight == 0 {
|
||||
if s[j].AtHeight == 0 && s[i].AtHeight > 0 {
|
||||
return false
|
||||
}
|
||||
return s[i].Value < s[j].Value
|
||||
|
@ -380,11 +380,11 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error) {
|
||||
wPKscripts := make([][]byte, len(ts.Adrs))
|
||||
aPKscripts := make([][]byte, len(ts.Adrs))
|
||||
|
||||
for i, adr := range ts.Adrs {
|
||||
for i, _ := range ts.Adrs {
|
||||
// iterate through all our addresses
|
||||
// convert regular address to witness address. (split adrs later)
|
||||
wa, err := btcutil.NewAddressWitnessPubKeyHash(
|
||||
adr.PkhAdr.ScriptAddress(), ts.Param)
|
||||
ts.Adrs[i].PkhAdr.ScriptAddress(), ts.Param)
|
||||
if err != nil {
|
||||
return hits, err
|
||||
}
|
||||
@ -393,7 +393,7 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error) {
|
||||
if err != nil {
|
||||
return hits, err
|
||||
}
|
||||
aPKscripts[i], err = txscript.PayToAddrScript(adr.PkhAdr)
|
||||
aPKscripts[i], err = txscript.PayToAddrScript(ts.Adrs[i].PkhAdr)
|
||||
if err != nil {
|
||||
return hits, err
|
||||
}
|
||||
@ -440,10 +440,8 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error) {
|
||||
return fmt.Errorf("error: db not initialized")
|
||||
}
|
||||
|
||||
// first see if we lose utxos
|
||||
// iterate through duffel bag and look for matches
|
||||
// this makes us lose money, which is regrettable, but we need to know.
|
||||
// var delOPs [][]byte
|
||||
for _, nOP := range spentOPs {
|
||||
v := duf.Get(nOP)
|
||||
if v != nil {
|
||||
@ -478,18 +476,20 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// stash for deletion
|
||||
// delOPs = append(delOPs, nOP)
|
||||
err = duf.Delete(nOP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//delete everything even if it doesn't exist!
|
||||
for _, dOP := range spentOPs {
|
||||
err = duf.Delete(dOP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// for _, dOP := range spentOPs {
|
||||
// err = duf.Delete(dOP)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// }
|
||||
// done losing utxos, next gain utxos
|
||||
// next add all new utxos to db, this is quick as the work is above
|
||||
for _, ub := range nUtxoBytes {
|
||||
|
Loading…
Reference in New Issue
Block a user