qln

package
v0.0.0-...-aeb2f35 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DUALFUND_DECLINE_REASON_USER                    = 0x01 // User manually declined
	DUALFUND_DECLINE_REASON_INSUFFICIENT_BALANCE    = 0x02 // Not enough balance to accept the request
	DUALFUND_DECLINE_REASON_UNSUPPORTED_COIN        = 0x03 // We don't have that coin type, so we declined automatically
	DUALFUND_DECLINE_REASON_ALREADY_PENDING_REQUEST = 0x04 // Current design only supports single dualfund request at a time. So decline when we have one in progress.

)
View Source
const (
	UseWallet             = 0 | hdkeychain.HardenedKeyStart
	UseChannelFund        = 20 | hdkeychain.HardenedKeyStart
	UseChannelRefund      = 30 | hdkeychain.HardenedKeyStart
	UseChannelWatchRefund = 31 | hdkeychain.HardenedKeyStart
	UseChannelHAKDBase    = 40 | hdkeychain.HardenedKeyStart
	UseChannelElkrem      = 8888 | hdkeychain.HardenedKeyStart

	// key derivation path for contract payout keys (the keys the contract pays
	// TO combined with the oracle's signature)
	UseContractPayoutBase = 50 | hdkeychain.HardenedKeyStart

	// key derivation path for contract spending keys (the keys the contract
	// pays FROM, and the funding TX pays TO)
	UseContractFundMultisig = 51 | hdkeychain.HardenedKeyStart

	// key derivation path for contract payout PKH (the hash the contract
	// pays TO)
	UseContractPayoutPKH = 52 | hdkeychain.HardenedKeyStart

	// links Id and channel. replaces UseChannelFund
	UseIdKey = 111 | hdkeychain.HardenedKeyStart
)

Variables

View Source
var (
	BKTChannel = []byte("chn") // all channel data is in this bucket.
	BKTPeers   = []byte("pir") // all peer data is in this bucket.
	BKTPeerMap = []byte("pmp") // map of peer index to pubkey
	BKTChanMap = []byte("cmp") // map of channel index to outpoint
	BKTWatch   = []byte("wch") // txids & signatures for export to watchtowers

	KEYIdx      = []byte("idx")  // index for key derivation
	KEYhost     = []byte("hst")  // hostname where peer lives
	KEYnickname = []byte("nick") // nickname where peer lives

	KEYutxo    = []byte("utx") // serialized utxo for the channel
	KEYState   = []byte("now") // channel state
	KEYElkRecv = []byte("elk") // elkrem receiver
	KEYqclose  = []byte("cls") // channel close outpoint & height
)

Functions

func Announce

func Announce(priv *btcec.PrivateKey, litport string, litadr string, trackerURL string) error

func GetStateIdxFromTx

func GetStateIdxFromTx(tx *wire.MsgTx, x uint64) uint64

GetStateIdxFromTx returns the state index from a commitment transaction. No errors; returns 0 if there is no retrievable index. Takes the xor input X which is derived from the 0th elkrems.

func Lookup

func Lookup(litadr string, trackerURL string, proxyURL string) (string, string, error)

func SetStateIdxBits

func SetStateIdxBits(tx *wire.MsgTx, idx, x uint64) error

SetStateIdxBits modifies the tx in place, setting the sequence and locktime fields to indicate the given state index.

func SpendMultiSigWitStack

func SpendMultiSigWitStack(pre, sigA, sigB []byte) [][]byte

the scriptsig to put on a P2SH input. Sigs need to be in order!

Types

type DualFundingResult

type DualFundingResult struct {
	ChannelId     uint32
	Error         bool
	Accepted      bool
	DeclineReason uint8
}

type InFlightDualFund

type InFlightDualFund struct {
	PeerIdx, ChanIdx, CoinType              uint32
	OurAmount, TheirAmount                  int64
	OurInputs, TheirInputs                  []lnutil.DualFundingInput
	OurChangeAddress, TheirChangeAddress    [20]byte
	OurPub, OurRefundPub, OurHAKDBase       [33]byte
	TheirPub, TheirRefundPub, TheirHAKDBase [33]byte
	OurSignatures, TheirSignatures          [][60]byte
	InitiatedByUs                           bool
	OutPoint                                *wire.OutPoint
	// contains filtered or unexported fields
}

InFlightDualFund is a dual funding transaction that has not yet been broadcast

func (*InFlightDualFund) Clear

func (inff *InFlightDualFund) Clear()

type InFlightFund

type InFlightFund struct {
	PeerIdx, ChanIdx, Coin uint32
	Amt, InitSend          int64

	Data [32]byte
	// contains filtered or unexported fields
}

InFlightFund is a funding transaction that has not yet been broadcast

func (*InFlightFund) Clear

