Skip to content

Commit

Permalink
don't wait for msg to land on chain
Browse files Browse the repository at this point in the history
  • Loading branch information
LexLuthr committed Aug 1, 2022
1 parent e9705c4 commit e0e0b0b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 30 deletions.
6 changes: 2 additions & 4 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ type StorageMiner interface {

// WithdrawBalance allows to withdraw balance from miner actor to owner address
// Specify amount as "0" to withdraw full balance. This method returns a message CID
// even when StateWaitMessage() fails and receipt exit code is non-zero
// User should check for message execution manually if this method returns a
// "Timeout waiting for withdrawal message" error.
WithdrawBalance(ctx context.Context, amount abi.TokenAmount, confidence uint64) (cid.Cid, error) //perm:admin
// and does not wait for message execution
WithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) //perm:admin

MiningBase(context.Context) (*types.TipSet, error) //perm:read

Expand Down
8 changes: 4 additions & 4 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
15 changes: 10 additions & 5 deletions cmd/lotus-miner/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,24 +243,29 @@ var actorWithdrawCmd = &cli.Command{

ctx := lcli.ReqContext(cctx)

res, err := nodeApi.WithdrawBalance(ctx, amount, uint64(cctx.Int("confidence")))
res, err := nodeApi.WithdrawBalance(ctx, amount)
if err != nil {
return err
}

msg, err := api.StateSearchMsg(ctx, res)
// wait for it to get mined into a block
wait, err := api.StateWaitMsg(ctx, res, uint64(cctx.Int("confidence")))
if err != nil {
return err
return xerrors.Errorf("Timeout waiting for withdrawal message %s", wait.Message)
}

if wait.Receipt.ExitCode != 0 {
return xerrors.Errorf("Failed to execute withdrawal message %s: %w", wait.Message, wait.Receipt.ExitCode.Error())
}

nv, err := api.StateNetworkVersion(ctx, msg.TipSet)
nv, err := api.StateNetworkVersion(ctx, wait.TipSet)
if err != nil {
return err
}

if nv >= network.Version14 {
var withdrawn abi.TokenAmount
if err := withdrawn.UnmarshalCBOR(bytes.NewReader(msg.Receipt.Return)); err != nil {
if err := withdrawn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil {
return err
}

Expand Down
7 changes: 2 additions & 5 deletions documentation/en/api-v0-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -3670,18 +3670,15 @@ Response: `true`
### WithdrawBalance
WithdrawBalance allows to withdraw balance from miner actor to owner address
Specify amount as "0" to withdraw full balance. This method returns a message CID
even when StateWaitMessage() fails and receipt exit code is non-zero
User should check for message execution manually if this method returns a
"Timeout waiting for withdrawal message" error.
and does not wait for message execution


Perms: admin

Inputs:
```json
[
"0",
42
"0"
]
```

Expand Down
14 changes: 2 additions & 12 deletions node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ func (sm *StorageMinerAPI) RuntimeSubsystems(context.Context) (res api.MinerSubs
return sm.EnabledSubsystems, nil
}

func (sm *StorageMinerAPI) WithdrawBalance(ctx context.Context, amount abi.TokenAmount, confidence uint64) (cid.Cid, error) {
func (sm *StorageMinerAPI) WithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) {
available, err := sm.Full.StateMinerAvailableBalance(ctx, sm.Miner.Address(), types.EmptyTSK)
if err != nil {
return cid.Undef, xerrors.Errorf("Error getting miner balance: %w", err)
Expand Down Expand Up @@ -1320,15 +1320,5 @@ func (sm *StorageMinerAPI) WithdrawBalance(ctx context.Context, amount abi.Token
return cid.Undef, err
}

// wait for it to get mined into a block
wait, err := sm.Full.StateWaitMsg(ctx, smsg.Cid(), confidence, abi.ChainEpoch(2), true)
if err != nil {
return smsg.Cid(), xerrors.Errorf("Timeout waiting for withdrawal message")
}

if wait.Receipt.ExitCode != 0 {
return wait.Message, xerrors.Errorf("Failed to execute withdrawal message: %w", err)
}

return wait.Message, nil
return smsg.Cid(), nil
}

0 comments on commit e0e0b0b

Please sign in to comment.