@@ -33,6 +33,7 @@ import (
33
33
"github.com/ipfs/go-datastore"
34
34
"github.com/ipfs/go-datastore/namespace"
35
35
cbor "github.com/ipfs/go-ipld-cbor"
36
+ "github.com/libp2p/go-libp2p/core/crypto"
36
37
"github.com/mitchellh/go-homedir"
37
38
"github.com/urfave/cli/v2"
38
39
"golang.org/x/net/context"
@@ -74,6 +75,21 @@ func migrate(cctx *cli.Context, repoDir string) error {
74
75
return err
75
76
}
76
77
78
+ keyStore , err := lr .KeyStore ()
79
+ if err != nil {
80
+ return fmt .Errorf ("failed to open Boost keystore" )
81
+ }
82
+
83
+ key , err := keyStore .Get ("libp2p-host" )
84
+ if err != nil {
85
+ return fmt .Errorf ("failed to get key from keystore: %w" , err )
86
+ }
87
+
88
+ pkey , err := crypto .UnmarshalPrivateKey (key .PrivateKey )
89
+ if err != nil {
90
+ return fmt .Errorf ("failed to unmarshal private key: %w" , err )
91
+ }
92
+
77
93
mds , err := lr .Datastore (ctx , "/metadata" )
78
94
if err != nil {
79
95
return err
@@ -160,6 +176,12 @@ func migrate(cctx *cli.Context, repoDir string) error {
160
176
if err := migrateDDODeals (ctx , full , activeSectors , maddr , hdb , sqldb , mdb ); err != nil {
161
177
return xerrors .Errorf ("failed to migrate DDO deals: %w" , err )
162
178
}
179
+
180
+ // Migrate libp2p key
181
+ if err := migrateKeys (ctx , maddr , pkey , hdb ); err != nil {
182
+ return xerrors .Errorf ("failed to migrate libp2p key: %w" , err )
183
+ }
184
+
163
185
return nil
164
186
}
165
187
@@ -555,3 +577,23 @@ func migrateDDODeals(ctx context.Context, full v1api.FullNode, activeSectors bit
555
577
556
578
return nil
557
579
}
580
+
581
+ func migrateKeys (ctx context.Context , maddr address.Address , priv crypto.PrivKey , hdb * harmonydb.DB ) error {
582
+
583
+ pkey , err := priv .Raw ()
584
+ if err != nil {
585
+ return err
586
+ }
587
+
588
+ mid , err := address .IDFromAddress (maddr )
589
+ if err != nil {
590
+ return err
591
+ }
592
+
593
+ _ , err = hdb .Exec (ctx , `INSERT INTO libp2p (sp_id, priv_key) VALUES ($1, $2) ON CONFLICT(sp_id) DO NOTHING` , mid , pkey )
594
+ if err != nil {
595
+ return fmt .Errorf ("inserting private key into libp2p table: %w" , err )
596
+ }
597
+
598
+ return nil
599
+ }
0 commit comments