func (inff *InFlightFund) Clear()

type JusticeTx

type JusticeTx struct {
	Sig  [64]byte
	Txid [16]byte
	Amt  int64
	Data [32]byte
	Pkh  [20]byte
	Idx  uint64
}

func JusticeTxFromBytes

func JusticeTxFromBytes(jte []byte) (JusticeTx, error)

func (*JusticeTx) ToBytes

func (jte *JusticeTx) ToBytes() ([]byte, error)

type LitNode

type LitNode struct {
	LitDB *bolt.DB // place to write all this down

	LitFolder string // path to save stuff

	IdentityKey *btcec.PrivateKey

	// all nodes have a watchtower.  but could have a tower without a node
	Tower watchtower.Watcher

	// discreet log contract manager
	DlcManager *dlc.DlcManager

	// BaseWallet is the underlying wallet which keeps track of utxos, secrets,
	// and network i/o
	// map of cointypes to wallets
	SubWallet map[uint32]UWallet
	// indicates if multiple wallets are connected
	MultiWallet bool
	// cointype of the first (possibly only) wallet connected
	DefaultCoin uint32

	RemoteCons map[uint32]*RemotePeer
	RemoteMtx  sync.Mutex

	// WatchCon is currently just for the watchtower
	WatchCon *lndc.LNDConn // merge these later

	// OmniChan is the channel for the OmniHandler
	OmniIn  chan lnutil.LitMsg
	OmniOut chan lnutil.LitMsg

	// the current channel that in the process of being created
	// (1 at a time for now)
	InProg *InFlightFund

	// the current channel in process of being dual funded
	InProgDual *InFlightDualFund

	// queue for async messages to RPC user
	UserMessageBox chan string

	// The port(s) in which it listens for incoming connections
	LisIpPorts []string

	// The URL from which lit attempts to resolve the LN address
	TrackerURL string

	ChannelMap    map[[20]byte][]lnutil.LinkMsg
	ChannelMapMtx sync.Mutex
	AdvTimeout    *time.Ticker

	// Contains the URL string to connect to a SOCKS5 proxy, if provided
	ProxyURL string
}

LnNode is the main struct for the node, keeping track of all channel state and communicating with the underlying UWallet

func NewLitNode

func NewLitNode(privKey *[32]byte, path string, trackerURL string, proxyURL string) (*LitNode, error)

Init starts up a lit node. Needs priv key, and a path. Does not activate a subwallet; do that after init.

func (*LitNode) AcceptDlc

func (nd *LitNode) AcceptDlc(cIdx uint64) error

func (*LitNode) AddContract

func (nd *LitNode) AddContract() (*lnutil.DlcContract, error)

func (*LitNode) AutoReconnect

func (nd *LitNode) AutoReconnect(listenPort string, interval int64)

AutoReconnect will start listening for incoming connections and attempt to automatically reconnect to all previously known peers.

func (*LitNode) BreakChannel

func (nd *LitNode) BreakChannel(q *Qchan) error

------------------------- break

func (*LitNode) BuildDlcFundingTransaction

func (nd *LitNode) BuildDlcFundingTransaction(c *lnutil.DlcContract) (wire.MsgTx, error)

func (*LitNode) BuildDualFundingTransaction

func (nd *LitNode) BuildDualFundingTransaction() (*wire.MsgTx, error)

func (*LitNode) BuildJusticeSig

func (nd *LitNode) BuildJusticeSig(q *Qchan) error

BuildWatchTxidSig builds the partial txid and signature pair which can be exported to the watchtower. This get a channel that is 1 state old. So we can produce a signature.

func (*LitNode) ChannelHandler

func (nd *LitNode) ChannelHandler(msg lnutil.LitMsg, peer *RemotePeer) error

func (*LitNode) CloseHandler

func (nd *LitNode) CloseHandler(msg lnutil.LitMsg) error

func (*LitNode) CloseReqHandler

func (nd *LitNode) CloseReqHandler(msg lnutil.CloseReqMsg)

func (*LitNode) ConnectedToPeer

func (nd *LitNode) ConnectedToPeer(peer uint32) bool

ConnectedToPeer checks whether you're connected to a specific peer

func (*LitNode) CoopClose

func (nd *LitNode) CoopClose(q *Qchan) error

CoopClose requests a cooperative close of the channel

func (*LitNode) DeclineDlc

func (nd *LitNode) DeclineDlc(cIdx uint64, reason uint8) error

func (*LitNode) DeltaSigHandler

func (nd *LitNode) DeltaSigHandler(msg lnutil.DeltaSigMsg, qc *Qchan) error

