Skip to content

Commit a36bd8e

Browse files
LexLuthrrvagg
authored andcommitted
send funds with miner create (#634)
1 parent e87225e commit a36bd8e

File tree

7 files changed

+131
-24
lines changed

7 files changed

+131
-24
lines changed

api/api_chain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ type CurioChainRPC interface {
100100
StateCirculatingSupply(context.Context, types.TipSetKey) (big.Int, error)
101101
StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error)
102102
MarketAddBalance(ctx context.Context, wallet, addr address.Address, amt types.BigInt) (cid.Cid, error)
103+
StateMinerCreationDeposit(ctx context.Context, tsk types.TipSetKey) (types.BigInt, error)
103104
}
104105

105106
var _ CurioChainRPC = api.FullNode(nil)

api/proxy_gen.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/openrpc/curio.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
"deprecated": false,
313313
"externalDocs": {
314314
"description": "Github remote link",
315-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L337"
315+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L340"
316316
}
317317
},
318318
{
@@ -335,7 +335,7 @@
335335
"deprecated": false,
336336
"externalDocs": {
337337
"description": "Github remote link",
338-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L348"
338+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L351"
339339
}
340340
},
341341
{
@@ -400,7 +400,7 @@
400400
"deprecated": false,
401401
"externalDocs": {
402402
"description": "Github remote link",
403-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L359"
403+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L362"
404404
}
405405
},
406406
{
@@ -484,7 +484,7 @@
484484
"deprecated": false,
485485
"externalDocs": {
486486
"description": "Github remote link",
487-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L370"
487+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L373"
488488
}
489489
},
490490
{
@@ -520,7 +520,7 @@
520520
"deprecated": false,
521521
"externalDocs": {
522522
"description": "Github remote link",
523-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L381"
523+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L384"
524524
}
525525
},
526526
{
@@ -574,7 +574,7 @@
574574
"deprecated": false,
575575
"externalDocs": {
576576
"description": "Github remote link",
577-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L392"
577+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L395"
578578
}
579579
},
580580
{
@@ -597,7 +597,7 @@
597597
"deprecated": false,
598598
"externalDocs": {
599599
"description": "Github remote link",
600-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L403"
600+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L406"
601601
}
602602
},
603603
{
@@ -636,7 +636,7 @@
636636
"deprecated": false,
637637
"externalDocs": {
638638
"description": "Github remote link",
639-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L414"
639+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L417"
640640
}
641641
},
642642
{
@@ -675,7 +675,7 @@
675675
"deprecated": false,
676676
"externalDocs": {
677677
"description": "Github remote link",
678-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L425"
678+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L428"
679679
}
680680
},
681681
{
@@ -869,7 +869,7 @@
869869
"deprecated": false,
870870
"externalDocs": {
871871
"description": "Github remote link",
872-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L436"
872+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L439"
873873
}
874874
},
875875
{
@@ -930,7 +930,7 @@
930930
"deprecated": false,
931931
"externalDocs": {
932932
"description": "Github remote link",
933-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L447"
933+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L450"
934934
}
935935
},
936936
{
@@ -1062,7 +1062,7 @@
10621062
"deprecated": false,
10631063
"externalDocs": {
10641064
"description": "Github remote link",
1065-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L458"
1065+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L461"
10661066
}
10671067
},
10681068
{
@@ -1196,7 +1196,7 @@
11961196
"deprecated": false,
11971197
"externalDocs": {
11981198
"description": "Github remote link",
1199-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L469"
1199+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L472"
12001200
}
12011201
},
12021202
{
@@ -1250,7 +1250,7 @@
12501250
"deprecated": false,
12511251
"externalDocs": {
12521252
"description": "Github remote link",
1253-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L480"
1253+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L483"
12541254
}
12551255
},
12561256
{
@@ -1284,7 +1284,7 @@
12841284
"deprecated": false,
12851285
"externalDocs": {
12861286
"description": "Github remote link",
1287-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L491"
1287+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L494"
12881288
}
12891289
},
12901290
{
@@ -1338,7 +1338,7 @@
13381338
"deprecated": false,
13391339
"externalDocs": {
13401340
"description": "Github remote link",
1341-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L502"
1341+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L505"
13421342
}
13431343
},
13441344
{
@@ -1415,7 +1415,7 @@
14151415
"deprecated": false,
14161416
"externalDocs": {
14171417
"description": "Github remote link",
1418-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L513"
1418+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L516"
14191419
}
14201420
},
14211421
{
@@ -1438,7 +1438,7 @@
14381438
"deprecated": false,
14391439
"externalDocs": {
14401440
"description": "Github remote link",
1441-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L524"
1441+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L527"
14421442
}
14431443
},
14441444
{
@@ -1476,7 +1476,7 @@
14761476
"deprecated": false,
14771477
"externalDocs": {
14781478
"description": "Github remote link",
1479-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L535"
1479+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L538"
14801480
}
14811481
}
14821482
]

