more switching over to correct cbor marshaling
This commit is contained in:
parent
1f1bbc9b8d
commit
2f019158d0
@ -5,9 +5,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -26,8 +28,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cbor.RegisterCborType(ExecParams{})
|
|
||||||
cbor.RegisterCborType(struct{}{})
|
|
||||||
|
|
||||||
n, err := cbor.WrapObject(map[string]string{}, mh.SHA2_256, -1)
|
n, err := cbor.WrapObject(map[string]string{}, mh.SHA2_256, -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -64,17 +64,16 @@ type ExecParams struct {
|
|||||||
Params []byte
|
Params []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateExecParams(act cid.Cid, obj interface{}) ([]byte, aerrors.ActorError) {
|
func CreateExecParams(act cid.Cid, obj cbg.CBORMarshaler) ([]byte, aerrors.ActorError) {
|
||||||
encparams, err := SerializeParams(obj)
|
encparams, err := SerializeParams(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.Wrap(err, "creating ExecParams")
|
return nil, aerrors.Wrap(err, "creating ExecParams")
|
||||||
}
|
}
|
||||||
|
|
||||||
var ep ExecParams
|
return SerializeParams(&ExecParams{
|
||||||
ep.Code = act
|
Code: act,
|
||||||
ep.Params = encparams
|
Params: encparams,
|
||||||
|
})
|
||||||
return SerializeParams(ep)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams) ([]byte, aerrors.ActorError) {
|
func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams) ([]byte, aerrors.ActorError) {
|
||||||
@ -117,10 +116,12 @@ func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams)
|
|||||||
Head: EmptyCBOR,
|
Head: EmptyCBOR,
|
||||||
Nonce: 0,
|
Nonce: 0,
|
||||||
}
|
}
|
||||||
_, err = vmctx.Storage().Put(struct{}{})
|
/*
|
||||||
if err != nil {
|
_, err = vmctx.Storage().Put(struct{}{})
|
||||||
return nil, err
|
if err != nil {
|
||||||
}
|
return nil, err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// The call to the actors constructor will set up the initial state
|
// The call to the actors constructor will set up the initial state
|
||||||
// from the given parameters, setting `actor.Head` to a new value when successful.
|
// from the given parameters, setting `actor.Head` to a new value when successful.
|
||||||
@ -153,7 +154,7 @@ func (ia InitActor) Exec(act *types.Actor, vmctx types.VMContext, p *ExecParams)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := vmctx.Storage().Put(self)
|
c, err := vmctx.Storage().Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -213,7 +214,7 @@ func (ias *InitActorState) Lookup(cst *hamt.CborIpldStore, addr address.Address)
|
|||||||
var val interface{}
|
var val interface{}
|
||||||
err = amap.Find(context.TODO(), string(addr.Bytes()), &val)
|
err = amap.Find(context.TODO(), string(addr.Bytes()), &val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return address.Undef, xerrors.Errorf("ias lookup failed to do lookup: %w", err)
|
return address.Undef, xerrors.Errorf("ias lookup failed to do find: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ival, ok := val.(uint64)
|
ival, ok := val.(uint64)
|
||||||
|
@ -2,6 +2,7 @@ package actors
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
@ -14,18 +15,6 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cbor.RegisterCborType(StorageMinerActorState{})
|
|
||||||
cbor.RegisterCborType(StorageMinerConstructorParams{})
|
|
||||||
cbor.RegisterCborType(CommitSectorParams{})
|
|
||||||
cbor.RegisterCborType(MinerInfo{})
|
|
||||||
cbor.RegisterCborType(SubmitPoStParams{})
|
|
||||||
cbor.RegisterCborType(PieceInclVoucherData{})
|
|
||||||
cbor.RegisterCborType(InclusionProof{})
|
|
||||||
cbor.RegisterCborType(PaymentVerifyParams{})
|
|
||||||
cbor.RegisterCborType(UpdatePeerIDParams{})
|
|
||||||
}
|
|
||||||
|
|
||||||
var ProvingPeriodDuration = uint64(2 * 60) // an hour, for now
|
var ProvingPeriodDuration = uint64(2 * 60) // an hour, for now
|
||||||
const POST_SECTORS_COUNT = 8192
|
const POST_SECTORS_COUNT = 8192
|
||||||
|
|
||||||
@ -190,7 +179,7 @@ func (sma StorageMinerActor) StorageMinerConstructor(act *types.Actor, vmctx typ
|
|||||||
self.Info = minfocid
|
self.Info = minfocid
|
||||||
|
|
||||||
storage := vmctx.Storage()
|
storage := vmctx.Storage()
|
||||||
c, err := storage.Put(self)
|
c, err := storage.Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -2,24 +2,13 @@ package actors
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
cbor.RegisterCborType(MultiSigActorState{})
|
)
|
||||||
cbor.RegisterCborType(MultiSigConstructorParams{})
|
|
||||||
cbor.RegisterCborType(MultiSigProposeParams{})
|
|
||||||
cbor.RegisterCborType(MultiSigTxID{})
|
|
||||||
cbor.RegisterCborType(MultiSigSwapSignerParams{})
|
|
||||||
cbor.RegisterCborType(MultiSigChangeReqParams{})
|
|
||||||
cbor.RegisterCborType(MTransaction{})
|
|
||||||
cbor.RegisterCborType(MultiSigRemoveSignerParam{})
|
|
||||||
cbor.RegisterCborType(MultiSigAddSignerParam{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type MultiSigActor struct{}
|
type MultiSigActor struct{}
|
||||||
type MultiSigActorState struct {
|
type MultiSigActorState struct {
|
||||||
@ -203,7 +192,9 @@ func (msa MultiSigActor) Propose(act *types.Actor, vmctx types.VMContext,
|
|||||||
return nil, aerrors.Wrap(err, "saving state")
|
return nil, aerrors.Wrap(err, "saving state")
|
||||||
}
|
}
|
||||||
|
|
||||||
return SerializeParams(tx.TxID)
|
// REVIEW: On one hand, I like being very explicit about how we're doing the serialization
|
||||||
|
// on the other, maybe we shouldnt do direct calls to underlying serialization libs?
|
||||||
|
return cbg.CborEncodeMajorType(cbg.MajUnsignedInt, tx.TxID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type MultiSigTxID struct {
|
type MultiSigTxID struct {
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/build"
|
"github.com/filecoin-project/go-lotus/build"
|
||||||
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
||||||
@ -13,14 +12,6 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cbor.RegisterCborType(PaymentChannelActorState{})
|
|
||||||
cbor.RegisterCborType(PCAConstructorParams{})
|
|
||||||
cbor.RegisterCborType(LaneState{})
|
|
||||||
cbor.RegisterCborType(PCAUpdateChannelStateParams{})
|
|
||||||
cbor.RegisterCborType(PaymentInfo{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type PaymentChannelActor struct{}
|
type PaymentChannelActor struct{}
|
||||||
|
|
||||||
type PaymentInfo struct {
|
type PaymentInfo struct {
|
||||||
@ -84,7 +75,7 @@ func (pca PaymentChannelActor) Constructor(act *types.Actor, vmctx types.VMConte
|
|||||||
self.LaneStates = make(map[string]*LaneState)
|
self.LaneStates = make(map[string]*LaneState)
|
||||||
|
|
||||||
storage := vmctx.Storage()
|
storage := vmctx.Storage()
|
||||||
c, err := storage.Put(self)
|
c, err := storage.Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -136,7 +127,7 @@ func (pca PaymentChannelActor) UpdateChannelState(act *types.Actor, vmctx types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if sv.Extra != nil {
|
if sv.Extra != nil {
|
||||||
encoded, err := SerializeParams(PaymentVerifyParams{sv.Extra.Data, params.Proof})
|
encoded, err := SerializeParams(&PaymentVerifyParams{sv.Extra.Data, params.Proof})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -203,7 +194,7 @@ func (pca PaymentChannelActor) UpdateChannelState(act *types.Actor, vmctx types.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ncid, err := storage.Put(self)
|
ncid, err := storage.Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -235,7 +226,7 @@ func (pca PaymentChannelActor) Close(act *types.Actor, vmctx types.VMContext, pa
|
|||||||
self.ClosingAt = self.MinCloseHeight
|
self.ClosingAt = self.MinCloseHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
ncid, err := storage.Put(self)
|
ncid, err := storage.Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -272,7 +263,7 @@ func (pca PaymentChannelActor) Collect(act *types.Actor, vmctx types.VMContext,
|
|||||||
|
|
||||||
self.ToSend = types.NewInt(0)
|
self.ToSend = types.NewInt(0)
|
||||||
|
|
||||||
ncid, err := storage.Put(self)
|
ncid, err := storage.Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -10,18 +10,10 @@ import (
|
|||||||
|
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
hamt "github.com/ipfs/go-hamt-ipld"
|
hamt "github.com/ipfs/go-hamt-ipld"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cbor.RegisterCborType(StorageMarketState{})
|
|
||||||
cbor.RegisterCborType(CreateStorageMinerParams{})
|
|
||||||
cbor.RegisterCborType(IsMinerParam{})
|
|
||||||
cbor.RegisterCborType(PowerLookupParams{})
|
|
||||||
cbor.RegisterCborType(UpdateStorageParams{})
|
|
||||||
}
|
|
||||||
|
|
||||||
type StorageMarketActor struct{}
|
type StorageMarketActor struct{}
|
||||||
|
|
||||||
type smaMethods struct {
|
type smaMethods struct {
|
||||||
@ -98,7 +90,7 @@ func (sma StorageMarketActor) CreateStorageMiner(act *types.Actor, vmctx types.V
|
|||||||
}
|
}
|
||||||
self.Miners = ncid
|
self.Miners = ncid
|
||||||
|
|
||||||
nroot, err := vmctx.Storage().Put(self)
|
nroot, err := vmctx.Storage().Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -139,7 +131,7 @@ func (sma StorageMarketActor) UpdateStorage(act *types.Actor, vmctx types.VMCont
|
|||||||
|
|
||||||
self.TotalStorage = types.BigAdd(self.TotalStorage, params.Delta)
|
self.TotalStorage = types.BigAdd(self.TotalStorage, params.Delta)
|
||||||
|
|
||||||
nroot, err := vmctx.Storage().Put(self)
|
nroot, err := vmctx.Storage().Put(&self)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -179,7 +171,7 @@ func (sma StorageMarketActor) PowerLookup(act *types.Actor, vmctx types.VMContex
|
|||||||
return nil, aerrors.New(1, "miner not registered with storage market")
|
return nil, aerrors.New(1, "miner not registered with storage market")
|
||||||
}
|
}
|
||||||
|
|
||||||
ret, err := vmctx.Send(params.Miner, MAMethods.GetPower, types.NewInt(0), EmptyStructCBOR)
|
ret, err := vmctx.Send(params.Miner, MAMethods.GetPower, types.NewInt(0), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.Wrap(err, "invoke Miner.GetPower")
|
return nil, aerrors.Wrap(err, "invoke Miner.GetPower")
|
||||||
}
|
}
|
||||||
@ -202,11 +194,7 @@ func (sma StorageMarketActor) IsMiner(act *types.Actor, vmctx types.VMContext, p
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := SerializeParams(has)
|
return cbg.EncodeBool(has), nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return out, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MinerSetHas(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddr address.Address) (bool, aerrors.ActorError) {
|
func MinerSetHas(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddr address.Address) (bool, aerrors.ActorError) {
|
||||||
@ -215,7 +203,7 @@ func MinerSetHas(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddr
|
|||||||
return false, aerrors.Escalate(err, "failed to load miner set")
|
return false, aerrors.Escalate(err, "failed to load miner set")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = nd.Find(context.TODO(), string(maddr.Bytes()))
|
err = nd.Find(context.TODO(), string(maddr.Bytes()), nil)
|
||||||
switch err {
|
switch err {
|
||||||
case hamt.ErrNotFound:
|
case hamt.ErrNotFound:
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -4,15 +4,9 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
|
||||||
mh "github.com/multiformats/go-multihash"
|
mh "github.com/multiformats/go-multihash"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cbor.RegisterCborType(InitActorState{})
|
|
||||||
cbor.RegisterCborType(AccountActorState{})
|
|
||||||
}
|
|
||||||
|
|
||||||
var AccountActorCodeCid cid.Cid
|
var AccountActorCodeCid cid.Cid
|
||||||
var StorageMarketActorCodeCid cid.Cid
|
var StorageMarketActorCodeCid cid.Cid
|
||||||
var StorageMinerCodeCid cid.Cid
|
var StorageMinerCodeCid cid.Cid
|
||||||
|
@ -39,7 +39,7 @@ func (t *InitActorState) UnmarshalCBOR(br io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if maj != cbg.MajArray {
|
if maj != cbg.MajArray {
|
||||||
return fmt.Errorf("cbor input should be of type array")
|
return fmt.Errorf("cbor input should be of type array (got %d, %d)", maj, extra)
|
||||||
}
|
}
|
||||||
|
|
||||||
if extra != 2 {
|
if extra != 2 {
|
||||||
@ -2007,7 +2007,7 @@ func (t *PaymentInfo) UnmarshalCBOR(br io.Reader) error {
|
|||||||
return fmt.Errorf("expected cbor array")
|
return fmt.Errorf("expected cbor array")
|
||||||
}
|
}
|
||||||
if extra > 0 {
|
if extra > 0 {
|
||||||
t.Vouchers = make([]types.SignedVoucher, extra)
|
t.Vouchers = make([]*types.SignedVoucher, extra)
|
||||||
}
|
}
|
||||||
for i := 0; i < int(extra); i++ {
|
for i := 0; i < int(extra); i++ {
|
||||||
var v types.SignedVoucher
|
var v types.SignedVoucher
|
||||||
@ -2015,7 +2015,7 @@ func (t *PaymentInfo) UnmarshalCBOR(br io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Vouchers[i] = v
|
t.Vouchers[i] = &v
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
package actors
|
package actors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
"github.com/filecoin-project/go-lotus/chain/actors/aerrors"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
EmptyStructCBOR = []byte{0xa0}
|
EmptyStructCBOR = []byte{0xa0}
|
||||||
)
|
)
|
||||||
|
|
||||||
func SerializeParams(i interface{}) ([]byte, aerrors.ActorError) {
|
func SerializeParams(i cbg.CBORMarshaler) ([]byte, aerrors.ActorError) {
|
||||||
dump, err := cbor.DumpObject(i)
|
buf := new(bytes.Buffer)
|
||||||
if err != nil {
|
if err := i.MarshalCBOR(buf); err != nil {
|
||||||
// TODO: shouldnt this be a fatal error?
|
// TODO: shouldnt this be a fatal error?
|
||||||
return nil, aerrors.Absorb(err, 1, "failed to encode parameter")
|
return nil, aerrors.Absorb(err, 1, "failed to encode parameter")
|
||||||
}
|
}
|
||||||
return dump, nil
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
hamt "github.com/ipfs/go-hamt-ipld"
|
hamt "github.com/ipfs/go-hamt-ipld"
|
||||||
bstore "github.com/ipfs/go-ipfs-blockstore"
|
bstore "github.com/ipfs/go-ipfs-blockstore"
|
||||||
peer "github.com/libp2p/go-libp2p-peer"
|
peer "github.com/libp2p/go-libp2p-peer"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
sharray "github.com/whyrusleeping/sharray"
|
sharray "github.com/whyrusleeping/sharray"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -161,7 +162,7 @@ type GenMinerCfg struct {
|
|||||||
PeerIDs []peer.ID
|
PeerIDs []peer.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustEnc(i interface{}) []byte {
|
func mustEnc(i cbg.CBORMarshaler) []byte {
|
||||||
enc, err := actors.SerializeParams(i)
|
enc, err := actors.SerializeParams(i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -180,7 +181,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
|||||||
worker := gmcfg.Workers[i]
|
worker := gmcfg.Workers[i]
|
||||||
pid := gmcfg.PeerIDs[i]
|
pid := gmcfg.PeerIDs[i]
|
||||||
|
|
||||||
params := mustEnc(actors.CreateStorageMinerParams{
|
params := mustEnc(&actors.CreateStorageMinerParams{
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Worker: worker,
|
Worker: worker,
|
||||||
SectorSize: types.NewInt(build.SectorSize),
|
SectorSize: types.NewInt(build.SectorSize),
|
||||||
@ -199,7 +200,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
|||||||
|
|
||||||
gmcfg.MinerAddrs = append(gmcfg.MinerAddrs, maddr)
|
gmcfg.MinerAddrs = append(gmcfg.MinerAddrs, maddr)
|
||||||
|
|
||||||
params = mustEnc(actors.UpdateStorageParams{Delta: types.NewInt(5000)})
|
params = mustEnc(&actors.UpdateStorageParams{Delta: types.NewInt(5000)})
|
||||||
|
|
||||||
_, err = doExec(ctx, vm, actors.StorageMarketAddress, maddr, actors.SMAMethods.UpdateStorage, params)
|
_, err = doExec(ctx, vm, actors.StorageMarketAddress, maddr, actors.SMAMethods.UpdateStorage, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -226,7 +227,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
|||||||
}
|
}
|
||||||
mstate.Power = types.NewInt(5000)
|
mstate.Power = types.NewInt(5000)
|
||||||
|
|
||||||
nstate, err := cst.Put(ctx, mstate)
|
nstate, err := cst.Put(ctx, &mstate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
@ -258,7 +259,7 @@ func doExec(ctx context.Context, vm *vm.VM, to, from address.Address, method uin
|
|||||||
Nonce: act.Nonce,
|
Nonce: act.Nonce,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, xerrors.Errorf("doExec apply message failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ret.ExitCode != 0 {
|
if ret.ExitCode != 0 {
|
||||||
|
@ -90,10 +90,10 @@ func (st *StateTree) GetActor(addr address.Address) (*types.Actor, error) {
|
|||||||
if addr.Protocol() != address.ID {
|
if addr.Protocol() != address.ID {
|
||||||
iaddr, err := st.lookupID(addr)
|
iaddr, err := st.lookupID(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == hamt.ErrNotFound {
|
if xerrors.Is(err, hamt.ErrNotFound) {
|
||||||
return nil, types.ErrActorNotFound
|
return nil, xerrors.Errorf("lookup failed: %w", types.ErrActorNotFound)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, xerrors.Errorf("address resolution: %w", err)
|
||||||
}
|
}
|
||||||
addr = iaddr
|
addr = iaddr
|
||||||
}
|
}
|
||||||
|
@ -26,12 +26,6 @@ func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate
|
|||||||
if msg.Value == types.EmptyInt {
|
if msg.Value == types.EmptyInt {
|
||||||
msg.Value = types.NewInt(0)
|
msg.Value = types.NewInt(0)
|
||||||
}
|
}
|
||||||
if msg.Params == nil {
|
|
||||||
msg.Params, err = actors.SerializeParams(struct{}{})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fromActor, err := vmi.StateTree().GetActor(msg.From)
|
fromActor, err := vmi.StateTree().GetActor(msg.From)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -124,13 +124,13 @@ func (sm *StateManager) GetActor(addr address.Address) (*types.Actor, error) {
|
|||||||
ts := sm.cs.GetHeaviestTipSet()
|
ts := sm.cs.GetHeaviestTipSet()
|
||||||
stcid, err := sm.TipSetState(ts.Cids())
|
stcid, err := sm.TipSetState(ts.Cids())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, xerrors.Errorf("tipset state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cst := hamt.CSTFromBstore(sm.cs.Blockstore())
|
cst := hamt.CSTFromBstore(sm.cs.Blockstore())
|
||||||
state, err := state.LoadStateTree(cst, stcid)
|
state, err := state.LoadStateTree(cst, stcid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, xerrors.Errorf("load state tree: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.GetActor(addr)
|
return state.GetActor(addr)
|
||||||
@ -139,7 +139,7 @@ func (sm *StateManager) GetActor(addr address.Address) (*types.Actor, error) {
|
|||||||
func (sm *StateManager) GetBalance(addr address.Address) (types.BigInt, error) {
|
func (sm *StateManager) GetBalance(addr address.Address) (types.BigInt, error) {
|
||||||
act, err := sm.GetActor(addr)
|
act, err := sm.GetActor(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return types.BigInt{}, err
|
return types.BigInt{}, xerrors.Errorf("get actor: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return act.Balance, nil
|
return act.Balance, nil
|
||||||
|
@ -256,7 +256,7 @@ func (tu *syncTestUtil) submitSourceBlocks(to int, h int, n int) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
func TestSyncSimple(t *testing.T) {
|
func TestSyncSimple(t *testing.T) {
|
||||||
H := 100
|
H := 15
|
||||||
tu := prepSyncTest(t, H)
|
tu := prepSyncTest(t, H)
|
||||||
|
|
||||||
client := tu.addClientNode()
|
client := tu.addClientNode()
|
||||||
|
@ -6,11 +6,12 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/address"
|
"github.com/filecoin-project/go-lotus/chain/address"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
"github.com/ipfs/go-hamt-ipld"
|
"github.com/ipfs/go-hamt-ipld"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Storage interface {
|
type Storage interface {
|
||||||
Put(interface{}) (cid.Cid, aerrors.ActorError)
|
Put(cbg.CBORMarshaler) (cid.Cid, aerrors.ActorError)
|
||||||
Get(cid.Cid, interface{}) aerrors.ActorError
|
Get(cid.Cid, cbg.CBORUnmarshaler) aerrors.ActorError
|
||||||
|
|
||||||
GetHead() cid.Cid
|
GetHead() cid.Cid
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ type storageWrapper struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sw *storageWrapper) Put(i interface{}) (cid.Cid, error) {
|
func (sw *storageWrapper) Put(i interface{}) (cid.Cid, error) {
|
||||||
c, err := sw.s.Put(i)
|
c, err := sw.s.Put(i.(cbg.CBORMarshaler))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, err
|
||||||
}
|
}
|
||||||
@ -51,7 +52,7 @@ func (sw *storageWrapper) Put(i interface{}) (cid.Cid, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sw *storageWrapper) Get(c cid.Cid, out interface{}) error {
|
func (sw *storageWrapper) Get(c cid.Cid, out interface{}) error {
|
||||||
if err := sw.s.Get(c, out); err != nil {
|
if err := sw.s.Get(c, out.(cbg.CBORUnmarshaler)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
actors "github.com/filecoin-project/go-lotus/chain/actors"
|
actors "github.com/filecoin-project/go-lotus/chain/actors"
|
||||||
@ -121,8 +123,7 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
|||||||
|
|
||||||
inBytes := in[2].Interface().([]byte)
|
inBytes := in[2].Interface().([]byte)
|
||||||
if len(inBytes) > 0 {
|
if len(inBytes) > 0 {
|
||||||
err := cbor.DecodeInto(inBytes, param.Interface())
|
if err := DecodeParams(inBytes, param.Interface()); err != nil {
|
||||||
if err != nil {
|
|
||||||
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
|
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
|
||||||
return []reflect.Value{
|
return []reflect.Value{
|
||||||
reflect.ValueOf([]byte{}),
|
reflect.ValueOf([]byte{}),
|
||||||
@ -142,6 +143,15 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
|||||||
return code, nil
|
return code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DecodeParams(b []byte, out interface{}) error {
|
||||||
|
um, ok := out.(cbg.CBORUnmarshaler)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("type %T does not implement UnmarshalCBOR", out)
|
||||||
|
}
|
||||||
|
|
||||||
|
return um.UnmarshalCBOR(bytes.NewReader(b))
|
||||||
|
}
|
||||||
|
|
||||||
func DumpActorState(code cid.Cid, b []byte) (interface{}, error) {
|
func DumpActorState(code cid.Cid, b []byte) (interface{}, error) {
|
||||||
i := newInvoker() // TODO: register builtins in init block
|
i := newInvoker() // TODO: register builtins in init block
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/chain/store"
|
"github.com/filecoin-project/go-lotus/chain/store"
|
||||||
"github.com/filecoin-project/go-lotus/chain/types"
|
"github.com/filecoin-project/go-lotus/chain/types"
|
||||||
"github.com/filecoin-project/go-lotus/lib/bufbstore"
|
"github.com/filecoin-project/go-lotus/lib/bufbstore"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"go.opencensus.io/trace"
|
"go.opencensus.io/trace"
|
||||||
|
|
||||||
block "github.com/ipfs/go-block-format"
|
block "github.com/ipfs/go-block-format"
|
||||||
@ -67,18 +68,19 @@ func (vmc *VMContext) Message() *types.Message {
|
|||||||
|
|
||||||
// Storage interface
|
// Storage interface
|
||||||
|
|
||||||
func (vmc *VMContext) Put(i interface{}) (cid.Cid, aerrors.ActorError) {
|
func (vmc *VMContext) Put(i cbg.CBORMarshaler) (cid.Cid, aerrors.ActorError) {
|
||||||
c, err := vmc.cst.Put(context.TODO(), i)
|
c, err := vmc.cst.Put(context.TODO(), i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if aerr := vmc.ChargeGas(0); aerr != nil {
|
if aerr := vmc.ChargeGas(0); aerr != nil {
|
||||||
return cid.Undef, aerrors.Absorb(err, outOfGasErrCode, "Put out of gas")
|
return cid.Undef, aerrors.Absorb(err, outOfGasErrCode, "Put out of gas")
|
||||||
}
|
}
|
||||||
return cid.Undef, aerrors.Escalate(err, "putting cid")
|
panic("no u")
|
||||||
|
return cid.Undef, aerrors.Escalate(err, fmt.Sprintf("putting object %T", i))
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vmc *VMContext) Get(c cid.Cid, out interface{}) aerrors.ActorError {
|
func (vmc *VMContext) Get(c cid.Cid, out cbg.CBORUnmarshaler) aerrors.ActorError {
|
||||||
err := vmc.cst.Get(context.TODO(), c, out)
|
err := vmc.cst.Get(context.TODO(), c, out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if aerr := vmc.ChargeGas(0); aerr != nil {
|
if aerr := vmc.ChargeGas(0); aerr != nil {
|
||||||
|
4
go.mod
4
go.mod
@ -22,7 +22,7 @@ require (
|
|||||||
github.com/ipfs/go-ds-badger v0.0.5
|
github.com/ipfs/go-ds-badger v0.0.5
|
||||||
github.com/ipfs/go-filestore v0.0.2
|
github.com/ipfs/go-filestore v0.0.2
|
||||||
github.com/ipfs/go-fs-lock v0.0.1
|
github.com/ipfs/go-fs-lock v0.0.1
|
||||||
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190830015840-8aabc0c74ac6
|
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190910032255-ee6e898f0456
|
||||||
github.com/ipfs/go-ipfs-blockstore v0.1.0
|
github.com/ipfs/go-ipfs-blockstore v0.1.0
|
||||||
github.com/ipfs/go-ipfs-chunker v0.0.1
|
github.com/ipfs/go-ipfs-chunker v0.0.1
|
||||||
github.com/ipfs/go-ipfs-ds-help v0.0.1
|
github.com/ipfs/go-ipfs-ds-help v0.0.1
|
||||||
@ -67,7 +67,7 @@ require (
|
|||||||
github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a
|
github.com/polydawn/refmt v0.0.0-20190809202753-05966cbd336a
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
|
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20190909233408-ae6265959798
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190910040623-f29470053db6
|
||||||
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
|
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7
|
||||||
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
|
github.com/whyrusleeping/pubsub v0.0.0-20131020042734-02de8aa2db3d
|
||||||
github.com/whyrusleeping/sharray v0.0.0-20190718051354-e41931821e33
|
github.com/whyrusleeping/sharray v0.0.0-20190718051354-e41931821e33
|
||||||
|
6
go.sum
6
go.sum
@ -170,6 +170,8 @@ github.com/ipfs/go-fs-lock v0.0.1 h1:XHX8uW4jQBYWHj59XXcjg7BHlHxV9ZOYs6Y43yb7/l0
|
|||||||
github.com/ipfs/go-fs-lock v0.0.1/go.mod h1:DNBekbboPKcxs1aukPSaOtFA3QfSdi5C855v0i9XJ8Y=
|
github.com/ipfs/go-fs-lock v0.0.1/go.mod h1:DNBekbboPKcxs1aukPSaOtFA3QfSdi5C855v0i9XJ8Y=
|
||||||
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190830015840-8aabc0c74ac6 h1:qVk+425ErvzJEz/9f38lhjPfmmu0GAj/BSNt56SW4xQ=
|
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190830015840-8aabc0c74ac6 h1:qVk+425ErvzJEz/9f38lhjPfmmu0GAj/BSNt56SW4xQ=
|
||||||
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190830015840-8aabc0c74ac6/go.mod h1:UPmViPxLn1GGxxnllIww8yWUVO60qEYLFFfF9e3ojgo=
|
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190830015840-8aabc0c74ac6/go.mod h1:UPmViPxLn1GGxxnllIww8yWUVO60qEYLFFfF9e3ojgo=
|
||||||
|
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190910032255-ee6e898f0456 h1:I0DHyyygfm9fxWK3dZ6XAXBHVY2u93ske4kprAmm4og=
|
||||||
|
github.com/ipfs/go-hamt-ipld v0.0.12-0.20190910032255-ee6e898f0456/go.mod h1:oVAOWGetjaaAPloFDCudyhxofsSG/WijXMJLTA0kRhM=
|
||||||
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
|
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
|
||||||
github.com/ipfs/go-ipfs-blockstore v0.0.2/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
|
github.com/ipfs/go-ipfs-blockstore v0.0.2/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
|
||||||
github.com/ipfs/go-ipfs-blockstore v0.1.0 h1:V1GZorHFUIB6YgTJQdq7mcaIpUfCM3fCyVi+MTo9O88=
|
github.com/ipfs/go-ipfs-blockstore v0.1.0 h1:V1GZorHFUIB6YgTJQdq7mcaIpUfCM3fCyVi+MTo9O88=
|
||||||
@ -530,6 +532,10 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20190909232404-de20c470a082 h1:Wh1Hyuaz
|
|||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20190909232404-de20c470a082/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190909232404-de20c470a082/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20190909233408-ae6265959798 h1:4j/w+x60KmMsRwRavx3cxDgdV0iCRVoNCizhiAo2vF8=
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190909233408-ae6265959798 h1:4j/w+x60KmMsRwRavx3cxDgdV0iCRVoNCizhiAo2vF8=
|
||||||
github.com/whyrusleeping/cbor-gen v0.0.0-20190909233408-ae6265959798/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190909233408-ae6265959798/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||||
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb h1:8yBVx6dgk1GfkiWOQ+RbeDDBLCOZxOtmZ949O2uj5H4=
|
||||||
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190910031516-c1cbffdb01bb/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||||
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190910040623-f29470053db6 h1:e46mGjWNMelsw+YLq/5TyMfwGz8p0cBY2cf91y6tSBA=
|
||||||
|
github.com/whyrusleeping/cbor-gen v0.0.0-20190910040623-f29470053db6/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||||
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E=
|
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E=
|
||||||
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
|
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
|
||||||
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
|
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
|
||||||
|
Loading…
Reference in New Issue
Block a user