virtualdefund

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: 12 Imported by: 0

README

a# Virtual defund 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 defund V

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.

Documentation

Index

Constants

View Source
const (
	WaitingForFinalStateFromAlice protocols.WaitingFor = "WaitingForFinalStateFromAlice"
	WaitingForSupportedFinalState protocols.WaitingFor = "WaitingForSupportedFinalState" // Round 1
	WaitingForDefundingOnMyLeft   protocols.WaitingFor = "WaitingForDefundingOnMyLeft"   // Round 2
	WaitingForDefundingOnMyRight  protocols.WaitingFor = "WaitingForDefundingOnMyRight"  // Round 2
	WaitingForNothing             protocols.WaitingFor = "WaitingForNothing"             // Finished
)
View Source
const (
	// SignedStatePayload indicates that the payload is a json serialized signed state
	SignedStatePayload protocols.PayloadType = "SignedStatePayload"
	// RequestFinalStatePayload indicates that the payload is a request for the final state
	// The actual payload is simply the channel id that the final state is for
	RequestFinalStatePayload protocols.PayloadType = "RequestFinalStatePayload"
)
View Source
const FinalTurnNum = 2

The turn number used for the final state

View Source
const ObjectivePrefix = "VirtualDefund-"

Variables

This section is empty.

Functions

func GetVirtualChannelFromObjectiveId

func GetVirtualChannelFromObjectiveId(id protocols.ObjectiveId) (types.Destination, error)

GetVirtualChannelFromObjectiveId gets the virtual channel id from the objective id.

func IsVirtualDefundObjective

func IsVirtualDefundObjective(id protocols.ObjectiveId) bool

IsVirtualDefundObjective inspects a objective id and returns true if the objective id is for a virtualdefund objective.

Types

type GetChannelByIdFunction

type GetChannelByIdFunction func(id types.Destination) (channel *channel.Channel, ok bool)

GetChannelByIdFunction specifies a function that can be used to retrieve channels from a store.

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 Objective

type Objective struct {
	Status protocols.ObjectiveStatus

	// MinimumPaymentAmount is the latest payment amount we have received from Alice before starting defunding.
	// This is set by Bob so he can ensure he receives the latest amount from any vouchers he's received.
	// If this is not set then virtual defunding will accept any final outcome from Alice.
	MinimumPaymentAmount *big.Int

	V *channel.VirtualChannel

	ToMyLeft  *consensus_channel.ConsensusChannel
	ToMyRight *consensus_channel.ConsensusChannel

	// MyRole is the index of the participant in the participants list
	// 0 is Alice
	// 1...n is Irene, Ivan, ... (the n intermediaries)
	// n+1 is Bob
	MyRole uint
}

Objective contains relevant information for the defund objective

func ConstructObjectiveFromPayload

func ConstructObjectiveFromPayload(
	p protocols.ObjectivePayload,
	preapprove bool,
	myAddress types.Address,
	getChannel GetChannelByIdFunction,
	getTwoPartyConsensusLedger GetTwoPartyConsensusLedgerFunction,
	latestVoucherAmount *big.Int,
) (Objective, error)

ConstructObjectiveFromPayload takes in a message payload and constructs an objective from it.

func NewObjective

func NewObjective(request ObjectiveRequest,
	preApprove bool,
	myAddress types.Address,
	largestPaymentAmount *big.Int,
	getChannel GetChannelByIdFunction,
	getConsensusChannel GetTwoPartyConsensusLedgerFunction,
) (Objective, error)

NewObjective constructs a new virtual defund objective

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.

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 VirtualDefundObjective

NOTE: Marshal -> Unmarshal is a lossy process. All channel data (other than Id) from the fields ToMyLeft,ToMyRight are discarded

func (*Objective) OwnsChannel

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

OwnsChannel returns the channel that the objective is funding.

func (*Objective) ReceiveProposal

ReceiveProposal receives a signed proposal and returns an updated VirtualDefund objective.

func (*Objective) Reject

Reject returns a rejected copy of the objective.

func (*Objective) Related

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

Related returns channels that need to be stored along with the objective.

func (*Objective) UnmarshalJSON

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

UnmarshalJSON populates the calling VirtualDefundObjective with the json-encoded data

NOTE: Marshal -> Unmarshal is a lossy process. All channel data (other than Id) from the fields ToMyLeft,ToMyRight are discarded

func (*Objective) Update

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

func (*Objective) VId

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

VId returns the channel id of the virtual channel.

type ObjectiveRequest

type ObjectiveRequest struct {
	ChannelId types.Destination
	// contains filtered or unexported fields
}

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

func NewObjectiveRequest

func NewObjectiveRequest(channelId types.Destination) ObjectiveRequest

NewObjectiveRequest creates a new ObjectiveRequest.

func (ObjectiveRequest) Id

Id returns the objective id for 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

Jump to

Keyboard shortcuts

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