Skip to content

Commit

Permalink
fix(dot/network): recreate incompatible libp2p datastore (#4382)
Browse files Browse the repository at this point in the history
  • Loading branch information
haikoschol authored Dec 5, 2024
1 parent a46ad52 commit 02f02f6
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit 02f02f6

Please sign in to comment.