channel

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Overview

Package channel defines types and methods for state channels.

Index

Constants

View Source
const (
	PreFundTurnNum uint64 = iota
	PostFundTurnNum
	MaxTurnNum = ^uint64(0) // MaxTurnNum is a reserved value which is taken to mean "there is not yet a supported state"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainUpdateData added in v0.1.1

type ChainUpdateData struct {
	BlockNum uint64
	TxIndex  uint
}

type Channel

type Channel struct {
	state.FixedPart
	Id      types.Destination
	MyIndex uint

	OnChain  OnChainData
	OffChain OffChainData

	LastChainUpdate ChainUpdateData
}

Channel contains states and metadata and exposes convenience methods.

func New

func New(s state.State, myIndex uint) (*Channel, error)

New constructs a new Channel from the supplied state.

func (*Channel) AddSignedState

func (c *Channel) AddSignedState(ss state.SignedState) bool

AddSignedState adds a signed state to the Channel, updating the LatestSupportedState and Support if appropriate. Returns false and does not alter the channel if the state is "stale", belongs to a different channel, or is signed by a non participant.

func (*Channel) AddStateWithSignature

func (c *Channel) AddStateWithSignature(s state.State, sig state.Signature) bool

AddStateWithSignature constructs a SignedState from the passed state and signature, and calls s.AddSignedState with it.

func (Channel) Affords

func (c Channel) Affords(
	allocationMap map[common.Address]outcome.Allocation,
	fundingMap types.Funds,
) bool

Affords returns true if, for each asset keying the input variables, the channel can afford the allocation given the funding. The decision is made based on the latest supported state of the channel.

Both arguments are maps keyed by the same asset

func (*Channel) Clone

func (c *Channel) Clone() *Channel

Clone returns a pointer to a new, deep copy of the receiver, or a nil pointer if the receiver is nil.

func (Channel) FinalCompleted

func (c Channel) FinalCompleted() bool

FinalCompleted returns true if I have a complete set of signatures on a final state, false otherwise.

func (Channel) FinalSignedByMe

func (c Channel) FinalSignedByMe() bool

FinalSignedByMe returns true if the calling client has signed a final state, false otherwise.

func (Channel) HasSupportedState

func (c Channel) HasSupportedState() bool

HasSupportedState returns true if the channel has a supported state, false otherwise.

func (Channel) LatestSignedState

func (c Channel) LatestSignedState() (state.SignedState, error)

LatestSignedState fetches the state with the largest turn number signed by at least one participant.

func (Channel) LatestSupportedState

func (c Channel) LatestSupportedState() (state.State, error)

LatestSupportedState returns the latest supported state. A state is supported if it is signed by all participants.

func (Channel) MarshalJSON

func (c Channel) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the Channel

func (Channel) MyDestination

func (c Channel) MyDestination() types.Destination

MyDestination returns the client's destination

func (Channel) PostFundComplete

func (c Channel) PostFundComplete() bool

PostFundComplete() returns true if I have a complete set of signatures on the pre fund setup state, false otherwise.

func (Channel) PostFundSignedByMe

func (c Channel) PostFundSignedByMe() bool

PostFundSignedByMe returns true if the calling client has signed the post fund setup state, false otherwise.

func (Channel) PostFundState

func (c Channel) PostFundState() state.State

PostFundState() returns the post fund setup state for the channel.

func (Channel) PreFundComplete

func (c Channel) PreFundComplete() bool

PreFundComplete() returns true if I have a complete set of signatures on the pre fund setup state, false otherwise.

func (Channel) PreFundSignedByMe

func (c Channel) PreFundSignedByMe() bool

PreFundSignedByMe returns true if the calling client has signed the pre fund setup state, false otherwise.

func (Channel) PreFundState

func (c Channel) PreFundState() state.State

PreFundState() returns the pre fund setup state for the channel.

func (*Channel) SignAndAddPostfund

func (c *Channel) SignAndAddPostfund(sk *[]byte) (state.SignedState, error)

SignAndAddPrefund signs and adds the postfund state for the channel, returning a state.SignedState suitable for sending to peers.

func (*Channel) SignAndAddPrefund

func (c *Channel) SignAndAddPrefund(sk *[]byte) (state.SignedState, error)

SignAndAddPrefund signs and adds the prefund state for the channel, returning a state.SignedState suitable for sending to peers.

func (*Channel) SignAndAddState

func (c *Channel) SignAndAddState(s state.State, sk *[]byte) (state.SignedState, error)

SignAndAddState signs and adds the state to the channel, returning a state.SignedState suitable for sending to peers.

func (Channel) SignedPostFundState

func (c Channel) SignedPostFundState() state.SignedState

SignedPostFundState() returns the SIGNED post fund setup state for the channel.

func (Channel) SignedPreFundState

func (c Channel) SignedPreFundState() state.SignedState

SignedPreFundState returns the signed pre fund setup state for the channel.

func (Channel) Total

func (c Channel) Total() types.Funds

Total() returns the total allocated of each asset allocated by the pre fund setup state of the Channel.

func (*Channel) UnmarshalJSON

func (c *Channel) UnmarshalJSON(data []byte) error

UnmarshalJSON populates the calling Channel with the json-encoded data

func (*Channel) UpdateWithChainEvent

func (c *Channel) UpdateWithChainEvent(event chainservice.Event) (*Channel, error)

UpdateWithChainEvent mutates the receiver with the supplied chain event, replacing the relevant data fields.

type OffChainData

type OffChainData struct {
	SignedStateForTurnNum       map[uint64]state.SignedState // Longer term, we should have a more efficient and smart mechanism to store states https://github.com/statechannels/go-nitro/issues/106
	LatestSupportedStateTurnNum uint64                       // largest uint64 value reserved for "no supported state"
}

type OnChainData

type OnChainData struct {
	Holdings  types.Funds
	Outcome   outcome.Exit
	StateHash common.Hash
}

type VirtualChannel

type VirtualChannel struct {
	Channel
}

func NewVirtualChannel

func NewVirtualChannel(s state.State, myIndex uint) (*VirtualChannel, error)

NewVirtualChannel returns a new VirtualChannel based on the supplied state.

Virtual channel protocol currently presumes exactly two "active" participants, Alice and Bob (p[0] and p[last]). They should be the only destinations allocated to in the supplied state's Outcome.

func (*VirtualChannel) Clone

func (v *VirtualChannel) Clone() *VirtualChannel

Clone returns a pointer to a new, deep copy of the receiver, or a nil pointer if the receiver is nil.

func (*VirtualChannel) GetPaidAndRemaining

func (v *VirtualChannel) GetPaidAndRemaining() (*big.Int, *big.Int)

Directories

Path Synopsis
Package consensus_channel manages a running ledger channel.
Package consensus_channel manages a running ledger channel.
Package state defines the data structures which are signed by channel participants.
Package state defines the data structures which are signed by channel participants.
outcome
Package outcome defines the data structures for expressing how channel funds are to be distributed on-chain.
Package outcome defines the data structures for expressing how channel funds are to be distributed on-chain.

Jump to

Keyboard shortcuts

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