From 830829a79f398ecfbec72f85fe5c879c02ad3da4 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 23 Jan 2014 12:34:41 -0500 Subject: [PATCH] Add dirty wallets to disc sync schedule. There were several places where various account files (wallet, tx, or utxo stores) were being marked as dirty, and then not being either immediately synced to disk or marked as a dirty account so they would be scheduled to be synced to disk. This change adds Account functions to mark as dirty and add the account to the map of scheduled accounts so they won't be missed by the disk syncer goroutine. --- account.go | 33 +++++++++++++++++++++++++++++++++ accountstore.go | 7 ++----- btcdrpc.go | 4 ++-- 3 files changed, 37 insertions(+), 7 deletions(-) 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