update specs-actors

This commit is contained in:
Łukasz Magiera 2020-02-21 17:57:40 +01:00
parent 00d7bd1a77
commit 57c43183e6
10 changed files with 77 additions and 14 deletions

View File

@ -95,6 +95,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
}
}
{
params := mustEnc(&m.Worker)
_, err := doExecValue(ctx, vm, actors.StorageMarketAddress, m.Worker, big.Zero(), builtin.MethodsMarket.AddBalance, params)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
}
}
// Publish preseal deals
@ -105,7 +112,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
params.Deals = append(params.Deals, market.ClientDealProposal{
Proposal: preseal.Deal,
ClientSignature: crypto.Signature{}, // TODO: do we want to sign these? Or do we want to fake signatures for genesis setup?
ClientSignature: crypto.Signature{Type:crypto.SigTypeBLS}, // TODO: do we want to sign these? Or do we want to fake signatures for genesis setup?
})
fmt.Printf("calling publish storage deals on miner %s with worker %s\n", preseal.Deal.Provider, m.Worker)
}
@ -197,7 +204,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
Info: miner.SectorPreCommitInfo{
SectorNumber: preseal.SectorID,
SealedCID: commcid.ReplicaCommitmentV1ToCID(preseal.CommR[:]),
SealEpoch: 0,
SealRandEpoch: 0,
DealIDs: []abi.DealID{dealIDs[pi]},
Expiration: preseal.Deal.EndEpoch,
},

View File

