Skip to content

Commit

Permalink
Improve wallet atomicity. (#339)
Browse files Browse the repository at this point in the history
This is a step towards completing #315.

This changes the database access APIs and each of the "manager"
packages (waddrmgr/wtxmgr/wstakemgr) so that transactions are
opened (only) by the wallet package and the namespace buckets
that each manager expects to operate on are passed in as
parameters.

This helps improve the atomicity situation as it means that many
calls to these APIs can be grouped together into a single
database transaction.

This change does not attempt to completely fix
the "half-processed" block problem. Mined transactions are still
added to the wallet database under their own database transaction
as this is how they are notified by the consensus JSON-RPC
server (as loose transactions, without the rest of the block that
contains them). It will make updating to a fixed notification
model significantly easier, as the same "manager" APIs can still
be used, but grouped into a single atomic transaction.
  • Loading branch information
jrick committed Sep 30, 2016
1 parent 867b3bb commit db64418
Show file tree
Hide file tree
Showing 36 changed files with 5,170 additions and 5,291 deletions.
26 changes: 0 additions & 26 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ type RPCClient struct {
dequeueVotingNotification chan interface{}
currentBlock chan *waddrmgr.BlockStamp

// Information for reorganization handling.
reorganizingLock sync.Mutex
reorganizeToHash chainhash.Hash
reorganizing bool

quit chan struct{}
wg sync.WaitGroup
started bool
Expand Down Expand Up @@ -68,8 +63,6 @@ func NewRPCClient(chainParams *chaincfg.Params, connect, user, pass string, cert
DisableConnectOnNew: true,
DisableTLS: disableTLS,
},
reorganizeToHash: chainhash.Hash{},
reorganizing: false,
chainParams: chainParams,
reconnectAttempts: reconnectAttempts,
enqueueNotification: make(chan interface{}),
Expand Down Expand Up @@ -229,25 +222,6 @@ type (
}
)

// SetReorganizingState allows you to set the flag for blockchain
// reorganization.
func (c *RPCClient) SetReorganizingState(is bool, hash chainhash.Hash) {
c.reorganizingLock.Lock()
defer c.reorganizingLock.Unlock()

c.reorganizing = is
c.reorganizeToHash = hash
}

// GetReorganizing allows you to get the value of the flag for blockchain
// reorganization.
func (c *RPCClient) GetReorganizing() (bool, chainhash.Hash) {
c.reorganizingLock.Lock()
defer c.reorganizingLock.Unlock()

return c.reorganizing, c.reorganizeToHash
}

// Notifications returns a channel of parsed notifications sent by the remote
// decred RPC server. This channel must be continually read or the process
// may abort for running out memory, as unread notifications are queued for
Expand Down
4 changes: 3 additions & 1 deletion cmd/dropwtxmgr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func mainInt() int {
}
defer db.Close()
fmt.Println("Dropping wtxmgr namespace")
err = db.DeleteNamespace(wtxmgrNamespace)
err = walletdb.Update(db, func(tx walletdb.ReadWriteTx) error {
return tx.DeleteTopLevelBucket(wtxmgrNamespace)
})
if err != nil && err != walletdb.ErrBucketNotFound {
fmt.Println("Failed to drop namespace:", err)
return 1
Expand Down
2 changes: 1 addition & 1 deletion goclean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -ex
# Automatic checks
test -z "$(go fmt $(glide novendor) | tee /dev/stderr)"
# test -z "$(goimports -l -w . | tee /dev/stderr)"
test -z "$(for package in $(glide novendor); do golint $package; done | grep -v 'ALL_CAPS\|OP_\|NewFieldVal\|RpcCommand\|RpcRawCommand\|RpcSend\|Dns\|api.pb.go\|StartConsensusRpc\|factory_test.go\|legacy' | tee /dev/stderr)"
test -z "$(for package in $(glide novendor); do golint $package; done | grep -v 'ALL_CAPS\|OP_\|NewFieldVal\|RpcCommand\|RpcRawCommand\|RpcSend\|Dns\|api.pb.go\|StartConsensusRpc\|factory_test.go\|legacy\|UnstableAPI' | tee /dev/stderr)"
test -z "$(go vet $(glide novendor) 2>&1 | grep -v '^exit status \|Example\|newestSha\| not a string in call to Errorf$' | tee /dev/stderr)"
############RE-ENABLE THIS WHEN TESTS ARE FIXED!!!!!!!!!!!###############
#env GORACE="halt_on_error=1" go test -v -race $(glide novendor)
Expand Down
Loading

0 comments on commit db64418

Please sign in to comment.