DeltaSigHandler takes in a DeltaSig and responds with a SigRev (normally) or a GapSigRev (if there's a collision) Leaves the channel either expecting a Rev (normally) or a GapSigRev (collision)

func (*LitNode) DialPeer

func (nd *LitNode) DialPeer(connectAdr string) error

DialPeer makes an outgoing connection to another node.

func (*LitNode) DlcAcceptHandler

func (nd *LitNode) DlcAcceptHandler(msg lnutil.DlcOfferAcceptMsg, peer *RemotePeer) error

func (*LitNode) DlcContractAckHandler

func (nd *LitNode) DlcContractAckHandler(msg lnutil.DlcContractAckMsg, peer *RemotePeer)

func (*LitNode) DlcDeclineHandler

func (nd *LitNode) DlcDeclineHandler(msg lnutil.DlcOfferDeclineMsg, peer *RemotePeer)

func (*LitNode) DlcFundingSigsHandler

func (nd *LitNode) DlcFundingSigsHandler(msg lnutil.DlcContractFundingSigsMsg, peer *RemotePeer)

func (*LitNode) DlcOfferHandler

func (nd *LitNode) DlcOfferHandler(msg lnutil.DlcOfferMsg, peer *RemotePeer)

func (*LitNode) DlcSigProofHandler

func (nd *LitNode) DlcSigProofHandler(msg lnutil.DlcContractSigProofMsg, peer *RemotePeer)

func (*LitNode) DualFundAccept

func (nd *LitNode) DualFundAccept() *DualFundingResult

func (*LitNode) DualFundChanAckHandler

func (nd *LitNode) DualFundChanAckHandler(msg lnutil.DualFundingChanAckMsg, peer *RemotePeer)

FUNDER QChanAckHandler takes in an acknowledgement multisig description. when a multisig outpoint is ackd, that causes the funder to sign and broadcast.

func (*LitNode) DualFundChanDescHandler

func (nd *LitNode) DualFundChanDescHandler(msg lnutil.ChanDescMsg)

RECIPIENT QChanDescHandler takes in a description of a channel output. It then saves it to the local db, and returns a channel acknowledgement

func (*LitNode) DualFundChannel

func (nd *LitNode) DualFundChannel(
	peerIdx, cointype uint32, ourAmount int64, theirAmount int64) (*DualFundingResult, error)

func (*LitNode) DualFundDecline

func (nd *LitNode) DualFundDecline(reason uint8)

Declines the in progress (received) dual funding request

func (*LitNode) DualFundSigProofHandler

func (nd *LitNode) DualFundSigProofHandler(msg lnutil.SigProofMsg, peer *RemotePeer)

RECIPIENT SigProofHandler saves the signature the recipient stores. In some cases you don't need this message.

func (*LitNode) DualFundingAcceptHandler

func (nd *LitNode) DualFundingAcceptHandler(msg lnutil.DualFundingAcceptMsg)

DualFundingAcceptHandler gets a message where the remote party is accepting the request to dualfund.

func (*LitNode) DualFundingDeclHandler

func (nd *LitNode) DualFundingDeclHandler(msg lnutil.DualFundingDeclMsg)

RECIPIENT DualFundingDeclHandler gets a message where the remote party is declining the request to dualfund.

func (*LitNode) DualFundingHandler

func (nd *LitNode) DualFundingHandler(msg lnutil.LitMsg, peer *RemotePeer) error

func (*LitNode) DualFundingReqHandler

func (nd *LitNode) DualFundingReqHandler(msg lnutil.DualFundingReqMsg)

RECIPIENT DualFundingReqHandler gets a request with the funding data of the remote peer, along with the amount of funding requested to return data for.

func (*LitNode) DumpJusticeDB

func (nd *LitNode) DumpJusticeDB() ([]JusticeTx, error)

func (*LitNode) FWDHandler

func (nd *LitNode) FWDHandler(msg lnutil.LitMsg) error

func (*LitNode) FundChannel

func (nd *LitNode) FundChannel(
	peerIdx, cointype uint32, ccap, initSend int64, data [32]byte) (uint32, error)

FundChannel opens a channel with a peer. Doesn't return until the channel has been created. Maybe timeout if it takes too long?

func (*LitNode) FundContract

func (nd *LitNode) FundContract(c *lnutil.DlcContract) error

func (*LitNode) GapSigRevHandler

func (nd *LitNode) GapSigRevHandler(msg lnutil.GapSigRevMsg, q *Qchan) error

GapSigRevHandler takes in a GapSigRev, responds with a Rev, and leaves the channel in a state expecting a Rev.

func (*LitNode) GetAllQchans

func (nd *LitNode) GetAllQchans() ([]*Qchan, error)

GetAllQchans returns a slice of all channels. empty slice is OK.

func (*LitNode) GetConnectedPeerList

func (nd *LitNode) GetConnectedPeerList() []PeerInfo

func (*LitNode) GetDHSecret

func (nd *LitNode) GetDHSecret(q *Qchan) ([]byte, error)

GetDHSecret gets a per-channel shared secret from the Diffie-Helman of the two pubkeys in the fund tx.

func (*LitNode) GetElkremRoot

func (nd *LitNode) GetElkremRoot(k portxo.KeyGen) (chainhash.Hash, error)

GetElkremRoot returns the Elkrem root for a given key path gets the use-pub for elkrems and hashes it. A little weird because it's a "pub" key you shouldn't reveal. either do this or export privkeys... or signing empty txs or something.

func (*LitNode) GetLisAddressAndPorts

func (nd *LitNode) GetLisAddressAndPorts() (
	string, []string)

Gets the list of ports where LitNode is listening for incoming connections, & the connection key

func (*LitNode) GetNicknameFromPeerIdx

func (nd *LitNode) GetNicknameFromPeerIdx(idx uint32) string

GetNicknameFromPeerIdx gets the nickname for a peer

func (*LitNode) GetPeerIdx

func (nd *LitNode) GetPeerIdx(pub *btcec.PublicKey, host string) (uint32, error)

GetPeerIdx returns the peer index given a pubkey. Creates it if it's not there yet! Also return a bool for new..? not needed?

func (*LitNode) GetPubHostFromPeerIdx

func (nd *LitNode) GetPubHostFromPeerIdx(idx uint32) ([33]byte, string)

GetPubHostFromPeerIdx gets the pubkey and internet host name for a peer

func (*LitNode) GetQchan

func (nd *LitNode) GetQchan(opArr [36]byte) (*Qchan, error)

GetQchan returns a single channel. pubkey and outpoint bytes.

func (*LitNode) GetQchanByIdx

func (nd *LitNode) GetQchanByIdx(cIdx uint32) (*Qchan, error)

GetQchanByIdx is a gets the channel when you don't know the peer bytes and outpoint. Probably shouldn't have to use this if the UI is done right though.

func (*LitNode) GetQchanOPfromIdx

func (nd *LitNode) GetQchanOPfromIdx(cIdx uint32) ([36]byte, error)

func (*LitNode) GetUsePub

func (nd *LitNode) GetUsePub(k portxo.KeyGen, use uint32) (pubArr [33]byte, err error)

GetUsePub gets a pubkey from the base wallet, but first modifies the "use" step

func (*LitNode) HandleContractOPEvent

func (nd *LitNode) HandleContractOPEvent(c *lnutil.DlcContract,
	opEvent *lnutil.OutPointEvent) error

func (*LitNode) IdKey

func (nd *LitNode) IdKey() *btcec.PrivateKey

IdKey returns the identity private key

func (*LitNode) InitRouting

func (nd *LitNode) InitRouting()

func (*LitNode) LNDCReader

func (nd *LitNode) LNDCReader(peer *RemotePeer) error

Every lndc has one of these running it listens for incoming messages on the lndc and hands it over to the OmniHandler via omnichan

func (*LitNode) LinkBaseWallet

func (nd *LitNode) LinkBaseWallet(
	privKey *[32]byte, birthHeight int32, resync bool, tower bool,
	host string, param *coinparam.Params) error

LinkBaseWallet activates a wallet and hooks it into the litnode.

func (*LitNode) LinkMsgHandler

func (nd *LitNode) LinkMsgHandler(msg lnutil.LinkMsg)

func (*LitNode) LoadJusticeSig

func (nd *LitNode) LoadJusticeSig(comnum uint64, pkh [20]byte) (JusticeTx, error)

func (*LitNode) NextChannelIdx

func (nd *LitNode) NextChannelIdx() (uint32, error)

NextIdx returns the next channel index to use.

func (*LitNode) OPEventHandler

func (nd *LitNode) OPEventHandler(OPEventChan chan lnutil.OutPointEvent)

OPEventHandler gets outpoint events from the base wallet, and modifies the ln node db to reflect confirmations. Can also respond with exporting txos to the base wallet, or penalty txs.

func (*LitNode) OfferDlc

func (nd *LitNode) OfferDlc(peerIdx uint32, cIdx uint64) error

func (*LitNode) OpenDB

func (nd *LitNode) OpenDB(filename string) error

Opens the DB file for the LnNode

func (*LitNode) OutMessager

func (nd *LitNode) OutMessager()

OutMessager takes messages from the outbox and sends them to the ether. net.

func (*LitNode) PeerHandler

func (nd *LitNode) PeerHandler(msg lnutil.LitMsg, q *Qchan, peer *RemotePeer) error

handles stuff that comes in over the wire. Not user-initiated.

func (*LitNode) PointReqHandler

func (nd *LitNode) PointReqHandler(msg lnutil.PointReqMsg)

RECIPIENT PubReqHandler gets a (content-less) pubkey request. Respond with a pubkey and a refund pubkey hash. (currently makes pubkey hash, need to only make 1) so if someone sends 10 pubkeyreqs, they'll get the same pubkey back 10 times. they have to provide an actual tx before the next pubkey will come out.

func (*LitNode) PointRespHandler

func (nd *LitNode) PointRespHandler(msg lnutil.PointRespMsg) error

FUNDER PointRespHandler takes in a point response, and returns a channel description

func (*LitNode) PopulateQchanMap

func (nd *LitNode) PopulateQchanMap(peer *RemotePeer) error

func (*LitNode) PushChannel

func (nd *LitNode) PushChannel(qc *Qchan, amt uint32, data [32]byte) error

PushChannel initiates a state update by sending a DeltaSig

func (*LitNode) PushPullHandler

func (nd *LitNode) PushPullHandler(routedMsg lnutil.LitMsg, q *Qchan) error

func (*LitNode) QChanAckHandler

func (nd *LitNode) QChanAckHandler(msg lnutil.ChanAckMsg, peer *RemotePeer)

FUNDER QChanAckHandler takes in an acknowledgement multisig description. when a multisig outpoint is ackd, that causes the funder to sign and broadcast.

func (*LitNode) QChanDescHandler

func (nd *LitNode) QChanDescHandler(msg lnutil.ChanDescMsg)

RECIPIENT QChanDescHandler takes in a description of a channel output. It then saves it to the local db, and returns a channel acknowledgement

func (*LitNode) QchanInfo

func (nd *LitNode) QchanInfo(q *Qchan) error

ChannelInfo prints info about a channel.

func (*LitNode) ReSendMsg

func (nd *LitNode) ReSendMsg(qc *Qchan) error

SendNextMsg determines what message needs to be sent next based on the channel state. It then calls the appropriate function.

func (*LitNode) ReloadQchanState

func (nd *LitNode) ReloadQchanState(q *Qchan) error

ReloadQchan loads updated data from the db into the qchan. Loads elkrem and state, but does not change qchan info itself. Faster than GetQchan() also reload the channel close state

func (*LitNode) RestoreQchanFromBucket

func (nd *LitNode) RestoreQchanFromBucket(bkt *bolt.Bucket) (*Qchan, error)

RestoreQchanFromBucket loads the full qchan into memory from the bucket where it's stored. Loads the channel info, the elkrems, and the current state. restore happens all at once, but saving to the db can happen incrementally (updating states) This should populate everything int he Qchan struct: the elkrems and the states. Elkrem sender always works; is derived from local key data. Elkrem receiver can be "empty" with nothing in it (no data in db)

func (*LitNode) RevHandler

func (nd *LitNode) RevHandler(msg lnutil.RevMsg, qc *Qchan) error

REVHandler takes in a REV and clears the state's prev HAKD. This is the final message in the state update process and there is no response. Leaves the channel in a clear / rest state.

func (*LitNode) SaveJusticeSig

func (nd *LitNode) SaveJusticeSig(comnum uint64, pkh [20]byte, txidsig [120]byte) error

SaveJusticeSig save the txid/sig of a justice transaction to the db. Pretty straightforward

func (*LitNode) SaveNicknameForPeerIdx

func (nd *LitNode) SaveNicknameForPeerIdx(nickname string, idx uint32) error

SaveNicknameForPeerIdx saves/overwrites a nickname for a given peer idx

func (*LitNode) SaveQChan

func (nd *LitNode) SaveQChan(q *Qchan) error

register a new Qchan in the db

func (*LitNode) SaveQchanState

func (nd *LitNode) SaveQchanState(q *Qchan) error

Save / overwrite state of qChan in db the descent into the qchan bucket is boilerplate and it'd be nice if we can make that it's own function. Get channel bucket maybe? But then you have to close it...

func (*LitNode) SaveQchanUtxoData

func (nd *LitNode) SaveQchanUtxoData(q *Qchan) error

SaveQchanUtxoData saves utxo data such as outpoint and close tx / status

func (*LitNode) SelfPushHandler

func (nd *LitNode) SelfPushHandler(msg lnutil.LitMsg) error

func (*LitNode) SendChat

func (nd *LitNode) SendChat(peer uint32, chat string) error

SendChat sends a text string to a peer

func (*LitNode) SendDeltaSig

func (nd *LitNode) SendDeltaSig(q *Qchan) error

SendDeltaSig initiates a push, sending the amount to be pushed and the new sig.

func (*LitNode) SendGapSigRev

func (nd *LitNode) SendGapSigRev(q *Qchan) error

SendGapSigRev is different; it signs for state+1 and revokes state-1

func (*LitNode) SendREV

func (nd *LitNode) SendREV(q *Qchan) error

SendREV sends a REV message based on channel info

func (*LitNode) SendSigRev

func (nd *LitNode) SendSigRev(q *Qchan) error

SendSigRev sends a SigRev message based on channel info

func (*LitNode) SendWatchComMsg

func (nd *LitNode) SendWatchComMsg(qc *Qchan, idx uint64, watchPeer uint32) error

send WatchComMsg generates and sends the ComMsg to a watchtower

func (*LitNode) SetQchanRefund

func (nd *LitNode) SetQchanRefund(q *Qchan, refund, hakdBase [33]byte) error

SetQchanRefund overwrites "theirrefund" and "theirHAKDbase" in a qchan.

This is needed after getting a chanACK.

func (*LitNode) SettleContract

func (nd *LitNode) SettleContract(cIdx uint64, oracleValue int64, oracleSig [32]byte) ([32]byte, [32]byte, error)

func (*LitNode) ShowJusticeDB

func (nd *LitNode) ShowJusticeDB() (string, error)

func (*LitNode) SigProofHandler

func (nd *LitNode) SigProofHandler(msg lnutil.SigProofMsg, peer *RemotePeer)

RECIPIENT SigProofHandler saves the signature the recipient stores. In some cases you don't need this message.

func (*LitNode) SigRevHandler

func (nd *LitNode) SigRevHandler(msg lnutil.SigRevMsg, qc *Qchan) error

SIGREVHandler takes in a SIGREV and responds with a REV (if everything goes OK) Leaves the channel in a clear / rest state.

func (*LitNode) SignBreakTx

func (nd *LitNode) SignBreakTx(q *Qchan) (*wire.MsgTx, error)

SignBreak signs YOUR tx, which you already have a sig for

func (*LitNode) SignClaimTx

func (nd *LitNode) SignClaimTx(claimTx *wire.MsgTx, value int64, pre []byte,
	priv *btcec.PrivateKey, timeout bool) error

SignClaimTx signs the given claim tx based on the passed preimage and value using the passed private key. Tx is modified in place. timeout=false means it's a regular claim, timeout=true means we're claiming an output that has expired (for instance if someone) published the wrong settlement TX, we can claim this output back to our wallet after the timelock expired.

func (*LitNode) SignSettlementDivisions

func (nd *LitNode) SignSettlementDivisions(c *lnutil.DlcContract) ([]lnutil.DlcContractSettlementSignature, error)

func (*LitNode) SignSettlementTx

func (nd *LitNode) SignSettlementTx(c *lnutil.DlcContract, tx *wire.MsgTx,
	priv *btcec.PrivateKey) ([64]byte, error)

SignSettlementTx signs the given settlement tx based on the passed contract using the passed private key. Tx is modified in place.

func (*LitNode) SignSimpleClose

func (nd *LitNode) SignSimpleClose(q *Qchan, tx *wire.MsgTx) ([64]byte, error)

SignSimpleClose signs the given simpleClose tx, given the other signature Tx is modified in place.

func (*LitNode) SignState

func (nd *LitNode) SignState(q *Qchan) ([64]byte, error)

SignNextState generates your signature for their state.

func (*LitNode) SyncWatch

func (nd *LitNode) SyncWatch(qc *Qchan, watchPeer uint32) error

SendWatch syncs up the remote watchtower with all justice signatures

func (*LitNode) TCPListener

func (nd *LitNode) TCPListener(
	lisIpPort string) (string, error)

TCPListener starts a litNode listening for incoming LNDC connections

func (*LitNode) VisualiseGraph

func (nd *LitNode) VisualiseGraph() string

type PeerInfo

type PeerInfo struct {
	PeerNumber uint32
	RemoteHost string
	LitAdr     string
	Nickname   string
}

type QCloseData

type QCloseData struct {
	// 3 txid / height pairs are stored.  All 3 only are used in the
	// case where you grab their invalid close.
	CloseTxid   chainhash.Hash
	CloseHeight int32
	Closed      bool // if channel is closed; if CloseTxid != -1
}

func QCloseFromBytes

func QCloseFromBytes(b []byte) (QCloseData, error)

QCloseFromBytes deserializes a Qclose. Note that a nil slice gives an empty / non closed qclose.

func (*QCloseData) ToBytes

func (c *QCloseData) ToBytes() ([]byte, error)

type Qchan

type Qchan struct {
	portxo.PorTxo            // S underlying utxo data
	CloseData     QCloseData // S closing outpoint

	MyPub    [33]byte // D my channel specific pubkey
	TheirPub [33]byte // S their channel specific pubkey

	// Refunds are also elkremified
	MyRefundPub    [33]byte // D my refund pubkey for channel break
	TheirRefundPub [33]byte // S their pubkey for channel break

	MyHAKDBase    [33]byte // D my base point for HAKD and timeout keys
	TheirHAKDBase [33]byte // S their base point for HAKD and timeout keys
	// PKH for penalty tx.  Derived
	WatchRefundAdr [20]byte

	// Elkrem is used for revoking state commitments
	ElkSnd *elkrem.ElkremSender   // D derived from channel specific key
	ElkRcv *elkrem.ElkremReceiver // S stored in db

	Delay uint16 // blocks for timeout (default 5 for testing)

	State *StatCom // S current state of channel

	ClearToSend chan bool // send a true here when you get a rev
	ChanMtx     sync.Mutex
}

Uhh, quick channel. For now. Once you get greater spire it upgrades to a full channel that can do everything.

func QchanFromBytes

func QchanFromBytes(b []byte) (Qchan, error)

QchanFromBytes turns bytes into a Qchan. the first 99 bytes are the 3 pubkeys: channel, refund, HAKD base then 8 bytes for the DH mask the rest is the utxo

func (*Qchan) AdvanceElkrem

func (q *Qchan) AdvanceElkrem(elk *chainhash.Hash, n2Elk [33]byte) error

func (*Qchan) BuildStateTx

func (q *Qchan) BuildStateTx(mine bool) (*wire.MsgTx, error)

BuildStateTx constructs and returns a state tx. As simple as I can make it. This func just makes the tx with data from State in ram, and HAKD key arg

func (*Qchan) Coin

func (q *Qchan) Coin() uint32

Coin returns the coin type of the channel

func (*Qchan) ElkPoint

func (q *Qchan) ElkPoint(mine bool, idx uint64) (p [33]byte, err error)

ElkPoint generates an elkrem Point. "My" elkrem point is the point I receive from the counter party, and can create after the state has been revoked. "Their" elkrem point (mine=false) is generated from my elkrem sender at any index. Elkrem points pubkeys where the scalar is a hash coming from the elkrem tree. With delinearized aggregation, only one point is needed. I'm pretty sure.

func (*Qchan) GetChanHint

func (q *Qchan) GetChanHint(mine bool) uint64

GetChanHint gives the 6 byte hint mask of the channel. It's derived from the hash of the PKH output pubkeys. "Mine" means the hint is in the tx I store. So it's actually a hint for them to decode... which is confusing, but consistent with the "mine" bool for transactions, so "my" tx has "my" hint. (1<<48 - 1 is the max valid value)

func (*Qchan) GetCloseTxos

func (q *Qchan) GetCloseTxos(tx *wire.MsgTx) ([]portxo.PorTxo, error)

GetCloseTxos takes in a tx and sets the QcloseTXO fields based on the tx. It also returns the spendable (u)txos generated by the close. TODO way too long. Need to split up. TODO problem with collisions, and insufficiently high elk receiver...?

func (*Qchan) Idx

func (q *Qchan) Idx() uint32

Idx returns the local index of the channel

func (*Qchan) ImFirst

func (q *Qchan) ImFirst() bool

ImFirst decides who goes first when it's unclear. Smaller pubkey goes first.

func (*Qchan) IngestElkrem

func (q *Qchan) IngestElkrem(elk *chainhash.Hash) error

IngestElkrem takes in an elkrem hash, performing 2 checks: that it produces the proper elk point, and that it fits into the elkrem tree. If either of these checks fail, and definitely the second one fails, I'm pretty sure the channel is not recoverable and needs to be closed.

func (*Qchan) N2ElkPointForThem

func (q *Qchan) N2ElkPointForThem() (p [33]byte, err error)

CurElkPointForThem makes the current state elkrem point to send out

func (*Qchan) Peer

func (q *Qchan) Peer() uint32

Peer returns the local peer index of the channel

func (*Qchan) SimpleCloseTx

func (q *Qchan) SimpleCloseTx() (*wire.MsgTx, error)

SimpleCloseTx produces a close tx based on the current state. The PKH addresses are my refund base with their r-elkrem point, and their refund base with my r-elkrem point. "Their" point means they have the point but not the scalar.

func (*Qchan) ToBytes

func (q *Qchan) ToBytes() ([]byte, error)

func (*Qchan) VerifySig

func (q *Qchan) VerifySig(sig [64]byte) error

VerifySig verifies their signature for your next state. it also saves the sig if it's good. do bool, error or just error? Bad sig is an error I guess. for verifying signature, always use theirHAKDpub, so generate & populate within this function.

type RemotePeer

type RemotePeer struct {
	Idx      uint32 // the peer index
	Nickname string
	Con      *lndc.LNDConn
	QCs      map[uint32]*Qchan   // keep map of all peer's channels in ram
	OpMap    map[[36]byte]uint32 // quick lookup for channels
}

type SigRevMsg

type SigRevMsg struct {
	Op    wire.OutPoint
	Delta int32
	Sig   [64]byte
}

example message struct

func SigRevFromBytes

func SigRevFromBytes(b []byte) (*SigRevMsg, error)

example deserialization method

func (*SigRevMsg) Bytes

func (m *SigRevMsg) Bytes() []byte

example serialization method

type StatCom

type StatCom struct {
	StateIdx uint64 // this is the n'th state commitment

	WatchUpTo uint64 // have sent out to watchtowers up to this state  ( < stateidx)

	MyAmt int64 // my channel allocation

	Fee int64 // symmetric fee in absolute satoshis

	Data [32]byte

	// their Amt is the utxo.Value minus this
	Delta int32 // fund amount in-transit; is negative for the pusher
	// Delta for when the channel is in a collision state which needs to be resolved
	Collision int32

	// Elkrem point from counterparty, used to make
	// Homomorphic Adversarial Key Derivation public keys (HAKD)
	ElkPoint     [33]byte // saved to disk, current revealable point
	NextElkPoint [33]byte // Point stored for next state
	N2ElkPoint   [33]byte // Point for state after next (in case of collision)
	// contains filtered or unexported fields
}

StatComs are State Commitments. all elements are saved to the db.

func StatComFromBytes

func StatComFromBytes(b []byte) (*StatCom, error)

StatComFromBytes turns 192 bytes into a StatCom

func (*StatCom) ToBytes

func (s *StatCom) ToBytes() ([]byte, error)

ToBytes turns a StatCom into 192ish bytes

type UWallet

type UWallet interface {
	// Ask for a pubkey based on a bip32 path
	GetPub(k portxo.KeyGen) *btcec.PublicKey

	// Have GetPriv for now.  Maybe later get rid of this and have
	// the underlying wallet sign?
	GetPriv(k portxo.KeyGen) (*btcec.PrivateKey, error)

	// export the chainhook that the UWallet uses, for pushTx and fullblock
	ExportHook() uspv.ChainHook

	PushTx(tx *wire.MsgTx) error

	// ExportUtxo gives a utxo to the underlying wallet; that wallet saves it
	// and can spend it later.  Doesn't return errors; error will exist only in
	// base wallet.
	ExportUtxo(txo *portxo.PorTxo)

	// MaybeSend makes an unsigned tx, populated with inputs and outputs.
	// The specified txouts are in there somewhere.
	// Only segwit txins are in the generated tx. (txid won't change)
	// There's probably an extra change txout in there which is OK.
	// The inputs are "frozen" until ReallySend / NahDontSend / program restart.
	// Retruns the txid, and then the txout indexes of the specified txos.
	// The outpoints returned will all have the same hash (txid)
	// So if you (as usual) just give one txo, you basically get back an outpoint.
	MaybeSend(txos []*wire.TxOut, onlyWit bool) ([]*wire.OutPoint, error)

	// ReallySend really sends the transaction specified previously in MaybeSend.
	// Underlying wallet does all needed signing.
	// Once you call ReallySend, the outpoint is tracked and responses are
	// sent through LetMeKnow
	ReallySend(txid *chainhash.Hash) error

	// NahDontSend cancels the MaybeSend transaction.
	NahDontSend(txid *chainhash.Hash) error

	// Return a new address
	NewAdr() ([20]byte, error)

	// Dump all the utxos in the sub wallet
	UtxoDump() ([]*portxo.PorTxo, error)

	// Dump all the addresses the sub wallet is watching
	AdrDump() ([][20]byte, error)

	// Return current height the wallet is synced to
	CurrentHeight() int32

	// WatchThis tells the basewallet to watch an outpoint
	WatchThis(wire.OutPoint) error

	// LetMeKnow opens the chan where OutPointEvent flows from the underlying
	// wallet up to the LN module.
	LetMeKnow() chan lnutil.OutPointEvent

	// Ask for network parameters
	Params() *coinparam.Params

	// Get current fee rate.
	Fee() int64

	// Set fee rate
	SetFee(int64) int64

	// ===== TESTING / SPAMMING ONLY, these funcs will not be in the real interface
	// Sweep sends lots of txs (uint32 of them) to the specified address.
	Sweep([]byte, uint32) ([]*chainhash.Hash, error)

	PickUtxos(amtWanted, outputByteSize,
		feePerByte int64, ow bool) (portxo.TxoSliceByBip69, int64, error)

	SignMyInputs(tx *wire.MsgTx) error

	DirectSendTx(tx *wire.MsgTx) error
}

The UWallet interface are the functions needed to work with the LnNode Verbs are from the perspective of the LnNode, not the underlying wallet

Jump to

Keyboard shortcuts

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