Skip to content

Commit

Permalink
Revert bbolt database to version 1.
Browse files Browse the repository at this point in the history
This removes all bbolt database upgrades and reverts the database version to 1.
All associated tests and test databases are also removed. I have left the
upgrade framework and the testing framework in place so as not to lose the baby
with the bathwater.

To support this change, I'd like to propose we label the next dcrpool release
2.0.0.
  • Loading branch information
jholdstock authored Sep 26, 2023
1 parent da7ead1 commit 3e5f073
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 1,245 deletions.
594 changes: 5 additions & 589 deletions pool/boltupgrades.go

Large diffs are not rendered by default.

253 changes: 1 addition & 252 deletions pool/boltupgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,20 @@
package pool

import (
"bytes"
"compress/gzip"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"

bolt "go.etcd.io/bbolt"
)

var boltDBUpgradeTests = [...]struct {
verify func(*testing.T, *BoltDB)
filename string // in testdata directory
}{
// No upgrade test for V1, it is a backwards-compatible upgrade
{verifyV2Upgrade, "v1.db.gz"},
{verifyV3Upgrade, "v2.db.gz"},
{verifyV4Upgrade, "v2.db.gz"},
{verifyV5Upgrade, "v4.db.gz"},
{verifyV6Upgrade, "v5.db.gz"},
// No upgrade test for V6, it is a backwards-compatible upgrade
// Add tests here when a database upgrade is necessary.
}

func TestBoltDBUpgrades(t *testing.T) {
Expand Down Expand Up @@ -84,242 +72,3 @@ func TestBoltDBUpgrades(t *testing.T) {
}
})
}

func verifyV2Upgrade(t *testing.T, db *BoltDB) {
const funcName = "verifyV2Upgrade"
err := db.DB.View(func(tx *bolt.Tx) error {
pbkt := tx.Bucket(poolBkt)
if pbkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(poolBkt))
}

sbkt := pbkt.Bucket(shareBkt)
if sbkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(shareBkt))
}

c := sbkt.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var share Share
err := json.Unmarshal(v, &share)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal share: %w",
funcName, err)
}

if string(k) != share.UUID {
return fmt.Errorf("%s: expected share id (%s) to be the same as "+
"its key (%x)", funcName, share.UUID, k)
}
}
return nil
})
if err != nil {
t.Error(err)
}
}

func verifyV3Upgrade(t *testing.T, db *BoltDB) {
const funcName = "verifyV3Upgrade"
err := db.DB.View(func(tx *bolt.Tx) error {
pbkt := tx.Bucket(poolBkt)
if pbkt == nil {
return fmt.Errorf("%s: bucket %s not found",
funcName, string(poolBkt))
}

sbkt := pbkt.Bucket(paymentBkt)
if sbkt == nil {
return fmt.Errorf("%s: bucket %s not found",
funcName, string(paymentBkt))
}

c := sbkt.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var payment Payment
err := json.Unmarshal(v, &payment)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal payment: %w",
funcName, err)
}

id := paymentID(payment.Height, payment.CreatedOn, payment.Account)
if !bytes.Equal(k, []byte(id)) {
return fmt.Errorf("%s: expected payment id (%s) to be "+
"the same as its key (%x)", funcName, id, k)
}

if payment.Source == nil {
return fmt.Errorf("%s: expected a non-nil payment source",
funcName)
}
}

abkt := pbkt.Bucket(paymentArchiveBkt)
if sbkt == nil {
return fmt.Errorf("%s: bucket %s not found",
funcName, string(paymentArchiveBkt))
}

c = abkt.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var payment Payment
err := json.Unmarshal(v, &payment)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal payment: %w",
funcName, err)
}

id := paymentID(payment.Height, payment.CreatedOn, payment.Account)
if !bytes.Equal(k, []byte(id)) {
return fmt.Errorf("%s: expected archived payment id "+
"(%s) to be the same as its key (%x)", funcName, id, k)
}

