lotus/chain/gen/genesis/t04_power.go

49 lines
1.3 KiB
Go
Raw Normal View History

2020-02-11 20:48:03 +00:00
package genesis
import (
"context"
2020-02-25 20:54:58 +00:00
"github.com/filecoin-project/specs-actors/actors/builtin"
2020-02-11 20:48:03 +00:00
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/ipfs/go-hamt-ipld"
bstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/filecoin-project/lotus/chain/types"
)
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
ctx := context.TODO()
cst := cbor.NewCborStore(bs)
2020-02-14 14:14:39 +00:00
nd := hamt.NewNode(cst, hamt.UseTreeBitWidth(5))
2020-02-11 20:48:03 +00:00
emptyhamt, err := cst.Put(ctx, nd)
if err != nil {
return nil, err
}
sms := &power.State{
TotalRawBytePower: big.NewInt(0),
2020-04-10 21:07:18 +00:00
TotalQualityAdjPower: big.NewInt(1), // TODO: has to be 1 initially to avoid div by zero. Kinda annoying, should find a way to fix
TotalPledgeCollateral: big.NewInt(0),
2020-02-11 20:48:03 +00:00
MinerCount: 0,
CronEventQueue: emptyhamt,
LastEpochTick: 0,
2020-02-11 20:48:03 +00:00
PoStDetectedFaultMiners: emptyhamt,
Claims: emptyhamt,
NumMinersMeetingMinPower: 0,
}
stcid, err := cst.Put(ctx, sms)
if err != nil {
return nil, err
}
return &types.Actor{
2020-02-25 20:54:58 +00:00
Code: builtin.StoragePowerActorCodeID,
2020-02-11 20:48:03 +00:00
Head: stcid,
Nonce: 0,
Balance: types.NewInt(0),
}, nil
}