paychmgr

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2021 License: Apache-2.0, MIT Imports: 34 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DirInbound  = 1
	DirOutbound = 2
)

Variables

View Source
var ErrChannelNotTracked = errors.New("channel not tracked")

Functions

func BestSpendableByLane

func BestSpendableByLane(ctx context.Context, api BestSpendableAPI, ch address.Address) (map[uint64]*paych.SignedVoucher, error)

BestSpendableByLane return spendable voucher in channel address

Types

type BestSpendableAPI

type BestSpendableAPI interface {
	PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error)
	PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error)
}

type ChannelAvailableFunds

type ChannelAvailableFunds struct {
	// Channel is the address of the channel
	Channel *address.Address
	// From is the from address of the channel (channel creator)
	From address.Address
	// To is the to address of the channel
	To address.Address
	// ConfirmedAmt is the amount of funds that have been confirmed on-chain
	// for the channel
	ConfirmedAmt big.Int
	// PendingAmt is the amount of funds that are pending confirmation on-chain
	PendingAmt big.Int
	// PendingWaitSentinel can be used with PaychGetWaitReady to wait for
	// confirmation of pending funds
	PendingWaitSentinel *cid.Cid
	// QueuedAmt is the amount that is queued up behind a pending request
	QueuedAmt big.Int
	// VoucherRedeemedAmt is the amount that is redeemed by vouchers on-chain
	// and in the local datastore
	VoucherReedeemedAmt big.Int
}

type ChannelInfo

type ChannelInfo struct {
	// ChannelID is a uuid set at channel creation
	ChannelID string
	// Channel address - may be nil if the channel hasn't been created yet
	Channel *address.Address
	// Control is the address of the local node
	Control address.Address
	// Target is the address of the remote node (on the other end of the channel)
	Target address.Address
	// Direction indicates if the channel is inbound (Control is the "to" address)
	// or outbound (Control is the "from" address)
	Direction uint64
	// Vouchers is a list of all vouchers sent on the channel
	Vouchers []*VoucherInfo
	// NextLane is the number of the next lane that should be used when the
	// client requests a new lane (eg to create a voucher for a new deal)
	NextLane uint64
	// Amount added to the channel.
	// Note: This amount is only used by GetPaych to keep track of how much
	// has locally been added to the channel. It should reflect the channel's
	// Balance on chain as long as all operations occur on the same datastore.
	Amount fbig.Int
	// PendingAmount is the amount that we're awaiting confirmation of
	PendingAmount fbig.Int
	// CreateMsg is the CID of a pending create message (while waiting for confirmation)
	CreateMsg *cid.Cid
	// AddFundsMsg is the CID of a pending add funds message (while waiting for confirmation)
	AddFundsMsg *cid.Cid
	// Settling indicates whether the channel has entered into the settling state
	Settling bool
}

ChannelInfo keeps track of information about a channel

func (*ChannelInfo) MarshalCBOR

func (t *ChannelInfo) MarshalCBOR(w io.Writer) error

func (*ChannelInfo) UnmarshalCBOR

func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error

type ErrInsufficientFunds

type ErrInsufficientFunds struct {
	// contains filtered or unexported fields
}

func (*ErrInsufficientFunds) Error

func (e *ErrInsufficientFunds) Error() string

func (*ErrInsufficientFunds) Shortfall

func (e *ErrInsufficientFunds) Shortfall() big.Int

type IChainInfo added in v1.1.0

type IChainInfo interface {
	StateAccountKey(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error)
	StateNetworkVersion(ctx context.Context, tsk types.TipSetKey) (network.Version, error)
	StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*apitypes.MsgLookup, error)
}

type IMessagePush added in v1.1.0

type IMessagePush interface {
	MpoolPushMessage(ctx context.Context, msg *types.UnsignedMessage, spec *types.MessageSendSpec) (*types.SignedMessage, error)
}

type IWalletAPI added in v1.1.0

type IWalletAPI interface {
	WalletHas(ctx context.Context, addr address.Address) (bool, error)
	WalletSign(ctx context.Context, k address.Address, msg []byte, meta wallet.MsgMeta) (*crypto.Signature, error)
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(ctx context.Context, ds datastore.Batching, params *ManagerParams) (*Manager, error)

func (*Manager) AddVoucherInbound

func (pm *Manager) AddVoucherInbound(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta big.Int) (big.Int, error)

AddVoucherInbound adds a voucher for an inbound channel. If the channel is not in the store, fetches the channel from state (and checks that the channel To address is owned by the wallet).

func (*Manager) AddVoucherOutbound

func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta big.Int) (big.Int, error)

AddVoucherOutbound adds a voucher for an outbound channel. Returns an error if the channel is not already in the store.

func (*Manager) AllocateLane

func (pm *Manager) AllocateLane(ch address.Address) (uint64, error)

func (*Manager) AvailableFunds

func (pm *Manager) AvailableFunds(ch address.Address) (*ChannelAvailableFunds, error)

func (*Manager) AvailableFundsByFromTo

func (pm *Manager) AvailableFundsByFromTo(from address.Address, to address.Address) (*ChannelAvailableFunds, error)

func (*Manager) CheckVoucherSpendable

func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error)

CheckVoucherSpendable checks if the given voucher is currently spendable

func (*Manager) CheckVoucherValid

func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error

CheckVoucherValid checks if the given voucher is valid (is or could become spendable at some point). If the channel is not in the store, fetches the channel from state (and checks that the channel To address is owned by the wallet).

func (*Manager) Collect

func (pm *Manager) Collect(ctx context.Context, addr address.Address) (cid.Cid, error)

func (*Manager) CreateVoucher

