virtualfund

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0, MIT Imports: 12 Imported by: 0

README

Virtual fund off-chain protocol

Single hop case

Take three actors Alice, Bob and Irene. Given a ledger channel L between Alice and Irene and a ledger channel L' between Bob and Irene, the clients send and wait on messages as shown in the below sequence diagram in order to create and fund a virtual channel V:

virtual funding

The diagram is generated at https://sequencediagram.org/. The source code for this diagram is co-located in this folder, and should be updated in concert with changing the diagram.

See ADR 9 for greater detail.

Documentation

Overview

Package virtualfund implements an off-chain protocol to virtually fund a channel.

Index

Constants

View Source
const (
	WaitingForCompletePrefund  protocols.WaitingFor = "WaitingForCompletePrefund"  // Round 1
	WaitingForCompleteFunding  protocols.WaitingFor = "WaitingForCompleteFunding"  // Round 2
	WaitingForCompletePostFund protocols.WaitingFor = "WaitingForCompletePostFund" // Round 3
	WaitingForNothing          protocols.WaitingFor = "WaitingForNothing"          // Finished
)
View Source
const ObjectivePrefix = "VirtualFund-"
View Source
const (
	SignedStatePayload protocols.PayloadType = "SignedStatePayload"
)

Variables

This section is empty.

Functions

func IsVirtualFundObjective

func IsVirtualFundObjective(id protocols.ObjectiveId) bool

IsVirtualFundObjective inspects a objective id and returns true if the objective id is for a virtual fund objective.

Types

type Connection

type Connection struct {
	Channel       *consensus_channel.ConsensusChannel
	GuaranteeInfo GuaranteeInfo
}

func (*Connection) IsFundingTheTarget

func (c *Connection) IsFundingTheTarget() bool

IsFundingTheTarget computes whether the ledger channel on the receiver funds the guarantee expected by this connection

func (Connection) MarshalJSON

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

MarshalJSON returns a JSON representation of the Connection NOTE: Marshal -> Unmarshal is a lossy process. All channel data other than the ID is dropped

func (*Connection) UnmarshalJSON

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

UnmarshalJSON populates the calling Connection with the json-encoded data

NOTE: Marshal -> Unmarshal is a lossy process. All channel data from

(other than Id) is discarded

type GetTwoPartyConsensusLedgerFunction

type GetTwoPartyConsensusLedgerFunction func(counterparty types.Address) (ledger *consensus_channel.ConsensusChannel, ok bool)

GetTwoPartyConsensusLedgerFuncion describes functions which return a ConsensusChannel ledger channel between the calling client and the given counterparty, if such a channel exists.

type GuaranteeInfo

type GuaranteeInfo struct {
	Left                 types.Destination
	Right                types.Destination
	LeftAmount           types.Funds
	RightAmount          types.Funds
	GuaranteeDestination types.Destination
}

GuaranteeInfo contains the information used to generate the expected guarantees.

type Objective

type Objective struct {
	Status protocols.ObjectiveStatus
	V      *channel.VirtualChannel

	ToMyLeft  *Connection
	ToMyRight *Connection

	MyRole uint // index in the virtual funding protocol. 0 for Alice, n+1 for Bob. Otherwise, one of the intermediaries.
	// contains filtered or unexported fields
}

Objective is a cache of data computed by reading from the store. It stores (potentially) infinite data.

func ConstructObjectiveFromPayload

func ConstructObjectiveFromPayload(
	p protocols.ObjectivePayload,
	preapprove bool,
	myAddress types.Address,
	getTwoPartyConsensusLedger GetTwoPartyConsensusLedgerFunction,
) (Objective, error)

ConstructObjectiveFromPayload takes in a message and constructs an objective from it. It accepts the message, myAddress, and a function to to retrieve ledgers from a store.

func NewObjective

func NewObjective(request ObjectiveRequest, preApprove bool, myAddress types.Address, chainId *big.Int, getTwoPartyConsensusLedger GetTwoPartyConsensusLedgerFunction) (Objective, error)

NewObjective creates a new virtual funding objective from a given request.

func (*Objective) Approve

func (o *Objective) Approve() protocols.Objective

Approve returns an approved copy of the objective.

func (*Objective) Crank

Crank inspects the extended state and declares a list of Effects to be executed It's like a state machine transition function where the finite / enumerable state is returned (computed from the extended state) rather than being independent of the extended state; and where there is only one type of event ("the crank") with no data on it at all.

func (*Objective) GetStatus

func (o *Objective) GetStatus() protocols.ObjectiveStatus

GetStatus returns the status of the objective.

func (*Objective) Id

Id returns the objective id.

func (Objective) MarshalJSON

func (o Objective) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON representation of the VirtualFundObjective NOTE: Marshal -> Unmarshal is a lossy process. All channel data from the virtual and ledger channels (other than Ids) is discarded

func (*Objective) OwnsChannel

func (o *Objective) OwnsChannel() types.Destination

OwnsChannel returns the channel that the objective is funding.

func (*Objective) ReceiveProposal

func (*Objective) Reject

Reject returns a rejected copy of the objective.

func (*Objective) Related

func (o *Objective) Related() []protocols.Storable

func (*Objective) UnmarshalJSON

func (o *Objective) UnmarshalJSON(data []byte) error

UnmarshalJSON populates the calling VirtualFundObjective with the json-encoded data

NOTE: Marshal -> Unmarshal is a lossy process. All channel data from

the virtual and ledger channels (other than Ids) is discarded

func (*Objective) Update

Update receives an protocols.ObjectiveEvent, applies all applicable event data to the VirtualFundObjective, and returns the updated state.

type ObjectiveRequest

type ObjectiveRequest struct {
	Intermediaries    []types.Address
	CounterParty      types.Address
	ChallengeDuration uint32
	Outcome           outcome.Exit
	Nonce             uint64
	AppDefinition     types.Address
	// contains filtered or unexported fields
}

ObjectiveRequest represents a request to create a new virtual funding objective.

func NewObjectiveRequest

func NewObjectiveRequest(intermediaries []types.Address,
	counterparty types.Address,
	challengeDuration uint32,
	outcome outcome.Exit,
	nonce uint64,
	appDefinition types.Address,
) ObjectiveRequest

NewObjectiveRequest creates a new ObjectiveRequest.

func (ObjectiveRequest) Id

func (r ObjectiveRequest) Id(myAddress types.Address, chainId *big.Int) protocols.ObjectiveId

Id returns the objective id for the request.

func (ObjectiveRequest) Response

func (r ObjectiveRequest) Response(myAddress types.Address) ObjectiveResponse

Response computes and returns the appropriate response from the request.

func (ObjectiveRequest) SignalObjectiveStarted

func (r ObjectiveRequest) SignalObjectiveStarted()

SignalObjectiveStarted is used by the engine to signal the objective has been started.

func (ObjectiveRequest) WaitForObjectiveToStart

func (r ObjectiveRequest) WaitForObjectiveToStart()

WaitForObjectiveToStart blocks until the objective starts

type ObjectiveResponse

type ObjectiveResponse struct {
	Id        protocols.ObjectiveId
	ChannelId types.Destination
}

ObjectiveResponse is the type returned across the API in response to the ObjectiveRequest.

Jump to

Keyboard shortcuts

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