From ef1d485c6e0b2c406f5d672affaecace834b0c91 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 23 Apr 2020 15:15:00 -0700 Subject: [PATCH] move head change type out of chainstore package --- api/api_full.go | 9 ++++++--- api/apistruct/struct.go | 9 ++++----- chain/events/events.go | 2 +- chain/store/store.go | 28 ++++++++++++---------------- node/impl/full/chain.go | 4 ++-- storage/miner.go | 3 +-- storage/wdpost_sched.go | 3 ++- 7 files changed, 28 insertions(+), 30 deletions(-) diff --git a/api/api_full.go b/api/api_full.go index 6c70fdda1..0db3e3b5c 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -18,7 +18,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/crypto" - "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" ) @@ -33,7 +32,7 @@ type FullNode interface { // ChainNotify returns channel with chain head updates // First message is guaranteed to be of len == 1, and type == 'current' - ChainNotify(context.Context) (<-chan []*store.HeadChange, error) + ChainNotify(context.Context) (<-chan []*HeadChange, error) ChainHead(context.Context) (*types.TipSet, error) ChainGetRandomness(ctx context.Context, tsk types.TipSetKey, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error) ChainGetBlock(context.Context, cid.Cid) (*types.BlockHeader, error) @@ -50,7 +49,7 @@ type FullNode interface { ChainTipSetWeight(context.Context, types.TipSetKey) (types.BigInt, error) ChainGetNode(ctx context.Context, p string) (*IpldObject, error) ChainGetMessage(context.Context, cid.Cid) (*types.Message, error) - ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*store.HeadChange, error) + ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*HeadChange, error) ChainExport(context.Context, types.TipSetKey) (<-chan []byte, error) // syncer @@ -406,3 +405,7 @@ type CommPRet struct { Root cid.Cid Size abi.UnpaddedPieceSize } +type HeadChange struct { + Type string + Val *types.TipSet +} diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index 96116f5cd..f236ec2e2 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -21,7 +21,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" sealing "github.com/filecoin-project/storage-fsm" @@ -55,7 +54,7 @@ type FullNodeStruct struct { CommonStruct Internal struct { - ChainNotify func(context.Context) (<-chan []*store.HeadChange, error) `perm:"read"` + ChainNotify func(context.Context) (<-chan []*api.HeadChange, error) `perm:"read"` ChainHead func(context.Context) (*types.TipSet, error) `perm:"read"` ChainGetRandomness func(context.Context, types.TipSetKey, crypto.DomainSeparationTag, abi.ChainEpoch, []byte) (abi.Randomness, error) `perm:"read"` ChainGetBlock func(context.Context, cid.Cid) (*types.BlockHeader, error) `perm:"read"` @@ -72,7 +71,7 @@ type FullNodeStruct struct { ChainTipSetWeight func(context.Context, types.TipSetKey) (types.BigInt, error) `perm:"read"` ChainGetNode func(ctx context.Context, p string) (*api.IpldObject, error) `perm:"read"` ChainGetMessage func(context.Context, cid.Cid) (*types.Message, error) `perm:"read"` - ChainGetPath func(context.Context, types.TipSetKey, types.TipSetKey) ([]*store.HeadChange, error) `perm:"read"` + ChainGetPath func(context.Context, types.TipSetKey, types.TipSetKey) ([]*api.HeadChange, error) `perm:"read"` ChainExport func(context.Context, types.TipSetKey) (<-chan []byte, error) `perm:"read"` SyncState func(context.Context) (*api.SyncState, error) `perm:"read"` @@ -424,7 +423,7 @@ func (c *FullNodeStruct) ChainGetParentMessages(ctx context.Context, b cid.Cid) return c.Internal.ChainGetParentMessages(ctx, b) } -func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan []*store.HeadChange, error) { +func (c *FullNodeStruct) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) { return c.Internal.ChainNotify(ctx) } @@ -460,7 +459,7 @@ func (c *FullNodeStruct) ChainGetMessage(ctx context.Context, mc cid.Cid) (*type return c.Internal.ChainGetMessage(ctx, mc) } -func (c *FullNodeStruct) ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*store.HeadChange, error) { +func (c *FullNodeStruct) ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*api.HeadChange, error) { return c.Internal.ChainGetPath(ctx, from, to) } diff --git a/chain/events/events.go b/chain/events/events.go index 217b6fb30..9f19b1691 100644 --- a/chain/events/events.go +++ b/chain/events/events.go @@ -32,7 +32,7 @@ type heightHandler struct { } type eventApi interface { - ChainNotify(context.Context) (<-chan []*store.HeadChange, error) + ChainNotify(context.Context) (<-chan []*api.HeadChange, error) ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error) ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error) StateGetReceipt(context.Context, cid.Cid, types.TipSetKey) (*types.MessageReceipt, error) diff --git a/chain/store/store.go b/chain/store/store.go index 63df6d7d9..cde8add51 100644 --- a/chain/store/store.go +++ b/chain/store/store.go @@ -17,6 +17,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/runtime" "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/vm" @@ -89,16 +90,16 @@ func NewChainStore(bs bstore.Blockstore, ds dstore.Batching, vmcalls runtime.Sys cs.pubLk.Lock() defer cs.pubLk.Unlock() - notif := make([]*HeadChange, len(rev)+len(app)) + notif := make([]*api.HeadChange, len(rev)+len(app)) for i, r := range rev { - notif[i] = &HeadChange{ + notif[i] = &api.HeadChange{ Type: HCRevert, Val: r, } } for i, r := range app { - notif[i+len(rev)] = &HeadChange{ + notif[i+len(rev)] = &api.HeadChange{ Type: HCApply, Val: r, } @@ -165,19 +166,14 @@ const ( HCCurrent = "current" ) -type HeadChange struct { - Type string - Val *types.TipSet -} - -func (cs *ChainStore) SubHeadChanges(ctx context.Context) chan []*HeadChange { +func (cs *ChainStore) SubHeadChanges(ctx context.Context) chan []*api.HeadChange { cs.pubLk.Lock() subch := cs.bestTips.Sub("headchange") head := cs.GetHeaviestTipSet() cs.pubLk.Unlock() - out := make(chan []*HeadChange, 16) - out <- []*HeadChange{{ + out := make(chan []*api.HeadChange, 16) + out <- []*api.HeadChange{{ Type: HCCurrent, Val: head, }} @@ -197,7 +193,7 @@ func (cs *ChainStore) SubHeadChanges(ctx context.Context) chan []*HeadChange { log.Warnf("head change sub is slow, has %d buffered entries", len(out)) } select { - case out <- val.([]*HeadChange): + case out <- val.([]*api.HeadChange): case <-ctx.Done(): } case <-ctx.Done(): @@ -748,7 +744,7 @@ func (cs *ChainStore) readMsgMetaCids(mmc cid.Cid) ([]cid.Cid, []cid.Cid, error) return blscids, secpkcids, nil } -func (cs *ChainStore) GetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*HeadChange, error) { +func (cs *ChainStore) GetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*api.HeadChange, error) { fts, err := cs.LoadTipSet(from) if err != nil { return nil, xerrors.Errorf("loading from tipset %s: %w", from, err) @@ -762,12 +758,12 @@ func (cs *ChainStore) GetPath(ctx context.Context, from types.TipSetKey, to type return nil, xerrors.Errorf("error getting tipset branches: %w", err) } - path := make([]*HeadChange, len(revert)+len(apply)) + path := make([]*api.HeadChange, len(revert)+len(apply)) for i, r := range revert { - path[i] = &HeadChange{Type: HCRevert, Val: r} + path[i] = &api.HeadChange{Type: HCRevert, Val: r} } for j, i := 0, len(apply)-1; i >= 0; j, i = j+1, i-1 { - path[j+len(revert)] = &HeadChange{Type: HCApply, Val: apply[i]} + path[j+len(revert)] = &api.HeadChange{Type: HCApply, Val: apply[i]} } return path, nil } diff --git a/node/impl/full/chain.go b/node/impl/full/chain.go index 3ddc516c0..076968987 100644 --- a/node/impl/full/chain.go +++ b/node/impl/full/chain.go @@ -45,7 +45,7 @@ type ChainAPI struct { Chain *store.ChainStore } -func (a *ChainAPI) ChainNotify(ctx context.Context) (<-chan []*store.HeadChange, error) { +func (a *ChainAPI) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) { return a.Chain.SubHeadChanges(ctx), nil } @@ -98,7 +98,7 @@ func (a *ChainAPI) ChainGetBlockMessages(ctx context.Context, msg cid.Cid) (*api }, nil } -func (a *ChainAPI) ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*store.HeadChange, error) { +func (a *ChainAPI) ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*api.HeadChange, error) { return a.Chain.GetPath(ctx, from, to) } diff --git a/storage/miner.go b/storage/miner.go index 78f88d797..c3b9d404f 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -23,7 +23,6 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/gen" - "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" sealing "github.com/filecoin-project/storage-fsm" @@ -62,7 +61,7 @@ type storageMinerApi interface { MpoolPushMessage(context.Context, *types.Message) (*types.SignedMessage, error) ChainHead(context.Context) (*types.TipSet, error) - ChainNotify(context.Context) (<-chan []*store.HeadChange, error) + ChainNotify(context.Context) (<-chan []*api.HeadChange, error) ChainGetRandomness(ctx context.Context, tsk types.TipSetKey, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error) ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, types.TipSetKey) (*types.TipSet, error) ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error) diff --git a/storage/wdpost_sched.go b/storage/wdpost_sched.go index 1f41418a2..81fc7bc5d 100644 --- a/storage/wdpost_sched.go +++ b/storage/wdpost_sched.go @@ -13,6 +13,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/builtin/miner" "github.com/filecoin-project/specs-storage/storage" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" ) @@ -67,7 +68,7 @@ func deadlineEquals(a, b *miner.DeadlineInfo) bool { func (s *WindowPoStScheduler) Run(ctx context.Context) { defer s.abortActivePoSt() - var notifs <-chan []*store.HeadChange + var notifs <-chan []*api.HeadChange var err error var gotCur bool