func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, voucher paych.SignedVoucher) (*VoucherCreateResult, error)

func (*Manager) GetChannelInfo

func (pm *Manager) GetChannelInfo(addr address.Address) (*ChannelInfo, error)

func (*Manager) GetPaych

func (pm *Manager) GetPaych(ctx context.Context, from, to address.Address, amt big.Int) (address.Address, cid.Cid, error)

func (*Manager) GetPaychWaitReady

func (pm *Manager) GetPaychWaitReady(ctx context.Context, mcid cid.Cid) (address.Address, error)

GetPaychWaitReady waits until the create channel / add funds message with the given message CID arrives. The returned channel address can safely be used against the Manager methods.

func (*Manager) ListChannels

func (pm *Manager) ListChannels() ([]address.Address, error)

func (*Manager) ListVouchers

func (pm *Manager) ListVouchers(ctx context.Context, ch address.Address) ([]*VoucherInfo, error)

func (*Manager) Settle

func (pm *Manager) Settle(ctx context.Context, addr address.Address) (cid.Cid, error)

func (*Manager) Start

func (pm *Manager) Start() error

Start restarts tracking of any messages that were sent to chain.

func (*Manager) Stop

func (pm *Manager) Stop()

Stop shuts down any processes used by the manager

func (*Manager) SubmitVoucher

func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error)

TODO: secret vs proof doesn't make sense, there is only one, not two

type ManagerParams

type ManagerParams struct {
	MPoolAPI     IMessagePush
	ChainInfoAPI IChainInfo
	WalletAPI    IWalletAPI
	SM           statemanger.IStateManager
}

type MsgInfo

type MsgInfo struct {
	// ChannelID links the message to a channel
	ChannelID string
	// MsgCid is the CID of the message
	MsgCid cid.Cid
	// Received indicates whether a response has been received
	Received bool
	// Err is the error received in the response
	Err string
}

MsgInfo stores information about a create channel / add funds message that has been sent

func (*MsgInfo) MarshalCBOR

func (t *MsgInfo) MarshalCBOR(w io.Writer) error

func (*MsgInfo) UnmarshalCBOR

func (t *MsgInfo) UnmarshalCBOR(r io.Reader) error

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(ds repo.Datastore) *Store

for test

func (*Store) AllocateLane

func (ps *Store) AllocateLane(ch address.Address) (uint64, error)

AllocateLane allocates a new lane for the given channel

func (*Store) ByAddress

func (ps *Store) ByAddress(addr address.Address) (*ChannelInfo, error)

ByAddress gets the channel that matches the given address

func (*Store) ByChannelID

func (ps *Store) ByChannelID(channelID string) (*ChannelInfo, error)

ByChannelID gets channel info by channel ID

func (*Store) ByMessageCid

func (ps *Store) ByMessageCid(mcid cid.Cid) (*ChannelInfo, error)

ByMessageCid gets the channel associated with a message

func (*Store) CreateChannel

func (ps *Store) CreateChannel(from address.Address, to address.Address, createMsgCid cid.Cid, amt fbig.Int) (*ChannelInfo, error)

CreateChannel creates an outbound channel for the given from / to

func (*Store) GetMessage

func (ps *Store) GetMessage(mcid cid.Cid) (*MsgInfo, error)

GetMessage gets the message info for a given message CID

func (*Store) ListChannels

func (ps *Store) ListChannels() ([]address.Address, error)

ListChannels returns the addresses of all channels that have been created

func (*Store) MarkVoucherSubmitted

func (ps *Store) MarkVoucherSubmitted(ci *ChannelInfo, sv *paych.SignedVoucher) error

func (*Store) OutboundActiveByFromTo

func (ps *Store) OutboundActiveByFromTo(from address.Address, to address.Address) (*ChannelInfo, error)

OutboundActiveByFromTo looks for outbound channels that have not been settled, with the given from / to addresses

func (*Store) RemoveChannel

func (ps *Store) RemoveChannel(channelID string) error

RemoveChannel removes the channel with the given channel ID

func (*Store) SaveMessageResult

func (ps *Store) SaveMessageResult(mcid cid.Cid, msgErr error) error

SaveMessageResult is called when the result of a message is received

func (*Store) SaveNewMessage

func (ps *Store) SaveNewMessage(channelID string, mcid cid.Cid) error

SaveNewMessage is called when a message is sent

func (*Store) TrackChannel

func (ps *Store) TrackChannel(ci *ChannelInfo) (*ChannelInfo, error)

TrackChannel stores a channel, returning an error if the channel was already being tracked

func (*Store) VouchersForPaych

func (ps *Store) VouchersForPaych(ch address.Address) ([]*VoucherInfo, error)

VouchersForPaych gets the vouchers for the given channel

func (*Store) WithPendingAddFunds

func (ps *Store) WithPendingAddFunds() ([]ChannelInfo, error)

WithPendingAddFunds is used on startup to find channels for which a create channel or add funds message has been sent, but lotus shut down before the response was received.

type VoucherCreateResult

type VoucherCreateResult struct {
	// Voucher that was created, or nil if there was an error or if there
	// were insufficient funds in the channel
	Voucher *paych.SignedVoucher
	// Shortfall is the additional amount that would be needed in the channel
	// in order to be able to create the voucher
	Shortfall big.Int
}

VoucherCreateResult is the response to calling PaychVoucherCreate

type VoucherInfo

type VoucherInfo struct {
	Voucher   *paych.SignedVoucher
	Proof     []byte // ignored
	Submitted bool
}

func (*VoucherInfo) MarshalCBOR

func (t *VoucherInfo) MarshalCBOR(w io.Writer) error

func (*VoucherInfo) UnmarshalCBOR

func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL