spects-actors: More type propagation

This commit is contained in:
Łukasz Magiera 2020-02-13 04:50:37 +01:00
parent 36aed6f871
commit 74bf9119cc
16 changed files with 110 additions and 52 deletions

View File

@ -227,9 +227,9 @@ type PaymentInfo struct {
}
type VoucherSpec struct {
Amount types.BigInt
TimeLock uint64
MinClose uint64
Amount types.BigInt
TimeLock abi.ChainEpoch
MinSettle abi.ChainEpoch
Extra *types.ModVerifyParams
}

View File

@ -4,6 +4,7 @@ import (
"context"
"sync"
"github.com/filecoin-project/specs-actors/actors/builtin"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@ -55,13 +56,20 @@ func (fm *FundMgr) EnsureAvailable(ctx context.Context, addr address.Address, am
fm.lk.Unlock()
var err error
params, err := actors.SerializeParams(&toAdd)
if err != nil {
return err
}
smsg, err := fm.mpool.MpoolPushMessage(ctx, &types.Message{
To: actors.StorageMarketAddress,
From: addr,
Value: toAdd,
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(1000000),
Method: actors.SMAMethods.AddBalance,
Method: builtin.MethodsMarket.AddBalance,
Params: params,
})
if err != nil {
return err

View File

@ -6,4 +6,4 @@ import (
type SignedStorageAsk = storagemarket.SignedStorageAsk
type StorageAsk = storagemarket.StorageAsk
type StorageAsk = storagemarket.StorageAsk

View File

@ -2,8 +2,6 @@ package types
import (
"fmt"
"github.com/filecoin-project/specs-actors/actors/crypto"
)
var (
@ -13,7 +11,7 @@ var (
// KeyInfo is used for storing keys in KeyStore
type KeyInfo struct {
Type crypto.SigType
Type string
PrivateKey []byte
}

View File

@ -24,6 +24,8 @@ var log = logging.Logger("wallet")
const (
KNamePrefix = "wallet-"
KDefault = "default"
KTBLS = "bls"
KTSecp256k1 = "secp256k1"
)
type Wallet struct {
@ -62,7 +64,7 @@ func (w *Wallet) Sign(ctx context.Context, addr address.Address, msg []byte) (*c
return nil, xerrors.Errorf("signing using key '%s': %w", addr.String(), types.ErrKeyInfoNotFound)
}
return sigs.Sign(ki.Type, ki.PrivateKey, msg)
return sigs.Sign(ActSigType(ki.Type), ki.PrivateKey, msg)
}
func (w *Wallet) findKey(addr address.Address) (*Key, error) {
@ -186,7 +188,7 @@ func GenerateKey(typ crypto.SigType) (*Key, error) {
return nil, err
}
ki := types.KeyInfo{
Type: typ,
Type: kstoreSigType(typ),
PrivateKey: pk,
}
return NewKey(ki)
@ -241,18 +243,18 @@ func NewKey(keyinfo types.KeyInfo) (*Key, error) {
}
var err error
k.PublicKey, err = sigs.ToPublic(k.Type, k.PrivateKey)
k.PublicKey, err = sigs.ToPublic(ActSigType(k.Type), k.PrivateKey)
if err != nil {
return nil, err
}
switch k.Type {
case crypto.SigTypeSecp256k1:
case KTSecp256k1:
k.Address, err = address.NewSecp256k1Address(k.PublicKey)
if err != nil {
return nil, xerrors.Errorf("converting Secp256k1 to address: %w", err)
}
case crypto.SigTypeBLS:
case KTBLS:
k.Address, err = address.NewBLSAddress(k.PublicKey)
if err != nil {
return nil, xerrors.Errorf("converting BLS to address: %w", err)
@ -263,3 +265,25 @@ func NewKey(keyinfo types.KeyInfo) (*Key, error) {
return k, nil
}
func kstoreSigType(typ crypto.SigType) string {
switch typ {
case crypto.SigTypeBLS:
return KTBLS
case crypto.SigTypeSecp256k1:
return KTSecp256k1
default:
return ""
}
}
func ActSigType(typ string) crypto.SigType {
switch typ {
case KTBLS:
return crypto.SigTypeBLS
case KTSecp256k1:
return crypto.SigTypeSecp256k1
default:
return 0
}
}

View File

@ -11,7 +11,11 @@ import (
"strings"
"time"
"github.com/filecoin-project/go-address"
cborutil "github.com/filecoin-project/go-cbor-util"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
cid "github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
@ -595,9 +599,22 @@ var slashConsensusFault = &cli.Command{
return err
}
params, err := actors.SerializeParams(&actors.ArbitrateConsensusFaultParams{
Block1: b1,
Block2: b2,
bh1, err := cborutil.Dump(b1)
if err != nil {
return err
}
bh2, err := cborutil.Dump(b2)
if err != nil {
return err
}
params, err := actors.SerializeParams(&power.ReportConsensusFaultParams{
BlockHeader1: bh1,
BlockHeader2: bh2,
Target: address.Address{},
FaultEpoch: 0,
FaultType: 0,
})
msg := &types.Message{
@ -606,7 +623,7 @@ var slashConsensusFault = &cli.Command{
Value: types.NewInt(0),
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(10000000),
Method: actors.SPAMethods.ArbitrateConsensusFault,
Method: builtin.MethodsPower.ReportConsensusFault,
Params: params,
}

View File

@ -14,7 +14,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket"
actors "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/types"
)
@ -291,27 +291,15 @@ var clientQueryAskCmd = &cli.Command{
}
pid = p
} else {
ret, err := api.StateCall(ctx, &types.Message{
To: maddr,
From: maddr,
Method: actors.MAMethods.GetPeerID,
}, nil)
p, err := api.StateMinerPeerID(ctx, maddr, nil)
if err != nil {
return xerrors.Errorf("failed to get peerID for miner: %w", err)
}
if ret.ExitCode != 0 {
return fmt.Errorf("call to GetPeerID was unsuccesful (exit code %d)", ret.ExitCode)
}
if peer.ID(ret.Return) == peer.ID("SETME") {
if p == peer.ID("SETME") {
return fmt.Errorf("the miner hasn't initialized yet")
}
p, err := peer.IDFromBytes(ret.Return)
if err != nil {
return err
}
pid = p
}

View File

@ -14,6 +14,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-hamt-ipld"
@ -104,9 +105,9 @@ var msigCreateCmd = &cli.Command{
}
// new actors are created by invoking 'exec' on the init actor with the constructor params
execParams := &actors.ExecParams{
Code: actors.MultisigCodeCid,
Params: enc,
execParams := &init_.ExecParams{
CodeCID: actors.MultisigCodeCid,
ConstructorParams: enc,
}
enc, err = actors.SerializeParams(execParams)
@ -118,7 +119,7 @@ var msigCreateCmd = &cli.Command{
msg := types.Message{
To: actors.InitAddress,
From: sendAddr,
Method: actors.IAMethods.Exec,
Method: builtin.MethodsInit.Exec,
Params: enc,
GasPrice: types.NewInt(1),
GasLimit: types.NewInt(1000000),
@ -347,7 +348,7 @@ var msigProposeCmd = &cli.Command{
To: msig,
From: from,
Value: types.NewInt(0),
Method: uint64(builtin.MethodsMultisig.Propose),
Method: builtin.MethodsMultisig.Propose,
Params: enc,
GasLimit: types.NewInt(100000),
GasPrice: types.NewInt(1),
@ -432,7 +433,7 @@ var msigApproveCmd = &cli.Command{
To: msig,
From: from,
Value: types.NewInt(0),
Method: uint64(builtin.MethodsMultisig.Approve),
Method: builtin.MethodsMultisig.Approve,
Params: enc,
GasLimit: types.NewInt(100000),
GasPrice: types.NewInt(1),

View File

@ -1,11 +1,15 @@
package cli
import (
"bytes"
"encoding/base64"
"fmt"
"github.com/filecoin-project/go-address"
types "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"gopkg.in/urfave/cli.v2"
types "github.com/filecoin-project/lotus/chain/types"
)
var paychCmd = &cli.Command{
@ -136,7 +140,7 @@ var paychVoucherCreateCmd = &cli.Command{
return err
}
enc, err := sv.EncodedString()
enc, err := EncodedString(sv)
if err != nil {
return err
}
@ -250,7 +254,7 @@ var paychVoucherListCmd = &cli.Command{
for _, v := range vouchers {
if cctx.Bool("export") {
enc, err := v.EncodedString()
enc, err := EncodedString(v)
if err != nil {
return err
}
@ -308,7 +312,7 @@ var paychVoucherBestSpendableCmd = &cli.Command{
return fmt.Errorf("No spendable vouchers for that channel")
}
enc, err := best.EncodedString()
enc, err := EncodedString(best)
if err != nil {
return err
}
@ -364,3 +368,12 @@ var paychVoucherSubmitCmd = &cli.Command{
return nil
},
}
func EncodedString(sv *paych.SignedVoucher) (string, error) {
buf := new(bytes.Buffer)
if err := sv.MarshalCBOR(buf); err != nil {
return "", err
}
return base64.RawURLEncoding.EncodeToString(buf.Bytes()), nil
}

View File

@ -721,7 +721,7 @@ var stateCallCmd = &cli.Command{
&cli.StringFlag{
Name: "from",
Usage: "",
Value: actors.NetworkAddress.String(),
Value: actors.SystemAddress.String(),
},
&cli.StringFlag{
Name: "value",
@ -788,7 +788,7 @@ var stateCallCmd = &cli.Command{
Value: types.BigInt(value),
GasLimit: types.NewInt(10000000000),
GasPrice: types.NewInt(0),
Method: method,
Method: abi.MethodNum(method),
Params: params,
}, ts)
if err != nil {

View File

@ -10,6 +10,8 @@ import (
"github.com/filecoin-project/go-address"
types "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/wallet"
"gopkg.in/urfave/cli.v2"
)
@ -44,7 +46,7 @@ var walletNew = &cli.Command{
t = "secp256k1"
}
nk, err := api.WalletNew(ctx, t)
nk, err := api.WalletNew(ctx, wallet.ActSigType(t))
if err != nil {
return err
}

1
go.mod
View File

@ -85,6 +85,7 @@ require (
github.com/multiformats/go-varint v0.0.5
github.com/opentracing/opentracing-go v1.1.0
github.com/prometheus/common v0.4.0
github.com/rogpeppe/go-internal v1.3.0
github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
github.com/whyrusleeping/cbor-gen v0.0.0-20200213013405-80352c7ae952

1
go.sum
View File

@ -691,6 +691,7 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/go-internal v1.3.0 h1:RR9dF3JtopPvtkroDZuVD7qquD0bnHlKSqaQhgwt8yk=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=

View File

@ -4,6 +4,8 @@ import (
"context"
"fmt"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
"github.com/ipfs/go-cid"
"go.uber.org/fx"
"golang.org/x/xerrors"
@ -64,9 +66,9 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address
Amount: v.Amount,
Lane: lane,
Extra: v.Extra,
TimeLock: v.TimeLock,
MinCloseHeight: v.MinClose,
Extra: v.Extra,
TimeLock: v.TimeLock,
MinSettleHeight: v.MinSettle,
})
if err != nil {
return nil, err
@ -103,6 +105,8 @@ func (a *PaychAPI) PaychStatus(ctx context.Context, pch address.Address) (*api.P
}
func (a *PaychAPI) PaychClose(ctx context.Context, addr address.Address) (cid.Cid, error) {
panic("TODO Settle logic")
ci, err := a.PaychMgr.GetChannelInfo(addr)
if err != nil {
return cid.Undef, err
@ -117,7 +121,7 @@ func (a *PaychAPI) PaychClose(ctx context.Context, addr address.Address) (cid.Ci
To: addr,
From: ci.Control,
Value: types.NewInt(0),
Method: actors.PCAMethods.Close,
Method: builtin.MethodsPaych.Settle,
Nonce: nonce,
GasLimit: types.NewInt(500),
@ -221,7 +225,7 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s
return cid.Undef, fmt.Errorf("cant handle more advanced payment channel stuff yet")
}
enc, err := actors.SerializeParams(&actors.PCAUpdateChannelStateParams{
enc, err := actors.SerializeParams(&paych.UpdateChannelStateParams{
Sv: *sv,
})
if err != nil {
@ -233,7 +237,7 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s
To: ch,
Value: types.NewInt(0),
Nonce: nonce,
Method: actors.PCAMethods.UpdateChannelState,
Method: builtin.MethodsPaych.UpdateChannelState,
Params: enc,
GasLimit: types.NewInt(100000),
GasPrice: types.NewInt(0),

View File

@ -229,7 +229,7 @@ func (s *FPoStScheduler) submitPost(ctx context.Context, proof *actors.SubmitFal
msg := &types.Message{
To: s.actor,
From: s.worker,
Method: actors.MAMethods.SubmitFallbackPoSt,
Method: builtin.MethodsMiner.SubmitFallbackPoSt,
Params: enc,
Value: types.NewInt(1000), // currently hard-coded late fee in actor, returned if not late
GasLimit: types.NewInt(10000000), // i dont know help

View File

@ -61,6 +61,7 @@ type storageMinerApi interface {
ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, *types.TipSet) (*types.TipSet, error)
ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error)
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
ChainHasObj(context.Context, cid.Cid) (bool, error)
WalletSign(context.Context, address.Address, []byte) (*types.Signature, error)
WalletBalance(context.Context, address.Address) (types.BigInt, error)