if payment.Source == nil {
return fmt.Errorf("%s: expected a non-nil payment source",
funcName)
}
}
return nil
})
if err != nil {
t.Error(err)
}
}

func verifyV4Upgrade(t *testing.T, db *BoltDB) {
const funcName = "verifyV4Upgrade"
err := db.DB.View(func(tx *bolt.Tx) error {
pbkt := tx.Bucket(poolBkt)
if pbkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(poolBkt))
}

v := pbkt.Get([]byte("txfeereserve"))
if v != nil {
return fmt.Errorf("%s: unexpected value found for "+
"txfeereserve", funcName)
}
return nil
})
if err != nil {
t.Error(err)
}
}

func verifyV5Upgrade(t *testing.T, db *BoltDB) {
const funcName = "verifyV5Upgrade"
err := db.DB.View(func(tx *bolt.Tx) error {
pbkt := tx.Bucket(poolBkt)
if pbkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(poolBkt))
}

sbkt := pbkt.Bucket(shareBkt)
if sbkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(shareBkt))
}

c := sbkt.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var share Share
err := json.Unmarshal(v, &share)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal share: %w",
funcName, err)
}

if share.CreatedOn == 0 {
return fmt.Errorf("%s: the created on "+
"value for %s is not set", funcName, share.UUID)
}

createdOnHex := hex.EncodeToString(nanoToBigEndianBytes(
share.CreatedOn))

if string(k[:16]) != createdOnHex {
return fmt.Errorf("%s: created on hex (%s) does not match "+
"the extracted value from key (%x)", funcName,
createdOnHex, k[:16])
}
}
return nil
})
if err != nil {
t.Error(err)
}
}

func verifyV6Upgrade(t *testing.T, db *BoltDB) {
const funcName = "verifyV6Upgrade"
err := db.DB.View(func(tx *bolt.Tx) error {
pbkt := tx.Bucket(poolBkt)
if pbkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(poolBkt))
}

pmtbkt := pbkt.Bucket(paymentBkt)
if pmtbkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(paymentBkt))
}

c := pmtbkt.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var pmt Payment
err := json.Unmarshal(v, &pmt)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal payment: %w",
funcName, err)
}

if pmt.UUID == "" {
return fmt.Errorf("%s: the payment UUID "+
"value for %s is not set", funcName, pmt.UUID)
}

if strings.Compare(string(k), pmt.UUID) != 0 {
return fmt.Errorf("%s: payment UUID (%s) does not match "+
"the payment key (%s)", funcName, pmt.UUID, string(k))
}
}

abkt := pbkt.Bucket(paymentArchiveBkt)
if abkt == nil {
return fmt.Errorf("%s: bucket %s not found", funcName,
string(paymentArchiveBkt))
}

c = abkt.Cursor()
for k, v := c.First(); k != nil; k, v = c.Next() {
var pmt Payment
err := json.Unmarshal(v, &pmt)
if err != nil {
return fmt.Errorf("%s: unable to unmarshal archived payment: %w",
funcName, err)
}

if pmt.UUID == "" {
return fmt.Errorf("%s: the payment UUID "+
"value for %s is not set", funcName, pmt.UUID)
}

if strings.Compare(string(k), pmt.UUID) != 0 {
return fmt.Errorf("%s: payment UUID (%s) does not match "+
"the payment key (%s)", funcName, pmt.UUID, string(k))
}
}

return nil
})
if err != nil {
t.Error(err)
}
}
2 changes: 0 additions & 2 deletions pool/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ type Payment struct {
PaidOnHeight uint32 `json:"paidonheight"`
TransactionID string `json:"transactionid"`

// The source could be empty if the payment was
// created before the version 3 db upgrade.
Source *PaymentSource `json:"source"`
}

Expand Down
87 changes: 0 additions & 87 deletions pool/testdata/v1.db.go

This file was deleted.

Binary file removed pool/testdata/v1.db.gz
Binary file not shown.
Loading

0 comments on commit 3e5f073

Please sign in to comment.