fix the boltdb problem

not that I know how I fixed it... just moved stuff around.
Oh, bolt.  Any time I see "})" I know I'm in bizzaro world.
This commit is contained in:
Tadge Dryja 2016-02-22 23:21:54 -08:00
parent dd1f2c00fe
commit a14b9a9e70

@ -439,21 +439,25 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error) {
// this makes us lose money, which is regrettable, but we need to know. // this makes us lose money, which is regrettable, but we need to know.
var delOPs [][]byte var delOPs [][]byte
fmt.Printf("%d nOP to iterate over\n", len(spentOPs)) // fmt.Printf("%d nOP to iterate over\n", len(spentOPs))
for _, nOP := range spentOPs { for _, nOP := range spentOPs {
duf.ForEach(func(k, v []byte) error { duf.ForEach(func(k, v []byte) error {
if bytes.Equal(k, nOP) { // matched, we lost utxo if bytes.Equal(k, nOP) { // matched, we lost utxo
fmt.Printf("will delete point %x\n", k)
hits++
// do all this just to figure out value we lost // do all this just to figure out value we lost
x := make([]byte, len(k)+len(v)) x := make([]byte, len(k)+len(v))
copy(x, k) copy(x, k)
// mark utxos for deletion y := make([]byte, len(k))
delOPs = append(delOPs, x) // mark utxo for deletion
copy(y, k)
delOPs = append(delOPs, y)
copy(x[len(k):], v) copy(x[len(k):], v)
lostTxo, err := UtxoFromBytes(x) lostTxo, err := UtxoFromBytes(x)
if err != nil { if err != nil {
return err return err
} }
hits++
// after marking for deletion, save stxo to old bucket // after marking for deletion, save stxo to old bucket
var st Stxo // generate spent txo var st Stxo // generate spent txo
@ -482,13 +486,15 @@ func (ts *TxStore) Ingest(tx *wire.MsgTx, height int32) (uint32, error) {
return nil // no match return nil // no match
}) })
// delete after done with foreach // delete after done with foreach
for _, k := range delOPs { }
err = duf.Delete(k) for _, y := range delOPs {
fmt.Printf("deleting outpoint %x\n", y)
err = duf.Delete(y)
if err != nil { if err != nil {
return err return err
} }
} }
} // done losing utxos, next gain utxos // done losing utxos, next gain utxos
// next add all new utxos to db, this is quick as the work is above // next add all new utxos to db, this is quick as the work is above
for _, ub := range nUtxoBytes { for _, ub := range nUtxoBytes {
err = duf.Put(ub[:36], ub[36:]) err = duf.Put(ub[:36], ub[36:])