6
6
package guidedsetup
7
7
8
8
import (
9
- "bytes"
10
9
"context"
11
10
"crypto/rand"
12
11
"encoding/base64"
13
- "encoding/json"
14
12
"fmt"
15
13
"io"
16
- "math/bits"
17
- "net/http"
18
14
"os"
19
15
"os/signal"
20
16
"path"
@@ -35,15 +31,13 @@ import (
35
31
"github.com/filecoin-project/go-state-types/abi"
36
32
37
33
"github.com/filecoin-project/curio/api"
38
- "github.com/filecoin-project/curio/build"
39
34
"github.com/filecoin-project/curio/cmd/curio/internal/translations"
40
35
"github.com/filecoin-project/curio/deps"
41
36
"github.com/filecoin-project/curio/deps/config"
42
37
"github.com/filecoin-project/curio/harmony/harmonydb"
43
38
"github.com/filecoin-project/curio/lib/createminer"
44
39
45
40
lapi "github.com/filecoin-project/lotus/api"
46
- "github.com/filecoin-project/lotus/chain/types"
47
41
cliutil "github.com/filecoin-project/lotus/cli/util"
48
42
"github.com/filecoin-project/lotus/node/repo"
49
43
)
@@ -177,7 +171,6 @@ var migrationSteps = []migrationStep{
177
171
yugabyteConnect , // Miner is updated
178
172
configToDB , // work on base configuration migration.
179
173
doc ,
180
- oneLastThing ,
181
174
complete ,
182
175
afterRan ,
183
176
}
@@ -189,7 +182,6 @@ var newMinerSteps = []newMinerStep{
189
182
stepCreateActor ,
190
183
stepNewMinerConfig ,
191
184
doc ,
192
- oneLastThing ,
193
185
completeInit ,
194
186
afterRan ,
195
187
}
@@ -200,7 +192,6 @@ var nonSPSteps = []nonSPStep{
200
192
stepPresteps ,
201
193
stepNewMinerConfig ,
202
194
doc ,
203
- oneLastThing ,
204
195
completeNonSP ,
205
196
afterRan ,
206
197
}
@@ -318,101 +309,6 @@ func configToDB(d *MigrationData) {
318
309
}
319
310
}
320
311
321
- // bucket returns the power's 4 highest bits (rounded down).
322
- func bucket (power * lapi.MinerPower ) uint64 {
323
- rawQAP := power .TotalPower .QualityAdjPower .Uint64 ()
324
- magnitude := lo .Max ([]int {bits .Len64 (rawQAP ), 5 })
325
-
326
- // shifting erases resolution so we cannot distinguish SPs of similar scales.
327
- return rawQAP >> (uint64 (magnitude ) - 4 ) << (uint64 (magnitude - 4 ))
328
- }
329
-
330
- type uploadType int
331
-
332
- const uploadTypeIndividual uploadType = 0
333
- const uploadTypeAggregate uploadType = 1
334
-
335
- // const uploadTypeHint uploadType = 2
336
- const uploadTypeNothing uploadType = 3
337
-
338
- func oneLastThing (d * MigrationData ) {
339
- d .say (section , "The Curio team wants to improve the software you use. Tell the team you're using `%s`." , "curio" )
340
- i , _ , err := (& promptui.Select {
341
- Label : d .T ("Select what you want to share with the Curio team." ),
342
- Items : []string {
343
- d .T ("Individual Data: Miner ID, Curio version, chain (%s or %s). Signed." , "mainnet" , "calibration" ),
344
- d .T ("Aggregate-Anonymous: version, chain, and Miner power (bucketed)." ),
345
- d .T ("Hint: I am someone running Curio on whichever chain." ),
346
- d .T ("Nothing." )},
347
- Templates : d .selectTemplates ,
348
- }).Run ()
349
- preference := uploadType (i )
350
- if err != nil {
351
- d .say (notice , "Aborting remaining steps." , err .Error ())
352
- os .Exit (1 )
353
- }
354
- if preference != uploadTypeNothing {
355
- msgMap := map [string ]any {
356
- "domain" : "curio-newuser" ,
357
- "net" : build .BuildTypeString (),
358
- }
359
- if preference == uploadTypeIndividual || preference == uploadTypeAggregate {
360
- // articles of incorporation
361
- power , err := d .full .StateMinerPower (context .Background (), d .MinerID , types .EmptyTSK )
362
- if err != nil {
363
- d .say (notice , "Error getting miner power: %s" , err .Error ())
364
- os .Exit (1 )
365
- }
366
- msgMap ["version" ] = build .BuildVersion
367
- msgMap ["net" ] = build .BuildType
368
- msgMap ["power" ] = map [uploadType ]uint64 {
369
- uploadTypeIndividual : power .MinerPower .QualityAdjPower .Uint64 (),
370
- uploadTypeAggregate : bucket (power )}[preference ]
371
-
372
- if preference == uploadTypeIndividual { // Sign it
373
- msgMap ["miner_id" ] = d .MinerID
374
- msg , err := json .Marshal (msgMap )
375
- if err != nil {
376
- d .say (notice , "Error marshalling message: %s" , err .Error ())
377
- os .Exit (1 )
378
- }
379
- mi , err := d .full .StateMinerInfo (context .Background (), d .MinerID , types .EmptyTSK )
380
- if err != nil {
381
- d .say (notice , "Error getting miner info: %s" , err .Error ())
382
- os .Exit (1 )
383
- }
384
- sig , err := d .full .WalletSign (context .Background (), mi .Worker , msg )
385
- if err != nil {
386
- d .say (notice , "Error signing message: %s" , err .Error ())
387
- os .Exit (1 )
388
- }
389
- msgMap ["signature" ] = base64 .StdEncoding .EncodeToString (sig .Data )
390
- }
391
- }
392
- msg , err := json .Marshal (msgMap )
393
- if err != nil {
394
- d .say (notice , "Error marshalling message: %s" , err .Error ())
395
- os .Exit (1 )
396
- }
397
-
398
- resp , err := http .DefaultClient .Post (DeveloperFocusRequestURL , "application/json" , bytes .NewReader (msg ))
399
- if err != nil {
400
- d .say (notice , "Error sending message: %s" , err .Error ())
401
- }
402
- if resp != nil {
403
- defer func () { _ = resp .Body .Close () }()
404
- if resp .StatusCode != 200 {
405
- b , err := io .ReadAll (resp .Body )
406
- if err == nil {
407
- d .say (notice , "Error sending message: Status %s, Message: " , resp .Status , string (b ))
408
- }
409
- } else {
410
- stepCompleted (d , d .T ("Message sent." ))
411
- }
412
- }
413
- }
414
- }
415
-
416
312
func doc (d * MigrationData ) {
417
313
d .say (plain , "Documentation: " )
418
314
d .say (plain , "The '%s' layer stores common configuration. All curio instances can include it in their %s argument." , "base" , "--layers" )
@@ -445,7 +341,7 @@ func readMinerConfig(d *MigrationData) {
445
341
return err
446
342
}
447
343
448
- dirs := map [string ]struct {}{"~/.lotusminer" : struct {}{} , "~/.lotus-miner-local-net" : struct {} {}}
344
+ dirs := map [string ]struct {}{"~/.lotusminer" : {} , "~/.lotus-miner-local-net" : {}}
449
345
if v := os .Getenv ("LOTUS_MINER_PATH" ); v != "" {
450
346
dirs [v ] = struct {}{}
451
347
}
0 commit comments