Skip to content

Commit

Permalink
Rename blockchain facade to chain state and remove msg.Sender plumbing
Browse files Browse the repository at this point in the history
  • Loading branch information
anorth committed May 22, 2019
1 parent 1bdb39d commit c34a516
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions commands/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/filecoin-project/go-filecoin/address"
"github.com/filecoin-project/go-filecoin/core"
"github.com/filecoin-project/go-filecoin/exec"
"github.com/filecoin-project/go-filecoin/plumbing/bcf"
"github.com/filecoin-project/go-filecoin/plumbing/cst"
"github.com/filecoin-project/go-filecoin/plumbing/msg"
"github.com/filecoin-project/go-filecoin/types"
)
Expand Down Expand Up @@ -169,7 +169,7 @@ var msgWaitCmd = &cmds.Command{
err = GetPorcelainAPI(env).MessageWait(req.Context, msgCid, func(blk *types.Block, msg *types.SignedMessage, receipt *types.MessageReceipt) error {
found = true
sig, err := GetPorcelainAPI(env).ActorGetSignature(req.Context, msg.To, msg.Method)
if err != nil && err != bcf.ErrNoMethod && err != bcf.ErrNoActorImpl {
if err != nil && err != cst.ErrNoMethod && err != cst.ErrNoActorImpl {
return errors.Wrap(err, "Couldn't get signature for message")
}

Expand Down
7 changes: 6 additions & 1 deletion core/outbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func NewOutbox(signer types.Signer, validator consensus.SignedMessageValidator,
}
}

// Queue returns the outbox's outbound message queue.
func (ob *Outbox) Queue() *MessageQueue {
return ob.queue
}

// Send marshals and sends a message, retaining it in the outbound message queue.
func (ob *Outbox) Send(ctx context.Context, from, to address.Address, value *types.AttoFIL,
gasPrice types.AttoFIL, gasLimit types.GasUnits, method string, params ...interface{}) (out cid.Cid, err error) {
Expand All @@ -78,7 +83,7 @@ func (ob *Outbox) Send(ctx context.Context, from, to address.Address, value *typ
return cid.Undef, errors.Wrap(err, "invalid params")
}

// Lock to avoid race for message nonce.
// Lock to avoid a race inspecting the actor state and message queue to calculate next nonce.
ob.nonceLock.Lock()
defer ob.nonceLock.Unlock()

Expand Down
13 changes: 6 additions & 7 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import (
"github.com/filecoin-project/go-filecoin/net/pubsub"
"github.com/filecoin-project/go-filecoin/paths"
"github.com/filecoin-project/go-filecoin/plumbing"
"github.com/filecoin-project/go-filecoin/plumbing/bcf"
"github.com/filecoin-project/go-filecoin/plumbing/cst"
"github.com/filecoin-project/go-filecoin/plumbing/cfg"
"github.com/filecoin-project/go-filecoin/plumbing/dag"
"github.com/filecoin-project/go-filecoin/plumbing/msg"
Expand Down Expand Up @@ -392,7 +392,7 @@ func (nc *Config) Build(ctx context.Context) (*Node, error) {

// set up chainstore
chainStore := chain.NewDefaultStore(nc.Repo.ChainDatastore(), genCid)
chainFacade := bcf.NewBlockChainFacade(chainStore, &cstOffline)
chainState := cst.NewChainStateProvider(chainStore, &cstOffline)
powerTable := &consensus.MarketView{}

// set up processor
Expand Down Expand Up @@ -425,25 +425,24 @@ func (nc *Config) Build(ctx context.Context) (*Node, error) {

// only the syncer gets the storage which is online connected
chainSyncer := chain.NewDefaultSyncer(&cstOffline, nodeConsensus, chainStore, fetcher)
msgPool := core.NewMessagePool(chainStore, nc.Repo.Config().Mpool, consensus.NewIngestionValidator(chainFacade, nc.Repo.Config().Mpool))
msgPool := core.NewMessagePool(chainStore, nc.Repo.Config().Mpool, consensus.NewIngestionValidator(chainState, nc.Repo.Config().Mpool))
msgQueue := core.NewMessageQueue()

msgPublisher := newDefaultMessagePublisher(pubsub.NewPublisher(fsub), core.Topic, msgPool)
outbox := core.NewOutbox(fcWallet, consensus.NewOutboundMessageValidator(), msgQueue, msgPublisher, chainStore, chainFacade)
outbox := core.NewOutbox(fcWallet, consensus.NewOutboundMessageValidator(), msgQueue, msgPublisher, chainStore, chainState)

PorcelainAPI := porcelain.New(plumbing.New(&plumbing.APIDeps{
Bitswap: bswap,
Chain: chainFacade,
Chain: chainState,
Config: cfg.NewConfig(nc.Repo),
DAG: dag.NewDAG(merkledag.NewDAGService(bservice)),
Deals: strgdls.New(nc.Repo.DealsDatastore()),
MsgPool: msgPool,
MsgPreviewer: msg.NewPreviewer(fcWallet, chainStore, &cstOffline, bs),
MsgQueryer: msg.NewQueryer(nc.Repo, fcWallet, chainStore, &cstOffline, bs),
MsgSender: msg.NewSender(outbox),
MsgWaiter: msg.NewWaiter(chainStore, bs, &cstOffline),
Network: net.New(peerHost, pubsub.NewPublisher(fsub), pubsub.NewSubscriber(fsub), net.NewRouter(router), bandwidthTracker, net.NewPinger(peerHost, pingService)),
Outbox: msgQueue,
Outbox: outbox,
Wallet: fcWallet,
}))

Expand Down
21 changes: 9 additions & 12 deletions plumbing/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/filecoin-project/go-filecoin/exec"
"github.com/filecoin-project/go-filecoin/net"
"github.com/filecoin-project/go-filecoin/net/pubsub"
"github.com/filecoin-project/go-filecoin/plumbing/bcf"
"github.com/filecoin-project/go-filecoin/plumbing/cst"
"github.com/filecoin-project/go-filecoin/plumbing/cfg"
"github.com/filecoin-project/go-filecoin/plumbing/dag"
"github.com/filecoin-project/go-filecoin/plumbing/msg"
Expand All @@ -43,34 +43,32 @@ type API struct {
logger logging.EventLogger

bitswap exchange.Interface
chain *bcf.BlockChainFacade
chain *cst.ChainStateProvider
config *cfg.Config
dag *dag.DAG
msgPool *core.MessagePool
msgPreviewer *msg.Previewer
msgQueryer *msg.Queryer
outbox *core.MessageQueue
msgSender *msg.Sender
msgWaiter *msg.Waiter
network *net.Network
outbox *core.Outbox
storagedeals *strgdls.Store
wallet *wallet.Wallet
}

// APIDeps contains all the API's dependencies
type APIDeps struct {
Bitswap exchange.Interface
Chain *bcf.BlockChainFacade
Chain *cst.ChainStateProvider
Config *cfg.Config
DAG *dag.DAG
Deals *strgdls.Store
MsgPool *core.MessagePool
MsgPreviewer *msg.Previewer
MsgQueryer *msg.Queryer
MsgSender *msg.Sender
MsgWaiter *msg.Waiter
Network *net.Network
Outbox *core.MessageQueue
Outbox *core.Outbox
Wallet *wallet.Wallet
}

Expand All @@ -86,7 +84,6 @@ func New(deps *APIDeps) *API {
msgPool: deps.MsgPool,
msgPreviewer: deps.MsgPreviewer,
msgQueryer: deps.MsgQueryer,
msgSender: deps.MsgSender,
msgWaiter: deps.MsgWaiter,
network: deps.Network,
outbox: deps.Outbox,
Expand Down Expand Up @@ -162,17 +159,17 @@ func (api *API) DealPut(storageDeal *storagedeal.Deal) error {

// OutboxQueues lists addresses with non-empty outbox queues (in no particular order).
func (api *API) OutboxQueues() []address.Address {
return api.outbox.Queues()
return api.outbox.Queue().Queues()
}

// OutboxQueueLs lists messages in the queue for an address.
func (api *API) OutboxQueueLs(sender address.Address) []*core.QueuedMessage {
return api.outbox.List(sender)
return api.outbox.Queue().List(sender)
}

// OutboxQueueClear clears messages in the queue for an address/
func (api *API) OutboxQueueClear(sender address.Address) {
api.outbox.Clear(sender)
api.outbox.Queue().Clear(sender)
}

// MessagePoolPending lists messages un-mined in the pool
Expand Down Expand Up @@ -209,7 +206,7 @@ func (api *API) MessageQuery(ctx context.Context, optFrom, to address.Address, m
// message to go on chain. Note that no default from address is provided. If you need
// a default address, use MessageSendWithDefaultAddress instead.
func (api *API) MessageSend(ctx context.Context, from, to address.Address, value *types.AttoFIL, gasPrice types.AttoFIL, gasLimit types.GasUnits, method string, params ...interface{}) (cid.Cid, error) {
return api.msgSender.Send(ctx, from, to, value, gasPrice, gasLimit, method, params...)
return api.outbox.Send(ctx, from, to, value, gasPrice, gasLimit, method, params...)
}

// MessageFind returns a message and receipt from the blockchain, if it exists.
Expand Down
39 changes: 18 additions & 21 deletions plumbing/bcf/blockchain_facade.go → plumbing/cst/chain_state.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bcf
package cst

import (
"context"
Expand All @@ -17,22 +17,19 @@ import (
"github.com/pkg/errors"
)

type bcfChainReader interface {
type chainReader interface {
BlockHeight() (uint64, error)
GetBlock(context.Context, cid.Cid) (*types.Block, error)
GetHead() types.SortedCidSet
GetTipSet(types.SortedCidSet) (*types.TipSet, error)
GetTipSetStateRoot(tsKey types.SortedCidSet) (cid.Cid, error)
}

// BlockChainFacade is a facade pattern for the chain core api. It provides a
// simple, unified interface to the complex set of calls in chain, state, exec,
// and sampling for use in protocols and commands.
type BlockChainFacade struct {
// To get the head tipset state root.
reader bcfChainReader
// To load the tree for the head tipset state root.
cst *hamt.CborIpldStore
// ChainStateProvider composes a chain and a state store to provide access to
// the state (including actors) derived from a chain.
type ChainStateProvider struct {
reader chainReader // Provides chain blocks and tipsets.
cst *hamt.CborIpldStore // Provides state trees.
}

var (
Expand All @@ -45,16 +42,16 @@ var (
ErrNoActorImpl = errors.New("no actor implementation")
)

// NewBlockChainFacade returns a new BlockChainFacade.
func NewBlockChainFacade(chainReader bcfChainReader, cst *hamt.CborIpldStore) *BlockChainFacade {
return &BlockChainFacade{
// NewChainStateProvider returns a new ChainStateProvider.
func NewChainStateProvider(chainReader chainReader, cst *hamt.CborIpldStore) *ChainStateProvider {
return &ChainStateProvider{
reader: chainReader,
cst: cst,
}
}

// Head returns the head tipset
func (chn *BlockChainFacade) Head() (*types.TipSet, error) {
func (chn *ChainStateProvider) Head() (*types.TipSet, error) {
ts, err := chn.reader.GetTipSet(chn.reader.GetHead())
if err != nil {
return nil, err
Expand All @@ -63,7 +60,7 @@ func (chn *BlockChainFacade) Head() (*types.TipSet, error) {
}

// Ls returns an iterator over tipsets from head to genesis.
func (chn *BlockChainFacade) Ls(ctx context.Context) (*chain.TipsetIterator, error) {
func (chn *ChainStateProvider) Ls(ctx context.Context) (*chain.TipsetIterator, error) {
ts, err := chn.reader.GetTipSet(chn.reader.GetHead())
if err != nil {
return nil, err
Expand All @@ -72,12 +69,12 @@ func (chn *BlockChainFacade) Ls(ctx context.Context) (*chain.TipsetIterator, err
}

// GetBlock gets a block by CID
func (chn *BlockChainFacade) GetBlock(ctx context.Context, id cid.Cid) (*types.Block, error) {
func (chn *ChainStateProvider) GetBlock(ctx context.Context, id cid.Cid) (*types.Block, error) {
return chn.reader.GetBlock(ctx, id)
}

// SampleRandomness samples randomness from the chain at the given height.
func (chn *BlockChainFacade) SampleRandomness(ctx context.Context, sampleHeight *types.BlockHeight) ([]byte, error) {
func (chn *ChainStateProvider) SampleRandomness(ctx context.Context, sampleHeight *types.BlockHeight) ([]byte, error) {
tipSetBuffer, err := chain.GetRecentAncestorsOfHeaviestChain(ctx, chn.reader, sampleHeight)
if err != nil {
return nil, errors.Wrap(err, "failed to get recent ancestors")
Expand All @@ -87,12 +84,12 @@ func (chn *BlockChainFacade) SampleRandomness(ctx context.Context, sampleHeight
}

// GetActorAt returns an actor from the latest state on the chain
func (chn *BlockChainFacade) GetActor(ctx context.Context, addr address.Address) (*actor.Actor, error) {
func (chn *ChainStateProvider) GetActor(ctx context.Context, addr address.Address) (*actor.Actor, error) {
return chn.GetActorAt(ctx, chn.reader.GetHead(), addr)
}

// GetActorAt returns an actor at a specified tipset key.
func (chn *BlockChainFacade) GetActorAt(ctx context.Context, tipKey types.SortedCidSet, addr address.Address) (*actor.Actor, error) {
func (chn *ChainStateProvider) GetActorAt(ctx context.Context, tipKey types.SortedCidSet, addr address.Address) (*actor.Actor, error) {
stateCid, err := chn.reader.GetTipSetStateRoot(tipKey)
if err != nil {
return nil, err
Expand All @@ -110,7 +107,7 @@ func (chn *BlockChainFacade) GetActorAt(ctx context.Context, tipKey types.Sorted
}

// LsActors returns a channel with actors from the latest state on the chain
func (chn *BlockChainFacade) LsActors(ctx context.Context) (<-chan state.GetAllActorsResult, error) {
func (chn *ChainStateProvider) LsActors(ctx context.Context) (<-chan state.GetAllActorsResult, error) {
st, err := chain.LatestState(ctx, chn.reader, chn.cst)
if err != nil {
return nil, err
Expand All @@ -121,7 +118,7 @@ func (chn *BlockChainFacade) LsActors(ctx context.Context) (<-chan state.GetAllA
// GetActorSignature returns the signature of the given actor's given method.
// The function signature is typically used to enable a caller to decode the
// output of an actor method call (message).
func (chn *BlockChainFacade) GetActorSignature(ctx context.Context, actorAddr address.Address, method string) (*exec.FunctionSignature, error) {
func (chn *ChainStateProvider) GetActorSignature(ctx context.Context, actorAddr address.Address, method string) (*exec.FunctionSignature, error) {
if method == "" {
return nil, ErrNoMethod
}
Expand Down

0 comments on commit c34a516

Please sign in to comment.