add error wraps and fix tests
This commit is contained in:
parent
e9d1f3e7c9
commit
2efab559ec
@ -16,6 +16,7 @@ func init() {
|
||||
cbor.RegisterCborType(CreateStorageMinerParams{})
|
||||
cbor.RegisterCborType(IsMinerParam{})
|
||||
cbor.RegisterCborType(PowerLookupParams{})
|
||||
cbor.RegisterCborType(UpdateStorageParams{})
|
||||
}
|
||||
|
||||
type StorageMarketActor struct{}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/ipfs/go-car"
|
||||
offline "github.com/ipfs/go-ipfs-exchange-offline"
|
||||
"github.com/ipfs/go-merkledag"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-lotus/chain/address"
|
||||
"github.com/filecoin-project/go-lotus/chain/store"
|
||||
@ -69,47 +70,46 @@ func NewGenerator() (*ChainGen, error) {
|
||||
mr := repo.NewMemory(nil)
|
||||
lr, err := mr.Lock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("taking mem-repo lock failed: %w", err)
|
||||
}
|
||||
|
||||
ds, err := lr.Datastore("/metadata")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("failed to get metadata datastore: %w", err)
|
||||
}
|
||||
|
||||
bds, err := lr.Datastore("/blocks")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("failed to get blocks datastore: %w", err)
|
||||
}
|
||||
|
||||
bs := mybs{blockstore.NewIdStore(blockstore.NewBlockstore(bds))}
|
||||
|
||||
ks, err := lr.KeyStore()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("getting repo keystore failed: %w", err)
|
||||
}
|
||||
|
||||
w, err := wallet.NewWallet(ks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("creating memrepo wallet failed: %w", err)
|
||||
}
|
||||
|
||||
worker, err := w.GenerateKey(types.KTBLS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("failed to generate worker key: %w", err)
|
||||
}
|
||||
|
||||
// KTBLS doesn't support signature verification or something like that yet
|
||||
banker, err := w.GenerateKey(types.KTSecp256k1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("failed to generate banker key: %w", err)
|
||||
}
|
||||
|
||||
receievers := make([]address.Address, msgsPerBlock)
|
||||
for r := range receievers {
|
||||
receievers[r], err = w.GenerateKey(types.KTBLS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("failed to generate receiver key: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ func NewGenerator() (*ChainGen, error) {
|
||||
banker: types.NewInt(90000000),
|
||||
}, minercfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("make genesis block failed: %w", err)
|
||||
}
|
||||
|
||||
cs := store.NewChainStore(bs, ds)
|
||||
@ -131,7 +131,7 @@ func NewGenerator() (*ChainGen, error) {
|
||||
genfb := &types.FullBlock{Header: genb.Genesis}
|
||||
|
||||
if err := cs.SetGenesis(genb.Genesis); err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("set genesis failed: %w", err)
|
||||
}
|
||||
|
||||
gen := &ChainGen{
|
||||
|
@ -162,7 +162,7 @@ func mustEnc(i interface{}) []byte {
|
||||
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, gmcfg *GenMinerCfg) (cid.Cid, error) {
|
||||
vm, err := vm.NewVM(sroot, 0, actors.NetworkAddress, cs)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err)
|
||||
}
|
||||
|
||||
params := mustEnc(actors.CreateStorageMinerParams{
|
||||
@ -189,16 +189,22 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
||||
_, err = doExec(ctx, vm, actors.StorageMarketAddress, maddr, actors.SMAMethods.UpdateStorage, params)
|
||||
|
||||
// UGLY HACKY MODIFICATION OF MINER POWER
|
||||
|
||||
// we have to flush the vm here because it buffers stuff internally for perf reasons
|
||||
if _, err := vm.Flush(ctx); err != nil {
|
||||
return cid.Undef, xerrors.Errorf("vm.Flush failed: %w", err)
|
||||
}
|
||||
|
||||
st := vm.StateTree()
|
||||
mact, err := st.GetActor(maddr)
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
return cid.Undef, xerrors.Errorf("get miner actor failed: %w", err)
|
||||
}
|
||||
|
||||
cst := hamt.CSTFromBstore(cs.Blockstore())
|
||||
var mstate actors.StorageMinerActorState
|
||||
if err := cst.Get(ctx, mact.Head, &mstate); err != nil {
|
||||
return cid.Undef, err
|
||||
return cid.Undef, xerrors.Errorf("getting miner actor state failed: %w", err)
|
||||
}
|
||||
mstate.Power = types.NewInt(5000)
|
||||
|
||||
@ -242,19 +248,19 @@ func MakeGenesisBlock(bs bstore.Blockstore, balances map[address.Address]types.B
|
||||
|
||||
state, err := MakeInitialStateTree(bs, balances)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("make initial state tree failed: %w", err)
|
||||
}
|
||||
|
||||
stateroot, err := state.Flush()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("flush state tree failed: %w", err)
|
||||
}
|
||||
|
||||
// temp chainstore
|
||||
cs := store.NewChainStore(bs, datastore.NewMapDatastore())
|
||||
stateroot, err = SetupStorageMiners(ctx, cs, stateroot, gmcfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, xerrors.Errorf("setup storage miners failed: %w", err)
|
||||
}
|
||||
|
||||
cst := hamt.CSTFromBstore(bs)
|
||||
|
Loading…
Reference in New Issue
Block a user