cmd/sptool/actor.go

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import (
55
"os"
66
"strings"
77

8+
"github.com/docker/go-units"
89
"github.com/fatih/color"
910
"github.com/urfave/cli/v2"
1011
"golang.org/x/xerrors"
1112

1213
"github.com/filecoin-project/go-address"
14+
"github.com/filecoin-project/go-state-types/abi"
1315

16+
"github.com/filecoin-project/curio/lib/createminer"
1417
"github.com/filecoin-project/curio/lib/reqcontext"
1518

1619
builtin2 "github.com/filecoin-project/lotus/chain/actors/builtin"
@@ -35,7 +38,7 @@ var actorCmd = &cli.Command{
3538
spcli.ActorCompactAllocatedCmd(SPTActorGetter),
3639
spcli.ActorProposeChangeBeneficiaryCmd(SPTActorGetter),
3740
spcli.ActorConfirmChangeBeneficiaryCmd(SPTActorGetter),
38-
spcli.ActorNewMinerCmd,
41+
ActorNewMinerCmd,
3942
},
4043
}
4144

@@ -142,3 +145,86 @@ func actorControlListCmd(getActor spcli.ActorAddressGetter) *cli.Command {
142145
},
143146
}
144147
}
148+
149+
var ActorNewMinerCmd = &cli.Command{
150+
Name: "new-miner",
151+
Usage: "Initializes a new miner actor",
152+
Flags: []cli.Flag{
153+
&cli.StringFlag{
154+
Name: "worker",
155+
Aliases: []string{"w"},
156+
Usage: "worker key to use for new miner initialisation",
157+
},
158+
&cli.StringFlag{
159+
Name: "owner",
160+
Aliases: []string{"o"},
161+
Usage: "owner key to use for new miner initialisation",
162+
},
163+
&cli.StringFlag{
164+
Name: "from",
165+
Aliases: []string{"f"},
166+
Usage: "address to send actor(miner) creation message from",
167+
},
168+
&cli.StringFlag{
169+
Name: "sector-size",
170+
Usage: "specify sector size to use for new miner initialisation",
171+
},
172+
&cli.IntFlag{
173+
Name: "confidence",
174+
Usage: "number of block confirmations to wait for",
175+
Value: 5,
176+
},
177+
},
178+
Action: func(cctx *cli.Context) error {
179+
ctx := cctx.Context
180+
181+
full, closer, err := cliutil.GetFullNodeAPIV1(cctx)
182+
if err != nil {
183+
return xerrors.Errorf("connecting to full node: %w", err)
184+
}
185+
defer closer()
186+
187+
var owner address.Address
188+
if cctx.String("owner") == "" {
189+
return xerrors.Errorf("must provide a owner address")
190+
}
191+
owner, err = address.NewFromString(cctx.String("owner"))
192+
193+
if err != nil {
194+
return err
195+
}
196+
197+
worker := owner
198+
if cctx.String("worker") != "" {
199+
worker, err = address.NewFromString(cctx.String("worker"))
200+
if err != nil {
201+
return xerrors.Errorf("could not parse worker address: %w", err)
202+
}
203+
}
204+
205+
sender := owner
206+
if fromstr := cctx.String("from"); fromstr != "" {
207+
faddr, err := address.NewFromString(fromstr)
208+
if err != nil {
209+
return xerrors.Errorf("could not parse from address: %w", err)
210+
}
211+
sender = faddr
212+
}
213+
214+
if !cctx.IsSet("sector-size") {
215+
return xerrors.Errorf("must define sector size")
216+
}
217+
218+
sectorSizeInt, err := units.RAMInBytes(cctx.String("sector-size"))
219+
if err != nil {
220+
return err
221+
}
222+
ssize := abi.SectorSize(sectorSizeInt)
223+
224+
_, err = createminer.CreateStorageMiner(ctx, full, owner, worker, sender, ssize, cctx.Uint64("confidence"))
225+
if err != nil {
226+
return err
227+
}
228+
return nil
229+
},
230+
}

