Skip to content

Commit

Permalink
Various minor cleanups.
Browse files Browse the repository at this point in the history
- Updating and adding some copyrights which were missed recently.
- Slight improvements to some commenting and naming.
  • Loading branch information
jholdstock committed May 24, 2021
1 parent 20cb546 commit 7b7c8e1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
3 changes: 1 addition & 2 deletions database/database.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 The Decred developers
// Copyright (c) 2020-2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -120,7 +120,6 @@ func CreateNew(dbFile, feeXPub string) error {

defer db.Close()

// Create all storage buckets of the VSP if they don't already exist.
err = db.Update(func(tx *bolt.Tx) error {
// Create parent bucket.
vspBkt, err := tx.CreateBucket(vspBktK)
Expand Down
4 changes: 4 additions & 0 deletions database/upgrade_v2.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package database

import (
Expand Down
4 changes: 4 additions & 0 deletions database/upgrade_v3.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package database

import (
Expand Down
4 changes: 4 additions & 0 deletions database/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package database

import (
Expand Down
18 changes: 9 additions & 9 deletions database/votechange.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020 The Decred developers
// Copyright (c) 2020-2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -39,16 +39,16 @@ func (vdb *VspDatabase) SaveVoteChange(ticketHash string, record VoteChangeRecor
// Loop through the bucket to count the records, as well as finding the
// most recent and the oldest record.
var count int
highest := uint32(0)
lowest := uint32(math.MaxUint32)
newest := uint32(0)
oldest := uint32(math.MaxUint32)
err = bkt.ForEach(func(k, v []byte) error {
count++
key := bytesToUint32(k)
if key > highest {
highest = key
if key > newest {
newest = key
}
if key < lowest {
lowest = key
if key < oldest {
oldest = key
}
return nil
})
Expand All @@ -59,7 +59,7 @@ func (vdb *VspDatabase) SaveVoteChange(ticketHash string, record VoteChangeRecor
// If bucket is at (or over) the limit of max allowed records, remove
// the oldest one.
if count >= vdb.maxVoteChangeRecords {
err = bkt.Delete(uint32ToBytes(lowest))
err = bkt.Delete(uint32ToBytes(oldest))
if err != nil {
return fmt.Errorf("failed to delete old vote change record: %w", err)
}
Expand All @@ -69,7 +69,7 @@ func (vdb *VspDatabase) SaveVoteChange(ticketHash string, record VoteChangeRecor
// otherwise use most recent + 1.
var newKey uint32
if count > 0 {
newKey = highest + 1
newKey = newest + 1
}

// Insert record.
Expand Down
8 changes: 4 additions & 4 deletions webapi/getfeeaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
// addrMtx protects getNewFeeAddress.
var addrMtx sync.Mutex

// getNewFeeAddress gets a new address from the address generator and stores the
// new address index in the database. In order to maintain consistency between
// the internal counter of address generator and the database, this function
// cannot be run concurrently.
// getNewFeeAddress gets a new address from the address generator, and updates
// the last used address index in the database. In order to maintain consistency
// between the internal counter of address generator and the database, this func
// uses a mutex to ensure it is not run concurrently.
func getNewFeeAddress(db *database.VspDatabase, addrGen *addressGenerator) (string, uint32, error) {
addrMtx.Lock()
defer addrMtx.Unlock()
Expand Down

0 comments on commit 7b7c8e1

Please sign in to comment.