Fix pond
This commit is contained in:
parent
23e0008b81
commit
d2412f4f00
@ -1,24 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
badger "github.com/ipfs/go-ds-badger"
|
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"golang.org/x/xerrors"
|
|
||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/address"
|
"github.com/filecoin-project/lotus/chain/address"
|
||||||
"github.com/filecoin-project/lotus/genesis"
|
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
|
||||||
"github.com/filecoin-project/lotus/lib/sectorbuilder"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Logger("lotus-seed")
|
var log = logging.Logger("lotus-seed")
|
||||||
@ -88,89 +79,6 @@ var preSealCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := §orbuilder.Config{
|
return seed.PreSeal(maddr, c.Uint64("sector-size"), c.Uint64("num-sectors"), sbroot, []byte(c.String("ticket-preimage")))
|
||||||
Miner: maddr,
|
|
||||||
SectorSize: c.Uint64("sector-size"),
|
|
||||||
CacheDir: filepath.Join(sbroot, "cache"),
|
|
||||||
SealedDir: filepath.Join(sbroot, "sealed"),
|
|
||||||
StagedDir: filepath.Join(sbroot, "staging"),
|
|
||||||
MetadataDir: filepath.Join(sbroot, "meta"),
|
|
||||||
WorkerThreads: 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, d := range []string{cfg.CacheDir, cfg.SealedDir, cfg.StagedDir, cfg.MetadataDir} {
|
|
||||||
if err := os.MkdirAll(d, 0775); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mds, err := badger.NewDatastore(filepath.Join(sbroot, "badger"), nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := build.GetParams(true, false); err != nil {
|
|
||||||
return xerrors.Errorf("getting params: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sb, err := sectorbuilder.New(cfg, mds)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
r := rand.New(rand.NewSource(101))
|
|
||||||
size := sectorbuilder.UserBytesForSectorSize(c.Uint64("sector-size"))
|
|
||||||
|
|
||||||
var sealedSectors []genesis.PreSeal
|
|
||||||
for i := uint64(1); i <= c.Uint64("num-sectors"); i++ {
|
|
||||||
sid, err := sb.AcquireSectorId()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
pi, err := sb.AddPiece(size, sid, r, nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
trand := sha256.Sum256([]byte(c.String("ticket-preimage")))
|
|
||||||
ticket := sectorbuilder.SealTicket{
|
|
||||||
TicketBytes: trand,
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Piece info: ", pi)
|
|
||||||
|
|
||||||
pco, err := sb.SealPreCommit(sid, ticket, []sectorbuilder.PublicPieceInfo{pi})
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("commit: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sealedSectors = append(sealedSectors, genesis.PreSeal{
|
|
||||||
CommR: pco.CommR,
|
|
||||||
CommD: pco.CommD,
|
|
||||||
SectorID: sid,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
output := map[string]genesis.GenesisMiner{
|
|
||||||
maddr.String(): genesis.GenesisMiner{
|
|
||||||
Sectors: sealedSectors,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := json.MarshalIndent(output, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := ioutil.WriteFile("pre-seal-"+maddr.String()+".json", out, 0664); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := mds.Close(); err != nil {
|
|
||||||
return xerrors.Errorf("closing datastore: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
106
cmd/lotus-seed/seed/seed.go
Normal file
106
cmd/lotus-seed/seed/seed.go
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package seed
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
badger "github.com/ipfs/go-ds-badger"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/address"
|
||||||
|
"github.com/filecoin-project/lotus/genesis"
|
||||||
|
"github.com/filecoin-project/lotus/lib/sectorbuilder"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PreSeal(maddr address.Address, ssize uint64, sectors uint64, sbroot string, preimage []byte) error {
|
||||||
|
cfg := §orbuilder.Config{
|
||||||
|
Miner: maddr,
|
||||||
|
SectorSize: ssize,
|
||||||
|
CacheDir: filepath.Join(sbroot, "cache"),
|
||||||
|
SealedDir: filepath.Join(sbroot, "sealed"),
|
||||||
|
StagedDir: filepath.Join(sbroot, "staging"),
|
||||||
|
MetadataDir: filepath.Join(sbroot, "meta"),
|
||||||
|
WorkerThreads: 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, d := range []string{cfg.CacheDir, cfg.SealedDir, cfg.StagedDir, cfg.MetadataDir} {
|
||||||
|
if err := os.MkdirAll(d, 0775); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mds, err := badger.NewDatastore(filepath.Join(sbroot, "badger"), nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := build.GetParams(true, false); err != nil {
|
||||||
|
return xerrors.Errorf("getting params: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sb, err := sectorbuilder.New(cfg, mds)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r := rand.New(rand.NewSource(101))
|
||||||
|
size := sectorbuilder.UserBytesForSectorSize(ssize)
|
||||||
|
|
||||||
|
var sealedSectors []genesis.PreSeal
|
||||||
|
for i := uint64(1); i <= sectors; i++ {
|
||||||
|
sid, err := sb.AcquireSectorId()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
pi, err := sb.AddPiece(size, sid, r, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
trand := sha256.Sum256(preimage)
|
||||||
|
ticket := sectorbuilder.SealTicket{
|
||||||
|
TicketBytes: trand,
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Piece info: ", pi)
|
||||||
|
|
||||||
|
pco, err := sb.SealPreCommit(sid, ticket, []sectorbuilder.PublicPieceInfo{pi})
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("commit: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sealedSectors = append(sealedSectors, genesis.PreSeal{
|
||||||
|
CommR: pco.CommR,
|
||||||
|
CommD: pco.CommD,
|
||||||
|
SectorID: sid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
output := map[string]genesis.GenesisMiner{
|
||||||
|
maddr.String(): genesis.GenesisMiner{
|
||||||
|
Sectors: sealedSectors,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := json.MarshalIndent(output, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(sbroot, "pre-seal-"+maddr.String()+".json"), out, 0664); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := mds.Close(); err != nil {
|
||||||
|
return xerrors.Errorf("closing datastore: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -45,8 +45,6 @@ class FullNode extends React.Component {
|
|||||||
return this.props.client.call('Filecoin.PaychVoucherList', [paych])
|
return this.props.client.call('Filecoin.PaychVoucherList', [paych])
|
||||||
}))
|
}))
|
||||||
|
|
||||||
let minerList = await this.props.client.call('Filecoin.MinerAddresses', [])
|
|
||||||
|
|
||||||
let mpoolPending = (await this.props.client.call('Filecoin.MpoolPending', [tipset])).length
|
let mpoolPending = (await this.props.client.call('Filecoin.MpoolPending', [tipset])).length
|
||||||
|
|
||||||
this.setState(() => ({
|
this.setState(() => ({
|
||||||
@ -62,8 +60,6 @@ class FullNode extends React.Component {
|
|||||||
vouchers: vouchers,
|
vouchers: vouchers,
|
||||||
|
|
||||||
defaultAddr: defaultAddr,
|
defaultAddr: defaultAddr,
|
||||||
|
|
||||||
minerList: minerList,
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,11 +106,6 @@ class FullNode extends React.Component {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let miners = <span/>
|
|
||||||
if(this.state.minerList.length > 0) {
|
|
||||||
miners = this.state.minerList.map((a, k) => <div key={k}><Address miner={true} client={this.props.client} addr={a} mountWindow={this.props.mountWindow}/></div>)
|
|
||||||
}
|
|
||||||
|
|
||||||
let storageMine = <a href="#" onClick={this.startStorageMiner} hidden={!this.props.spawnStorageNode}>[Spawn Storage Miner]</a>
|
let storageMine = <a href="#" onClick={this.startStorageMiner} hidden={!this.props.spawnStorageNode}>[Spawn Storage Miner]</a>
|
||||||
|
|
||||||
let addresses = this.state.addrs.map((addr) => {
|
let addresses = this.state.addrs.map((addr) => {
|
||||||
@ -153,7 +144,6 @@ class FullNode extends React.Component {
|
|||||||
<div>
|
<div>
|
||||||
<div>Balances: [New <a href="#" onClick={this.newSecpAddr}>[Secp256k1]</a> <a href="#" onClick={this.newBLSAddr}>[BLS]</a>]</div>
|
<div>Balances: [New <a href="#" onClick={this.newSecpAddr}>[Secp256k1]</a> <a href="#" onClick={this.newBLSAddr}>[BLS]</a>]</div>
|
||||||
<div>{addresses}</div>
|
<div>{addresses}</div>
|
||||||
<div>{miners}</div>
|
|
||||||
<div>{paychannels}</div>
|
<div>{paychannels}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -11,6 +11,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/address"
|
||||||
|
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (api *api) Spawn() (nodeInfo, error) {
|
func (api *api) Spawn() (nodeInfo, error) {
|
||||||
@ -19,9 +23,24 @@ func (api *api) Spawn() (nodeInfo, error) {
|
|||||||
return nodeInfo{}, err
|
return nodeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
params := []string{"daemon", "--bootstrap=false"}
|
||||||
genParam := "--genesis=" + api.genesis
|
genParam := "--genesis=" + api.genesis
|
||||||
|
|
||||||
id := atomic.AddInt32(&api.cmds, 1)
|
id := atomic.AddInt32(&api.cmds, 1)
|
||||||
if id == 1 {
|
if id == 1 {
|
||||||
|
// preseal
|
||||||
|
|
||||||
|
genMiner, err := address.NewIDAddress(101)
|
||||||
|
if err != nil {
|
||||||
|
return nodeInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = seed.PreSeal(genMiner, build.SectorSizes[0], 1, filepath.Join(dir, "preseal"), []byte("8"))
|
||||||
|
if err != nil {
|
||||||
|
return nodeInfo{}, xerrors.Errorf("preseal failed: %w", err)
|
||||||
|
}
|
||||||
|
params = append(params, "--genesis-presealed-sectors="+filepath.Join(dir, "preseal", "pre-seal-t0101.json"))
|
||||||
|
|
||||||
// make genesis
|
// make genesis
|
||||||
genf, err := ioutil.TempFile(os.TempDir(), "lotus-genesis-")
|
genf, err := ioutil.TempFile(os.TempDir(), "lotus-genesis-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -54,7 +73,7 @@ func (api *api) Spawn() (nodeInfo, error) {
|
|||||||
return nodeInfo{}, err
|
return nodeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("./lotus", "daemon", "--bootstrap=false", genParam)
|
cmd := exec.Command("./lotus", append(params, genParam)...)
|
||||||
|
|
||||||
cmd.Stderr = io.MultiWriter(os.Stderr, errlogfile, mux.errpw)
|
cmd.Stderr = io.MultiWriter(os.Stderr, errlogfile, mux.errpw)
|
||||||
cmd.Stdout = io.MultiWriter(os.Stdout, logfile, mux.outpw)
|
cmd.Stdout = io.MultiWriter(os.Stdout, logfile, mux.outpw)
|
||||||
@ -114,7 +133,7 @@ func (api *api) SpawnStorage(fullNodeRepo string) (nodeInfo, error) {
|
|||||||
|
|
||||||
initArgs := []string{"init"}
|
initArgs := []string{"init"}
|
||||||
if fullNodeRepo == api.running[1].meta.Repo {
|
if fullNodeRepo == api.running[1].meta.Repo {
|
||||||
initArgs = []string{"init", "--actor=t0101", "--genesis-miner"}
|
initArgs = []string{"init", "--actor=t0101", "--genesis-miner", "--pre-sealed-sectors=" + filepath.Join(fullNodeRepo, "preseal")}
|
||||||
}
|
}
|
||||||
|
|
||||||
id := atomic.AddInt32(&api.cmds, 1)
|
id := atomic.AddInt32(&api.cmds, 1)
|
||||||
|
@ -239,6 +239,8 @@ func (m *Miner) GetBestMiningCandidate(ctx context.Context) (*MiningBase, error)
|
|||||||
|
|
||||||
func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningBase) (*types.BlockMsg, error) {
|
func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningBase) (*types.BlockMsg, error) {
|
||||||
log.Debugw("attempting to mine a block", "tipset", types.LogCids(base.ts.Cids()))
|
log.Debugw("attempting to mine a block", "tipset", types.LogCids(base.ts.Cids()))
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
ticket, err := m.computeTicket(ctx, addr, base)
|
ticket, err := m.computeTicket(ctx, addr, base)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("scratching ticket failed: %w", err)
|
return nil, xerrors.Errorf("scratching ticket failed: %w", err)
|
||||||
@ -260,6 +262,9 @@ func (m *Miner) mineOne(ctx context.Context, addr address.Address, base *MiningB
|
|||||||
}
|
}
|
||||||
log.Infow("mined new block", "cid", b.Cid())
|
log.Infow("mined new block", "cid", b.Cid())
|
||||||
|
|
||||||
|
dur := time.Now().Sub(start)
|
||||||
|
log.Infof("Creating block took %s", dur)
|
||||||
|
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,32 +219,32 @@ func (p *post) commitPost(ctx context.Context) (err error) {
|
|||||||
panic("NYI")
|
panic("NYI")
|
||||||
/*
|
/*
|
||||||
|
|
||||||
params := &actors.SubmitPoStParams{
|
params := &actors.SubmitPoStParams{
|
||||||
//Proof: p.proof,
|
//Proof: p.proof,
|
||||||
|
}
|
||||||
|
|
||||||
|
enc, aerr := actors.SerializeParams(params)
|
||||||
|
if aerr != nil {
|
||||||
|
return xerrors.Errorf("could not serialize submit post parameters: %w", aerr)
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := &types.Message{
|
||||||
|
To: p.m.maddr,
|
||||||
|
From: p.m.worker,
|
||||||
|
Method: actors.MAMethods.SubmitPoSt,
|
||||||
|
Params: enc,
|
||||||
|
Value: types.NewInt(1000), // currently hard-coded late fee in actor, returned if not late
|
||||||
|
GasLimit: types.NewInt(1000000), // i dont know help
|
||||||
|
GasPrice: types.NewInt(1),
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("mpush")
|
||||||
|
|
||||||
|
p.smsg, err = p.m.api.MpoolPushMessage(ctx, msg)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("pushing message to mpool: %w", err)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
enc, aerr := actors.SerializeParams(params)
|
|
||||||
if aerr != nil {
|
|
||||||
return xerrors.Errorf("could not serialize submit post parameters: %w", aerr)
|
|
||||||
}
|
|
||||||
|
|
||||||
msg := &types.Message{
|
|
||||||
To: p.m.maddr,
|
|
||||||
From: p.m.worker,
|
|
||||||
Method: actors.MAMethods.SubmitPoSt,
|
|
||||||
Params: enc,
|
|
||||||
Value: types.NewInt(1000), // currently hard-coded late fee in actor, returned if not late
|
|
||||||
GasLimit: types.NewInt(1000000), // i dont know help
|
|
||||||
GasPrice: types.NewInt(1),
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("mpush")
|
|
||||||
|
|
||||||
p.smsg, err = p.m.api.MpoolPushMessage(ctx, msg)
|
|
||||||
if err != nil {
|
|
||||||
return xerrors.Errorf("pushing message to mpool: %w", err)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user