docker/curio/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if [ ! -f $CURIO_REPO_PATH/.init.curio ]; then
2525
if [ ! -f $CURIO_REPO_PATH/.init.setup ]; then
2626
export DEFAULT_WALLET=`lotus wallet default`
2727
echo Create a new miner actor ...
28-
lotus-shed miner create $DEFAULT_WALLET $DEFAULT_WALLET $DEFAULT_WALLET 8MiB
28+
sptool --actor t01000 actor new-miner --owner $DEFAULT_WALLET --worker $DEFAULT_WALLET --send $DEFAULT_WALLET 8MiB
2929
touch $CURIO_REPO_PATH/.init.setup
3030
fi
3131

lib/createminer/create_miner.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/filecoin-project/go-address"
1212
"github.com/filecoin-project/go-state-types/abi"
13-
"github.com/filecoin-project/go-state-types/big"
1413
"github.com/filecoin-project/go-state-types/network"
1514
power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power"
1615
power6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/power"
@@ -27,6 +26,7 @@ type CreateMinerChainAPI interface {
2726
MpoolPushMessage(context.Context, *types.Message, *api.MessageSendSpec) (*types.SignedMessage, error)
2827
StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) //perm:read
2928
StateNetworkVersion(context.Context, types.TipSetKey) (network.Version, error)
29+
StateMinerCreationDeposit(ctx context.Context, tsk types.TipSetKey) (types.BigInt, error)
3030
}
3131

3232
func CreateStorageMiner(ctx context.Context, chain CreateMinerChainAPI, owner, worker, sender address.Address, ssize abi.SectorSize, confidence uint64) (address.Address, error) {
@@ -103,10 +103,15 @@ func CreateStorageMiner(ctx context.Context, chain CreateMinerChainAPI, owner, w
103103
return address.Undef, err
104104
}
105105

106+
value, err := chain.StateMinerCreationDeposit(ctx, types.EmptyTSK)
107+
if err != nil {
108+
return address.Undef, xerrors.Errorf("getting miner creation deposit: %w", err)
109+
}
110+
106111
createStorageMinerMsg := &types.Message{
107112
To: power.Address,
108113
From: sender,
109-
Value: big.Zero(),
114+
Value: value,
110115

111116
Method: power.Methods.CreateMiner,
112117
Params: params,

web/api/webrpc/cluster.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ func (a *WebRPC) ClusterNodeMetrics(ctx context.Context, id int64) (string, erro
510510
if err != nil {
511511
return "", xerrors.Errorf("failed to fetch metrics from %s: %w", url, err)
512512
}
513-
defer resp.Body.Close()
513+
defer func() {
514+
_ = resp.Body.Close()
515+
}()
514516

515517
if resp.StatusCode != http.StatusOK {
516518
return "", xerrors.Errorf("metrics endpoint returned status %d", resp.StatusCode)

0 commit comments

Comments
 (0)