diff --git a/account.go b/account.go index 23fea34..1b51609 100644 --- a/account.go +++ b/account.go @@ -84,6 +84,39 @@ type Account struct { } } +// MarkDirtyWallet marks an account's wallet as dirty, and adds the +// account to the list of dirty accounts to be schedule to be synced to +// disk. It is a runtime error to call this without holding the wallet +// writer lock. +func (a *Account) MarkDirtyWallet() { + a.dirty = true + dirtyAccounts.Lock() + dirtyAccounts.m[a] = true + dirtyAccounts.Unlock() +} + +// MarkDirtyUtxoStore marks an account's utxo store as dirty, and adds +// the account to the list of dirty accounts to be schedule to be synced to +// disk. It is a runtime error to call this without holding the utxo store +// writer lock. +func (a *Account) MarkDirtyUtxoStore() { + a.UtxoStore.dirty = true + dirtyAccounts.Lock() + dirtyAccounts.m[a] = true + dirtyAccounts.Unlock() +} + +// MarkDirtyTxStore marks an account's tx store as dirty, and adds the +// account to the list of dirty accounts to be schedule to be synced to +// disk. It is a runtime error to call this without holding the tx store +// writer lock. +func (a *Account) MarkDirtyTxStore() { + a.TxStore.dirty = true + dirtyAccounts.Lock() + dirtyAccounts.m[a] = true + dirtyAccounts.Unlock() +} + // Lock locks the underlying wallet for an account. func (a *Account) Lock() error { a.mtx.Lock() diff --git a/accountstore.go b/accountstore.go index 4937535..6584025 100644 --- a/accountstore.go +++ b/accountstore.go @@ -112,11 +112,8 @@ func (store *AccountStore) BlockNotify(bs *wallet.BlockStamp) { // next scheduled disk sync. a.mtx.Lock() a.Wallet.SetSyncedWith(bs) - a.dirty = true + a.MarkDirtyWallet() a.mtx.Unlock() - dirtyAccounts.Lock() - dirtyAccounts.m[a] = true - dirtyAccounts.Unlock() } } @@ -146,7 +143,7 @@ func (store *AccountStore) RecordMinedTx(txid *btcwire.ShaHash, sendtx.BlockHeight = blkheight sendtx.BlockIndex = int32(blkindex) sendtx.BlockTime = blktime - account.TxStore.dirty = true + account.MarkDirtyTxStore() account.TxStore.Unlock() return nil } diff --git a/btcdrpc.go b/btcdrpc.go index 4ab5d29..563ce24 100644 --- a/btcdrpc.go +++ b/btcdrpc.go @@ -368,7 +368,7 @@ func NtfnProcessedTx(n btcjson.Cmd, marshaled []byte) { // Record the tx history. a.TxStore.Lock() a.TxStore.s.InsertRecvTx(t) - a.TxStore.dirty = true + a.MarkDirtyTxStore() a.TxStore.Unlock() // Notify frontends of tx. If the tx is unconfirmed, it is always @@ -404,7 +404,7 @@ func NtfnProcessedTx(n btcjson.Cmd, marshaled []byte) { copy(u.BlockHash[:], blockHash[:]) a.UtxoStore.Lock() a.UtxoStore.s.Insert(u) - a.UtxoStore.dirty = true + a.MarkDirtyUtxoStore() a.UtxoStore.Unlock() // If this notification came from mempool, notify frontends of