From e08e7974c177d03c79bef6808eee3be20968e76b Mon Sep 17 00:00:00 2001 From: zl Date: Mon, 7 Feb 2022 17:45:51 +0800 Subject: [PATCH] upgrate convert tool --- .gitignore | 5 +- tool/convert-with-lotus/from-lotus/main.go | 250 +-- tool/convert-with-lotus/modules/modules.go | 53 + tool/convert-with-lotus/to-lotus/main.go | 244 +-- tool/convert-with-lotus/types/README.md | 10 + tool/convert-with-lotus/types/cbor_gen.go | 1471 ++++++++--------- .../convert-with-lotus/types/cbor_gen/main.go | 22 + tool/convert-with-lotus/types/convert.go | 162 ++ tool/convert-with-lotus/types/sector_state.go | 78 + tool/convert-with-lotus/types/types.go | 113 +- 10 files changed, 1175 insertions(+), 1233 deletions(-) create mode 100644 tool/convert-with-lotus/modules/modules.go create mode 100644 tool/convert-with-lotus/types/README.md create mode 100644 tool/convert-with-lotus/types/cbor_gen/main.go create mode 100644 tool/convert-with-lotus/types/convert.go diff --git a/.gitignore b/.gitignore index e16978e2..d20bab9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +datastore/ +sealer.db* venus-sealer venus-worker ./venus-sealer @@ -8,7 +10,8 @@ app/sealer/sealer sealing.db* venus-sealer venus-worker - +lotus-convert +lotus-fix .task .idea .vscode diff --git a/tool/convert-with-lotus/from-lotus/main.go b/tool/convert-with-lotus/from-lotus/main.go index 491162cf..c190544a 100644 --- a/tool/convert-with-lotus/from-lotus/main.go +++ b/tool/convert-with-lotus/from-lotus/main.go @@ -1,192 +1,28 @@ package main import ( - "bytes" - "context" - "encoding/json" "flag" "fmt" - "path/filepath" - "reflect" - - cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/go-state-types/abi" - - "github.com/google/uuid" - "github.com/mitchellh/go-homedir" - "go.uber.org/multierr" - "golang.org/x/xerrors" - "gorm.io/driver/sqlite" - "gorm.io/gorm" - - "github.com/ipfs/go-datastore" + "github.com/filecoin-project/venus-sealer/config" + "github.com/filecoin-project/venus-sealer/models/sqlite" + "github.com/filecoin-project/venus-sealer/tool/convert-with-lotus/modules" "github.com/ipfs/go-datastore/namespace" - "github.com/ipfs/go-datastore/query" - levelds "github.com/ipfs/go-ds-leveldb" - ldbopts "github.com/syndtr/goleveldb/leveldb/opt" + "path/filepath" "github.com/filecoin-project/venus-sealer/tool/convert-with-lotus/types" + "github.com/mitchellh/go-homedir" + "golang.org/x/xerrors" ) -type SectorPreCommitInfo struct { - SealProof int64 `gorm:"column:seal_proof;type:bigint;" json:"seal_proof"` - SealedCID string `gorm:"column:sealed_cid;type:varchar(256);" json:"sealed_cid"` - SealRandEpoch int64 `gorm:"column:seal_rand_epoch;type:bigint;" json:"seal_rand_epoch"` - // []uint64 - DealIDs string `gorm:"column:deal_ids;type:text;" json:"deal_ids"` - Expiration int64 `gorm:"column:expiration;type:bigint;" json:"expiration"` - //-1 false 1 true - ReplaceCapacity int `gorm:"column:replace_capacity;type:int;" json:"replace_capacity"` - ReplaceSectorDeadline uint64 `gorm:"column:replace_sector_deadline;type:unsigned bigint;" json:"replace_sector_deadline"` - ReplaceSectorPartition uint64 `gorm:"column:replace_sector_partition;type:unsigned bigint;" json:"replace_sector_partition"` - ReplaceSectorNumber uint64 `gorm:"column:replace_sector_number;type:unsigned bigint;" json:"replace_sector_number"` -} - -type sectorInfo struct { - Id string `gorm:"column:id;type:varchar(36);primary_key;" json:"id"` // 主键 - SectorNumber uint64 `gorm:"uniqueIndex;column:sector_number;type:unsigned bigint;" json:"sector_number"` - State string `gorm:"column:state;type:varchar(256);" json:"state"` - SectorType int64 `gorm:"column:sector_type;type:bigint;" json:"sector_type"` - - // Packing []Piece - CreationTime int64 `gorm:"column:create_time;type:bigint;" json:"create_time"` - Pieces []byte `gorm:"column:pieces;type:blob;" json:"pieces"` - - // PreCommit1 - TicketValue []byte `gorm:"column:ticket_value;type:blob;" json:"ticket_value"` - TicketEpoch int64 `gorm:"column:ticket_epoch;type:bigint;" json:"ticket_epoch"` - PreCommit1Out []byte `gorm:"column:pre_commit1_out;type:blob;" json:"pre_commit1_out"` - - // PreCommit2 - CommD string `gorm:"column:commd;type:varchar(256);" json:"commd"` - CommR string `gorm:"column:commr;type:varchar(256);" json:"commr"` - Proof []byte `gorm:"column:proof;type:blob;" json:"proof"` - - //*miner.SectorPreCommitInfo - PreCommitInfo SectorPreCommitInfo `gorm:"embedded;embeddedPrefix:precommit_"` - PreCommitDeposit string `gorm:"column:pre_commit_deposit;type:varchar(256);" json:"pre_commit_deposit"` - PreCommitMessage string `gorm:"column:pre_commit_message;type:varchar(256);" json:"pre_commit_message"` - PreCommitTipSet []byte `gorm:"column:pre_commit_tipset;type:blob;" json:"pre_commit_tipset"` - - PreCommit2Fails uint64 `gorm:"column:pre_commit2_fails;type:unsigned bigint;" json:"pre_commit2_fails"` - - // WaitSeed - SeedValue []byte `gorm:"column:seed_value;type:blob;" json:"seed_value"` - SeedEpoch int64 `gorm:"column:seed_epoch;type:bigint;" json:"seed_epoch"` - - // Committing - CommitMessage string `gorm:"column:commit_message;type:text;" json:"commit_message"` - InvalidProofs uint64 `gorm:"column:invalid_proofs;type:unsigned bigint;" json:"invalid_proofs"` - - // Faults - FaultReportMsg string `gorm:"column:fault_report_msg;type:text;" json:"fault_report_msg"` - - // Recovery - Return string `gorm:"column:return;type:text;" json:"return"` - - // Termination - TerminateMessage string `gorm:"column:terminate_message;type:text;" json:"terminate_message"` - TerminatedAt int64 `gorm:"column:terminated_at;type:bigint;" json:"terminated_at"` - - // Debug - LastErr string `gorm:"column:last_err;type:text;" json:"last_err"` -} - -func (sectorInfo *sectorInfo) TableName() string { - return "sectors_infos" -} - -func fromSectorInfo(sector *types.SectorInfo) (*sectorInfo, error) { - sectorInfo := §orInfo{ - Id: uuid.New().String(), - SectorNumber: uint64(sector.SectorNumber), - State: string(sector.State), - SectorType: int64(sector.SectorType), - CreationTime: sector.CreationTime, - TicketValue: sector.TicketValue, - TicketEpoch: int64(sector.TicketEpoch), - PreCommit1Out: sector.PreCommit1Out, - Proof: sector.Proof, - //PreCommitDeposit: sector.PreCommitDeposit, - PreCommitMessage: "", - PreCommitTipSet: sector.PreCommitTipSet, - PreCommit2Fails: sector.PreCommit2Fails, - SeedValue: sector.SeedValue, - SeedEpoch: int64(sector.SeedEpoch), - CommitMessage: "", - InvalidProofs: sector.InvalidProofs, - FaultReportMsg: "", - Return: string(sector.Return), - TerminateMessage: "", - TerminatedAt: int64(sector.TerminatedAt), - LastErr: sector.LastErr, - } - - if sector.PreCommitDeposit.Int == nil { - sectorInfo.PreCommitDeposit = "0" - } - if len(sector.Pieces) > 0 { - pieces, err := json.Marshal(sector.Pieces) - if err != nil { - return nil, err - } - sectorInfo.Pieces = pieces - } - - if sector.CommD != nil { - sectorInfo.CommD = sector.CommD.String() - } - - if sector.CommR != nil { - sectorInfo.CommR = sector.CommR.String() - } - - if sector.PreCommitInfo != nil { - dealIds, err := json.Marshal(sector.PreCommitInfo.DealIDs) - if err != nil { - return nil, err - } - - replaceCapacity := -1 - if sector.PreCommitInfo.ReplaceCapacity { - replaceCapacity = 1 - } - sectorInfo.PreCommitInfo = SectorPreCommitInfo{ - SealProof: int64(sector.PreCommitInfo.SealProof), - SealedCID: sector.PreCommitInfo.SealedCID.String(), - SealRandEpoch: int64(sector.PreCommitInfo.SealRandEpoch), - DealIDs: string(dealIds), - Expiration: int64(sector.PreCommitInfo.Expiration), - ReplaceCapacity: replaceCapacity, - ReplaceSectorDeadline: sector.PreCommitInfo.ReplaceSectorDeadline, - ReplaceSectorPartition: sector.PreCommitInfo.ReplaceSectorPartition, - ReplaceSectorNumber: uint64(sector.PreCommitInfo.ReplaceSectorNumber), - } - } - return sectorInfo, nil -} - -const ( - fsDatastore = "datastore" - SectorStorePrefix = "/sectors" -) - -func levelDs(path string, readonly bool) (datastore.Batching, error) { - return levelds.NewDatastore(path, &levelds.Options{ - Compression: ldbopts.NoCompression, - NoSync: false, - Strict: ldbopts.StrictAll, - ReadOnly: readonly, - }) -} - func ImportFromLotus(lmRepo, vsRepo string, sid abi.SectorNumber, taskType int) error { // db for lotus - lds, err := levelDs(filepath.Join(lmRepo, fsDatastore, "metadata"), true) + ds, err := modules.OpenLotusDatastore(lmRepo, true) if err != nil { return err } - ds := namespace.Wrap(lds, datastore.NewKey(SectorStorePrefix)) + ds = namespace.Wrap(ds, modules.SectorPrefixKey) + defer ds.Close() // db for venus @@ -195,74 +31,26 @@ func ImportFromLotus(lmRepo, vsRepo string, sid abi.SectorNumber, taskType int) return xerrors.Errorf("expand path error %v", err) } - db, err := gorm.Open(sqlite.Open(path+"?cache=shared&_cache_size=204800&_journal_mode=wal&sync=normal"), &gorm.Config{ - // Logger: logger.Default.LogMode(logger.Info), - }) + db, err := sqlite.OpenSqlite(&config.SqliteConfig{Path: path}) if err != nil { return xerrors.Errorf("fail to connect sqlite: %v", err) } - db.Set("gorm:table_options", "CHARSET=utf8mb4") - - sqlDB, err := db.DB() - if err != nil { - return err - } - - sqlDB.SetMaxOpenConns(1) - sqlDB.SetMaxIdleConns(1) - defer sqlDB.Close() var maxSectorID abi.SectorNumber = 0 - var sectors []types.SectorInfo - res, err := ds.Query(context.TODO(), query.Query{}) - if err != nil { - return err - } - defer res.Close() - - outT := reflect.TypeOf(§ors).Elem().Elem() - rout := reflect.ValueOf(§ors) - - var errs error - - for { - res, ok := res.NextSync() - if !ok { - break - } - if res.Error != nil { - return res.Error - } - - elem := reflect.New(outT) - err := cborutil.ReadCborRPC(bytes.NewReader(res.Value), elem.Interface()) - if err != nil { - errs = multierr.Append(errs, xerrors.Errorf("decoding state for key '%s': %w", res.Key, err)) - continue - } - rout.Elem().Set(reflect.Append(rout.Elem(), elem.Elem())) - } - - if errs != nil { - return errs - } - - for _, sector := range sectors { + if err = modules.ForEachSector(ds, func(sector *types.SectorInfo) error { if taskType > 0 { - sSector, err := fromSectorInfo(§or) - if err != nil { - return err - } - sSector.Id = uuid.New().String() - err = db.Create(&sSector).Error - if err != nil { - fmt.Printf("put [%d] err: %s \n", sSector.SectorNumber, err.Error()) + vSector := sector.ToVenus() + if err = db.SectorInfoRepo().Save(vSector); err != nil { + fmt.Printf("put [%d] err: %s \n", vSector.SectorNumber, err.Error()) } } if maxSectorID < sector.SectorNumber { maxSectorID = sector.SectorNumber } + return nil + }); err != nil { + return err } if taskType == 1 { @@ -273,8 +61,8 @@ func ImportFromLotus(lmRepo, vsRepo string, sid abi.SectorNumber, taskType int) if sid > 0 { maxSectorID = sid } - err = db.Exec("update `metadata` set `sector_count`=?", maxSectorID).Error - if err != nil { + + if err = db.MetaDataRepo().SetStorageCounter(uint64(maxSectorID)); err != nil { return xerrors.Errorf("fail to update latest sector id: %v", err) } fmt.Printf("latest sector id: %d\n", maxSectorID) diff --git a/tool/convert-with-lotus/modules/modules.go b/tool/convert-with-lotus/modules/modules.go new file mode 100644 index 00000000..71457f60 --- /dev/null +++ b/tool/convert-with-lotus/modules/modules.go @@ -0,0 +1,53 @@ +package modules + +import ( + "bytes" + "context" + "github.com/filecoin-project/venus-sealer/tool/convert-with-lotus/types" + "github.com/ipfs/go-datastore" + "github.com/ipfs/go-datastore/query" + levelds "github.com/ipfs/go-ds-leveldb" + ldbopts "github.com/syndtr/goleveldb/leveldb/opt" + "go.uber.org/multierr" + "golang.org/x/xerrors" + "path/filepath" +) + +const ( + fsDatastore = "datastore" + SectorStorePrefix = "/sectors" +) + +var SectorPrefixKey = datastore.NewKey(SectorStorePrefix) + +func OpenLotusDatastore(repoPath string, readonly bool) (datastore.Batching, error) { + path := filepath.Join(repoPath, fsDatastore, "metadata") + return levelds.NewDatastore(path, &levelds.Options{ + Compression: ldbopts.NoCompression, + NoSync: false, + Strict: ldbopts.StrictAll, + ReadOnly: readonly, + }) +} + +func ForEachSector(ds datastore.Batching, cb func(info *types.SectorInfo) error) error { + res, err := ds.Query(context.TODO(), query.Query{}) + if err != nil { + return err + } + + defer res.Close() + + var errs error + for v, isOk := res.NextSync(); isOk; v, isOk = res.NextSync() { + var sector types.SectorInfo + if err := sector.UnmarshalCBOR(bytes.NewReader(v.Value)); err != nil { + errs = multierr.Append(errs, xerrors.Errorf("decoding state for key '%s': %w", v.Key, err)) + continue + } + if err := cb(§or); err != nil { + return err + } + } + return errs +} diff --git a/tool/convert-with-lotus/to-lotus/main.go b/tool/convert-with-lotus/to-lotus/main.go index 9a198cad..49d7c385 100644 --- a/tool/convert-with-lotus/to-lotus/main.go +++ b/tool/convert-with-lotus/to-lotus/main.go @@ -3,216 +3,22 @@ package main import ( "context" "encoding/binary" - "encoding/json" "flag" "fmt" + sqlite "github.com/filecoin-project/venus-sealer/models/sqlite" + "github.com/filecoin-project/venus-sealer/tool/convert-with-lotus/modules" "path/filepath" cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin/miner" - - "github.com/ipfs/go-cid" - "github.com/ipfs/go-datastore" - levelds "github.com/ipfs/go-ds-leveldb" - u "github.com/ipfs/go-ipfs-util" - "github.com/mitchellh/go-homedir" - ldbopts "github.com/syndtr/goleveldb/leveldb/opt" - "golang.org/x/xerrors" - "gorm.io/driver/sqlite" - "gorm.io/gorm" - "github.com/filecoin-project/venus-sealer/api" "github.com/filecoin-project/venus-sealer/config" "github.com/filecoin-project/venus-sealer/tool/convert-with-lotus/types" + "github.com/ipfs/go-datastore" + "github.com/mitchellh/go-homedir" + "golang.org/x/xerrors" ) -type SectorPreCommitInfo struct { - SealProof int64 `gorm:"column:seal_proof;type:bigint;" json:"seal_proof"` - SealedCID string `gorm:"column:sealed_cid;type:varchar(256);" json:"sealed_cid"` - SealRandEpoch int64 `gorm:"column:seal_rand_epoch;type:bigint;" json:"seal_rand_epoch"` - // []uint64 - DealIDs string `gorm:"column:deal_ids;type:text;" json:"deal_ids"` - Expiration int64 `gorm:"column:expiration;type:bigint;" json:"expiration"` - //-1 false 1 true - ReplaceCapacity int `gorm:"column:replace_capacity;type:int;" json:"replace_capacity"` - ReplaceSectorDeadline uint64 `gorm:"column:replace_sector_deadline;type:unsigned bigint;" json:"replace_sector_deadline"` - ReplaceSectorPartition uint64 `gorm:"column:replace_sector_partition;type:unsigned bigint;" json:"replace_sector_partition"` - ReplaceSectorNumber uint64 `gorm:"column:replace_sector_number;type:unsigned bigint;" json:"replace_sector_number"` -} - -type sectorInfo struct { - Id string `gorm:"column:id;type:varchar(36);primary_key;" json:"id"` // 主键 - SectorNumber uint64 `gorm:"uniqueIndex;column:sector_number;type:unsigned bigint;" json:"sector_number"` - State string `gorm:"column:state;type:varchar(256);" json:"state"` - SectorType int64 `gorm:"column:sector_type;type:bigint;" json:"sector_type"` - - // Packing []Piece - Pieces []byte `gorm:"column:pieces;type:blob;" json:"pieces"` - - // PreCommit1 - TicketValue []byte `gorm:"column:ticket_value;type:blob;" json:"ticket_value"` - TicketEpoch int64 `gorm:"column:ticket_epoch;type:bigint;" json:"ticket_epoch"` - PreCommit1Out []byte `gorm:"column:pre_commit1_out;type:blob;" json:"pre_commit1_out"` - - // PreCommit2 - CommD string `gorm:"column:commd;type:varchar(256);" json:"commd"` - CommR string `gorm:"column:commr;type:varchar(256);" json:"commr"` - Proof []byte `gorm:"column:proof;type:blob;" json:"proof"` - - //*miner.SectorPreCommitInfo - PreCommitInfo SectorPreCommitInfo `gorm:"embedded;embeddedPrefix:precommit_"` - PreCommitDeposit string `gorm:"column:pre_commit_deposit;type:varchar(256);" json:"pre_commit_deposit"` - PreCommitMessage string `gorm:"column:pre_commit_message;type:varchar(256);" json:"pre_commit_message"` - PreCommitTipSet []byte `gorm:"column:pre_commit_tipset;type:blob;" json:"pre_commit_tipset"` - - PreCommit2Fails uint64 `gorm:"column:pre_commit2_fails;type:unsigned bigint;" json:"pre_commit2_fails"` - - // WaitSeed - SeedValue []byte `gorm:"column:seed_value;type:blob;" json:"seed_value"` - SeedEpoch int64 `gorm:"column:seed_epoch;type:bigint;" json:"seed_epoch"` - - // Committing - CommitMessage string `gorm:"column:commit_message;type:text;" json:"commit_message"` - InvalidProofs uint64 `gorm:"column:invalid_proofs;type:unsigned bigint;" json:"invalid_proofs"` - - // Faults - FaultReportMsg string `gorm:"column:fault_report_msg;type:text;" json:"fault_report_msg"` - - // Recovery - Return string `gorm:"column:return;type:text;" json:"return"` - - // Termination - TerminateMessage string `gorm:"column:terminate_message;type:text;" json:"terminate_message"` - TerminatedAt int64 `gorm:"column:terminated_at;type:bigint;" json:"terminated_at"` - - // Debug - LastErr string `gorm:"column:last_err;type:text;" json:"last_err"` -} - -func (sectorInfo *sectorInfo) SectorInfo(api api.IMessager) (*types.SectorInfo, error) { - tc := cid.NewCidV0(u.Hash([]byte("undef"))) - - pcCid := &tc - cCid := &tc - frCid := &tc - tCid := &tc - if msg, err := api.GetMessageByUid(context.TODO(), sectorInfo.PreCommitMessage); err == nil && msg.SignedCid != nil { - pcCid = msg.SignedCid - } - - if msg, err := api.GetMessageByUid(context.TODO(), sectorInfo.CommitMessage); err == nil && msg.SignedCid != nil { - pcCid = msg.SignedCid - } - - if msg, err := api.GetMessageByUid(context.TODO(), sectorInfo.FaultReportMsg); err == nil && msg.SignedCid != nil { - frCid = msg.SignedCid - } - - if msg, err := api.GetMessageByUid(context.TODO(), sectorInfo.TerminateMessage); err == nil && msg.SignedCid != nil { - tCid = msg.SignedCid - } - - sinfo := &types.SectorInfo{ - State: types.SectorState(sectorInfo.State), - SectorNumber: abi.SectorNumber(sectorInfo.SectorNumber), - SectorType: abi.RegisteredSealProof(sectorInfo.SectorType), - // Pieces: pieces, - TicketValue: sectorInfo.TicketValue, - TicketEpoch: abi.ChainEpoch(sectorInfo.TicketEpoch), - PreCommit1Out: sectorInfo.PreCommit1Out, - // CommD: &commD, - //CommR: &commR, - Proof: sectorInfo.Proof, - //PreCommitInfo: sectorInfo.PreCommitInfo, - // PreCommitDeposit: deposit, - PreCommitMessage: pcCid, - PreCommitTipSet: sectorInfo.PreCommitTipSet, - PreCommit2Fails: sectorInfo.PreCommit2Fails, - SeedValue: sectorInfo.SeedValue, - SeedEpoch: abi.ChainEpoch(sectorInfo.SeedEpoch), - CommitMessage: cCid, - InvalidProofs: sectorInfo.InvalidProofs, - FaultReportMsg: frCid, - Return: types.ReturnState(sectorInfo.Return), - TerminateMessage: tCid, - TerminatedAt: abi.ChainEpoch(sectorInfo.TerminatedAt), - LastErr: sectorInfo.LastErr, - } - if len(sectorInfo.Pieces) > 0 { - err := json.Unmarshal(sectorInfo.Pieces, &sinfo.Pieces) - if err != nil { - return nil, err - } - } - - if len(sectorInfo.CommD) > 0 { - commD, err := cid.Decode(sectorInfo.CommD) - if err != nil { - return nil, err - } - sinfo.CommD = &commD - } - if len(sectorInfo.CommR) > 0 { - commR, err := cid.Decode(sectorInfo.CommR) - if err != nil { - return nil, err - } - sinfo.CommR = &commR - } - - if len(sectorInfo.PreCommitDeposit) > 0 { - deposit, err := big.FromString(sectorInfo.PreCommitDeposit) - if err != nil { - return nil, err - } - sinfo.PreCommitDeposit = deposit - } - - if len(sectorInfo.PreCommitInfo.SealedCID) > 0 { - sealedCid, err := cid.Decode(sectorInfo.PreCommitInfo.SealedCID) - if err != nil { - return nil, err - } - - sinfo.PreCommitInfo = &miner.SectorPreCommitInfo{ - SealProof: abi.RegisteredSealProof(sectorInfo.PreCommitInfo.SealProof), - SectorNumber: abi.SectorNumber(sectorInfo.SectorNumber), - SealedCID: sealedCid, - SealRandEpoch: abi.ChainEpoch(sectorInfo.PreCommitInfo.SealRandEpoch), - DealIDs: nil, - Expiration: abi.ChainEpoch(sectorInfo.PreCommitInfo.Expiration), - ReplaceCapacity: sectorInfo.PreCommitInfo.ReplaceCapacity != -1, - ReplaceSectorDeadline: sectorInfo.PreCommitInfo.ReplaceSectorDeadline, - ReplaceSectorPartition: sectorInfo.PreCommitInfo.ReplaceSectorPartition, - ReplaceSectorNumber: abi.SectorNumber(sectorInfo.PreCommitInfo.ReplaceSectorNumber), - } - if len(sectorInfo.PreCommitInfo.DealIDs) > 0 { - err := json.Unmarshal([]byte(sectorInfo.PreCommitInfo.DealIDs), &sinfo.PreCommitInfo.DealIDs) - if err != nil { - return nil, err - } - } - } - - return sinfo, nil -} - -const ( - fsDatastore = "datastore" - SectorStorePrefix = "/sectors" -) - -func levelDs(path string, readonly bool) (datastore.Batching, error) { - return levelds.NewDatastore(path, &levelds.Options{ - Compression: ldbopts.NoCompression, - NoSync: false, - Strict: ldbopts.StrictAll, - ReadOnly: readonly, - }) -} - func ImportToLotusMiner(lmRepo, vsRepo string, sid abi.SectorNumber, taskType int) error { // db for venus path, err := homedir.Expand(filepath.Join(vsRepo, "sealer.db")) @@ -220,37 +26,26 @@ func ImportToLotusMiner(lmRepo, vsRepo string, sid abi.SectorNumber, taskType in return xerrors.Errorf("expand path error %v", err) } - db, err := gorm.Open(sqlite.Open(path+"?cache=shared&_cache_size=204800&_journal_mode=wal&sync=normal"), &gorm.Config{ - // Logger: logger.Default.LogMode(logger.Info), - }) + db, err := sqlite.OpenSqlite(&config.SqliteConfig{Path: path}) if err != nil { return xerrors.Errorf("fail to connect sqlite: %v", err) } - db.Set("gorm:table_options", "CHARSET=utf8mb4") - - sqlDB, err := db.DB() - if err != nil { - return err - } - - sqlDB.SetMaxOpenConns(1) - sqlDB.SetMaxIdleConns(1) - defer sqlDB.Close() + defer db.DbClose() // db for lotus - ds, err := levelDs(filepath.Join(lmRepo, fsDatastore, "metadata"), false) + ds, err := modules.OpenLotusDatastore(lmRepo, false) if err != nil { return err } defer ds.Close() if taskType > 0 { - var sectorInfos []*sectorInfo - err = db.Table("sectors_infos").Find(§orInfos).Error + sectorInfos, err := db.SectorInfoRepo().GetAllSectorInfos() if err != nil { return err } + // var mc api.IMessager // read message config cfgPath := config.FsConfig(vsRepo) cfg, err := config.MinerFromFile(cfgPath) @@ -266,11 +61,7 @@ func ImportToLotusMiner(lmRepo, vsRepo string, sid abi.SectorNumber, taskType in result := make([]types.SectorInfo, len(sectorInfos)) for index, st := range sectorInfos { - newSt, err := st.SectorInfo(mc) - if err != nil { - return err - } - result[index] = *newSt + result[index].FromVenus(st, mc) } for _, sector := range result { @@ -278,11 +69,9 @@ func ImportToLotusMiner(lmRepo, vsRepo string, sid abi.SectorNumber, taskType in if err != nil { return xerrors.Errorf("serializing refs: %w", err) } - - sectorKey := datastore.NewKey(SectorStorePrefix).ChildString(fmt.Sprint(sector.SectorNumber)) - err = ds.Put(context.TODO(), sectorKey, b) - if err != nil { - fmt.Printf("put [%s] err: %s \n", sectorKey, err.Error()) + sectorKey := modules.SectorPrefixKey.ChildString(fmt.Sprintf("%d", sector.SectorNumber)) + if err = ds.Put(context.TODO(), sectorKey, b); err != nil { + fmt.Printf("put sector info [%s] err: %s \n", sectorKey, err.Error()) } } } @@ -296,8 +85,7 @@ func ImportToLotusMiner(lmRepo, vsRepo string, sid abi.SectorNumber, taskType in if sid > 0 { maxSectorID = sid } else { - err = db.Raw("select `sector_count` from `metadata` LIMIT 1").Scan(&maxSectorID).Error - if err != nil { + if maxSectorID, err = db.MetaDataRepo().GetStorageCounter(); err != nil { return xerrors.Errorf("fail to query latest sector id: %v", err) } } @@ -317,7 +105,7 @@ func main() { var ( lmRepo, vsRepo string sid uint64 - taskType int + taskType int ) flag.StringVar(&lmRepo, "lotus-miner-repo", "", "repo path for lotus-miner") diff --git a/tool/convert-with-lotus/types/README.md b/tool/convert-with-lotus/types/README.md new file mode 100644 index 00000000..bb27cc6c --- /dev/null +++ b/tool/convert-with-lotus/types/README.md @@ -0,0 +1,10 @@ +All types in this package fetched from lotus@v1.14.0-rc4. + +We should go mod init 'convert-with-lotus' director, ref the `SectorInfo`(and it's member fields types) defined in lotus directly. + +but because of following reason: + +the lotus@v1.14.0 use a package: `github.com/ipfs/go-datastore@v0.4.6` +which doesn't compatible with the version(v0.5.1) referenced by venus-sealer. + +we HAVE TO use this temporary way to use the type: `SectorInfo`(and it's member fields types) defined in louts. diff --git a/tool/convert-with-lotus/types/cbor_gen.go b/tool/convert-with-lotus/types/cbor_gen.go index bb8c666e..b9c5f3db 100644 --- a/tool/convert-with-lotus/types/cbor_gen.go +++ b/tool/convert-with-lotus/types/cbor_gen.go @@ -9,12 +9,11 @@ import ( "sort" abi "github.com/filecoin-project/go-state-types/abi" + market "github.com/filecoin-project/specs-actors/actors/builtin/market" miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" - - market "github.com/filecoin-project/specs-actors/actors/builtin/market" ) var _ = xerrors.Errorf @@ -49,7 +48,7 @@ func (t *Piece) MarshalCBOR(w io.Writer) error { return err } - // t.DealInfo (PieceDealInfo) (struct) + // t.DealInfo (types.PieceDealInfo) (struct) if len("DealInfo") > cbg.MaxLength { return xerrors.Errorf("Value in field \"DealInfo\" was too long") } @@ -110,7 +109,7 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error { } } - // t.DealInfo (api.PieceDealInfo) (struct) + // t.DealInfo (types.PieceDealInfo) (struct) case "DealInfo": { @@ -139,354 +138,732 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error { return nil } -func (t *SectorInfo) MarshalCBOR(w io.Writer) error { +func (t *DealSchedule) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{184, 26}); err != nil { + if _, err := w.Write([]byte{162}); err != nil { return err } scratch := make([]byte, 9) - // t.State (sealing.SectorState) (string) - if len("State") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"State\" was too long") + // t.StartEpoch (abi.ChainEpoch) (int64) + if len("StartEpoch") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"StartEpoch\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("State"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("StartEpoch"))); err != nil { return err } - if _, err := io.WriteString(w, string("State")); err != nil { + if _, err := io.WriteString(w, string("StartEpoch")); err != nil { return err } - if len(t.State) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.State was too long") + if t.StartEpoch >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.StartEpoch)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.StartEpoch-1)); err != nil { + return err + } } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.State))); err != nil { + // t.EndEpoch (abi.ChainEpoch) (int64) + if len("EndEpoch") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"EndEpoch\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("EndEpoch"))); err != nil { return err } - if _, err := io.WriteString(w, string(t.State)); err != nil { + if _, err := io.WriteString(w, string("EndEpoch")); err != nil { return err } - // t.SectorNumber (abi.SectorNumber) (uint64) - if len("SectorNumber") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"SectorNumber\" was too long") + if t.EndEpoch >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.EndEpoch)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.EndEpoch-1)); err != nil { + return err + } } + return nil +} - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorNumber"))); err != nil { +func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { + *t = DealSchedule{} + + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { return err } - if _, err := io.WriteString(w, string("SectorNumber")); err != nil { - return err + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorNumber)); err != nil { - return err + if extra > cbg.MaxLength { + return fmt.Errorf("DealSchedule: map struct too large (%d)", extra) } - // t.SectorType (abi.RegisteredSealProof) (int64) - if len("SectorType") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"SectorType\" was too long") + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.StartEpoch (abi.ChainEpoch) (int64) + case "StartEpoch": + { + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.StartEpoch = abi.ChainEpoch(extraI) + } + // t.EndEpoch (abi.ChainEpoch) (int64) + case "EndEpoch": + { + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.EndEpoch = abi.ChainEpoch(extraI) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorType"))); err != nil { + return nil +} +func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) return err } - if _, err := io.WriteString(w, string("SectorType")); err != nil { + if _, err := w.Write([]byte{165}); err != nil { return err } - if t.SectorType >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorType)); err != nil { - return err - } - } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.SectorType-1)); err != nil { - return err - } - } + scratch := make([]byte, 9) - // t.CreationTime (int64) (int64) - if len("CreationTime") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"CreationTime\" was too long") + // t.PublishCid (cid.Cid) (struct) + if len("PublishCid") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PublishCid\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CreationTime"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PublishCid"))); err != nil { return err } - if _, err := io.WriteString(w, string("CreationTime")); err != nil { + if _, err := io.WriteString(w, string("PublishCid")); err != nil { return err } - if t.CreationTime >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.CreationTime)); err != nil { + if t.PublishCid == nil { + if _, err := w.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.CreationTime-1)); err != nil { - return err + if err := cbg.WriteCidBuf(scratch, w, *t.PublishCid); err != nil { + return xerrors.Errorf("failed to write cid field t.PublishCid: %w", err) } } - // t.Pieces ([]sealing.Piece) (slice) - if len("Pieces") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"Pieces\" was too long") + // t.DealID (abi.DealID) (uint64) + if len("DealID") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"DealID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Pieces"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealID"))); err != nil { return err } - if _, err := io.WriteString(w, string("Pieces")); err != nil { + if _, err := io.WriteString(w, string("DealID")); err != nil { return err } - if len(t.Pieces) > cbg.MaxLength { - return xerrors.Errorf("Slice value in field t.Pieces was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Pieces))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.DealID)); err != nil { return err } - for _, v := range t.Pieces { - if err := v.MarshalCBOR(w); err != nil { - return err - } - } - // t.TicketValue (abi.SealRandomness) (slice) - if len("TicketValue") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"TicketValue\" was too long") + // t.DealProposal (market.DealProposal) (struct) + if len("DealProposal") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"DealProposal\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TicketValue"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("TicketValue")); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealProposal"))); err != nil { return err } - - if len(t.TicketValue) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.TicketValue was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.TicketValue))); err != nil { + if _, err := io.WriteString(w, string("DealProposal")); err != nil { return err } - if _, err := w.Write(t.TicketValue[:]); err != nil { + if err := t.DealProposal.MarshalCBOR(w); err != nil { return err } - // t.TicketEpoch (abi.ChainEpoch) (int64) - if len("TicketEpoch") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"TicketEpoch\" was too long") + // t.DealSchedule (types.DealSchedule) (struct) + if len("DealSchedule") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"DealSchedule\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TicketEpoch"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealSchedule"))); err != nil { return err } - if _, err := io.WriteString(w, string("TicketEpoch")); err != nil { + if _, err := io.WriteString(w, string("DealSchedule")); err != nil { return err } - if t.TicketEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TicketEpoch)); err != nil { - return err - } - } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TicketEpoch-1)); err != nil { - return err - } + if err := t.DealSchedule.MarshalCBOR(w); err != nil { + return err } - // t.PreCommit1Out (storage.PreCommit1Out) (slice) - if len("PreCommit1Out") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PreCommit1Out\" was too long") + // t.KeepUnsealed (bool) (bool) + if len("KeepUnsealed") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"KeepUnsealed\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommit1Out"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("PreCommit1Out")); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("KeepUnsealed"))); err != nil { return err } - - if len(t.PreCommit1Out) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.PreCommit1Out was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.PreCommit1Out))); err != nil { + if _, err := io.WriteString(w, string("KeepUnsealed")); err != nil { return err } - if _, err := w.Write(t.PreCommit1Out[:]); err != nil { + if err := cbg.WriteBool(w, t.KeepUnsealed); err != nil { return err } + return nil +} - // t.CommD (cid.Cid) (struct) - if len("CommD") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"CommD\" was too long") - } +func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { + *t = PieceDealInfo{} - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CommD"))); err != nil { + br := cbg.GetPeeker(r) + scratch := make([]byte, 8) + + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + if err != nil { return err } - if _, err := io.WriteString(w, string("CommD")); err != nil { - return err + if maj != cbg.MajMap { + return fmt.Errorf("cbor input should be of type map") } - if t.CommD == nil { - if _, err := w.Write(cbg.CborNull); err != nil { - return err - } - } else { - if err := cbg.WriteCidBuf(scratch, w, *t.CommD); err != nil { - return xerrors.Errorf("failed to write cid field t.CommD: %w", err) - } + if extra > cbg.MaxLength { + return fmt.Errorf("PieceDealInfo: map struct too large (%d)", extra) } - // t.CommR (cid.Cid) (struct) - if len("CommR") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"CommR\" was too long") + var name string + n := extra + + for i := uint64(0); i < n; i++ { + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + name = string(sval) + } + + switch name { + // t.PublishCid (cid.Cid) (struct) + case "PublishCid": + + { + + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.PublishCid: %w", err) + } + + t.PublishCid = &c + } + + } + // t.DealID (abi.DealID) (uint64) + case "DealID": + + { + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") + } + t.DealID = abi.DealID(extra) + + } + // t.DealProposal (market.DealProposal) (struct) + case "DealProposal": + + { + + b, err := br.ReadByte() + if err != nil { + return err + } + if b != cbg.CborNull[0] { + if err := br.UnreadByte(); err != nil { + return err + } + t.DealProposal = new(market.DealProposal) + if err := t.DealProposal.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.DealProposal pointer: %w", err) + } + } + + } + // t.DealSchedule (types.DealSchedule) (struct) + case "DealSchedule": + + { + + if err := t.DealSchedule.UnmarshalCBOR(br); err != nil { + return xerrors.Errorf("unmarshaling t.DealSchedule: %w", err) + } + + } + // t.KeepUnsealed (bool) (bool) + case "KeepUnsealed": + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.KeepUnsealed = false + case 21: + t.KeepUnsealed = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } + + default: + // Field doesn't exist on this type, so ignore it + cbg.ScanForLinks(r, func(cid.Cid) {}) + } } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CommR"))); err != nil { + return nil +} +func (t *SectorInfo) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) return err } - if _, err := io.WriteString(w, string("CommR")); err != nil { + if _, err := w.Write([]byte{184, 32}); err != nil { return err } - if t.CommR == nil { - if _, err := w.Write(cbg.CborNull); err != nil { - return err - } - } else { - if err := cbg.WriteCidBuf(scratch, w, *t.CommR); err != nil { - return xerrors.Errorf("failed to write cid field t.CommR: %w", err) - } - } + scratch := make([]byte, 9) - // t.Proof ([]uint8) (slice) - if len("Proof") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"Proof\" was too long") + // t.State (types.SectorState) (string) + if len("State") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"State\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Proof"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("State"))); err != nil { return err } - if _, err := io.WriteString(w, string("Proof")); err != nil { + if _, err := io.WriteString(w, string("State")); err != nil { return err } - if len(t.Proof) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Proof was too long") + if len(t.State) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.State was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Proof))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.State))); err != nil { return err } - - if _, err := w.Write(t.Proof[:]); err != nil { + if _, err := io.WriteString(w, string(t.State)); err != nil { return err } - // t.PreCommitInfo (miner.SectorPreCommitInfo) (struct) - if len("PreCommitInfo") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PreCommitInfo\" was too long") + // t.SectorNumber (abi.SectorNumber) (uint64) + if len("SectorNumber") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"SectorNumber\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitInfo"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorNumber"))); err != nil { return err } - if _, err := io.WriteString(w, string("PreCommitInfo")); err != nil { + if _, err := io.WriteString(w, string("SectorNumber")); err != nil { return err } - if err := t.PreCommitInfo.MarshalCBOR(w); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorNumber)); err != nil { return err } - // t.PreCommitDeposit (big.Int) (struct) - if len("PreCommitDeposit") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PreCommitDeposit\" was too long") + // t.SectorType (abi.RegisteredSealProof) (int64) + if len("SectorType") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"SectorType\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitDeposit"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorType"))); err != nil { return err } - if _, err := io.WriteString(w, string("PreCommitDeposit")); err != nil { + if _, err := io.WriteString(w, string("SectorType")); err != nil { return err } - if err := t.PreCommitDeposit.MarshalCBOR(w); err != nil { - return err + if t.SectorType >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorType)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.SectorType-1)); err != nil { + return err + } } - // t.PreCommitMessage (cid.Cid) (struct) - if len("PreCommitMessage") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long") + // t.CreationTime (int64) (int64) + if len("CreationTime") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"CreationTime\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitMessage"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CreationTime"))); err != nil { return err } - if _, err := io.WriteString(w, string("PreCommitMessage")); err != nil { + if _, err := io.WriteString(w, string("CreationTime")); err != nil { return err } - if t.PreCommitMessage == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if t.CreationTime >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.CreationTime)); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.PreCommitMessage); err != nil { - return xerrors.Errorf("failed to write cid field t.PreCommitMessage: %w", err) + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.CreationTime-1)); err != nil { + return err } } - // t.PreCommitTipSet (sealing.TipSetToken) (slice) - if len("PreCommitTipSet") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PreCommitTipSet\" was too long") + // t.Pieces ([]types.Piece) (slice) + if len("Pieces") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Pieces\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitTipSet"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Pieces"))); err != nil { return err } - if _, err := io.WriteString(w, string("PreCommitTipSet")); err != nil { + if _, err := io.WriteString(w, string("Pieces")); err != nil { return err } - if len(t.PreCommitTipSet) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.PreCommitTipSet was too long") + if len(t.Pieces) > cbg.MaxLength { + return xerrors.Errorf("Slice value in field t.Pieces was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.PreCommitTipSet))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Pieces))); err != nil { return err } - - if _, err := w.Write(t.PreCommitTipSet[:]); err != nil { - return err + for _, v := range t.Pieces { + if err := v.MarshalCBOR(w); err != nil { + return err + } } - // t.PreCommit2Fails (uint64) (uint64) - if len("PreCommit2Fails") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PreCommit2Fails\" was too long") + // t.TicketValue (abi.SealRandomness) (slice) + if len("TicketValue") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"TicketValue\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommit2Fails"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TicketValue"))); err != nil { return err } - if _, err := io.WriteString(w, string("PreCommit2Fails")); err != nil { + if _, err := io.WriteString(w, string("TicketValue")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.PreCommit2Fails)); err != nil { + if len(t.TicketValue) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.TicketValue was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.TicketValue))); err != nil { + return err + } + + if _, err := w.Write(t.TicketValue[:]); err != nil { + return err + } + + // t.TicketEpoch (abi.ChainEpoch) (int64) + if len("TicketEpoch") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"TicketEpoch\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TicketEpoch"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("TicketEpoch")); err != nil { + return err + } + + if t.TicketEpoch >= 0 { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TicketEpoch)); err != nil { + return err + } + } else { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TicketEpoch-1)); err != nil { + return err + } + } + + // t.PreCommit1Out (storage.PreCommit1Out) (slice) + if len("PreCommit1Out") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PreCommit1Out\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommit1Out"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PreCommit1Out")); err != nil { + return err + } + + if len(t.PreCommit1Out) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.PreCommit1Out was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.PreCommit1Out))); err != nil { + return err + } + + if _, err := w.Write(t.PreCommit1Out[:]); err != nil { + return err + } + + // t.CommD (cid.Cid) (struct) + if len("CommD") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"CommD\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CommD"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("CommD")); err != nil { + return err + } + + if t.CommD == nil { + if _, err := w.Write(cbg.CborNull); err != nil { + return err + } + } else { + if err := cbg.WriteCidBuf(scratch, w, *t.CommD); err != nil { + return xerrors.Errorf("failed to write cid field t.CommD: %w", err) + } + } + + // t.CommR (cid.Cid) (struct) + if len("CommR") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"CommR\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CommR"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("CommR")); err != nil { + return err + } + + if t.CommR == nil { + if _, err := w.Write(cbg.CborNull); err != nil { + return err + } + } else { + if err := cbg.WriteCidBuf(scratch, w, *t.CommR); err != nil { + return xerrors.Errorf("failed to write cid field t.CommR: %w", err) + } + } + + // t.Proof ([]uint8) (slice) + if len("Proof") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Proof\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Proof"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Proof")); err != nil { + return err + } + + if len(t.Proof) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.Proof was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Proof))); err != nil { + return err + } + + if _, err := w.Write(t.Proof[:]); err != nil { + return err + } + + // t.PreCommitInfo (miner.SectorPreCommitInfo) (struct) + if len("PreCommitInfo") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PreCommitInfo\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitInfo"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PreCommitInfo")); err != nil { + return err + } + + if err := t.PreCommitInfo.MarshalCBOR(w); err != nil { + return err + } + + // t.PreCommitDeposit (big.Int) (struct) + if len("PreCommitDeposit") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PreCommitDeposit\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitDeposit"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PreCommitDeposit")); err != nil { + return err + } + + if err := t.PreCommitDeposit.MarshalCBOR(w); err != nil { + return err + } + + // t.PreCommitMessage (cid.Cid) (struct) + if len("PreCommitMessage") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitMessage"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PreCommitMessage")); err != nil { + return err + } + + if t.PreCommitMessage == nil { + if _, err := w.Write(cbg.CborNull); err != nil { + return err + } + } else { + if err := cbg.WriteCidBuf(scratch, w, *t.PreCommitMessage); err != nil { + return xerrors.Errorf("failed to write cid field t.PreCommitMessage: %w", err) + } + } + + // t.PreCommitTipSet (types.TipSetToken) (slice) + if len("PreCommitTipSet") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PreCommitTipSet\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitTipSet"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PreCommitTipSet")); err != nil { + return err + } + + if len(t.PreCommitTipSet) > cbg.ByteArrayMaxLen { + return xerrors.Errorf("Byte array in field t.PreCommitTipSet was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.PreCommitTipSet))); err != nil { + return err + } + + if _, err := w.Write(t.PreCommitTipSet[:]); err != nil { + return err + } + + // t.PreCommit2Fails (uint64) (uint64) + if len("PreCommit2Fails") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"PreCommit2Fails\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommit2Fails"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("PreCommit2Fails")); err != nil { + return err + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.PreCommit2Fails)); err != nil { return err } @@ -590,7 +967,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return err } - // t.CCPieces ([]sealing.Piece) (slice) + // t.CCPieces ([]types.Piece) (slice) if len("CCPieces") > cbg.MaxLength { return xerrors.Errorf("Value in field \"CCPieces\" was too long") } @@ -727,7 +1104,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } } - // t.Return (sealing.ReturnState) (string) + // t.Return (types.ReturnState) (string) if len("Return") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Return\" was too long") } @@ -817,7 +1194,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return err } - // t.Log ([]sealing.Log) (slice) + // t.Log ([]types.Log) (slice) if len("Log") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Log\" was too long") } @@ -877,7 +1254,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { } switch name { - // t.State (sealing.SectorState) (string) + // t.State (types.SectorState) (string) case "State": { @@ -955,7 +1332,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.CreationTime = int64(extraI) } - // t.Pieces ([]sealing.Piece) (slice) + // t.Pieces ([]types.Piece) (slice) case "Pieces": maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) @@ -1176,7 +1553,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { } } - // t.PreCommitTipSet (sealing.TipSetToken) (slice) + // t.PreCommitTipSet (types.TipSetToken) (slice) case "PreCommitTipSet": maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) @@ -1317,7 +1694,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { default: return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) } - // t.CCPieces ([]sealing.Piece) (slice) + // t.CCPieces ([]types.Piece) (slice) case "CCPieces": maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) @@ -1461,7 +1838,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { } } - // t.Return (sealing.ReturnState) (string) + // t.Return (types.ReturnState) (string) case "Return": { @@ -1471,466 +1848,9 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { } t.Return = ReturnState(sval) - } - // t.TerminateMessage (cid.Cid) (struct) - case "TerminateMessage": - - { - - b, err := br.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { - return err - } - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.TerminateMessage: %w", err) - } - - t.TerminateMessage = &c - } - - } - // t.TerminatedAt (abi.ChainEpoch) (int64) - case "TerminatedAt": - { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - var extraI int64 - if err != nil { - return err - } - switch maj { - case cbg.MajUnsignedInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 positive overflow") - } - case cbg.MajNegativeInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 negative oveflow") - } - extraI = -1 - extraI - default: - return fmt.Errorf("wrong type for int64 field: %d", maj) - } - - t.TerminatedAt = abi.ChainEpoch(extraI) - } - // t.LastErr (string) (string) - case "LastErr": - - { - sval, err := cbg.ReadStringBuf(br, scratch) - if err != nil { - return err - } - - t.LastErr = string(sval) - } - // t.Log ([]sealing.Log) (slice) - case "Log": - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - - if extra > cbg.MaxLength { - return fmt.Errorf("t.Log: array too large (%d)", extra) - } - - if maj != cbg.MajArray { - return fmt.Errorf("expected cbor array") - } - - if extra > 0 { - t.Log = make([]Log, extra) - } - - for i := 0; i < int(extra); i++ { - - var v Log - if err := v.UnmarshalCBOR(br); err != nil { - return err - } - - t.Log[i] = v - } - - default: - // Field doesn't exist on this type, so ignore it - cbg.ScanForLinks(r, func(cid.Cid) {}) - } - } - - return nil -} -func (t *Log) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{164}); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.Timestamp (uint64) (uint64) - if len("Timestamp") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"Timestamp\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Timestamp"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("Timestamp")); err != nil { - return err - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Timestamp)); err != nil { - return err - } - - // t.Trace (string) (string) - if len("Trace") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"Trace\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Trace"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("Trace")); err != nil { - return err - } - - if len(t.Trace) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Trace was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Trace))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Trace)); err != nil { - return err - } - - // t.Message (string) (string) - if len("Message") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"Message\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Message"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("Message")); err != nil { - return err - } - - if len(t.Message) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Message was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Message))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Message)); err != nil { - return err - } - - // t.Kind (string) (string) - if len("Kind") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"Kind\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Kind"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("Kind")); err != nil { - return err - } - - if len(t.Kind) > cbg.MaxLength { - return xerrors.Errorf("Value in field t.Kind was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Kind))); err != nil { - return err - } - if _, err := io.WriteString(w, string(t.Kind)); err != nil { - return err - } - return nil -} - -func (t *Log) UnmarshalCBOR(r io.Reader) error { - *t = Log{} - - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) - - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajMap { - return fmt.Errorf("cbor input should be of type map") - } - - if extra > cbg.MaxLength { - return fmt.Errorf("Log: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadStringBuf(br, scratch) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.Timestamp (uint64) (uint64) - case "Timestamp": - - { - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.Timestamp = uint64(extra) - - } - // t.Trace (string) (string) - case "Trace": - - { - sval, err := cbg.ReadStringBuf(br, scratch) - if err != nil { - return err - } - - t.Trace = string(sval) - } - // t.Message (string) (string) - case "Message": - - { - sval, err := cbg.ReadStringBuf(br, scratch) - if err != nil { - return err - } - - t.Message = string(sval) - } - // t.Kind (string) (string) - case "Kind": - - { - sval, err := cbg.ReadStringBuf(br, scratch) - if err != nil { - return err - } - - t.Kind = string(sval) - } - - default: - // Field doesn't exist on this type, so ignore it - cbg.ScanForLinks(r, func(cid.Cid) {}) - } - } - - return nil -} - -func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { - if t == nil { - _, err := w.Write(cbg.CborNull) - return err - } - if _, err := w.Write([]byte{165}); err != nil { - return err - } - - scratch := make([]byte, 9) - - // t.PublishCid (cid.Cid) (struct) - if len("PublishCid") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"PublishCid\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PublishCid"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("PublishCid")); err != nil { - return err - } - - if t.PublishCid == nil { - if _, err := w.Write(cbg.CborNull); err != nil { - return err - } - } else { - if err := cbg.WriteCidBuf(scratch, w, *t.PublishCid); err != nil { - return xerrors.Errorf("failed to write cid field t.PublishCid: %w", err) - } - } - - // t.DealID (abi.DealID) (uint64) - if len("DealID") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"DealID\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealID"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("DealID")); err != nil { - return err - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.DealID)); err != nil { - return err - } - - // t.DealProposal (market.DealProposal) (struct) - if len("DealProposal") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"DealProposal\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealProposal"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("DealProposal")); err != nil { - return err - } - - if err := t.DealProposal.MarshalCBOR(w); err != nil { - return err - } - - // t.DealSchedule (api.DealSchedule) (struct) - if len("DealSchedule") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"DealSchedule\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealSchedule"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("DealSchedule")); err != nil { - return err - } - - if err := t.DealSchedule.MarshalCBOR(w); err != nil { - return err - } - - // t.KeepUnsealed (bool) (bool) - if len("KeepUnsealed") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"KeepUnsealed\" was too long") - } - - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("KeepUnsealed"))); err != nil { - return err - } - if _, err := io.WriteString(w, string("KeepUnsealed")); err != nil { - return err - } - - if err := cbg.WriteBool(w, t.KeepUnsealed); err != nil { - return err - } - return nil -} - -func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { - *t = PieceDealInfo{} - - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) - - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajMap { - return fmt.Errorf("cbor input should be of type map") - } - - if extra > cbg.MaxLength { - return fmt.Errorf("PieceDealInfo: map struct too large (%d)", extra) - } - - var name string - n := extra - - for i := uint64(0); i < n; i++ { - - { - sval, err := cbg.ReadStringBuf(br, scratch) - if err != nil { - return err - } - - name = string(sval) - } - - switch name { - // t.PublishCid (cid.Cid) (struct) - case "PublishCid": - - { - - b, err := br.ReadByte() - if err != nil { - return err - } - if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { - return err - } - - c, err := cbg.ReadCid(br) - if err != nil { - return xerrors.Errorf("failed to read cid field t.PublishCid: %w", err) - } - - t.PublishCid = &c - } - - } - // t.DealID (abi.DealID) (uint64) - case "DealID": - - { - - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) - if err != nil { - return err - } - if maj != cbg.MajUnsignedInt { - return fmt.Errorf("wrong type for uint64 field") - } - t.DealID = abi.DealID(extra) - - } - // t.DealProposal (market.DealProposal) (struct) - case "DealProposal": + } + // t.TerminateMessage (cid.Cid) (struct) + case "TerminateMessage": { @@ -1942,40 +1862,81 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { if err := br.UnreadByte(); err != nil { return err } - t.DealProposal = new(market.DealProposal) - if err := t.DealProposal.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.DealProposal pointer: %w", err) + + c, err := cbg.ReadCid(br) + if err != nil { + return xerrors.Errorf("failed to read cid field t.TerminateMessage: %w", err) } + + t.TerminateMessage = &c } } - // t.DealSchedule (api.DealSchedule) (struct) - case "DealSchedule": - + // t.TerminatedAt (abi.ChainEpoch) (int64) + case "TerminatedAt": { + maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } - if err := t.DealSchedule.UnmarshalCBOR(br); err != nil { - return xerrors.Errorf("unmarshaling t.DealSchedule: %w", err) + t.TerminatedAt = abi.ChainEpoch(extraI) + } + // t.LastErr (string) (string) + case "LastErr": + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err } + t.LastErr = string(sval) } - // t.KeepUnsealed (bool) (bool) - case "KeepUnsealed": + // t.Log ([]types.Log) (slice) + case "Log": maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } - if maj != cbg.MajOther { - return fmt.Errorf("booleans must be major type 7") + + if extra > cbg.MaxLength { + return fmt.Errorf("t.Log: array too large (%d)", extra) } - switch extra { - case 20: - t.KeepUnsealed = false - case 21: - t.KeepUnsealed = true - default: - return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + + if maj != cbg.MajArray { + return fmt.Errorf("expected cbor array") + } + + if extra > 0 { + t.Log = make([]Log, extra) + } + + for i := 0; i < int(extra); i++ { + + var v Log + if err := v.UnmarshalCBOR(br); err != nil { + return err + } + + t.Log[i] = v } default: @@ -1986,66 +1947,106 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { return nil } - -func (t *DealSchedule) MarshalCBOR(w io.Writer) error { +func (t *Log) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{162}); err != nil { + if _, err := w.Write([]byte{164}); err != nil { return err } scratch := make([]byte, 9) - // t.StartEpoch (abi.ChainEpoch) (int64) - if len("StartEpoch") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"StartEpoch\" was too long") + // t.Timestamp (uint64) (uint64) + if len("Timestamp") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Timestamp\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("StartEpoch"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Timestamp"))); err != nil { return err } - if _, err := io.WriteString(w, string("StartEpoch")); err != nil { + if _, err := io.WriteString(w, string("Timestamp")); err != nil { return err } - if t.StartEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.StartEpoch)); err != nil { - return err - } - } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.StartEpoch-1)); err != nil { - return err - } + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Timestamp)); err != nil { + return err } - // t.EndEpoch (abi.ChainEpoch) (int64) - if len("EndEpoch") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"EndEpoch\" was too long") + // t.Trace (string) (string) + if len("Trace") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Trace\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("EndEpoch"))); err != nil { + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Trace"))); err != nil { return err } - if _, err := io.WriteString(w, string("EndEpoch")); err != nil { + if _, err := io.WriteString(w, string("Trace")); err != nil { return err } - if t.EndEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.EndEpoch)); err != nil { - return err - } - } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.EndEpoch-1)); err != nil { - return err - } + if len(t.Trace) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Trace was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Trace))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Trace)); err != nil { + return err + } + + // t.Message (string) (string) + if len("Message") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Message\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Message"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Message")); err != nil { + return err + } + + if len(t.Message) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Message was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Message))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Message)); err != nil { + return err + } + + // t.Kind (string) (string) + if len("Kind") > cbg.MaxLength { + return xerrors.Errorf("Value in field \"Kind\" was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Kind"))); err != nil { + return err + } + if _, err := io.WriteString(w, string("Kind")); err != nil { + return err + } + + if len(t.Kind) > cbg.MaxLength { + return xerrors.Errorf("Value in field t.Kind was too long") + } + + if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Kind))); err != nil { + return err + } + if _, err := io.WriteString(w, string(t.Kind)); err != nil { + return err } return nil } -func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { - *t = DealSchedule{} +func (t *Log) UnmarshalCBOR(r io.Reader) error { + *t = Log{} br := cbg.GetPeeker(r) scratch := make([]byte, 8) @@ -2059,7 +2060,7 @@ func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { } if extra > cbg.MaxLength { - return fmt.Errorf("DealSchedule: map struct too large (%d)", extra) + return fmt.Errorf("Log: map struct too large (%d)", extra) } var name string @@ -2077,57 +2078,53 @@ func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { } switch name { - // t.StartEpoch (abi.ChainEpoch) (int64) - case "StartEpoch": + // t.Timestamp (uint64) (uint64) + case "Timestamp": + { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - var extraI int64 + + maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) if err != nil { return err } - switch maj { - case cbg.MajUnsignedInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 positive overflow") - } - case cbg.MajNegativeInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 negative oveflow") - } - extraI = -1 - extraI - default: - return fmt.Errorf("wrong type for int64 field: %d", maj) + if maj != cbg.MajUnsignedInt { + return fmt.Errorf("wrong type for uint64 field") } + t.Timestamp = uint64(extra) - t.StartEpoch = abi.ChainEpoch(extraI) } - // t.EndEpoch (abi.ChainEpoch) (int64) - case "EndEpoch": + // t.Trace (string) (string) + case "Trace": + { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) - var extraI int64 + sval, err := cbg.ReadStringBuf(br, scratch) if err != nil { return err } - switch maj { - case cbg.MajUnsignedInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 positive overflow") - } - case cbg.MajNegativeInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 negative oveflow") - } - extraI = -1 - extraI - default: - return fmt.Errorf("wrong type for int64 field: %d", maj) + + t.Trace = string(sval) + } + // t.Message (string) (string) + case "Message": + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err } - t.EndEpoch = abi.ChainEpoch(extraI) + t.Message = string(sval) + } + // t.Kind (string) (string) + case "Kind": + + { + sval, err := cbg.ReadStringBuf(br, scratch) + if err != nil { + return err + } + + t.Kind = string(sval) } default: diff --git a/tool/convert-with-lotus/types/cbor_gen/main.go b/tool/convert-with-lotus/types/cbor_gen/main.go new file mode 100644 index 00000000..1c4ebacf --- /dev/null +++ b/tool/convert-with-lotus/types/cbor_gen/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + "github.com/filecoin-project/venus-sealer/tool/convert-with-lotus/types" + gen "github.com/whyrusleeping/cbor-gen" + "os" +) + +func main() { + err := gen.WriteMapEncodersToFile("./types/cbor_gen.go", "types", + types.Piece{}, + types.DealSchedule{}, + types.PieceDealInfo{}, + types.SectorInfo{}, + types.Log{}, + ) + if err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/tool/convert-with-lotus/types/convert.go b/tool/convert-with-lotus/types/convert.go new file mode 100644 index 00000000..9ca62074 --- /dev/null +++ b/tool/convert-with-lotus/types/convert.go @@ -0,0 +1,162 @@ +package types + +import ( + "context" + "github.com/filecoin-project/venus-sealer/types" + "github.com/ipfs/go-cid" + u "github.com/ipfs/go-ipfs-util" +) + +func (p *PieceDealInfo) SetWithVenus(deal *types.PieceDealInfo) *PieceDealInfo { + if deal == nil { + return nil + } + p.PublishCid = deal.PublishCid + p.DealID = deal.DealID + p.DealProposal = &(*deal.DealProposal) + p.DealSchedule.EndEpoch = deal.DealSchedule.EndEpoch + p.DealSchedule.StartEpoch = deal.DealSchedule.StartEpoch + p.KeepUnsealed = deal.KeepUnsealed + return p +} + +func (p *PieceDealInfo) ToVenus() *types.PieceDealInfo { + if p == nil { + return nil + } + return &types.PieceDealInfo{ + PublishCid: p.PublishCid, + DealID: p.DealID, + DealProposal: &(*p.DealProposal), + DealSchedule: types.DealSchedule{ + StartEpoch: p.DealSchedule.StartEpoch, + EndEpoch: p.DealSchedule.EndEpoch, + }, + KeepUnsealed: p.KeepUnsealed, + } +} + +func (t *SectorInfo) FromVenus(vSector *types.SectorInfo, getter msgCidGetter) *SectorInfo { + var toChainCid = func(id string) *cid.Cid { + undef := cid.NewCidV0(u.Hash([]byte("undef"))) + if len(id) == 0 || getter == nil { + return &undef + } + if msg, err := getter.GetMessageByUid(context.TODO(), id); err == nil { + return msg.SignedCid + } + return &undef + } + var copyPieces = func(vPieces []types.Piece) []Piece { + if len(vPieces) == 0 { + return nil + } + pieces := make([]Piece, len(vPieces)) + for idx, piece := range vPieces { + pieces[idx].Piece = piece.Piece + pieces[idx].DealInfo = (&PieceDealInfo{}).SetWithVenus(piece.DealInfo) + } + return pieces + } + t.State = SectorState(vSector.State) + t.SectorNumber = vSector.SectorNumber + t.SectorType = vSector.SectorType + t.CreationTime = vSector.CreationTime + t.Pieces = copyPieces(vSector.Pieces) + // PreCommit1 + t.TicketValue = vSector.TicketValue + t.TicketEpoch = vSector.TicketEpoch + t.PreCommit1Out = vSector.PreCommit1Out + // PreCommit2 + t.CommD = vSector.CommD + t.CommR = vSector.CommR + t.Proof = vSector.Proof + t.PreCommitInfo = vSector.PreCommitInfo + t.PreCommitDeposit = vSector.PreCommitDeposit + t.PreCommitMessage = toChainCid(vSector.PreCommitMessage) + t.PreCommitTipSet = TipSetToken(vSector.PreCommitTipSet) + t.PreCommit2Fails = vSector.PreCommit2Fails + // WaitSeed + t.SeedValue = vSector.SeedValue + t.SeedEpoch = vSector.SeedEpoch + // Committing + t.CommitMessage = toChainCid(vSector.CommitMessage) + t.InvalidProofs = vSector.InvalidProofs + // CCUpdate + t.CCUpdate = vSector.CCUpdate + t.CCPieces = copyPieces(vSector.CCPieces) + t.UpdateSealed = vSector.UpdateSealed + t.UpdateUnsealed = vSector.UpdateUnsealed + t.ReplicaUpdateProof = vSector.ReplicaUpdateProof + t.ReplicaUpdateMessage = toChainCid(vSector.ReplicaUpdateMessage) + // Faults + t.FaultReportMsg = toChainCid(vSector.FaultReportMsg) + // Recovery + t.Return = ReturnState(vSector.Return) + // Termination + t.TerminateMessage = toChainCid(vSector.TerminateMessage) + t.TerminatedAt = vSector.TerminatedAt + // Debug + t.LastErr = vSector.LastErr + //t.Log = copyLogs(vSector.Logs) + return t +} + +func (t *SectorInfo) ToVenus() *types.SectorInfo { + var v types.SectorInfo + + var copyPieces = func(pieces []Piece) []types.Piece { + if len(pieces) == 0 { + return nil + } + vPieces := make([]types.Piece, len(pieces)) + for idx, piece := range pieces { + vPieces[idx].Piece = piece.Piece + vPieces[idx].DealInfo = piece.DealInfo.ToVenus() + } + return vPieces + } + + v.State = types.SectorState(t.State) + v.SectorNumber = t.SectorNumber + v.SectorType = t.SectorType + // Packing + v.CreationTime = t.CreationTime + v.Pieces = copyPieces(t.Pieces) + // PreCommit1 + v.TicketValue = t.TicketValue + v.TicketEpoch = t.TicketEpoch + v.PreCommit1Out = t.PreCommit1Out + // PreCommit2 + v.CommD = t.CommD + v.CommR = t.CommR + v.Proof = t.Proof + v.PreCommitInfo = t.PreCommitInfo + v.PreCommitDeposit = t.PreCommitDeposit + //v.PreCommitMessage = t.PreCommitMessage + //v.PreCommitTipSet = t.PreCommitTipSet + v.PreCommit2Fails = t.PreCommit2Fails + // WaitSeed + v.SeedValue = t.SeedValue + v.SeedEpoch = t.SeedEpoch + // Committing + //v.CommitMessage = t.CommitMessage + v.InvalidProofs = t.InvalidProofs + // CCUpdate + v.CCUpdate = t.CCUpdate + v.CCPieces = copyPieces(t.CCPieces) + v.UpdateSealed = t.UpdateSealed + v.UpdateUnsealed = t.UpdateUnsealed + v.ReplicaUpdateProof = t.ReplicaUpdateProof + //v.ReplicaUpdateMessage = t.ReplicaUpdateMessage + // Faults + //v.FaultReportMsg = t.FaultReportMsg + // Recovery + v.Return = types.ReturnState(t.Return) + // Termination + //v.TerminateMessage = t.TerminateMessage + v.TerminatedAt = t.TerminatedAt + // Debug + v.LastErr = t.LastErr + return &v +} diff --git a/tool/convert-with-lotus/types/sector_state.go b/tool/convert-with-lotus/types/sector_state.go index d385d29f..d0b21208 100644 --- a/tool/convert-with-lotus/types/sector_state.go +++ b/tool/convert-with-lotus/types/sector_state.go @@ -2,6 +2,66 @@ package types type SectorState string +var ExistSectorStateList = map[SectorState]struct{}{ + Empty: {}, + WaitDeals: {}, + Packing: {}, + AddPiece: {}, + AddPieceFailed: {}, + GetTicket: {}, + PreCommit1: {}, + PreCommit2: {}, + PreCommitting: {}, + PreCommitWait: {}, + SubmitPreCommitBatch: {}, + PreCommitBatchWait: {}, + WaitSeed: {}, + Committing: {}, + CommitFinalize: {}, + CommitFinalizeFailed: {}, + SubmitCommit: {}, + CommitWait: {}, + SubmitCommitAggregate: {}, + CommitAggregateWait: {}, + FinalizeSector: {}, + Proving: {}, + FailedUnrecoverable: {}, + SealPreCommit1Failed: {}, + SealPreCommit2Failed: {}, + PreCommitFailed: {}, + ComputeProofFailed: {}, + CommitFailed: {}, + PackingFailed: {}, + FinalizeFailed: {}, + DealsExpired: {}, + RecoverDealIDs: {}, + Faulty: {}, + FaultReported: {}, + FaultedFinal: {}, + Terminating: {}, + TerminateWait: {}, + TerminateFinality: {}, + TerminateFailed: {}, + Removing: {}, + RemoveFailed: {}, + Removed: {}, + SnapDealsWaitDeals: {}, + SnapDealsAddPiece: {}, + SnapDealsPacking: {}, + UpdateReplica: {}, + ProveReplicaUpdate: {}, + SubmitReplicaUpdate: {}, + ReplicaUpdateWait: {}, + FinalizeReplicaUpdate: {}, + SnapDealsAddPieceFailed: {}, + SnapDealsDealsExpired: {}, + SnapDealsRecoverDealIDs: {}, + ReplicaUpdateFailed: {}, + AbortUpgrade: {}, +} + +// cmd/lotus-miner/info.go defines CLI colors corresponding to these states +// update files there when adding new states const ( UndefinedSectorState SectorState = "" @@ -34,6 +94,17 @@ const ( FinalizeSector SectorState = "FinalizeSector" Proving SectorState = "Proving" + + // snap deals / cc update + SnapDealsWaitDeals SectorState = "SnapDealsWaitDeals" + SnapDealsAddPiece SectorState = "SnapDealsAddPiece" + SnapDealsPacking SectorState = "SnapDealsPacking" + UpdateReplica SectorState = "UpdateReplica" + ProveReplicaUpdate SectorState = "ProveReplicaUpdate" + SubmitReplicaUpdate SectorState = "SubmitReplicaUpdate" + ReplicaUpdateWait SectorState = "ReplicaUpdateWait" + FinalizeReplicaUpdate SectorState = "FinalizeReplicaUpdate" + // error modes FailedUnrecoverable SectorState = "FailedUnrecoverable" AddPieceFailed SectorState = "AddPieceFailed" @@ -47,6 +118,13 @@ const ( DealsExpired SectorState = "DealsExpired" RecoverDealIDs SectorState = "RecoverDealIDs" + // snap deals error modes + SnapDealsAddPieceFailed SectorState = "SnapDealsAddPieceFailed" + SnapDealsDealsExpired SectorState = "SnapDealsDealsExpired" + SnapDealsRecoverDealIDs SectorState = "SnapDealsRecoverDealIDs" + AbortUpgrade SectorState = "AbortUpgrade" + ReplicaUpdateFailed SectorState = "ReplicaUpdateFailed" + Faulty SectorState = "Faulty" // sector is corrupted or gone for some reason FaultReported SectorState = "FaultReported" // sector has been declared as a fault on chain FaultedFinal SectorState = "FaultedFinal" // fault declared on chain diff --git a/tool/convert-with-lotus/types/types.go b/tool/convert-with-lotus/types/types.go index f8896a55..1ff09ccf 100644 --- a/tool/convert-with-lotus/types/types.go +++ b/tool/convert-with-lotus/types/types.go @@ -1,31 +1,30 @@ package types import ( - "bytes" - + "context" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" + "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" + miner0 "github.com/filecoin-project/venus/venus-shared/actors/builtin/miner" "github.com/ipfs/go-cid" - "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" - - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/specs-storage/storage" + mTypes "github.com/filecoin-project/venus-messager/types" ) type SectorPreCommitInfo = miner0.SectorPreCommitInfo -// DealSchedule communicates the time interval of a storage deal. The deal must -// appear in a sealed (proven) sector no later than StartEpoch, otherwise it -// is invalid. +type PieceWithDealInfo struct { + Piece abi.PieceInfo + DealInfo PieceDealInfo +} + type DealSchedule struct { StartEpoch abi.ChainEpoch EndEpoch abi.ChainEpoch } -// DealInfo is a tuple of deal identity and its schedule type PieceDealInfo struct { PublishCid *cid.Cid DealID abi.DealID @@ -34,14 +33,13 @@ type PieceDealInfo struct { KeepUnsealed bool } -// Piece is a tuple of piece and deal info -type PieceWithDealInfo struct { +// Piece is a tuple of piece info and optional deal +type Piece struct { Piece abi.PieceInfo - DealInfo PieceDealInfo + DealInfo *PieceDealInfo // nil for pieces which do not appear in deals (e.g. filler pieces) } -// Piece is a tuple of piece info and optional deal -type Piece struct { +type SectorPiece struct { Piece abi.PieceInfo DealInfo *PieceDealInfo // nil for pieces which do not appear in deals (e.g. filler pieces) } @@ -58,13 +56,6 @@ type Log struct { type ReturnState string -const ( - RetPreCommit1 = ReturnState(PreCommit1) - RetPreCommitting = ReturnState(PreCommitting) - RetPreCommitFailed = ReturnState(PreCommitFailed) - RetCommitFailed = ReturnState(CommitFailed) -) - type SectorInfo struct { State SectorState SectorNumber abi.SectorNumber @@ -124,24 +115,74 @@ type SectorInfo struct { Log []Log } -type SectorIDCounter interface { - Next() (abi.SectorNumber, error) +type msgCidGetter interface { + GetMessageByUid(context.Context, string) (*mTypes.Message, error) } -type TipSetToken []byte -type MsgLookup struct { - Receipt MessageReceipt - TipSetTok TipSetToken - Height abi.ChainEpoch +func (t *SectorInfo) pieceInfos() []abi.PieceInfo { + out := make([]abi.PieceInfo, len(t.Pieces)) + for i, p := range t.Pieces { + out[i] = p.Piece + } + return out +} + +func (t *SectorInfo) dealIDs() []abi.DealID { + out := make([]abi.DealID, 0, len(t.Pieces)) + for _, p := range t.Pieces { + if p.DealInfo == nil { + continue + } + out = append(out, p.DealInfo.DealID) + } + return out } -type MessageReceipt struct { - ExitCode exitcode.ExitCode - Return []byte - GasUsed int64 +func (t *SectorInfo) existingPieceSizes() []abi.UnpaddedPieceSize { + out := make([]abi.UnpaddedPieceSize, len(t.Pieces)) + for i, p := range t.Pieces { + out[i] = p.Piece.Size.Unpadded() + } + return out } -func (mr *MessageReceipt) Equals(o *MessageReceipt) bool { - return mr.ExitCode == o.ExitCode && bytes.Equal(mr.Return, o.Return) && mr.GasUsed == o.GasUsed +func (t *SectorInfo) hasDeals() bool { + for _, piece := range t.Pieces { + if piece.DealInfo != nil { + return true + } + } + return false } + +// Returns list of offset/length tuples of sector data ranges which clients +// requested to keep unsealed +func (t *SectorInfo) keepUnsealedRanges(invert, alwaysKeep bool) []storage.Range { + var out []storage.Range + + var at abi.UnpaddedPieceSize + for _, piece := range t.Pieces { + psize := piece.Piece.Size.Unpadded() + at += psize + + if piece.DealInfo == nil { + continue + } + + keep := piece.DealInfo.KeepUnsealed || alwaysKeep + + if keep == invert { + continue + } + + out = append(out, storage.Range{ + Offset: at - psize, + Size: psize, + }) + } + + return out +} + +type TipSetToken []byte