Skip to content

Commit

Permalink
cmd: gracefully close stores on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Jan 10, 2024
1 parent 5b9ee6a commit 442e7c8
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions cmd/walletd/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,23 @@ func (db *boltDB) Close() error {
}

type node struct {
cm *chain.Manager
s *syncer.Syncer
wm *wallet.Manager
chainStore *boltDB
cm *chain.Manager

s *syncer.Syncer

walletStore *sqlite.Store
wm *wallet.Manager

Start func() (stop func())
}

// Close shuts down the node and closes its database.
func (n *node) Close() error {
n.chainStore.Close()
return n.walletStore.Close()
}

func newNode(addr, dir string, chainNetwork string, useUPNP bool, log *zap.Logger) (*node, error) {
var network *consensus.Network
var genesisBlock types.Block
Expand Down Expand Up @@ -215,9 +225,11 @@ func newNode(addr, dir string, chainNetwork string, useUPNP bool, log *zap.Logge
}

return &node{
cm: cm,
s: s,
wm: wm,
chainStore: db,
cm: cm,
s: s,
walletStore: walletDB,
wm: wm,
Start: func() func() {
ch := make(chan struct{})
go func() {
Expand Down

0 comments on commit 442e7c8

Please sign in to comment.