Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Nov 9, 2021
1 parent d1641c4 commit d5fc628
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
5 changes: 1 addition & 4 deletions client/db/bolt/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ var (
outerKeyParamsKey = []byte("outerKeyParams")
legacyKeyParamsKey = []byte("keyParams")
byteTrue = encode.ByteTrue
byteFalse = encode.ByteFalse
byteEpoch = uint16Bytes(uint16(order.OrderStatusEpoch))
byteBooked = uint16Bytes(uint16(order.OrderStatusBooked))
backupDir = "backup"
)

Expand Down Expand Up @@ -1376,7 +1373,7 @@ func (db *BoltDB) walletsUpdate(f bucketFunc) error {
// SaveNotification saves the notification.
func (db *BoltDB) SaveNotification(note *dexdb.Notification) error {
if note.Severeness < dexdb.Success {
return fmt.Errorf("Storage of notification with severity %s is forbidden.", note.Severeness)
return fmt.Errorf("storage of notification with severity %s is forbidden", note.Severeness)
}
return db.notesUpdate(func(master *bbolt.Bucket) error {
noteB := note.Encode()
Expand Down
36 changes: 13 additions & 23 deletions client/db/bolt/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import (

type upgradefunc func(tx *bbolt.Tx) error

// TODO: consider changing upgradefunc to accept a bbolt.DB so it may create its
// own transactions. The individual upgrades have to happen in separate
// transactions because they get too big for a single transaction. Plus we
// should consider switching certain upgrades from ForEach to a more cumbersome
// Cursor()-based iteration that will facilitate partitioning updates into
// smaller batches of buckets.

// Each database upgrade function should be keyed by the database
// version it upgrades.
var upgrades = [...]upgradefunc{
Expand Down Expand Up @@ -71,14 +78,6 @@ func (db *BoltDB) upgradeDB() error {

db.log.Infof("Upgrading database from version %d to %d", version, DBVersion)

// matches, err := db.filteredMatches(func(*bbolt.Bucket) bool { return true }, false, true)
// if err != nil {
// return err
// }
// for i := range matches {
// db.log.Info(matches[i])
// }

// Backup the current version's DB file before processing the upgrades to
// DBVersion. Note that any intermediate versions are not stored.
currentFile := filepath.Base(db.Path())
Expand Down Expand Up @@ -287,6 +286,12 @@ func v5Upgrade(dbtx *bbolt.Tx) error {
// matches any longer. This upgrade moves active matches as opposed to inactive
// matches under the assumption that there are less active matches to move, and
// so a smaller database transaction occurs.
//
// NOTE: Earlier taker cancel order matches may be MatchComplete AND have an
// Address set because the msgjson.Match included the maker's/trade's address.
// However, this upgrades does not patch the address field because MatchIsActive
// instead keys off of InitSig to detect cancel matches, and this is a
// potentially huge set of matches and bolt eats too much memory with ForEach.
func v6Upgrade(dbtx *bbolt.Tx) error {
const oldVersion = 5

Expand Down Expand Up @@ -331,21 +336,6 @@ func v6Upgrade(dbtx *bbolt.Tx) error {
return nil
}

/* Patching the Address is commented because it may be massive.
// Earlier taker cancel order matches may be MatchComplete and have an
// Address set because the msgjson.Match included the maker's/trade's
// address. Detect this and patch the address field to reflect that it
// is a cancel order match with no counterparty/trade.
if match.Status == order.MatchComplete && len(proof.Auth.InitSig) == 0 {
// Set match.Address to empty so it is considered inactive in the
// future by MatchIsActive.
fmt.Println("patching complete cancel match", match.MatchID)
match.Address = ""
return archivedMBkt.Put(matchKey, order.EncodeMatch(match))
}
*/

activeMBkt, err := activeMatchesBkt.CreateBucket(k)
if err != nil {
return err
Expand Down
11 changes: 7 additions & 4 deletions client/db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ func (m *MetaMatch) MatchOrderUniqueID() []byte {
}

// MatchIsActive returns false (i.e. the match is inactive) if: (1) status is
// complete AND (proof.RedeemSig is set OR no match address signaling a cancel
// order match that is always inactive), (2) the match is refunded, or (3) it is
// revoked and this side of the match requires no further action like refund or
// auto-redeem.
// complete AND (RedeemSig is set, signalling completed swap OR InitSig unset,
// signaling a cancel order match, which is never active), (2) the match is
// refunded, or (3) it is revoked and this side of the match requires no further
// action like refund or auto-redeem.
//
// WARNING: Do not modify this function without preserving a version for
// v6Upgrade or any other upgrade that relies on a particular behavior.
func MatchIsActive(match *order.UserMatch, proof *MatchProof) bool {
// MatchComplete only means inactive if: (a) cancel order match or (b) the
// redeem request was accepted for trade orders. A cancel order match starts
Expand Down

0 comments on commit d5fc628

Please sign in to comment.