Skip to content

Commit

Permalink
Merge pull request #4475 from filecoin-project/fix/miner-init-createw…
Browse files Browse the repository at this point in the history
…orker

miner: fix init --create-worker-key
  • Loading branch information
magik6k authored Oct 22, 2020
2 parents 29cda82 + 869d714 commit 6bdf993
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions cmd/lotus-storage-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,6 @@ func configureStorageMiner(ctx context.Context, api lapi.FullNode, addr address.
}

func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID, gasPrice types.BigInt, cctx *cli.Context) (address.Address, error) {
log.Info("Creating StorageMarket.CreateStorageMiner message")

var err error
var owner address.Address
if cctx.String("owner") != "" {
Expand All @@ -627,9 +625,32 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID,
} else if cctx.Bool("create-worker-key") { // TODO: Do we need to force this if owner is Secpk?
worker, err = api.WalletNew(ctx, types.KTBLS)
}
// TODO: Transfer some initial funds to worker
if err != nil {
return address.Undef, err
return address.Address{}, err
}

// make sure the worker account exists on chain
_, err = api.StateLookupID(ctx, worker, types.EmptyTSK)
if err != nil {
signed, err := api.MpoolPushMessage(ctx, &types.Message{
From: owner,
To: worker,
Value: types.NewInt(0),
}, nil)
if err != nil {
return address.Undef, xerrors.Errorf("push worker init: %w", err)
}

log.Infof("Initializing worker account %s, message: %s", worker, signed.Cid())
log.Infof("Waiting for confirmation")

mw, err := api.StateWaitMsg(ctx, signed.Cid(), build.MessageConfidence)
if err != nil {
return address.Undef, xerrors.Errorf("waiting for worker init: %w", err)
}
if mw.Receipt.ExitCode != 0 {
return address.Undef, xerrors.Errorf("initializing worker account failed: exit code %d", mw.Receipt.ExitCode)
}
}

spt, err := ffiwrapper.SealProofTypeFromSectorSize(abi.SectorSize(ssize))
Expand Down Expand Up @@ -670,15 +691,15 @@ func createStorageMiner(ctx context.Context, api lapi.FullNode, peerid peer.ID,

signed, err := api.MpoolPushMessage(ctx, createStorageMinerMsg, nil)
if err != nil {
return address.Undef, err
return address.Undef, xerrors.Errorf("pushing createMiner message: %w", err)
}

log.Infof("Pushed StorageMarket.CreateStorageMiner, %s to Mpool", signed.Cid())
log.Infof("Pushed CreateMiner message: %s", signed.Cid())
log.Infof("Waiting for confirmation")

mw, err := api.StateWaitMsg(ctx, signed.Cid(), build.MessageConfidence)
if err != nil {
return address.Undef, err
return address.Undef, xerrors.Errorf("waiting for createMiner message: %w", err)
}

if mw.Receipt.ExitCode != 0 {
Expand Down

0 comments on commit 6bdf993

Please sign in to comment.