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

fix(dot/network): recreate incompatible libp2p datastore #4382

Merged
merged 1 commit into from
Dec 5, 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
19 changes: 17 additions & 2 deletions dot/network/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"log"
"net"
"os"
"path"
"strconv"
"strings"
Expand Down Expand Up @@ -177,9 +178,23 @@ func newHost(ctx context.Context, cfg *Config) (*host, error) {
// format protocol id
pid := protocol.ID(cfg.ProtocolID)

ds, err := badger.NewDatastore(path.Join(cfg.BasePath, "libp2p-datastore"), &badger.DefaultOptions)
dsPath := path.Join(cfg.BasePath, "libp2p-datastore")
ds, err := badger.NewDatastore(dsPath, &badger.DefaultOptions)
if err != nil {
return nil, fmt.Errorf("failed to create libp2p datastore: %w", err)
// unfortunately we have to use this brittle hack instead of errors.Is()
// https://github.com/ipfs/go-ds-badger4/blob/v0.1.5/datastore.go#L188
if strings.HasPrefix(err.Error(), "unsupported badger version") {
logger.Warn("unable to reuse libp2p datastore, recreating it")
if err := os.RemoveAll(dsPath); err != nil {
return nil, fmt.Errorf("removing libp2p datastore: %w", err)
}

if ds, err = badger.NewDatastore(dsPath, &badger.DefaultOptions); err != nil {
return nil, fmt.Errorf("failed to create libp2p datastore: %w", err)
}
} else {
return nil, fmt.Errorf("failed to create libp2p datastore: %w", err)
}
}

ps, err := mempstore.NewPeerstore()
Expand Down
Loading