From aa5cec39ca8961a02cf1f3f8e30eecfdec18bb8c Mon Sep 17 00:00:00 2001 From: Henri S Date: Fri, 10 Apr 2020 11:14:43 -0400 Subject: [PATCH 01/26] first stab --- chain/types/blockheader.go | 9 +++ chain/vm/syscalls.go | 124 ++++++++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 3 deletions(-) diff --git a/chain/types/blockheader.go b/chain/types/blockheader.go index de96e535e..8716c9170 100644 --- a/chain/types/blockheader.go +++ b/chain/types/blockheader.go @@ -161,6 +161,15 @@ func CidArrsEqual(a, b []cid.Cid) bool { return true } +func CidArrsContains(a []cid.Cid, b cid.Cid) bool { + for _, elem := range a { + if elem.Equals(b) { + return true + } + } + return false +} + var blocksPerEpoch = NewInt(build.BlocksPerEpoch) const sha256bits = 256 diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index 53a162553..63d25095b 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -1,14 +1,21 @@ package vm import ( + "bytes" "context" "fmt" "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + "github.com/minio/blake2b-simd" mh "github.com/multiformats/go-multihash" + "github.com/pkg/errors" "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/chain/state" + "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/runtime" @@ -27,6 +34,10 @@ func Syscalls(verifier ffiwrapper.Verifier) runtime.Syscalls { } type syscallShim struct { + ctx context.Context + + cstate *state.StateTree + cst *cbor.BasicIpldStore verifier ffiwrapper.Verifier } @@ -46,15 +57,122 @@ func (ss *syscallShim) ComputeUnsealedSectorCID(st abi.RegisteredProof, pieces [ } func (ss *syscallShim) HashBlake2b(data []byte) [32]byte { - panic("NYI") + return blake2b.Sum256(data) } +// Checks validity of the submitted consensus fault with the two block headers needed to prove the fault +// and an optional extra one to check common ancestry (as needed). +// Note that the blocks are ordered: the method requires a.Epoch() <= b.Epoch(). func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte, epoch abi.ChainEpoch) (*runtime.ConsensusFault, error) { - panic("NYI") + // Note that block syntax is not validated. Any validly signed block will be accepted pursuant to the below conditions. + // Whether or not it could ever have been accepted in a chain is not checked/does not matter here. + // for that reason when checking block parent relationships, rather than instantiating a Tipset to do so + // (which runs a syntactic check), we do it directly on the CIDs. + + // (0) cheap preliminary checks + + // are blocks the same? + if bytes.Equal(a, b) { + return nil, fmt.Errorf("no consensus fault: submitted blocks are the same") + } + + // can blocks be decoded properly? + var blockA, blockB, blockC types.BlockHeader + if decodeErr := blockA.UnmarshalCBOR(bytes.NewReader(a)); decodeErr != nil { + return nil, errors.Wrapf(decodeErr, "cannot decode first block header") + } + + if decodeErr := blockB.UnmarshalCBOR(bytes.NewReader(b)); decodeErr != nil { + return nil, errors.Wrapf(decodeErr, "cannot decode second block header") + } + + if len(extra) > 0 { + if decodeErr := blockC.UnmarshalCBOR(bytes.NewReader(extra)); decodeErr != nil { + return nil, errors.Wrapf(decodeErr, "cannot decode extra") + } + } + + // (1) check conditions necessary to any consensus fault + + // were blocks mined by same miner? + if blockA.Miner != blockB.Miner { + return nil, fmt.Errorf("no consensus fault: blocks not mined by same miner") + } + + // block a must be earlier or equal to block b, epoch wise (ie at least as early in the chain). + if blockB.Height < blockA.Height { + return nil, fmt.Errorf("first block must not be of higher height than second") + } + + // (2) check the consensus faults themselves + var consensusFault *runtime.ConsensusFault + + // (a) double-fork mining fault + if blockA.Height == blockB.Height { + consensusFault = &runtime.ConsensusFault{ + Target: blockA.Miner, + Epoch: blockB.Height, + Type: runtime.ConsensusFaultDoubleForkMining, + } + } + + // (b) time-offset mining fault + // strictly speaking no need to compare heights based on double fork mining check above, + // but at same height this would be a different fault. + if !types.CidArrsEqual(blockA.Parents, blockB.Parents) && blockA.Height != blockB.Height { + consensusFault = &runtime.ConsensusFault{ + Target: blockA.Miner, + Epoch: blockB.Height, + Type: runtime.ConsensusFaultTimeOffsetMining, + } + } + + // (c) parent-grinding fault + // TODO HS: check is the blockB.height == blockA.height + 1 cond nec? + // Here extra is the "witness", a third block that shows the connection between A and B + // Specifically, since A is of lower height, it must be that B was mined omitting A from its tipset + // so there must be a block C such that A and C are siblings and C is B's parent + if types.CidArrsEqual(blockA.Parents, blockC.Parents) && types.CidArrsContains(blockB.Parents, blockC.Cid()) && + !types.CidArrsContains(blockB.Parents, blockA.Cid()) && blockB.Height == blockA.Height+1 { + consensusFault = &runtime.ConsensusFault{ + Target: blockA.Miner, + Epoch: blockB.Height, + Type: runtime.ConsensusFaultParentGrinding, + } + } + + // (3) expensive final checks + + // check blocks are properly signed by their respective miner + // note we do not need to check extra's: it is a parent to block b + // which itself is signed, so it was willingly included by the miner + if sigErr := ss.VerifyBlockSig(&blockA); sigErr != nil { + return nil, errors.Wrapf(sigErr, "cannot verify first block sig") + } + + if sigErr := ss.VerifyBlockSig(&blockB); sigErr != nil { + return nil, errors.Wrapf(sigErr, "cannot verify first block sig") + } + + return consensusFault, nil +} + +func (ss *syscallShim) VerifyBlockSig(blk *types.BlockHeader) error { + + // // load actorState + + // // get publicKeyAddr + // waddr := ss.ResolveToKeyAddr(ss.cstate, ss.cst, mas.Info.Worker) + + if err := sigs.CheckBlockSignature(blk, ss.ctx, waddr); err != nil { + return err + } + + return nil } func (ss *syscallShim) VerifyPoSt(proof abi.PoStVerifyInfo) error { - ok, err := ss.verifier.VerifyFallbackPost(context.TODO(), proof) + ok, err := ss.verifier.VerifyFallbackPost(ss.ctx, proof) if err != nil { return err } From 23dc776bd1a4f8af86ebb44afaba339a08656273 Mon Sep 17 00:00:00 2001 From: Henri S Date: Fri, 10 Apr 2020 16:22:24 -0400 Subject: [PATCH 02/26] finalize logic, still need to import appropriate fields to the shim --- chain/vm/syscalls.go | 73 ++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index 63d25095b..b09b929be 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -10,13 +10,13 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" "github.com/minio/blake2b-simd" mh "github.com/multiformats/go-multihash" - "github.com/pkg/errors" "golang.org/x/xerrors" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-actors/actors/crypto" "github.com/filecoin-project/specs-actors/actors/runtime" @@ -30,7 +30,7 @@ func init() { // Actual type is defined in chain/types/vmcontext.go because the VMContext interface is there func Syscalls(verifier ffiwrapper.Verifier) runtime.Syscalls { - return &syscallShim{verifier} + return &syscallShim{verifier: verifier} } type syscallShim struct { @@ -77,19 +77,13 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte, epoch abi.ChainE } // can blocks be decoded properly? - var blockA, blockB, blockC types.BlockHeader + var blockA, blockB types.BlockHeader if decodeErr := blockA.UnmarshalCBOR(bytes.NewReader(a)); decodeErr != nil { - return nil, errors.Wrapf(decodeErr, "cannot decode first block header") + return nil, xerrors.Errorf("cannot decode first block header: %w", decodeErr) } if decodeErr := blockB.UnmarshalCBOR(bytes.NewReader(b)); decodeErr != nil { - return nil, errors.Wrapf(decodeErr, "cannot decode second block header") - } - - if len(extra) > 0 { - if decodeErr := blockC.UnmarshalCBOR(bytes.NewReader(extra)); decodeErr != nil { - return nil, errors.Wrapf(decodeErr, "cannot decode extra") - } + return nil, xerrors.Errorf("cannot decode second block header: %f", decodeErr) } // (1) check conditions necessary to any consensus fault @@ -104,7 +98,7 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte, epoch abi.ChainE return nil, fmt.Errorf("first block must not be of higher height than second") } - // (2) check the consensus faults themselves + // (2) check for the consensus faults themselves var consensusFault *runtime.ConsensusFault // (a) double-fork mining fault @@ -128,30 +122,42 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte, epoch abi.ChainE } // (c) parent-grinding fault - // TODO HS: check is the blockB.height == blockA.height + 1 cond nec? - // Here extra is the "witness", a third block that shows the connection between A and B + // Here extra is the "witness", a third block that shows the connection between A and B as + // A's sibling and B's parent. // Specifically, since A is of lower height, it must be that B was mined omitting A from its tipset - // so there must be a block C such that A and C are siblings and C is B's parent - if types.CidArrsEqual(blockA.Parents, blockC.Parents) && types.CidArrsContains(blockB.Parents, blockC.Cid()) && - !types.CidArrsContains(blockB.Parents, blockA.Cid()) && blockB.Height == blockA.Height+1 { - consensusFault = &runtime.ConsensusFault{ - Target: blockA.Miner, - Epoch: blockB.Height, - Type: runtime.ConsensusFaultParentGrinding, + var blockC types.BlockHeader + if len(extra) > 0 { + if decodeErr := blockC.UnmarshalCBOR(bytes.NewReader(extra)); decodeErr != nil { + return nil, xerrors.Errorf("cannot decode extra: %w", decodeErr) + } + + if types.CidArrsEqual(blockA.Parents, blockC.Parents) && types.CidArrsContains(blockB.Parents, blockC.Cid()) && + !types.CidArrsContains(blockB.Parents, blockA.Cid()) { + consensusFault = &runtime.ConsensusFault{ + Target: blockA.Miner, + Epoch: blockB.Height, + Type: runtime.ConsensusFaultParentGrinding, + } } } - // (3) expensive final checks + // (3) return if no consensus fault by now + if consensusFault == nil { + return consensusFault, nil + } + + // else + // (4) expensive final checks // check blocks are properly signed by their respective miner // note we do not need to check extra's: it is a parent to block b // which itself is signed, so it was willingly included by the miner if sigErr := ss.VerifyBlockSig(&blockA); sigErr != nil { - return nil, errors.Wrapf(sigErr, "cannot verify first block sig") + return nil, xerrors.Errorf("cannot verify first block sig: %w", sigErr) } if sigErr := ss.VerifyBlockSig(&blockB); sigErr != nil { - return nil, errors.Wrapf(sigErr, "cannot verify first block sig") + return nil, xerrors.Errorf("cannot verify first block sig: %w", sigErr) } return consensusFault, nil @@ -159,10 +165,23 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte, epoch abi.ChainE func (ss *syscallShim) VerifyBlockSig(blk *types.BlockHeader) error { - // // load actorState + // get appropriate miner actor + act, err := ss.cstate.GetActor(blk.Miner) + if err != nil { + return err + } - // // get publicKeyAddr - // waddr := ss.ResolveToKeyAddr(ss.cstate, ss.cst, mas.Info.Worker) + // use that to get the miner state + var mas miner.State + if err = ss.cst.Get(ss.ctx, act.Head, &mas); err != nil { + return err + } + + // and use to get resolved workerKey + waddr, err := ResolveToKeyAddr(ss.cstate, ss.cst, mas.Info.Worker) + if err != nil { + return err + } if err := sigs.CheckBlockSignature(blk, ss.ctx, waddr); err != nil { return err From a4cdfe89fd0b9be376df00c4db521f1778cb04df Mon Sep 17 00:00:00 2001 From: Henri S Date: Fri, 10 Apr 2020 16:34:04 -0400 Subject: [PATCH 03/26] fix parent grinding check --- chain/vm/syscalls.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index b09b929be..2b5cceb3e 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -131,8 +131,8 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte, epoch abi.ChainE return nil, xerrors.Errorf("cannot decode extra: %w", decodeErr) } - if types.CidArrsEqual(blockA.Parents, blockC.Parents) && types.CidArrsContains(blockB.Parents, blockC.Cid()) && - !types.CidArrsContains(blockB.Parents, blockA.Cid()) { + if types.CidArrsEqual(blockA.Parents, blockC.Parents) && blockA.Height == blockB.Height && + types.CidArrsContains(blockB.Parents, blockC.Cid()) && !types.CidArrsContains(blockB.Parents, blockA.Cid()) { consensusFault = &runtime.ConsensusFault{ Target: blockA.Miner, Epoch: blockB.Height, From 674be39af1767dbbc59549c2a1a404f8c5cb353b Mon Sep 17 00:00:00 2001 From: Jeromy Date: Mon, 13 Apr 2020 20:05:19 -0700 Subject: [PATCH 04/26] real drand network integration --- build/params_shared.go | 4 + chain/beacon/beacon.go | 7 +- chain/beacon/drand/drand.go | 140 ++++++++++++++++++++++++++++---- chain/beacon/mock.go | 5 +- chain/sync.go | 43 +++++----- chain/types/blockheader.go | 14 ++++ cmd/lotus-storage-miner/init.go | 13 ++- go.mod | 8 +- go.sum | 29 +++++++ miner/testminer.go | 7 +- node/builder.go | 1 + node/modules/services.go | 13 ++- node/modules/storageminer.go | 14 ++++ node/node_test.go | 10 ++- 14 files changed, 250 insertions(+), 58 deletions(-) diff --git a/build/params_shared.go b/build/params_shared.go index 203ef4541..90d8b9e71 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -6,6 +6,8 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" "github.com/filecoin-project/lotus/node/modules/dtypes" + sabig "github.com/filecoin-project/specs-actors/actors/abi/big" + "github.com/filecoin-project/specs-actors/actors/builtin/power" ) // Core network constants @@ -86,6 +88,8 @@ var InitialRewardBalance *big.Int func init() { InitialRewardBalance = big.NewInt(MiningRewardTotal) InitialRewardBalance = InitialRewardBalance.Mul(InitialRewardBalance, big.NewInt(FilecoinPrecision)) + + power.ConsensusMinerMinPower = sabig.NewInt(2048) } // Sync diff --git a/chain/beacon/beacon.go b/chain/beacon/beacon.go index 4838e1a98..34405f3c8 100644 --- a/chain/beacon/beacon.go +++ b/chain/beacon/beacon.go @@ -39,7 +39,7 @@ func ValidateBlockValues(b RandomBeacon, h *types.BlockHeader, prevEntry types.B for i, e := range h.BeaconEntries { if err := b.VerifyEntry(e, prevEntry); err != nil { - return xerrors.Errorf("beacon entry %d was invalid: %w", i, err) + return xerrors.Errorf("beacon entry %d (%d - %x (%d)) was invalid: %w", i, e.Round, e.Data, len(e.Data), err) } prevEntry = e } @@ -55,6 +55,11 @@ func BeaconEntriesForBlock(ctx context.Context, beacon RandomBeacon, round abi.C return nil, nil } + // TODO: this is a sketchy way to handle the genesis block not having a beacon entry + if prev.Round == 0 { + prev.Round = maxRound - 1 + } + cur := maxRound var out []types.BeaconEntry for cur > prev.Round { diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index b75a51314..74818d312 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -2,35 +2,121 @@ package drand import ( "context" + "fmt" "sync" + "time" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/abi" + "golang.org/x/xerrors" + logging "github.com/ipfs/go-log" + + "github.com/drand/drand/core" + dkey "github.com/drand/drand/key" dnet "github.com/drand/drand/net" dproto "github.com/drand/drand/protobuf/drand" ) -type DrandBeacon struct { - client dnet.Client +var log = logging.Logger("drand") - cacheLk sync.Mutex - localCache map[int64]types.BeaconEntry +var drandServers = []string{ + "drand-test1.nikkolasg.xyz:5001", } -func NewDrandBeacon() *DrandBeacon { - return &DrandBeacon{ +type drandPeer struct { + addr string + tls bool +} + +func (dp *drandPeer) Address() string { + return dp.addr +} + +func (dp *drandPeer) IsTLS() bool { + return dp.tls +} + +type DrandBeacon struct { + client dnet.Client + peers []dnet.Peer + + pubkey *dkey.DistPublic + + // seconds + interval time.Duration + + drandGenTime uint64 + filGenTime uint64 + filRoundTime uint64 + + cacheLk sync.Mutex + localCache map[uint64]types.BeaconEntry +} + +func NewDrandBeacon(genesisTs, interval uint64) (*DrandBeacon, error) { + if genesisTs == 0 { + panic("what are you doing this cant be zero") + } + db := &DrandBeacon{ client: dnet.NewGrpcClient(), - localCache: make(map[int64]types.BeaconEntry), + localCache: make(map[uint64]types.BeaconEntry), + } + for _, ds := range drandServers { + db.peers = append(db.peers, &drandPeer{addr: ds, tls: true}) + } + + groupResp, err := db.client.Group(context.TODO(), db.peers[0], &dproto.GroupRequest{}) + if err != nil { + return nil, xerrors.Errorf("failed to get group response from beacon peer: %w", err) + } + + kgroup, err := core.ProtoToGroup(groupResp) + if err != nil { + return nil, xerrors.Errorf("failed to parse group response: %w", err) + } + + // TODO: verify these values are what we expect them to be + db.pubkey = kgroup.PublicKey + db.interval = kgroup.Period + db.drandGenTime = uint64(kgroup.GenesisTime) + db.filRoundTime = interval + db.filGenTime = genesisTs + + // TODO: the stream currently gives you back *all* values since drand genesis. + // Having the stream in the background is merely an optimization, so not a big deal to disable it for now + //go db.handleStreamingUpdates() + + return db, nil +} + +func (db *DrandBeacon) handleStreamingUpdates() { + for { + ch, err := db.client.PublicRandStream(context.Background(), db.peers[0], &dproto.PublicRandRequest{}) + if err != nil { + log.Warnf("failed to get public rand stream: %s", err) + log.Warnf("trying again in 10 seconds") + time.Sleep(time.Second * 10) + continue + } + + for e := range ch { + fmt.Println("Entry: ", e.Round, e.Signature) + db.cacheValue(e.Round, types.BeaconEntry{ + Round: e.Round, + Data: e.Signature, + }) + } + log.Warn("drand beacon stream broke, reconnecting in 10 seconds") + time.Sleep(time.Second * 10) } } -//func (db *DrandBeacon) - func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response { + fmt.Println("requesting drand entry: ", round) // check cache, it it if there, otherwise query the endpoint - resp, err := db.client.PublicRand(nil, &dproto.PublicRandRequest{Round: round}) + resp, err := db.client.PublicRand(ctx, db.peers[0], &dproto.PublicRandRequest{Round: round}) var br beacon.Response if err != nil { @@ -47,13 +133,37 @@ func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Re return out } -func (db *DrandBeacon) VerifyEntry(types.BeaconEntry, types.BeaconEntry) error { - return nil +func (db *DrandBeacon) cacheValue(round uint64, e types.BeaconEntry) { + db.cacheLk.Lock() + defer db.cacheLk.Unlock() + db.localCache[round] = e } -func (db *DrandBeacon) MaxBeaconRoundForEpoch(abi.ChainEpoch, types.BeaconEntry) uint64 { - // this is just some local math - return 0 +func (db *DrandBeacon) getCachedValue(round uint64) *types.BeaconEntry { + db.cacheLk.Lock() + defer db.cacheLk.Unlock() + v, ok := db.localCache[round] + if !ok { + return nil + } + return &v +} + +func (db *DrandBeacon) VerifyEntry(from types.BeaconEntry, to types.BeaconEntry) error { + return nil + // TODO: this doesnt work for some reason + //return dbeacon.Verify(db.pubkey.Key(), from.Data, to.Round, from.Round) +} + +func (db *DrandBeacon) MaxBeaconRoundForEpoch(filEpoch abi.ChainEpoch, prevEntry types.BeaconEntry) uint64 { + fmt.Println("MAX BEACON ROUND FOR EPOCH: ", filEpoch) + fmt.Println("filecoin genesis time: ", db.filGenTime) + fmt.Println("drand genesis time: ", db.drandGenTime) + // TODO: sometimes the genesis time for filecoin is zero and this goes negative + latestTs := ((uint64(filEpoch) * db.filRoundTime) + db.filGenTime) - db.filRoundTime + dround := (latestTs - db.drandGenTime) / uint64(db.interval.Seconds()) + fmt.Println("max beacon round will be: ", dround) + return dround } var _ beacon.RandomBeacon = (*DrandBeacon)(nil) diff --git a/chain/beacon/mock.go b/chain/beacon/mock.go index 4dcda2e8b..dd3ba5b2f 100644 --- a/chain/beacon/mock.go +++ b/chain/beacon/mock.go @@ -27,10 +27,6 @@ func (mb *mockBeacon) RoundTime() time.Duration { return mb.interval } -func (mb *mockBeacon) LastEntry() (types.BeaconEntry, error) { - panic("NYI") -} - func (mb *mockBeacon) entryForIndex(index uint64) types.BeaconEntry { buf := make([]byte, 8) binary.BigEndian.PutUint64(buf, index) @@ -42,6 +38,7 @@ func (mb *mockBeacon) entryForIndex(index uint64) types.BeaconEntry { } func (mb *mockBeacon) Entry(ctx context.Context, index uint64) <-chan Response { + panic("dont do this to me") e := mb.entryForIndex(index) out := make(chan Response, 1) out <- Response{Entry: e} diff --git a/chain/sync.go b/chain/sync.go index f177566cc..11bfa97af 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -980,36 +980,35 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to } } - { - // ensure consistency of beacon entires - targetBE := from.Blocks()[0].BeaconEntries - if len(targetBE) == 0 { - syncer.bad.Add(from.Cids()[0], "no beacon entires") - return nil, xerrors.Errorf("block (%s) contained no drand entires", from.Cids()[0]) - } - cur := targetBE[0].Round + /* + { + // TODO: Not sure what this check is aiming to do exactly, but it doesnt quite work + // ensure consistency of beacon entires + targetBE := from.Blocks()[0].BeaconEntries - for _, e := range targetBE[1:] { - if cur >= e.Round { - syncer.bad.Add(from.Cids()[0], "wrong order of beacon entires") - return nil, xerrors.Errorf("wrong order of beacon entires") - } + for _, e := range targetBE[1:] { + if cur >= e.Round { + syncer.bad.Add(from.Cids()[0], "wrong order of beacon entires") + return nil, xerrors.Errorf("wrong order of beacon entires") + } - } - for _, bh := range from.Blocks()[1:] { - if len(targetBE) != len(bh.BeaconEntries) { - // cannot mark bad, I think @Kubuxu - return nil, xerrors.Errorf("tipset contained different number for beacon entires") } - for i, be := range bh.BeaconEntries { - if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) { + for _, bh := range from.Blocks()[1:] { + beacon.ValidateBlockValues() + if len(targetBE) != len(bh.BeaconEntries) { // cannot mark bad, I think @Kubuxu return nil, xerrors.Errorf("tipset contained different number for beacon entires") } - } + for i, be := range bh.BeaconEntries { + if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) { + // cannot mark bad, I think @Kubuxu + return nil, xerrors.Errorf("tipset contained different number for beacon entires") + } + } + } } - } + */ blockSet := []*types.TipSet{from} diff --git a/chain/types/blockheader.go b/chain/types/blockheader.go index de96e535e..65e593a91 100644 --- a/chain/types/blockheader.go +++ b/chain/types/blockheader.go @@ -29,6 +29,20 @@ type ElectionProof struct { type BeaconEntry struct { Round uint64 Data []byte + + prevRound uint64 +} + +func NewBeaconEntry(round, prevRound uint64, data []byte) BeaconEntry { + return BeaconEntry{ + Round: round, + Data: data, + prevRound: prevRound, + } +} + +func (be *BeaconEntry) PrevRound() uint64 { + return be.prevRound } type BlockHeader struct { diff --git a/cmd/lotus-storage-miner/init.go b/cmd/lotus-storage-miner/init.go index 2ecfe8b74..e679a49fc 100644 --- a/cmd/lotus-storage-miner/init.go +++ b/cmd/lotus-storage-miner/init.go @@ -11,7 +11,6 @@ import ( "os" "path/filepath" "strconv" - "time" "github.com/docker/go-units" "github.com/google/uuid" @@ -38,7 +37,7 @@ import ( lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/beacon" + "github.com/filecoin-project/lotus/chain/beacon/drand" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/genesis" @@ -445,7 +444,15 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode, } epp := storage.NewElectionPoStProver(smgr, dtypes.MinerID(mid)) - beacon := beacon.NewMockBeacon(build.BlockDelay * time.Second) + gen, err := api.ChainGetGenesis(ctx) + if err != nil { + return err + } + + beacon, err := drand.NewDrandBeacon(gen.Blocks()[0].Timestamp, build.BlockDelay) + if err != nil { + return err + } m := miner.NewMiner(api, epp, beacon) { diff --git a/go.mod b/go.mod index 919060f25..a26801f36 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,12 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/GeertJohan/go.rice v1.0.0 github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee + github.com/benbjohnson/clock v1.0.0 // indirect github.com/coreos/go-systemd/v22 v22.0.0 github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect github.com/docker/go-units v0.4.0 - github.com/drand/drand v0.5.4 + github.com/drand/drand v0.7.2 + github.com/drand/kyber v1.0.1-0.20200331114745-30e90cc60f99 github.com/filecoin-project/chain-validation v0.0.6-0.20200331143132-15970e639ac2 github.com/filecoin-project/filecoin-ffi v0.0.0-20200326153646-e899cc1dd072 github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be @@ -63,6 +65,7 @@ require ( github.com/ipld/go-ipld-prime v0.0.2-0.20191108012745-28a82f04c785 github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect + github.com/kilic/bls12-381 v0.0.0-20191103193557-038659eaa189 // indirect github.com/lib/pq v1.2.0 github.com/libp2p/go-eventbus v0.1.0 github.com/libp2p/go-libp2p v0.6.1 @@ -93,6 +96,7 @@ require ( github.com/multiformats/go-multihash v0.0.13 github.com/opentracing/opentracing-go v1.1.0 github.com/stretchr/testify v1.4.0 + github.com/urfave/cli v1.22.2 // indirect github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba github.com/whyrusleeping/cbor-gen v0.0.0-20200402171437-3d27c146c105 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 @@ -104,7 +108,7 @@ require ( go.uber.org/multierr v1.5.0 go.uber.org/zap v1.14.1 golang.org/x/net v0.0.0-20200301022130-244492dfa37a // indirect - golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d + golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 gopkg.in/urfave/cli.v2 v2.0.0-20180128182452-d3ae77c26ac8 diff --git a/go.sum b/go.sum index e31fcfdbe..782072c4e 100644 --- a/go.sum +++ b/go.sum @@ -106,11 +106,21 @@ github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/drand/bls12-381 v0.0.0-20200110233355-faca855b3a67 h1:+zwFBPeS6Tx0ShngG44wyJ8wBh8ENK9upPxN2fE58Uc= github.com/drand/bls12-381 v0.0.0-20200110233355-faca855b3a67/go.mod h1:HRtP9ULniFcAfoXvSrD5Kebk1e3/g4cvtBfjlT80PuQ= +github.com/drand/bls12-381 v0.2.0 h1:nsHrbHaz5Ys0OwAdWERn49hRSkoWUr7lwXrT+ZRLybY= +github.com/drand/bls12-381 v0.2.0/go.mod h1:dtcLgPtYT38L3NO6mPDYH0nbpc5tjPassDqiniuAt4Y= github.com/drand/drand v0.5.4 h1:DyCkE4YHy1klVtu0YgYiYtsryyzyc0x6Y78HM2C9Mws= github.com/drand/drand v0.5.4/go.mod h1:n9JV/s1TIL/kx/4002pct7qjilbdzScQKVu05IfHf8c= +github.com/drand/drand v0.6.2-0.20200409185413-906ab2ad44a2 h1:4vhjpLXKfNlDUXt0vgCeH9/4ujuwJDS6tgXuPUHaayI= +github.com/drand/drand v0.6.2-0.20200409185413-906ab2ad44a2/go.mod h1:EFtHvQMalVRnRqlCBhhnaTSixhjgVsJOYCt3TM6CoaA= +github.com/drand/drand v0.7.1 h1:azaHMzno1DcC0U5tEbF4NaPJkeguET8tafkS9SGooG8= +github.com/drand/drand v0.7.1/go.mod h1:fsPW9+Vl3h4/6Gjjt2ZNJc+fjo1lJeqbBcG0t8MCoxo= +github.com/drand/drand v0.7.2 h1:y18ZS0UgIvZVhKiib0rOYn0Gn3ZlZ8zicW20UmE3404= +github.com/drand/drand v0.7.2/go.mod h1:fsPW9+Vl3h4/6Gjjt2ZNJc+fjo1lJeqbBcG0t8MCoxo= github.com/drand/kyber v1.0.1-0.20200110225416-8de27ed8c0e2/go.mod h1:UpXoA0Upd1N9l4TvRPHr1qAUBBERj6JQ/mnKI3BPEmw= github.com/drand/kyber v1.0.1-0.20200128205555-52819dbafde7 h1:ItV7+85W8JU5bQd/DxjT9y5Khsetlrp9CErHvDtYlE4= github.com/drand/kyber v1.0.1-0.20200128205555-52819dbafde7/go.mod h1:Rzu9PGFt3q8d7WWdrHmR8dktHucO0dSTWlMYrgqjSpA= +github.com/drand/kyber v1.0.1-0.20200331114745-30e90cc60f99 h1:BxLbcT0yq9ii6ShXn7U+0oXB2ABfEfw6GutaVPxoj2Y= +github.com/drand/kyber v1.0.1-0.20200331114745-30e90cc60f99/go.mod h1:Rzu9PGFt3q8d7WWdrHmR8dktHucO0dSTWlMYrgqjSpA= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= @@ -215,6 +225,9 @@ github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls= +github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -241,6 +254,8 @@ github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvK github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway v1.12.1 h1:zCy2xE9ablevUOrUZc3Dl72Dt+ya2FNAvC2yLYMHzi4= github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= +github.com/grpc-ecosystem/grpc-gateway v1.14.3 h1:OCJlWkOUoTnl0neNGlf4fUm3TmbEtguw7vR+nGtnDjY= +github.com/grpc-ecosystem/grpc-gateway v1.14.3/go.mod h1:6CwZWGDSPRJidgKAtJVvND6soZe6fT7iteq8wDPdhb0= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/gxed/pubsub v0.0.0-20180201040156-26ebdf44f824/go.mod h1:OiEWyHgK+CWrmOlVquHaIK1vhpUJydC9m0Je6mhaiNE= @@ -439,6 +454,8 @@ github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGAR github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= +github.com/jonboulle/clockwork v0.1.1-0.20190114141812-62fb9bc030d1 h1:qBCV/RLV02TSfQa7tFmxTihnG+u+7JXByOkhlkR5rmQ= +github.com/jonboulle/clockwork v0.1.1-0.20190114141812-62fb9bc030d1/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= @@ -862,6 +879,8 @@ github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.0.0 h1:+HU9SCbu8GnEUFtIBfuUNXN39ofWViIEJIp6SURMpCg= github.com/urfave/cli/v2 v2.0.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= +github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= +github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8= @@ -973,6 +992,8 @@ golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6 h1:TjszyFsQsyZNHwdVdZ5m7bjmreu0znc2kRYsEml9/Ww= golang.org/x/crypto v0.0.0-20200317142112-1b76d66859c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20200406173513-056763e48d71 h1:DOmugCavvUtnUD114C1Wh+UgTgQZ4pMLzXxi1pSt+/Y= +golang.org/x/crypto v0.0.0-20200406173513-056763e48d71/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -1052,6 +1073,8 @@ golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d h1:62ap6LNOjDU6uGmKXHJbSfciMoV+FeI1sRXx/pLDL44= golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa h1:mQTN3ECqfsViCNBgq+A40vdwhkGykrrQlYe3mPj6BoU= +golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -1099,6 +1122,8 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20200117163144-32f20d992d24 h1:wDju+RU97qa0FZT0QnZDg9Uc2dH0Ql513kFvHocz+WM= google.golang.org/genproto v0.0.0-20200117163144-32f20d992d24/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/genproto v0.0.0-20200406120821-33397c535dc2 h1:KlOjjpQjL4dqscfbhtQvAnRMm5PaRTchHHczffkUiq0= +google.golang.org/genproto v0.0.0-20200406120821-33397c535dc2/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= @@ -1106,6 +1131,8 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -1129,6 +1156,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/miner/testminer.go b/miner/testminer.go index 7b7d6f476..6b7a04c5c 100644 --- a/miner/testminer.go +++ b/miner/testminer.go @@ -10,16 +10,15 @@ import ( lru "github.com/hashicorp/golang-lru" ) -func NewTestMiner(nextCh <-chan struct{}, addr address.Address) func(api.FullNode, gen.ElectionPoStProver) *Miner { - return func(api api.FullNode, epp gen.ElectionPoStProver) *Miner { +func NewTestMiner(nextCh <-chan struct{}, addr address.Address) func(api.FullNode, gen.ElectionPoStProver, beacon.RandomBeacon) *Miner { + return func(api api.FullNode, epp gen.ElectionPoStProver, b beacon.RandomBeacon) *Miner { arc, err := lru.NewARC(10000) if err != nil { panic(err) } - beacon := beacon.NewMockBeacon(0) m := &Miner{ - beacon: beacon, + beacon: b, api: api, waitFunc: chanWaiter(nextCh), epp: epp, diff --git a/node/builder.go b/node/builder.go index 4b799fcf7..c96f08856 100644 --- a/node/builder.go +++ b/node/builder.go @@ -283,6 +283,7 @@ func Online() Option { Override(new(sealing.TicketFn), modules.SealTicketGen), Override(new(*storage.Miner), modules.StorageMiner), Override(new(dtypes.NetworkName), modules.StorageNetworkName), + Override(new(beacon.RandomBeacon), modules.MinerRandomBeacon), Override(new(dtypes.StagingBlockstore), modules.StagingBlockstore), Override(new(dtypes.StagingDAG), modules.StagingDAG), diff --git a/node/modules/services.go b/node/modules/services.go index 774c0a6fe..64fca5b27 100644 --- a/node/modules/services.go +++ b/node/modules/services.go @@ -2,7 +2,6 @@ package modules import ( "context" - "time" eventbus "github.com/libp2p/go-eventbus" event "github.com/libp2p/go-libp2p-core/event" @@ -18,8 +17,10 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain" "github.com/filecoin-project/lotus/chain/beacon" + "github.com/filecoin-project/lotus/chain/beacon/drand" "github.com/filecoin-project/lotus/chain/blocksync" "github.com/filecoin-project/lotus/chain/messagepool" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/sub" "github.com/filecoin-project/lotus/lib/peermgr" "github.com/filecoin-project/lotus/node/hello" @@ -117,6 +118,12 @@ func RetrievalResolver(l *discovery.Local) retrievalmarket.PeerResolver { return discovery.Multi(l) } -func RandomBeacon() beacon.RandomBeacon { - return beacon.NewMockBeacon(build.BlockDelay * time.Second) +func RandomBeacon(cs *store.ChainStore, _ dtypes.AfterGenesisSet) (beacon.RandomBeacon, error) { + gen, err := cs.GetGenesis() + if err != nil { + return nil, err + } + + //return beacon.NewMockBeacon(build.BlockDelay * time.Second) + return drand.NewDrandBeacon(gen.Timestamp, build.BlockDelay) } diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 03cd736da..f69e58a9b 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -2,6 +2,7 @@ package modules import ( "context" + "fmt" "net/http" "reflect" @@ -43,6 +44,7 @@ import ( lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/beacon" + "github.com/filecoin-project/lotus/chain/beacon/drand" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/markets/retrievaladapter" @@ -375,3 +377,15 @@ func StorageAuth(ctx helpers.MetricsCtx, ca lapi.Common) (sectorstorage.StorageA headers.Add("Authorization", "Bearer "+string(token)) return sectorstorage.StorageAuth(headers), nil } + +func MinerRandomBeacon(api lapi.FullNode) (beacon.RandomBeacon, error) { + gents, err := api.ChainGetGenesis(context.TODO()) + if err != nil { + return nil, err + } + + fmt.Println("Making miner random beacon: ", gents.Blocks()[0].Timestamp) + + //return beacon.NewMockBeacon(build.BlockDelay * time.Second) + return drand.NewDrandBeacon(gents.Blocks()[0].Timestamp, build.BlockDelay) +} diff --git a/node/node_test.go b/node/node_test.go index 2b650658a..5bac49c22 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -206,8 +206,9 @@ func builder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []test.Te } templ := &genesis.Template{ - Accounts: genaccs, - Miners: genms, + Accounts: genaccs, + Miners: genms, + Timestamp: uint64(time.Now().Unix() - 1000), // some time sufficiently far in the past } // END PRESEAL SECTION @@ -335,8 +336,9 @@ func mockSbBuilder(t *testing.T, nFull int, storage []int) ([]test.TestNode, []t genms = append(genms, *genm) } templ := &genesis.Template{ - Accounts: genaccs, - Miners: genms, + Accounts: genaccs, + Miners: genms, + Timestamp: uint64(time.Now().Unix() - 1000), } // END PRESEAL SECTION From 2a10a79460d9e9030d1757306d0684d0279b45dc Mon Sep 17 00:00:00 2001 From: Da Yu Date: Tue, 14 Apr 2020 17:18:19 +0800 Subject: [PATCH 05/26] fix error unknown address protocol when run lotus msig create in cli/mutisig.go --- cli/multisig.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cli/multisig.go b/cli/multisig.go index cf9579664..0b09e8924 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -144,14 +144,22 @@ var msigCreateCmd = &cli.Command{ fmt.Println("actor creation failed!") return err } + // get address of newly created miner - msigaddr, err := address.NewFromBytes(wait.Receipt.Return) - if err != nil { + // msigaddr, err := address.NewFromBytes(wait.Receipt.Return) + // if err != nil { + // return err + // } + + // fmt.Println("Created new multisig: ", msigaddr.String()) + + var execreturn init_.ExecReturn + if err := execreturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { return err } - - fmt.Println("Created new multisig: ", msigaddr.String()) + fmt.Println("Created new multisig: ", execreturn.IDAddress, execreturn.RobustAddress) + // TODO: maybe register this somewhere return nil }, From 3e976fd74bc5f69837b6dae8413258cea9a36db5 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 14 Apr 2020 16:09:11 +0200 Subject: [PATCH 06/26] Make tests pass Signed-off-by: Jakub Sztandera --- chain/gen/gen.go | 9 ++++++-- chain/sync.go | 54 +++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/chain/gen/gen.go b/chain/gen/gen.go index d75215083..34e9b9bd0 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -28,6 +28,7 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/beacon" + "github.com/filecoin-project/lotus/chain/beacon/drand" genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" @@ -188,7 +189,7 @@ func NewGenerator() (*ChainGen, error) { *genm2, }, NetworkName: "", - Timestamp: 100000, + Timestamp: uint64(time.Now().Add(-500 * build.BlockDelay * time.Second).Unix()), } genb, err := genesis2.MakeGenesisBlock(context.TODO(), bs, sys, tpl) @@ -214,7 +215,11 @@ func NewGenerator() (*ChainGen, error) { miners := []address.Address{maddr1, maddr2} - beac := beacon.NewMockBeacon(time.Second) + //beac := beacon.NewMockBeacon(time.Second) + beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay) + if err != nil { + return nil, xerrors.Errorf("could not create beacon: %w", err) + } gen := &ChainGen{ bs: bs, diff --git a/chain/sync.go b/chain/sync.go index 11bfa97af..68e118594 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -5,6 +5,7 @@ import ( "context" "errors" "fmt" + "sort" "strings" "sync" "time" @@ -980,35 +981,32 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to } } - /* - { - // TODO: Not sure what this check is aiming to do exactly, but it doesnt quite work - // ensure consistency of beacon entires - targetBE := from.Blocks()[0].BeaconEntries - - for _, e := range targetBE[1:] { - if cur >= e.Round { - syncer.bad.Add(from.Cids()[0], "wrong order of beacon entires") - return nil, xerrors.Errorf("wrong order of beacon entires") - } - - } - for _, bh := range from.Blocks()[1:] { - beacon.ValidateBlockValues() - if len(targetBE) != len(bh.BeaconEntries) { - // cannot mark bad, I think @Kubuxu - return nil, xerrors.Errorf("tipset contained different number for beacon entires") - } - for i, be := range bh.BeaconEntries { - if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) { - // cannot mark bad, I think @Kubuxu - return nil, xerrors.Errorf("tipset contained different number for beacon entires") - } - } - - } + { + // TODO: Not sure what this check is aiming to do exactly, but it doesnt quite work + // ensure consistency of beacon entires + targetBE := from.Blocks()[0].BeaconEntries + sorted := sort.SliceIsSorted(targetBE, func(i, j int) bool { + return targetBE[i].Round < targetBE[j].Round + }) + if !sorted { + syncer.bad.Add(from.Cids()[0], "wrong order of beacon entires") + return nil, xerrors.Errorf("wrong order of beacon entires") } - */ + + for _, bh := range from.Blocks()[1:] { + if len(targetBE) != len(bh.BeaconEntries) { + // cannot mark bad, I think @Kubuxu + return nil, xerrors.Errorf("tipset contained different number for beacon entires") + } + for i, be := range bh.BeaconEntries { + if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) { + // cannot mark bad, I think @Kubuxu + return nil, xerrors.Errorf("tipset contained different beacon entires") + } + } + + } + } blockSet := []*types.TipSet{from} From 624dd7d2ce799bfa359047bb10c3c0a74b8f0ed0 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 14 Apr 2020 16:18:34 +0200 Subject: [PATCH 07/26] Verify PrevRound too Signed-off-by: Jakub Sztandera --- chain/sync.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chain/sync.go b/chain/sync.go index 68e118594..d1c44b875 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -999,7 +999,8 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to return nil, xerrors.Errorf("tipset contained different number for beacon entires") } for i, be := range bh.BeaconEntries { - if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) { + if targetBE[i].Round != be.Round || !bytes.Equal(targetBE[i].Data, be.Data) || + targetBE[i].PrevRound() != be.PrevRound() { // cannot mark bad, I think @Kubuxu return nil, xerrors.Errorf("tipset contained different beacon entires") } From 5ab96363654860ca20cf49c6ae7cf17fda9acc73 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 14 Apr 2020 16:52:18 +0200 Subject: [PATCH 08/26] Call VerifyBeacon, hack around genesis Signed-off-by: Jakub Sztandera --- chain/beacon/drand/drand.go | 18 ++++++++++++++---- chain/store/store.go | 3 +-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index 74818d312..f2e0fcb54 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -13,6 +13,7 @@ import ( logging "github.com/ipfs/go-log" + dbeacon "github.com/drand/drand/beacon" "github.com/drand/drand/core" dkey "github.com/drand/drand/key" dnet "github.com/drand/drand/net" @@ -149,10 +150,19 @@ func (db *DrandBeacon) getCachedValue(round uint64) *types.BeaconEntry { return &v } -func (db *DrandBeacon) VerifyEntry(from types.BeaconEntry, to types.BeaconEntry) error { - return nil - // TODO: this doesnt work for some reason - //return dbeacon.Verify(db.pubkey.Key(), from.Data, to.Round, from.Round) +func (db *DrandBeacon) VerifyEntry(curr types.BeaconEntry, prev types.BeaconEntry) error { + if prev.Round == 0 { + // TODO handle genesis better + return nil + } + b := &dbeacon.Beacon{ + PreviousRound: prev.Round, + PreviousSig: prev.Data, + Round: curr.Round, + Signature: curr.Data, + } + //log.Warnw("VerifyEntry", "beacon", b) + return dbeacon.VerifyBeacon(db.pubkey.Key(), b) } func (db *DrandBeacon) MaxBeaconRoundForEpoch(filEpoch abi.ChainEpoch, prevEntry types.BeaconEntry) uint64 { diff --git a/chain/store/store.go b/chain/store/store.go index fc032f5f9..6d8bf4ce9 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -23,7 +23,6 @@ import ( "go.opencensus.io/stats" "go.opencensus.io/trace" "go.uber.org/multierr" - "go.uber.org/zap" amt "github.com/filecoin-project/go-amt-ipld/v2" @@ -894,7 +893,7 @@ func (cs *ChainStore) TryFillTipSet(ts *types.TipSet) (*FullTipSet, error) { } func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { - log.Desugar().WithOptions(zap.AddCallerSkip(2)).Sugar().Warnw("DrawRandomness", "base", rbase, "dsep", pers, "round", round, "entropy", entropy) + //log.Desugar().WithOptions(zap.AddCallerSkip(2)).Sugar().Warnw("DrawRandomness", "base", rbase, "dsep", pers, "round", round, "entropy", entropy) h := blake2b.New256() if err := binary.Write(h, binary.BigEndian, int64(pers)); err != nil { return nil, xerrors.Errorf("deriving randomness: %w", err) From eb501f7290f445e497ba541b296d57d34b827a39 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 14 Apr 2020 19:55:53 +0200 Subject: [PATCH 09/26] Cache more Signed-off-by: Jakub Sztandera --- chain/beacon/drand/drand.go | 45 ++++++++++++++++++++++++------------- chain/beacon/mock.go | 1 - 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index f2e0fcb54..2484f3c43 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -104,7 +104,7 @@ func (db *DrandBeacon) handleStreamingUpdates() { for e := range ch { fmt.Println("Entry: ", e.Round, e.Signature) - db.cacheValue(e.Round, types.BeaconEntry{ + db.cacheValue(types.BeaconEntry{ Round: e.Round, Data: e.Signature, }) @@ -116,28 +116,39 @@ func (db *DrandBeacon) handleStreamingUpdates() { func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response { fmt.Println("requesting drand entry: ", round) - // check cache, it it if there, otherwise query the endpoint - resp, err := db.client.PublicRand(ctx, db.peers[0], &dproto.PublicRandRequest{Round: round}) - - var br beacon.Response - if err != nil { - br.Err = err - } else { - br.Entry.Round = resp.GetRound() - br.Entry.Data = resp.GetSignature() + cres := db.getCachedValue(round) + if cres != nil { + out := make(chan beacon.Response, 1) + out <- beacon.Response{Entry: *cres} + close(out) + return out } out := make(chan beacon.Response, 1) - out <- br - close(out) + + go func() { + // check cache, it it if there, otherwise query the endpoint + resp, err := db.client.PublicRand(ctx, db.peers[0], &dproto.PublicRandRequest{Round: round}) + + var br beacon.Response + if err != nil { + br.Err = err + } else { + br.Entry.Round = resp.GetRound() + br.Entry.Data = resp.GetSignature() + } + + out <- br + close(out) + }() return out } -func (db *DrandBeacon) cacheValue(round uint64, e types.BeaconEntry) { +func (db *DrandBeacon) cacheValue(e types.BeaconEntry) { db.cacheLk.Lock() defer db.cacheLk.Unlock() - db.localCache[round] = e + db.localCache[e.Round] = e } func (db *DrandBeacon) getCachedValue(round uint64) *types.BeaconEntry { @@ -162,7 +173,11 @@ func (db *DrandBeacon) VerifyEntry(curr types.BeaconEntry, prev types.BeaconEntr Signature: curr.Data, } //log.Warnw("VerifyEntry", "beacon", b) - return dbeacon.VerifyBeacon(db.pubkey.Key(), b) + err := dbeacon.VerifyBeacon(db.pubkey.Key(), b) + if err == nil { + db.cacheValue(curr) + } + return err } func (db *DrandBeacon) MaxBeaconRoundForEpoch(filEpoch abi.ChainEpoch, prevEntry types.BeaconEntry) uint64 { diff --git a/chain/beacon/mock.go b/chain/beacon/mock.go index dd3ba5b2f..dc45ae895 100644 --- a/chain/beacon/mock.go +++ b/chain/beacon/mock.go @@ -38,7 +38,6 @@ func (mb *mockBeacon) entryForIndex(index uint64) types.BeaconEntry { } func (mb *mockBeacon) Entry(ctx context.Context, index uint64) <-chan Response { - panic("dont do this to me") e := mb.entryForIndex(index) out := make(chan Response, 1) out <- Response{Entry: e} From 0c5e3e25331598a40dc38dbb40278b7645f44427 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 14 Apr 2020 20:41:05 +0200 Subject: [PATCH 10/26] Make tests use mock beacon Signed-off-by: Jakub Sztandera --- chain/gen/gen.go | 11 +++++------ node/builder.go | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 34e9b9bd0..aa1c1956c 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -28,7 +28,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/beacon" - "github.com/filecoin-project/lotus/chain/beacon/drand" genesis2 "github.com/filecoin-project/lotus/chain/gen/genesis" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" @@ -215,11 +214,11 @@ func NewGenerator() (*ChainGen, error) { miners := []address.Address{maddr1, maddr2} - //beac := beacon.NewMockBeacon(time.Second) - beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay) - if err != nil { - return nil, xerrors.Errorf("could not create beacon: %w", err) - } + beac := beacon.NewMockBeacon(time.Second) + //beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay) + //if err != nil { + //return nil, xerrors.Errorf("could not create beacon: %w", err) + //} gen := &ChainGen{ bs: bs, diff --git a/node/builder.go b/node/builder.go index c96f08856..469daa821 100644 --- a/node/builder.go +++ b/node/builder.go @@ -486,5 +486,6 @@ func Test() Option { return Options( Unset(RunPeerMgrKey), Unset(new(*peermgr.PeerMgr)), + Override(new(beacon.RandomBeacon), testing.RandomBeacon), ) } From 0feab0aad4d4290749658162bcdd87054ca81c0c Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 14 Apr 2020 22:34:44 +0200 Subject: [PATCH 11/26] Bake drand public key into build params Signed-off-by: Jakub Sztandera --- build/params_shared.go | 6 ++++++ chain/beacon/drand/drand.go | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/build/params_shared.go b/build/params_shared.go index 90d8b9e71..6df1479e5 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -103,3 +103,9 @@ const BlsSignatureCacheSize = 40000 // Limits const BlockMessageLimit = 512 + +var DrandCoeffs = []string{ + "a2a34cf9a6be2f66b5385caa520364f994ae7dbac08371ffaca575dfb3e04c8e149b32dc78f077322c613a151dc07440", + "b0c5baca062191f13099229c9a229a9946204f74fc28baa212745243553ab1f50b581b2086e24374ceb40fe34bd23ca2", + "a9c6449cf647e0a0ffaf1e01277e2821213c80310165990daf77610208abfa0ce56c7e40995e26aff3873c624362ca78", +} diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index 2484f3c43..f20d36a70 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -6,6 +6,7 @@ import ( "sync" "time" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/specs-actors/actors/abi" @@ -26,6 +27,16 @@ var drandServers = []string{ "drand-test1.nikkolasg.xyz:5001", } +var drandPubKey *dkey.DistPublic + +func init() { + drandPubKey = new(dkey.DistPublic) + err := drandPubKey.FromTOML(&dkey.DistPublicTOML{build.DrandCoeffs}) + if err != nil { + panic(err) + } +} + type drandPeer struct { addr string tls bool @@ -79,7 +90,11 @@ func NewDrandBeacon(genesisTs, interval uint64) (*DrandBeacon, error) { } // TODO: verify these values are what we expect them to be - db.pubkey = kgroup.PublicKey + if !kgroup.PublicKey.Equal(drandPubKey) { + return nil, xerrors.Errorf("public key does not match") + } + // fmt.Printf("Drand Pubkey:\n%#v\n", kgroup.PublicKey.TOML()) // use to print public key + db.pubkey = drandPubKey db.interval = kgroup.Period db.drandGenTime = uint64(kgroup.GenesisTime) db.filRoundTime = interval From 4e6839b5ef839c867c3d26b23831edd708dddd8d Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 14 Apr 2020 15:13:52 -0700 Subject: [PATCH 12/26] some small cleanup --- chain/beacon/drand/drand.go | 9 +-------- chain/gen/gen.go | 4 ---- chain/store/store.go | 1 - node/modules/storageminer.go | 4 ---- 4 files changed, 1 insertion(+), 17 deletions(-) diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index f20d36a70..7d6c6746d 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -2,7 +2,6 @@ package drand import ( "context" - "fmt" "sync" "time" @@ -118,7 +117,6 @@ func (db *DrandBeacon) handleStreamingUpdates() { } for e := range ch { - fmt.Println("Entry: ", e.Round, e.Signature) db.cacheValue(types.BeaconEntry{ Round: e.Round, Data: e.Signature, @@ -130,7 +128,7 @@ func (db *DrandBeacon) handleStreamingUpdates() { } func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response { - fmt.Println("requesting drand entry: ", round) + // check cache, it it if there, otherwise query the endpoint cres := db.getCachedValue(round) if cres != nil { out := make(chan beacon.Response, 1) @@ -142,7 +140,6 @@ func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Re out := make(chan beacon.Response, 1) go func() { - // check cache, it it if there, otherwise query the endpoint resp, err := db.client.PublicRand(ctx, db.peers[0], &dproto.PublicRandRequest{Round: round}) var br beacon.Response @@ -196,13 +193,9 @@ func (db *DrandBeacon) VerifyEntry(curr types.BeaconEntry, prev types.BeaconEntr } func (db *DrandBeacon) MaxBeaconRoundForEpoch(filEpoch abi.ChainEpoch, prevEntry types.BeaconEntry) uint64 { - fmt.Println("MAX BEACON ROUND FOR EPOCH: ", filEpoch) - fmt.Println("filecoin genesis time: ", db.filGenTime) - fmt.Println("drand genesis time: ", db.drandGenTime) // TODO: sometimes the genesis time for filecoin is zero and this goes negative latestTs := ((uint64(filEpoch) * db.filRoundTime) + db.filGenTime) - db.filRoundTime dround := (latestTs - db.drandGenTime) / uint64(db.interval.Seconds()) - fmt.Println("max beacon round will be: ", dround) return dround } diff --git a/chain/gen/gen.go b/chain/gen/gen.go index aa1c1956c..05083f3d7 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -215,10 +215,6 @@ func NewGenerator() (*ChainGen, error) { miners := []address.Address{maddr1, maddr2} beac := beacon.NewMockBeacon(time.Second) - //beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay) - //if err != nil { - //return nil, xerrors.Errorf("could not create beacon: %w", err) - //} gen := &ChainGen{ bs: bs, diff --git a/chain/store/store.go b/chain/store/store.go index 6d8bf4ce9..d076d2599 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -893,7 +893,6 @@ func (cs *ChainStore) TryFillTipSet(ts *types.TipSet) (*FullTipSet, error) { } func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round abi.ChainEpoch, entropy []byte) ([]byte, error) { - //log.Desugar().WithOptions(zap.AddCallerSkip(2)).Sugar().Warnw("DrawRandomness", "base", rbase, "dsep", pers, "round", round, "entropy", entropy) h := blake2b.New256() if err := binary.Write(h, binary.BigEndian, int64(pers)); err != nil { return nil, xerrors.Errorf("deriving randomness: %w", err) diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index f69e58a9b..a50dbfeb2 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -2,7 +2,6 @@ package modules import ( "context" - "fmt" "net/http" "reflect" @@ -384,8 +383,5 @@ func MinerRandomBeacon(api lapi.FullNode) (beacon.RandomBeacon, error) { return nil, err } - fmt.Println("Making miner random beacon: ", gents.Blocks()[0].Timestamp) - - //return beacon.NewMockBeacon(build.BlockDelay * time.Second) return drand.NewDrandBeacon(gents.Blocks()[0].Timestamp, build.BlockDelay) } From 05536042f916f33e25bb9c7479de5ca32906266f Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 14 Apr 2020 16:37:10 -0700 Subject: [PATCH 13/26] drop outdated comment --- chain/sync.go | 1 - 1 file changed, 1 deletion(-) diff --git a/chain/sync.go b/chain/sync.go index d1c44b875..e5d5a5ff0 100644 --- a/chain/sync.go +++ b/chain/sync.go @@ -982,7 +982,6 @@ func (syncer *Syncer) collectHeaders(ctx context.Context, from *types.TipSet, to } { - // TODO: Not sure what this check is aiming to do exactly, but it doesnt quite work // ensure consistency of beacon entires targetBE := from.Blocks()[0].BeaconEntries sorted := sort.SliceIsSorted(targetBE, func(i, j int) bool { From 08e74a90f9da741119cd6be46d4b41ccb3991f66 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 15 Apr 2020 16:13:20 +0200 Subject: [PATCH 14/26] Add missing files Signed-off-by: Jakub Sztandera --- chain/beacon/drand/drand_test.go | 14 ++++++++++++++ node/modules/testing/beacon.go | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 chain/beacon/drand/drand_test.go create mode 100644 node/modules/testing/beacon.go diff --git a/chain/beacon/drand/drand_test.go b/chain/beacon/drand/drand_test.go new file mode 100644 index 000000000..2055597bd --- /dev/null +++ b/chain/beacon/drand/drand_test.go @@ -0,0 +1,14 @@ +package drand + +import ( + "fmt" + "testing" +) + +func TestPrintDrandPubkey(t *testing.T) { + bc, err := NewDrandBeacon(1, 1) + if err != nil { + t.Fatal(err) + } + fmt.Printf("Drand Pubkey:\n%#v\n", bc.pubkey.TOML()) +} diff --git a/node/modules/testing/beacon.go b/node/modules/testing/beacon.go new file mode 100644 index 000000000..37d229982 --- /dev/null +++ b/node/modules/testing/beacon.go @@ -0,0 +1,12 @@ +package testing + +import ( + "time" + + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/beacon" +) + +func RandomBeacon() (beacon.RandomBeacon, error) { + return beacon.NewMockBeacon(build.BlockDelay * time.Second), nil +} From c2db85b99bf7e569df3a0fbbc60ea356cb554d00 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 15 Apr 2020 16:36:21 +0200 Subject: [PATCH 15/26] mod tidy Signed-off-by: Jakub Sztandera --- go.mod | 4 ---- go.sum | 25 ++++--------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index a26801f36..345379919 100644 --- a/go.mod +++ b/go.mod @@ -8,12 +8,10 @@ require ( github.com/BurntSushi/toml v0.3.1 github.com/GeertJohan/go.rice v1.0.0 github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee - github.com/benbjohnson/clock v1.0.0 // indirect github.com/coreos/go-systemd/v22 v22.0.0 github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect github.com/docker/go-units v0.4.0 github.com/drand/drand v0.7.2 - github.com/drand/kyber v1.0.1-0.20200331114745-30e90cc60f99 github.com/filecoin-project/chain-validation v0.0.6-0.20200331143132-15970e639ac2 github.com/filecoin-project/filecoin-ffi v0.0.0-20200326153646-e899cc1dd072 github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be @@ -65,7 +63,6 @@ require ( github.com/ipld/go-ipld-prime v0.0.2-0.20191108012745-28a82f04c785 github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect - github.com/kilic/bls12-381 v0.0.0-20191103193557-038659eaa189 // indirect github.com/lib/pq v1.2.0 github.com/libp2p/go-eventbus v0.1.0 github.com/libp2p/go-libp2p v0.6.1 @@ -96,7 +93,6 @@ require ( github.com/multiformats/go-multihash v0.0.13 github.com/opentracing/opentracing-go v1.1.0 github.com/stretchr/testify v1.4.0 - github.com/urfave/cli v1.22.2 // indirect github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba github.com/whyrusleeping/cbor-gen v0.0.0-20200402171437-3d27c146c105 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 diff --git a/go.sum b/go.sum index 782072c4e..8b1774503 100644 --- a/go.sum +++ b/go.sum @@ -36,8 +36,6 @@ github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQY github.com/apache/thrift v0.12.0 h1:pODnxUFNcjP9UTLZGTdeh+j16A8lJbRvD3rOtrk/7bs= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/benbjohnson/clock v1.0.0 h1:78Jk/r6m4wCi6sndMpty7A//t4dw/RW5fV4ZgDVfX1w= -github.com/benbjohnson/clock v1.0.0/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= @@ -104,21 +102,11 @@ github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczC github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/drand/bls12-381 v0.0.0-20200110233355-faca855b3a67 h1:+zwFBPeS6Tx0ShngG44wyJ8wBh8ENK9upPxN2fE58Uc= -github.com/drand/bls12-381 v0.0.0-20200110233355-faca855b3a67/go.mod h1:HRtP9ULniFcAfoXvSrD5Kebk1e3/g4cvtBfjlT80PuQ= github.com/drand/bls12-381 v0.2.0 h1:nsHrbHaz5Ys0OwAdWERn49hRSkoWUr7lwXrT+ZRLybY= github.com/drand/bls12-381 v0.2.0/go.mod h1:dtcLgPtYT38L3NO6mPDYH0nbpc5tjPassDqiniuAt4Y= -github.com/drand/drand v0.5.4 h1:DyCkE4YHy1klVtu0YgYiYtsryyzyc0x6Y78HM2C9Mws= -github.com/drand/drand v0.5.4/go.mod h1:n9JV/s1TIL/kx/4002pct7qjilbdzScQKVu05IfHf8c= -github.com/drand/drand v0.6.2-0.20200409185413-906ab2ad44a2 h1:4vhjpLXKfNlDUXt0vgCeH9/4ujuwJDS6tgXuPUHaayI= -github.com/drand/drand v0.6.2-0.20200409185413-906ab2ad44a2/go.mod h1:EFtHvQMalVRnRqlCBhhnaTSixhjgVsJOYCt3TM6CoaA= -github.com/drand/drand v0.7.1 h1:azaHMzno1DcC0U5tEbF4NaPJkeguET8tafkS9SGooG8= -github.com/drand/drand v0.7.1/go.mod h1:fsPW9+Vl3h4/6Gjjt2ZNJc+fjo1lJeqbBcG0t8MCoxo= github.com/drand/drand v0.7.2 h1:y18ZS0UgIvZVhKiib0rOYn0Gn3ZlZ8zicW20UmE3404= github.com/drand/drand v0.7.2/go.mod h1:fsPW9+Vl3h4/6Gjjt2ZNJc+fjo1lJeqbBcG0t8MCoxo= github.com/drand/kyber v1.0.1-0.20200110225416-8de27ed8c0e2/go.mod h1:UpXoA0Upd1N9l4TvRPHr1qAUBBERj6JQ/mnKI3BPEmw= -github.com/drand/kyber v1.0.1-0.20200128205555-52819dbafde7 h1:ItV7+85W8JU5bQd/DxjT9y5Khsetlrp9CErHvDtYlE4= -github.com/drand/kyber v1.0.1-0.20200128205555-52819dbafde7/go.mod h1:Rzu9PGFt3q8d7WWdrHmR8dktHucO0dSTWlMYrgqjSpA= github.com/drand/kyber v1.0.1-0.20200331114745-30e90cc60f99 h1:BxLbcT0yq9ii6ShXn7U+0oXB2ABfEfw6GutaVPxoj2Y= github.com/drand/kyber v1.0.1-0.20200331114745-30e90cc60f99/go.mod h1:Rzu9PGFt3q8d7WWdrHmR8dktHucO0dSTWlMYrgqjSpA= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -204,6 +192,7 @@ github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -252,8 +241,6 @@ github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grpc-ecosystem/grpc-gateway v1.12.1 h1:zCy2xE9ablevUOrUZc3Dl72Dt+ya2FNAvC2yLYMHzi4= -github.com/grpc-ecosystem/grpc-gateway v1.12.1/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/grpc-ecosystem/grpc-gateway v1.14.3 h1:OCJlWkOUoTnl0neNGlf4fUm3TmbEtguw7vR+nGtnDjY= github.com/grpc-ecosystem/grpc-gateway v1.14.3/go.mod h1:6CwZWGDSPRJidgKAtJVvND6soZe6fT7iteq8wDPdhb0= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= @@ -464,7 +451,6 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/kabukky/httpscerts v0.0.0-20150320125433-617593d7dcb3 h1:Iy7Ifq2ysilWU4QlCx/97OoI4xT1IV7i8byT/EyIT/M= github.com/kabukky/httpscerts v0.0.0-20150320125433-617593d7dcb3/go.mod h1:BYpt4ufZiIGv2nXn4gMxnfKV306n3mWXgNu/d2TqdTU= github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d/go.mod h1:P2viExyCEfeWGU259JnaQ34Inuec4R38JCyBx2edgD0= -github.com/kilic/bls12-381 v0.0.0-20191103193557-038659eaa189/go.mod h1:INznczsRc7ASFbWFUI9GnIvpi9s2FhenKE+24rdTmBQ= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -875,8 +861,6 @@ github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpP github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= -github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.0.0 h1:+HU9SCbu8GnEUFtIBfuUNXN39ofWViIEJIp6SURMpCg= github.com/urfave/cli/v2 v2.0.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= @@ -928,13 +912,16 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJ github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs= go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw= go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ= +go.dedis.ch/kyber/v3 v3.0.9 h1:i0ZbOQocHUjfFasBiUql5zVeC7u/vahFd96DFA8UOWk= go.dedis.ch/kyber/v3 v3.0.9/go.mod h1:rhNjUUg6ahf8HEg5HUvVBYoWY4boAafX8tYxX+PS+qg= go.dedis.ch/protobuf v1.0.5/go.mod h1:eIV4wicvi6JK0q/QnfIEGeSFNG0ZeB24kzut5+HaRLo= go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI4= go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo= go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4= +go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= @@ -1120,8 +1107,6 @@ google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20200117163144-32f20d992d24 h1:wDju+RU97qa0FZT0QnZDg9Uc2dH0Ql513kFvHocz+WM= -google.golang.org/genproto v0.0.0-20200117163144-32f20d992d24/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200406120821-33397c535dc2 h1:KlOjjpQjL4dqscfbhtQvAnRMm5PaRTchHHczffkUiq0= google.golang.org/genproto v0.0.0-20200406120821-33397c535dc2/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= @@ -1129,8 +1114,6 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= -google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= From 56eaf143db795f278f3aaf65e85968bc6d28e5f5 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 15 Apr 2020 16:37:03 +0200 Subject: [PATCH 16/26] fix lint Signed-off-by: Jakub Sztandera --- chain/beacon/drand/drand.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index 7d6c6746d..be231e74c 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -30,7 +30,7 @@ var drandPubKey *dkey.DistPublic func init() { drandPubKey = new(dkey.DistPublic) - err := drandPubKey.FromTOML(&dkey.DistPublicTOML{build.DrandCoeffs}) + err := drandPubKey.FromTOML(&dkey.DistPublicTOML{Coefficients: build.DrandCoeffs}) if err != nil { panic(err) } From c34fb24cef876cdd664979e6822b06310588d5bb Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 15 Apr 2020 16:49:17 +0200 Subject: [PATCH 17/26] Reove 2048 min power in shared params Signed-off-by: Jakub Sztandera --- build/params_shared.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/build/params_shared.go b/build/params_shared.go index 6df1479e5..310333710 100644 --- a/build/params_shared.go +++ b/build/params_shared.go @@ -6,8 +6,6 @@ import ( "github.com/libp2p/go-libp2p-core/protocol" "github.com/filecoin-project/lotus/node/modules/dtypes" - sabig "github.com/filecoin-project/specs-actors/actors/abi/big" - "github.com/filecoin-project/specs-actors/actors/builtin/power" ) // Core network constants @@ -88,8 +86,6 @@ var InitialRewardBalance *big.Int func init() { InitialRewardBalance = big.NewInt(MiningRewardTotal) InitialRewardBalance = InitialRewardBalance.Mul(InitialRewardBalance, big.NewInt(FilecoinPrecision)) - - power.ConsensusMinerMinPower = sabig.NewInt(2048) } // Sync From fc933858e1a68043b5da575014658a403b482ac1 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 3 Apr 2020 18:17:57 -0400 Subject: [PATCH 18/26] Add an API method to calculate piece CIDs --- api/api_full.go | 7 ++ api/apistruct/struct.go | 9 ++ cli/client.go | 66 +++++++++++++- node/impl/client/client.go | 179 ++++++++++++++++++++++++++----------- 4 files changed, 210 insertions(+), 51 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 724b721d7..3bd9434f6 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -101,6 +101,8 @@ type FullNode interface { ClientFindData(ctx context.Context, root cid.Cid) ([]QueryOffer, error) ClientRetrieve(ctx context.Context, order RetrievalOrder, ref FileRef) error ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) + ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*CommPRet, error) + ClientGenCar(ctx context.Context, ref FileRef, outpath string) error // ClientUnimport removes references to the specified file from filestore //ClientUnimport(path string) @@ -398,3 +400,8 @@ type BlockTemplate struct { Epoch abi.ChainEpoch Timestamp uint64 } + +type CommPRet struct { + Root cid.Cid + Size abi.UnpaddedPieceSize +} diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 3bbe9d40d..603af0ad0 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -112,6 +112,8 @@ type FullNodeStruct struct { ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"` ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref api.FileRef) error `perm:"admin"` ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"` + ClientCalcCommP func(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) `perm:"read"` + ClientGenCar func(ctx context.Context, ref api.FileRef, outpath string) error `perm:"write"` StateNetworkName func(context.Context) (dtypes.NetworkName, error) `perm:"read"` StateMinerSectors func(context.Context, address.Address, types.TipSetKey) ([]*api.ChainSectorInfo, error) `perm:"read"` @@ -309,6 +311,13 @@ func (c *FullNodeStruct) ClientRetrieve(ctx context.Context, order api.Retrieval func (c *FullNodeStruct) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) { return c.Internal.ClientQueryAsk(ctx, p, miner) } +func (c *FullNodeStruct) ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) { + return c.Internal.ClientCalcCommP(ctx, inpath, miner) +} + +func (c *FullNodeStruct) ClientGenCar(ctx context.Context, ref api.FileRef, outpath string) error { + return c.Internal.ClientGenCar(ctx, ref, outpath) +} func (c *FullNodeStruct) MpoolPending(ctx context.Context, tsk types.TipSetKey) ([]*types.SignedMessage, error) { return c.Internal.MpoolPending(ctx, tsk) diff --git a/cli/client.go b/cli/client.go index 9f6b12e69..7a5359ce2 100644 --- a/cli/client.go +++ b/cli/client.go @@ -25,12 +25,14 @@ var clientCmd = &cli.Command{ Usage: "Make deals, store data, retrieve data", Subcommands: []*cli.Command{ clientImportCmd, + clientCommPCmd, clientLocalCmd, clientDealCmd, clientFindCmd, clientRetrieveCmd, clientQueryAskCmd, clientListDeals, + clientCarGenCmd, }, } @@ -41,7 +43,7 @@ var clientImportCmd = &cli.Command{ Flags: []cli.Flag{ &cli.BoolFlag{ Name: "car", - Usage: "export to a car file instead of a regular file", + Usage: "import from a car file instead of a regular file", }, }, Action: func(cctx *cli.Context) error { @@ -69,6 +71,68 @@ var clientImportCmd = &cli.Command{ }, } +var clientCommPCmd = &cli.Command{ + Name: "commP", + Usage: "calculate the piece-cid (commP) of a CAR file", + ArgsUsage: "[inputFile minerAddress]", + Action: func(cctx *cli.Context) error { + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + if cctx.Args().Len() != 2 { + return fmt.Errorf("usage: commP ") + } + + miner, err := address.NewFromString(cctx.Args().Get(1)) + if err != nil { + return err + } + + ret, err := api.ClientCalcCommP(ctx, cctx.Args().Get(0), miner) + + if err != nil { + return err + } + fmt.Println("CID: ", ret.Root) + fmt.Println("Piece size: ", ret.Size) + return nil + }, +} + +var clientCarGenCmd = &cli.Command{ + Name: "generate-car", + Usage: "generate a car file from input", + ArgsUsage: "[inputPath outputPath]", + Action: func(cctx *cli.Context) error { + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + if cctx.Args().Len() != 2 { + return fmt.Errorf("usage: generate-car ") + } + + ref := lapi.FileRef{ + Path: cctx.Args().First(), + IsCAR: false, + } + + op := cctx.Args().Get(1) + + if err = api.ClientGenCar(ctx, ref, op); err != nil { + return err + } + return nil + }, +} + var clientLocalCmd = &cli.Command{ Name: "local", Usage: "List locally imported data", diff --git a/node/impl/client/client.go b/node/impl/client/client.go index c912d93fb..fe6abaf9e 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -3,6 +3,11 @@ package client import ( "context" "errors" + "github.com/filecoin-project/go-fil-markets/pieceio" + ipldfree "github.com/ipld/go-ipld-prime/impl/free" + "github.com/ipld/go-ipld-prime/traversal/selector" + "github.com/ipld/go-ipld-prime/traversal/selector/builder" + "io" "os" @@ -202,63 +207,15 @@ func (a *API) ClientFindData(ctx context.Context, root cid.Cid) ([]api.QueryOffe } func (a *API) ClientImport(ctx context.Context, ref api.FileRef) (cid.Cid, error) { - f, err := os.Open(ref.Path) - if err != nil { - return cid.Undef, err - } - - stat, err := f.Stat() - if err != nil { - return cid.Undef, err - } - - file, err := files.NewReaderPathFile(ref.Path, f, stat) - if err != nil { - return cid.Undef, err - } - if ref.IsCAR { - var store car.Store - if a.Filestore == nil { - store = a.Blockstore - } else { - store = (*filestore.Filestore)(a.Filestore) - } - result, err := car.LoadCar(store, file) - if err != nil { - return cid.Undef, err - } - - if len(result.Roots) != 1 { - return cid.Undef, xerrors.New("cannot import car with more than one root") - } - - return result.Roots[0], nil - } bufferedDS := ipld.NewBufferedDAG(ctx, a.LocalDAG) + nd, err := a.clientImport(ref, bufferedDS) - params := ihelper.DagBuilderParams{ - Maxlinks: build.UnixfsLinksPerLevel, - RawLeaves: true, - CidBuilder: nil, - Dagserv: bufferedDS, - NoCopy: true, - } - - db, err := params.New(chunker.NewSizeSplitter(file, int64(build.UnixfsChunkSize))) - if err != nil { - return cid.Undef, err - } - nd, err := balanced.Layout(db) if err != nil { return cid.Undef, err } - if err := bufferedDS.Commit(); err != nil { - return cid.Undef, err - } - - return nd.Cid(), nil + return nd, nil } func (a *API) ClientImportLocal(ctx context.Context, f io.Reader) (cid.Cid, error) { @@ -410,3 +367,125 @@ func (a *API) ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Addre } return signedAsk, nil } + +func (a *API) ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) { + ssize, err := a.StateMinerSectorSize(ctx, miner, types.EmptyTSK) + if err != nil { + return nil, xerrors.Errorf("failed checking miners sector size: %w", err) + } + + rt, _, err := ffiwrapper.ProofTypeFromSectorSize(ssize) + if err != nil { + return nil, xerrors.Errorf("bad sector size: %w", err) + } + + rdr, err := os.Open(inpath) + if err != nil { + return nil, err + } + + stat, err := rdr.Stat() + if err != nil { + return nil, err + } + + commP, pieceSize, err := pieceio.GeneratePieceCommitment(rt, rdr, uint64(stat.Size())) + + if err != nil { + return nil, xerrors.Errorf("computing commP failed: %w", err) + } + + return &api.CommPRet{ + Root: commP, + Size: pieceSize, + }, nil +} + +func (a *API) ClientGenCar(ctx context.Context, ref api.FileRef, outputPath string) error { + + bufferedDS := ipld.NewBufferedDAG(ctx, a.LocalDAG) + c, err := a.clientImport(ref, bufferedDS) + + if err != nil { + return err + } + + defer bufferedDS.Remove(ctx, c) + ssb := builder.NewSelectorSpecBuilder(ipldfree.NodeBuilder()) + + // entire DAG selector + allSelector := ssb.ExploreRecursive(selector.RecursionLimitNone(), + ssb.ExploreAll(ssb.ExploreRecursiveEdge())).Node() + + f, err := os.Create(outputPath) + defer f.Close() + if err != nil { + return err + } + + sc := car.NewSelectiveCar(ctx, a.Blockstore, []car.Dag{{Root: c, Selector: allSelector}}) + if err = sc.Write(f); err != nil { + return err + } + + return nil +} + +func (a *API) clientImport(ref api.FileRef, bufferedDS *ipld.BufferedDAG) (cid.Cid, error) { + f, err := os.Open(ref.Path) + if err != nil { + return cid.Undef, err + } + + stat, err := f.Stat() + if err != nil { + return cid.Undef, err + } + + file, err := files.NewReaderPathFile(ref.Path, f, stat) + if err != nil { + return cid.Undef, err + } + + if ref.IsCAR { + var store car.Store + if a.Filestore == nil { + store = a.Blockstore + } else { + store = (*filestore.Filestore)(a.Filestore) + } + result, err := car.LoadCar(store, file) + if err != nil { + return cid.Undef, err + } + + if len(result.Roots) != 1 { + return cid.Undef, xerrors.New("cannot import car with more than one root") + } + + return result.Roots[0], nil + } + + params := ihelper.DagBuilderParams{ + Maxlinks: build.UnixfsLinksPerLevel, + RawLeaves: true, + CidBuilder: nil, + Dagserv: bufferedDS, + NoCopy: true, + } + + db, err := params.New(chunker.NewSizeSplitter(file, int64(build.UnixfsChunkSize))) + if err != nil { + return cid.Undef, err + } + nd, err := balanced.Layout(db) + if err != nil { + return cid.Undef, err + } + + if err := bufferedDS.Commit(); err != nil { + return cid.Undef, err + } + + return nd.Cid(), nil +} From efd435d76337da1a09716905e56f2d8fbffca38f Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Sun, 5 Apr 2020 23:30:11 -0400 Subject: [PATCH 19/26] Treat proposed deals as manual iff a commP is provided --- cli/client.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/cli/client.go b/cli/client.go index 7a5359ce2..530fd7ae0 100644 --- a/cli/client.go +++ b/cli/client.go @@ -160,17 +160,13 @@ var clientDealCmd = &cli.Command{ Usage: "Initialize storage deal with a miner", ArgsUsage: "[dataCid miner price duration]", Flags: []cli.Flag{ - &cli.BoolFlag{ - Name: "manual-transfer", - Usage: "data will be transferred out of band", - }, &cli.StringFlag{ Name: "manual-piece-cid", - Usage: "manually specify piece commitment for data", + Usage: "manually specify piece commitment for data (dataCid must be to a car file)", }, &cli.Int64Flag{ Name: "manual-piece-size", - Usage: "if manually specifying piece cid, used to specify size", + Usage: "if manually specifying piece cid, used to specify size (dataCid must be to a car file)", }, &cli.StringFlag{ Name: "from", @@ -189,7 +185,7 @@ var clientDealCmd = &cli.Command{ return xerrors.New("expected 4 args: dataCid, miner, price, duration") } - // [data, miner, dur] + // [data, miner, price, dur] data, err := cid.Parse(cctx.Args().Get(0)) if err != nil { @@ -230,9 +226,6 @@ var clientDealCmd = &cli.Command{ TransferType: storagemarket.TTGraphsync, Root: data, } - if cctx.Bool("manual-transfer") { - ref.TransferType = storagemarket.TTManual - } if mpc := cctx.String("manual-piece-cid"); mpc != "" { c, err := cid.Parse(mpc) @@ -248,6 +241,8 @@ var clientDealCmd = &cli.Command{ } ref.PieceSize = abi.UnpaddedPieceSize(psize) + + ref.TransferType = storagemarket.TTManual } proposal, err := api.ClientStartDeal(ctx, &lapi.StartDealParams{ From c0204cdd83e5f93c27001eb5c5335783d384dc9c Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 15 Apr 2020 13:50:46 -0400 Subject: [PATCH 20/26] Add a shed command to turn raw commPs into CIDs --- cmd/lotus-shed/commp.go | 17 +++++++++++++++++ cmd/lotus-shed/main.go | 1 + 2 files changed, 18 insertions(+) create mode 100644 cmd/lotus-shed/commp.go diff --git a/cmd/lotus-shed/commp.go b/cmd/lotus-shed/commp.go new file mode 100644 index 000000000..c9808c19a --- /dev/null +++ b/cmd/lotus-shed/commp.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + commcid "github.com/filecoin-project/go-fil-commcid" + "gopkg.in/urfave/cli.v2" +) + +var commpToCidCmd = &cli.Command{ + Name: "commp-to-cid", + Description: "Convert a raw commP to a piece-Cid", + Action: func(cctx *cli.Context) error { + cp := []byte(cctx.Args().Get(0)) + fmt.Println(commcid.PieceCommitmentV1ToCID(cp)) + return nil + }, +} diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index d31151184..7a950e14a 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -23,6 +23,7 @@ func main() { bigIntParseCmd, staterootStatsCmd, importCarCmd, + commpToCidCmd, } app := &cli.App{ From 14ad808a005a5f51010c1149773880b8a6dc7e37 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 7 Apr 2020 14:26:43 -0400 Subject: [PATCH 21/26] Remove unused fields from VM --- chain/gen/genesis/miners.go | 2 +- chain/stmgr/call.go | 4 +--- chain/stmgr/forks_test.go | 4 ++-- chain/stmgr/stmgr.go | 7 +++---- chain/stmgr/utils.go | 2 +- chain/store/weight.go | 2 +- chain/validation/applier.go | 2 +- chain/vm/vm.go | 8 +------- 8 files changed, 11 insertions(+), 20 deletions(-) diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 9a11c7277..d3e6b44ee 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -41,7 +41,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid networkPower = big.Add(networkPower, big.NewInt(int64(m.SectorSize)*int64(len(m.Sectors)))) } - vm, err := vm.NewVM(sroot, 0, &fakeRand{}, builtin.SystemActorAddr, cs.Blockstore(), cs.VMSys()) + vm, err := vm.NewVM(sroot, 0, &fakeRand{}, cs.Blockstore(), cs.VMSys()) if err != nil { return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err) } diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index 293f18ef7..b9635696f 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -4,8 +4,6 @@ import ( "context" "fmt" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/abi" "github.com/ipfs/go-cid" "go.opencensus.io/trace" @@ -21,7 +19,7 @@ func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate ctx, span := trace.StartSpan(ctx, "statemanager.CallRaw") defer span.End() - vmi, err := vm.NewVM(bstate, bheight, r, builtin.SystemActorAddr, sm.cs.Blockstore(), sm.cs.VMSys()) + vmi, err := vm.NewVM(bstate, bheight, r, sm.cs.Blockstore(), sm.cs.VMSys()) if err != nil { return nil, xerrors.Errorf("failed to set up vm: %w", err) } diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 9979ebc55..a77e63591 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -158,8 +158,8 @@ func TestForkHeightTriggers(t *testing.T) { } inv.Register(actcid, &testActor{}, &testActorState{}) - sm.SetVMConstructor(func(c cid.Cid, h abi.ChainEpoch, r vm.Rand, a address.Address, b blockstore.Blockstore, s runtime.Syscalls) (*vm.VM, error) { - nvm, err := vm.NewVM(c, h, r, a, b, s) + sm.SetVMConstructor(func(c cid.Cid, h abi.ChainEpoch, r vm.Rand, b blockstore.Blockstore, s runtime.Syscalls) (*vm.VM, error) { + nvm, err := vm.NewVM(c, h, r, b, s) if err != nil { return nil, err } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index b71bbaa3c..33e227811 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -40,7 +40,7 @@ type StateManager struct { stCache map[string][]cid.Cid compWait map[string]chan struct{} stlk sync.Mutex - newVM func(cid.Cid, abi.ChainEpoch, vm.Rand, address.Address, blockstore.Blockstore, runtime.Syscalls) (*vm.VM, error) + newVM func(cid.Cid, abi.ChainEpoch, vm.Rand, blockstore.Blockstore, runtime.Syscalls) (*vm.VM, error) } func NewStateManager(cs *store.ChainStore) *StateManager { @@ -149,7 +149,7 @@ type BlockMessages struct { type ExecCallback func(cid.Cid, *types.Message, *vm.ApplyRet) error func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []BlockMessages, epoch abi.ChainEpoch, r vm.Rand, cb ExecCallback) (cid.Cid, cid.Cid, error) { - vmi, err := sm.newVM(pstate, epoch, r, address.Undef, sm.cs.Blockstore(), sm.cs.VMSys()) + vmi, err := sm.newVM(pstate, epoch, r, sm.cs.Blockstore(), sm.cs.VMSys()) if err != nil { return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err) } @@ -157,7 +157,6 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []B var receipts []cbg.CBORMarshaler processedMsgs := map[cid.Cid]bool{} for _, b := range bms { - vmi.SetBlockMiner(b.Miner) penalty := types.NewInt(0) gasReward := big.Zero() @@ -781,6 +780,6 @@ func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) err return nil } -func (sm *StateManager) SetVMConstructor(nvm func(cid.Cid, abi.ChainEpoch, vm.Rand, address.Address, blockstore.Blockstore, runtime.Syscalls) (*vm.VM, error)) { +func (sm *StateManager) SetVMConstructor(nvm func(cid.Cid, abi.ChainEpoch, vm.Rand, blockstore.Blockstore, runtime.Syscalls) (*vm.VM, error)) { sm.newVM = nvm } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 8ef88a12b..d4af8a842 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -364,7 +364,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, } r := store.NewChainRand(sm.cs, ts.Cids(), height) - vmi, err := vm.NewVM(fstate, height, r, builtin.SystemActorAddr, sm.cs.Blockstore(), sm.cs.VMSys()) + vmi, err := vm.NewVM(fstate, height, r, sm.cs.Blockstore(), sm.cs.VMSys()) if err != nil { return cid.Undef, nil, err } diff --git a/chain/store/weight.go b/chain/store/weight.go index 16a833a8c..029d7c0e4 100644 --- a/chain/store/weight.go +++ b/chain/store/weight.go @@ -72,7 +72,7 @@ func (cs *ChainStore) call(ctx context.Context, msg *types.Message, ts *types.Ti r := NewChainRand(cs, ts.Cids(), ts.Height()) - vmi, err := vm.NewVM(bstate, ts.Height(), r, builtin.SystemActorAddr, cs.bs, cs.vmcalls) + vmi, err := vm.NewVM(bstate, ts.Height(), r, cs.bs, cs.vmcalls) if err != nil { return nil, xerrors.Errorf("failed to set up vm: %w", err) } diff --git a/chain/validation/applier.go b/chain/validation/applier.go index 658b199f7..d049397fb 100644 --- a/chain/validation/applier.go +++ b/chain/validation/applier.go @@ -120,7 +120,7 @@ func (a *Applier) applyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWra base := st.Root() randSrc := &vmRand{eCtx} - lotusVM, err := vm.NewVM(base, eCtx.Epoch, randSrc, eCtx.Miner, st.bs, vdrivers.NewChainValidationSyscalls()) + lotusVM, err := vm.NewVM(base, eCtx.Epoch, randSrc, st.bs, vdrivers.NewChainValidationSyscalls()) if err != nil { return vtypes.MessageReceipt{}, big.Zero(), big.Zero(), err } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 71a3fe8d0..33810f183 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -129,14 +129,13 @@ type VM struct { cst *cbor.BasicIpldStore buf *bufbstore.BufferedBS blockHeight abi.ChainEpoch - blockMiner address.Address inv *invoker rand Rand Syscalls runtime.Syscalls } -func NewVM(base cid.Cid, height abi.ChainEpoch, r Rand, maddr address.Address, cbs blockstore.Blockstore, syscalls runtime.Syscalls) (*VM, error) { +func NewVM(base cid.Cid, height abi.ChainEpoch, r Rand, cbs blockstore.Blockstore, syscalls runtime.Syscalls) (*VM, error) { buf := bufbstore.NewBufferedBstore(cbs) cst := cbor.NewCborStore(buf) state, err := state.LoadStateTree(cst, base) @@ -150,7 +149,6 @@ func NewVM(base cid.Cid, height abi.ChainEpoch, r Rand, maddr address.Address, c cst: cst, buf: buf, blockHeight: height, - blockMiner: maddr, inv: NewInvoker(), rand: r, // TODO: Probably should be a syscall Syscalls: syscalls, @@ -416,10 +414,6 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, }, nil } -func (vm *VM) SetBlockMiner(m address.Address) { - vm.blockMiner = m -} - func (vm *VM) ActorBalance(addr address.Address) (types.BigInt, aerrors.ActorError) { act, err := vm.cstate.GetActor(addr) if err != nil { From 4a93ad33f920671484ca897d0041e0dfac58e062 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 7 Apr 2020 14:33:12 -0400 Subject: [PATCH 22/26] Propose Deal: Fail early if data doesn't fit in a sector --- node/impl/client/client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/node/impl/client/client.go b/node/impl/client/client.go index fe6abaf9e..4cf5a7969 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -90,12 +90,16 @@ func (a *API) ClientStartDeal(ctx context.Context, params *api.StartDealParams) return nil, xerrors.Errorf("failed checking miners sector size: %w", err) } + if uint64(params.Data.PieceSize.Padded()) > uint64(ssize) { + return nil, xerrors.New("data doesn't fit in a sector") + } + rt, _, err := ffiwrapper.ProofTypeFromSectorSize(ssize) if err != nil { return nil, xerrors.Errorf("bad sector size: %w", err) } - providerInfo := utils.NewStorageProviderInfo(params.Miner, mw, 0, pid) + providerInfo := utils.NewStorageProviderInfo(params.Miner, mw, ssize, pid) ts, err := a.ChainHead(ctx) if err != nil { return nil, xerrors.Errorf("failed getting chain height: %w", err) From 6a8e4bf87ec3ce9d476b8590ceebcdd050b03b96 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 9 Apr 2020 23:34:01 -0400 Subject: [PATCH 23/26] Lower a log level --- chain/vm/syscalls.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index 53a162553..7380de526 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -91,7 +91,7 @@ func (ss *syscallShim) VerifySeal(info abi.SealVerifyInfo) error { proof := []byte(info.OnChain.Proof) seed := []byte(info.InteractiveRandomness) - log.Infof("Verif r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", info.OnChain.SealedCID, info.UnsealedCID, miner, ticket, seed, info.SectorID.Number, proof) + log.Debugf("Verif r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", info.OnChain.SealedCID, info.UnsealedCID, miner, ticket, seed, info.SectorID.Number, proof) //func(ctx context.Context, maddr address.Address, ssize abi.SectorSize, commD, commR, ticket, proof, seed []byte, sectorID abi.SectorNumber) ok, err := ss.verifier.VerifySeal(info) From 8594af970f830ecd1aa39d45ced51d60a757af64 Mon Sep 17 00:00:00 2001 From: Henri S Date: Thu, 16 Apr 2020 15:52:49 -0400 Subject: [PATCH 24/26] fix typo: --- chain/vm/syscalls.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index 2b5cceb3e..9af8ecfa0 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -131,7 +131,7 @@ func (ss *syscallShim) VerifyConsensusFault(a, b, extra []byte, epoch abi.ChainE return nil, xerrors.Errorf("cannot decode extra: %w", decodeErr) } - if types.CidArrsEqual(blockA.Parents, blockC.Parents) && blockA.Height == blockB.Height && + if types.CidArrsEqual(blockA.Parents, blockC.Parents) && blockA.Height == blockC.Height && types.CidArrsContains(blockB.Parents, blockC.Cid()) && !types.CidArrsContains(blockB.Parents, blockA.Cid()) { consensusFault = &runtime.ConsensusFault{ Target: blockA.Miner, From f7666bc6410e00437515da57883e5d986f0c6077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 17 Apr 2020 18:24:23 +0200 Subject: [PATCH 25/26] Drop commented-out code --- cli/multisig.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cli/multisig.go b/cli/multisig.go index 0b09e8924..18690c6c9 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -147,12 +147,6 @@ var msigCreateCmd = &cli.Command{ // get address of newly created miner - // msigaddr, err := address.NewFromBytes(wait.Receipt.Return) - // if err != nil { - // return err - // } - - // fmt.Println("Created new multisig: ", msigaddr.String()) var execreturn init_.ExecReturn if err := execreturn.UnmarshalCBOR(bytes.NewReader(wait.Receipt.Return)); err != nil { From ebc2895d155021b929dc463c8626c98a937d56e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 17 Apr 2020 18:27:11 +0200 Subject: [PATCH 26/26] gofmt, mod tidy --- cli/multisig.go | 3 +-- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cli/multisig.go b/cli/multisig.go index 18690c6c9..0913c1ff9 100644 --- a/cli/multisig.go +++ b/cli/multisig.go @@ -144,7 +144,6 @@ var msigCreateCmd = &cli.Command{ fmt.Println("actor creation failed!") return err } - // get address of newly created miner @@ -153,7 +152,7 @@ var msigCreateCmd = &cli.Command{ return err } fmt.Println("Created new multisig: ", execreturn.IDAddress, execreturn.RobustAddress) - + // TODO: maybe register this somewhere return nil }, diff --git a/go.mod b/go.mod index 345379919..ea2811884 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663 github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/sector-storage v0.0.0-20200406195014-a6d093838576 - github.com/filecoin-project/specs-actors v0.0.0-20200324235424-aef9b20a9fb1 + github.com/filecoin-project/specs-actors v0.0.0-20200409043918-e569f4a2f504 github.com/filecoin-project/specs-storage v0.0.0-20200317225704-7420bc655c38 github.com/filecoin-project/storage-fsm v0.0.0-20200408153957-1c356922353f github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 diff --git a/go.sum b/go.sum index 8b1774503..b3ca8cea8 100644 --- a/go.sum +++ b/go.sum @@ -174,6 +174,8 @@ github.com/filecoin-project/specs-actors v0.0.0-20200226200336-94c9b92b2775/go.m github.com/filecoin-project/specs-actors v0.0.0-20200302223606-0eaf97b10aaf/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU= github.com/filecoin-project/specs-actors v0.0.0-20200324235424-aef9b20a9fb1 h1:IL6A1yAamz0HtLQEdZS57hnRZHPL11VIrQxMZ1Nn5hI= github.com/filecoin-project/specs-actors v0.0.0-20200324235424-aef9b20a9fb1/go.mod h1:5WngRgTN5Eo4+0SjCBqLzEr2l6Mj45DrP2606gBhqI0= +github.com/filecoin-project/specs-actors v0.0.0-20200409043918-e569f4a2f504 h1:mwuAaqxKThl70+7FkGdFKVLdwaQZQ8XmscKdhSBBtnc= +github.com/filecoin-project/specs-actors v0.0.0-20200409043918-e569f4a2f504/go.mod h1:mdJraXq5vMy0+/FqVQIrnNlpQ/Em6zeu06G/ltQ0/lA= github.com/filecoin-project/specs-storage v0.0.0-20200317225704-7420bc655c38 h1:ky+rfX3bG1TjOBLn14V674q+iwZpalyKzZxGRNzA11I= github.com/filecoin-project/specs-storage v0.0.0-20200317225704-7420bc655c38/go.mod h1:dUmzHS7izOD6HW3/JpzFrjxnptxbsHXBlO8puK2UzBk= github.com/filecoin-project/storage-fsm v0.0.0-20200408153957-1c356922353f h1:ocVYJgS622P5p/LOOPzb875M+wlJHe6in2DcoGcd9J8=