@ -2,24 +2,30 @@ package genesis
import (
"context"
"github.com/filecoin-project/go-amt-ipld/v2"
"github.com/ipfs/go-hamt-ipld"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
bstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
)
func SetupStorageMarketActor(bs bstore.Blockstore) (*types.Actor, error) {
cst := cbor.NewCborStore(bs)
ast := store.ActorStore(context.TODO(), bs)
sms, err := market.ConstructState(ast)
a, err := amt.NewAMT(cst).Flush(context.TODO())
if err != nil {
return nil, err
}
h, err := cst.Put(context.TODO(), hamt.NewNode(cst, hamt.UseTreeBitWidth(5)))
if err != nil {
return nil, err
}
sms := market.ConstructState(a, h, h)
stcid, err := cst.Put(context.TODO(), sms)
if err != nil {

View File

@ -2,6 +2,7 @@ package stmgr
import (
"context"
"github.com/filecoin-project/lotus/chain/state"
amt "github.com/filecoin-project/go-amt-ipld/v2"
commcid "github.com/filecoin-project/go-fil-commcid"
@ -42,7 +43,13 @@ func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr
return address.Undef, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
}
return mas.Info.Worker, nil
cst := cbor.NewCborStore(sm.cs.Blockstore())
state, err := state.LoadStateTree(cst, st)
if err != nil {
return address.Undef, xerrors.Errorf("load state tree: %w", err)
}
return vm.ResolveToKeyAddr(state, cst, mas.Info.Worker)
}
func GetMinerOwner(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) {
@ -52,7 +59,13 @@ func GetMinerOwner(ctx context.Context, sm *StateManager, st cid.Cid, maddr addr
return address.Undef, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
}
return mas.Info.Owner, nil
cst := cbor.NewCborStore(sm.cs.Blockstore())
state, err := state.LoadStateTree(cst, st)
if err != nil {
return address.Undef, xerrors.Errorf("load state tree: %w", err)
}
return vm.ResolveToKeyAddr(state, cst, mas.Info.Owner)
}
func GetPower(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (types.BigInt, types.BigInt, error) {

View File

@ -41,6 +41,7 @@ type VMContext interface {
Storage() Storage
StateTree() (StateTree, aerrors.ActorError)
ActorCodeCID(address.Address) (cid.Cid, error)
LookupID(address.Address) (address.Address, error)
VerifySignature(sig *crypto.Signature, from address.Address, data []byte) aerrors.ActorError
ChargeGas(uint64) aerrors.ActorError
GetRandomness(height abi.ChainEpoch) ([]byte, aerrors.ActorError)

View File

@ -5,6 +5,7 @@ import (
"context"
"encoding/binary"
"fmt"
"os"
"runtime/debug"
"github.com/filecoin-project/go-address"
@ -25,6 +26,14 @@ type runtimeShim struct {
vmctx types.VMContext
}
func (rs *runtimeShim) ResolveAddress(address address.Address) (ret address.Address, ok bool) {
r, err := rs.vmctx.LookupID(address)
if err != nil { // TODO: check notfound
rs.Abortf(exitcode.ErrPlaceholder, "resolve address: %v", err)
}
return r, true
}
func (rs *runtimeShim) Get(c cid.Cid, o vmr.CBORUnmarshaler) bool {
err := rs.vmctx.Storage().Get(c, o)
if err != nil { // todo: not found
@ -47,12 +56,12 @@ func (rs *runtimeShim) shimCall(f func() interface{}) (rval []byte, aerr aerrors
defer func() {
if r := recover(); r != nil {
if ar, ok := r.(aerrors.ActorError); ok {
fmt.Println("VM.Call failure: ", ar)
fmt.Fprintln(os.Stderr, "VM.Call failure: ", ar)
debug.PrintStack()
aerr = ar
return
}
fmt.Println("caught one of those actor errors: ", r)
fmt.Fprintln(os.Stderr, "caught one of those actor errors: ", r)
debug.PrintStack()
log.Errorf("ERROR")
aerr = aerrors.Newf(1, "generic spec actors failure")
@ -77,7 +86,20 @@ func (rs *runtimeShim) shimCall(f func() interface{}) (rval []byte, aerr aerrors
}
func (rs *runtimeShim) Message() vmr.Message {
return rs.vmctx.Message()
var err error
rawm := *rs.vmctx.Message() // TODO: normalize addresses earlier
rawm.From, err = rs.vmctx.LookupID(rawm.From)
if err != nil {
rs.Abortf(exitcode.ErrPlaceholder, "resolve from address: %v", err)
}
rawm.To, err = rs.vmctx.LookupID(rawm.To)
if err != nil {
rs.Abortf(exitcode.ErrPlaceholder, "resolve to address: %v", err)
}
return &rawm
}
func (rs *runtimeShim) ValidateImmediateCallerAcceptAny() {
@ -185,8 +207,13 @@ func (rs *runtimeShim) StartSpan(name string) vmr.TraceSpan {
}
func (rs *runtimeShim) ValidateImmediateCallerIs(as ...address.Address) {
imm, err := rs.vmctx.LookupID(rs.vmctx.Message().From)
if err != nil {
rs.Abortf(exitcode.ErrIllegalState, "couldn't resolve immediate caller")
}
for _, a := range as {
if rs.vmctx.Message().From == a {
if imm == a {
return
}
}

View File

@ -199,6 +199,10 @@ func (vmc *VMContext) ActorCodeCID(addr address.Address) (ret cid.Cid, err error
return act.Code, nil
}
func (vmc *VMContext) LookupID(a address.Address) (address.Address, error) {
return vmc.state.LookupID(a)
}
const GasVerifySignature = 50
func (vmctx *VMContext) VerifySignature(sig *crypto.Signature, act address.Address, data []byte) aerrors.ActorError {

View File

@ -74,7 +74,7 @@ func PreSeal(maddr address.Address, ssize abi.SectorSize, offset abi.SectorNumbe
TicketBytes: trand,
}
fmt.Printf("sector-id: %d, piece info: %v", sid, pi)
fmt.Printf("sector-id: %d, piece info: %v\n", sid, pi)
pco, err := sb.SealPreCommit(context.TODO(), sid, ticket, []sectorbuilder.PublicPieceInfo{pi})
if err != nil {

3
go.mod
View File

@ -13,6 +13,7 @@ require (
github.com/filecoin-project/chain-validation v0.0.3
github.com/filecoin-project/filecoin-ffi v0.0.0-20191219131535-bb699517a590
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be
github.com/filecoin-project/go-amt-ipld v1.0.0 // indirect
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
github.com/filecoin-project/go-cbor-util v0.0.0-20191219014500-08c40a1e63a2
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
@ -23,7 +24,7 @@ require (
github.com/filecoin-project/go-paramfetch v0.0.1
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200210220012-eb75ec747d6b
github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/specs-actors v0.0.0-20200219191759-7e15e5c89659
github.com/filecoin-project/specs-actors v0.0.0-20200221155838-19bb26c4b9d7
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/gorilla/mux v1.7.3

4
go.sum
View File

@ -132,6 +132,10 @@ github.com/filecoin-project/specs-actors v0.0.0-20200218211922-372fea3f131f h1:x
github.com/filecoin-project/specs-actors v0.0.0-20200218211922-372fea3f131f/go.mod h1:Ecx+3v6Bn4exCS0NbPu7VjrDCu2J+t1PdEpYin1/qOU=
github.com/filecoin-project/specs-actors v0.0.0-20200219191759-7e15e5c89659 h1:qHn5166bAy0dVEZr1Z4TPoveZNEEcFVz+RumCSM6QqA=
github.com/filecoin-project/specs-actors v0.0.0-20200219191759-7e15e5c89659/go.mod h1:Ecx+3v6Bn4exCS0NbPu7VjrDCu2J+t1PdEpYin1/qOU=
github.com/filecoin-project/specs-actors v0.0.0-20200221134721-ef38bdd3e05f h1:XplJWD0+rmozthAz4idL2wGyScmw9XlEZDaNmUKoY00=
github.com/filecoin-project/specs-actors v0.0.0-20200221134721-ef38bdd3e05f/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
github.com/filecoin-project/specs-actors v0.0.0-20200221155838-19bb26c4b9d7 h1:iBqYva5s34J0LVBe7Fqrv/ToNVUFyKwpaXLk47wjq3A=
github.com/filecoin-project/specs-actors v0.0.0-20200221155838-19bb26c4b9d7/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 h1:EzDjxMg43q1tA2c0MV3tNbaontnHLplHyFF6M5KiVP0=

View File

@ -103,7 +103,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
SectorNumber: sector.SectorID,
SealedCID: commcid.ReplicaCommitmentV1ToCID(sector.CommR),
SealEpoch: sector.Ticket.BlockHeight,
SealRandEpoch: sector.Ticket.BlockHeight,
DealIDs: nil, // sector.deals(), // TODO: REFACTOR
}
enc, aerr := actors.SerializeParams(params)