func (w *Wallet) threadedDBUpdate() {
	if err := w.tg.Add(); err != nil {
		return
	}
	defer w.tg.Done()
	for {
		select {
		case <-time.After(2 * time.Minute):
		case <-w.tg.StopChan():
			return
		}
		w.mu.Lock()
		err := w.syncDB()
		w.mu.Unlock()
		if err != nil {
			w.log.Severe("ERROR: syncDB encountered an error. Closing database to protect wallet. wallet may crash:", err)
			w.db.Close()
			return
		}
	}
}
threadedDBUpdate commits the active database transaction and starts a new
transaction.
package wallet
import (
	"encoding/binary"
	"fmt"
	"reflect"
	"time"
	"github.com/NebulousLabs/Sia/encoding"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/types"
	"github.com/NebulousLabs/errors"
	"github.com/NebulousLabs/fastrand"
	"github.com/coreos/bbolt"
)
var (
	bucketProcessedTransactions = []byte("bucketProcessedTransactions")
	bucketProcessedTxnIndex = []byte("bucketProcessedTxnKey")
	bucketAddrTransactions = []byte("bucketAddrTransactions")
	bucketSiacoinOutputs = []byte("bucketSiacoinOutputs")
	bucketSiafundOutputs = []byte("bucketSiafundOutputs")
	bucketSpentOutputs = []byte("bucketSpentOutputs")
	bucketWallet = []byte("bucketWallet")
	dbBuckets = [][]byte{
		bucketProcessedTransactions,
		bucketProcessedTxnIndex,
		bucketAddrTransactions,
		bucketSiacoinOutputs,
		bucketSiafundOutputs,
		bucketSpentOutputs,
		bucketWallet,
	}
	errNoKey = errors.New("key does not exist")
	keyAuxiliarySeedFiles     = []byte("keyAuxiliarySeedFiles")
	keyConsensusChange        = []byte("keyConsensusChange")
	keyConsensusHeight        = []byte("keyConsensusHeight")
	keyEncryptionVerification = []byte("keyEncryptionVerification")
	keyPrimarySeedFile        = []byte("keyPrimarySeedFile")
	keyPrimarySeedProgress    = []byte("keyPrimarySeedProgress")
	keySiafundPool            = []byte("keySiafundPool")
	keySpendableKeyFiles      = []byte("keySpendableKeyFiles")
	keyUID                    = []byte("keyUID")
)