diff --git a/build/testing_flags.go b/build/testing_flags.go new file mode 100644 index 000000000..1f26121e7 --- /dev/null +++ b/build/testing_flags.go @@ -0,0 +1,3 @@ +package build + +var InsecurePoStValidation = false diff --git a/chain/actors/actor_miner.go b/chain/actors/actor_miner.go index b5442b1fa..853d048af 100644 --- a/chain/actors/actor_miner.go +++ b/chain/actors/actor_miner.go @@ -345,7 +345,7 @@ func (sma StorageMinerActor) ProveCommitSector(act *types.Actor, vmctx types.VMC // Note: There must exist a unique index in the miner's sector set for each // sector ID. The `faults`, `recovered`, and `done` parameters of the // SubmitPoSt method express indices into this sector set. - nssroot, err := AddToSectorSet(ctx, vmctx.Storage(), self.Sectors, params.SectorID, us.Info.CommR, commD) + nssroot, err := AddToSectorSet(ctx, types.WrapStorage(vmctx.Storage()), self.Sectors, params.SectorID, us.Info.CommR, commD) if err != nil { return nil, err } @@ -593,8 +593,8 @@ func SectorIsUnique(ctx context.Context, s types.Storage, sroot cid.Cid, sid uin return !found, nil } -func AddToSectorSet(ctx context.Context, s types.Storage, ss cid.Cid, sectorID uint64, commR, commD []byte) (cid.Cid, ActorError) { - ssr, err := amt.LoadAMT(types.WrapStorage(s), ss) +func AddToSectorSet(ctx context.Context, blks amt.Blocks, ss cid.Cid, sectorID uint64, commR, commD []byte) (cid.Cid, ActorError) { + ssr, err := amt.LoadAMT(blks, ss) if err != nil { return cid.Undef, aerrors.HandleExternalError(err, "could not load sector set node") } diff --git a/chain/gen/gen.go b/chain/gen/gen.go index e0db5e1ec..741af0351 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -408,6 +408,7 @@ type ElectionPoStProver interface { } type eppProvider struct { + sectors []sectorbuilder.SectorInfo } func (epp *eppProvider) GenerateCandidates(ctx context.Context, eprand []byte) ([]sectorbuilder.EPostCandidate, error) { @@ -422,7 +423,8 @@ func (epp *eppProvider) GenerateCandidates(ctx context.Context, eprand []byte) ( } func (epp *eppProvider) ComputeProof(ctx context.Context, eprand []byte, winners []sectorbuilder.EPostCandidate) ([]byte, error) { - return []byte("this is an election post proof"), nil + + return []byte("valid proof"), nil } func IsRoundWinner(ctx context.Context, ts *types.TipSet, round int64, miner address.Address, epp ElectionPoStProver, a MiningCheckAPI) (bool, *types.EPostProof, error) { diff --git a/chain/gen/utils.go b/chain/gen/utils.go index 38591870d..754275208 100644 --- a/chain/gen/utils.go +++ b/chain/gen/utils.go @@ -291,6 +291,15 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } mstate.Power = types.NewInt(5000) + commD := make([]byte, 32) + commR := make([]byte, 32) + blks := amt.WrapBlockstore(cs.Blockstore()) + nssroot, err := actors.AddToSectorSet(ctx, blks, mstate.Sectors, 1, commD, commR) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to add fake sector to sector set: %w", err) + } + mstate.Sectors = nssroot + nstate, err := cst.Put(ctx, &mstate) if err != nil { return cid.Undef, err diff --git a/chain/sync.go b/chain/sync.go index af915cfba..8608e717d 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -478,6 +478,9 @@ var ErrTemporal = errors.New("temporal error") func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) error { ctx, span := trace.StartSpan(ctx, "validateBlock") defer span.End() + if build.InsecurePoStValidation { + log.Warn("insecure test validation is enabled, if you see this outside of a test, it is a severe bug!") + } h := b.Header @@ -634,6 +637,12 @@ func (syncer *Syncer) VerifyElectionPoStProof(ctx context.Context, h *types.Bloc return xerrors.Errorf("getting election post sector set: %w", err) } + if build.InsecurePoStValidation { + if string(h.EPostProof.Proof) == "valid proof" { + return nil + } + return xerrors.Errorf("[TESTING] election post was invalid") + } ok, err := sectorbuilder.VerifyPost(ctx, ssize, *sectorInfo, h.EPostProof.PostRand, h.EPostProof.Proof, winners, waddr) if err != nil { return xerrors.Errorf("failed to verify election post: %w", err) diff --git a/chain/sync_test.go b/chain/sync_test.go index c5cf21c1e..49e26774a 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -23,6 +23,10 @@ import ( "github.com/filecoin-project/lotus/node/repo" ) +func init() { + build.InsecurePoStValidation = true +} + const source = 0 func (tu *syncTestUtil) repoWithChain(t testing.TB, h int) (repo.Repo, []byte, []*store.FullTipSet) { diff --git a/chain/types/vmcontext.go b/chain/types/vmcontext.go index 388396881..5e2963483 100644 --- a/chain/types/vmcontext.go +++ b/chain/types/vmcontext.go @@ -3,7 +3,7 @@ package types import ( "context" - amt "github.com/filecoin-project/go-amt-ipld" + "github.com/filecoin-project/go-amt-ipld" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/address" cid "github.com/ipfs/go-cid" @@ -48,8 +48,8 @@ type storageWrapper struct { s Storage } -func (sw *storageWrapper) Put(i interface{}) (cid.Cid, error) { - c, err := sw.s.Put(i.(cbg.CBORMarshaler)) +func (sw *storageWrapper) Put(i cbg.CBORMarshaler) (cid.Cid, error) { + c, err := sw.s.Put(i) if err != nil { return cid.Undef, err } @@ -57,8 +57,8 @@ func (sw *storageWrapper) Put(i interface{}) (cid.Cid, error) { return c, nil } -func (sw *storageWrapper) Get(c cid.Cid, out interface{}) error { - if err := sw.s.Get(c, out.(cbg.CBORUnmarshaler)); err != nil { +func (sw *storageWrapper) Get(c cid.Cid, out cbg.CBORUnmarshaler) error { + if err := sw.s.Get(c, out); err != nil { return err } diff --git a/go.mod b/go.mod index 676e52615..37ef67f4d 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/btcsuite/btcd v0.0.0-20190807005414-4063feeff79a // indirect github.com/fatih/color v1.7.0 // indirect github.com/filecoin-project/chain-validation v0.0.0-20191106200742-11986803c0f7 - github.com/filecoin-project/go-amt-ipld v0.0.0-20190919045431-3650716fff16 + github.com/filecoin-project/go-amt-ipld v0.0.0-20191122035745-59b9dfc0efc7 github.com/filecoin-project/go-bls-sigs v0.0.0-20190718224239-4bc4b8a7bbf8 github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543 github.com/filecoin-project/go-sectorbuilder v0.0.0-00010101000000-000000000000 diff --git a/go.sum b/go.sum index 3e34b558a..f095026ec 100644 --- a/go.sum +++ b/go.sum @@ -80,6 +80,8 @@ github.com/filecoin-project/chain-validation v0.0.0-20191106200742-11986803c0f7 github.com/filecoin-project/chain-validation v0.0.0-20191106200742-11986803c0f7/go.mod h1:0/0/QUNqpF/jVzLHFncGeT3NvGPODBhGzQlNgzmoZew= github.com/filecoin-project/go-amt-ipld v0.0.0-20190919045431-3650716fff16 h1:NzojcJU1VbS6zdLG13JMYis/cQy/MrN3rxmZRq56jKA= github.com/filecoin-project/go-amt-ipld v0.0.0-20190919045431-3650716fff16/go.mod h1:lKjJYPg2kwbav5f78i5YA8kGccnZn18IySbpneXvaQs= +github.com/filecoin-project/go-amt-ipld v0.0.0-20191122035745-59b9dfc0efc7 h1:lKSMm8Go6qI7+Dk3rWCNIh57wBOqVNJ21re/p7D58gc= +github.com/filecoin-project/go-amt-ipld v0.0.0-20191122035745-59b9dfc0efc7/go.mod h1:lKjJYPg2kwbav5f78i5YA8kGccnZn18IySbpneXvaQs= github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543 h1:aMJGfgqe1QDhAVwxRg5fjCRF533xHidiKsugk7Vvzug= github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543/go.mod h1:mjrHv1cDGJWDlGmC0eDc1E5VJr8DmL9XMUcaFwiuKg8= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= diff --git a/miner/miner.go b/miner/miner.go index 47958bab1..56f78e5fe 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -36,6 +36,7 @@ type api struct { func NewMiner(api api) *Miner { return &Miner{ api: api, + epp: nil, waitFunc: func(ctx context.Context) error { // Wait around for half the block time in case other parents come in time.Sleep(build.BlockDelay * time.Second / 2)