Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database: Don't run unnecessary upgrades. #477

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ func (vdb *VspDatabase) WriteHotBackupFile() error {
// - the provided extended pubkey (to be used for deriving fee addresses).
// - an ed25519 keypair to sign API responses.
// - a secret key to use for initializing a HTTP cookie store.
// Note: CreateNew should always initialize a database of the most recent
// version, meaning that every change described in upgrade_vX.go files is
// already applied.
func CreateNew(dbFile, feeXPub string) error {

db, err := bolt.Open(dbFile, 0600, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
return fmt.Errorf("unable to open db file: %w", err)
Expand All @@ -108,13 +110,13 @@ func CreateNew(dbFile, feeXPub string) error {
return fmt.Errorf("failed to create %s bucket: %w", string(vspBktK), err)
}

// Initialize with initial database version (1).
err = vspBkt.Put(versionK, uint32ToBytes(initialVersion))
// Set the database version number to the latest.
err = vspBkt.Put(versionK, uint32ToBytes(latestVersion))
if err != nil {
return err
}

// Generate ed25519 key
// Generate ed25519 key.
_, signKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return fmt.Errorf("failed to generate signing key: %w", err)
Expand All @@ -135,7 +137,7 @@ func CreateNew(dbFile, feeXPub string) error {
return err
}

// Store fee xpub
// Store fee xpub.
err = vspBkt.Put(feeXPubK, []byte(feeXPub))
if err != nil {
return err
Expand All @@ -153,6 +155,12 @@ func CreateNew(dbFile, feeXPub string) error {
return fmt.Errorf("failed to create %s bucket: %w", string(voteChangeBktK), err)
}

// Create alternate signing address bucket (added in upgrade to v4).
_, err = vspBkt.CreateBucket(altSignAddrBktK)
if err != nil {
return fmt.Errorf("failed to create %s bucket: %w", altSignAddrBktK, err)
}

return nil
})

Expand Down
Loading