Added ReservationID for funding_requeset

This commit is contained in:
Joseph Poon 2015-12-31 01:19:54 -08:00 committed by Olaoluwa Osuntokun
parent 84df87255f
commit bf8e0d727d
4 changed files with 24 additions and 11 deletions

@ -5,14 +5,12 @@ This is two-party funder for a single Funding Transaction (more efficient and
makes the channel creation atomic, but doesn't work for
CSV-no-malleability-fix).
Funding Request
---------------
Someone wants to open a channel. The requester provides any inputs and relevant
information on how much they want to fund and the parameters, these paramters
are a proposal.
Funding Response
----------------
If the responder accepts the request, they also provide any inputs, and returns
@ -21,7 +19,6 @@ negotation has finished. If the requester doesn't agree with the new conditions,
they stop. The response also contains the first Commitment pubkey provided by the
responder, which refunds the initial balance back to both parties.
Funding SignAccept
------------
The requester now has sufficient information to get a refund if the transaction
@ -29,7 +26,6 @@ is ever broadcast. The requester signs the Funding Transaction and this message
gives the signature to the responder. The requester also provides the signature
for the initial Commitment Transaction.
Funding SignComplete
---------------
The responder has sufficient information to broadcast the Funding Transaction
@ -49,13 +45,13 @@ Requires the cooperation of both parites for this type. In the event of
non-cooperation, either party may broadcast the most recent Commitment
Transaction.
Close Channel
Close Request
-------------
One party unilaterally sends their sig and fee amount to the other party. No
further channel updates are possible. In the future, we might include HTLCs in
the outputs, but for now, we're assuming *all* HTLCs are cleared out.
Close Channel Complete
Close Complete
----------------------
Returns the Txid and sig as a courtesy. The counterparty might not send this if
they're being non-cooperative.

@ -9,6 +9,8 @@ import (
)
type FundingRequest struct {
ReservationID uint64
ChannelType uint8
RequesterFundingAmount btcutil.Amount
@ -23,6 +25,9 @@ type FundingRequest struct {
//THIS VALUE GOES INTO THE RESPONDER'S FUNDING AMOUNT
//total requester input value = RequesterFundingAmount + PaymentAmount + "Total Change" + Fees(?)
//RequesterFundingAmount = "Available Balance" + RequesterReserveAmount
//Payment SHOULD NOT be acknowledged until the minimum confirmation has elapsed
//(Due to double-spend risks the recipient will not want to acknolwedge confirmation until later)
//This is to make a payment as part of opening the channel
PaymentAmount btcutil.Amount
//Minimum number of confirmations to validate transaction
@ -49,6 +54,7 @@ type FundingRequest struct {
}
func (c *FundingRequest) Decode(r io.Reader, pver uint32) error {
//Reservation ID (8)
//Channel Type (1)
//Funding Amount (8)
//Channel Minimum Capacity (8)
@ -68,6 +74,7 @@ func (c *FundingRequest) Decode(r io.Reader, pver uint32) error {
// First byte is number of inputs
// For each input, it's 32bytes txin & 4bytes index
err := readElements(r,
&c.ReservationID,
&c.ChannelType,
&c.RequesterFundingAmount,
&c.MinTotalFundingAmount,
@ -110,6 +117,7 @@ func (c *FundingRequest) Encode(w io.Writer, pver uint32) error {
//ChangePkScript
//Inputs: Append the actual Txins
err := writeElements(w,
c.ReservationID,
c.ChannelType,
c.RequesterFundingAmount,
c.MinTotalFundingAmount,
@ -136,8 +144,8 @@ func (c *FundingRequest) Command() uint32 {
}
func (c *FundingRequest) MaxPayloadLength(uint32) uint32 {
//102 (base size) + 26 (pkscript) + 26 (pkscript) + 1 (numTxes) + 127*36(127 inputs * sha256+idx)
return 4727
//110 (base size) + 26 (pkscript) + 26 (pkscript) + 1 (numTxes) + 127*36(127 inputs * sha256+idx)
return 4735
}
//Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
@ -210,6 +218,7 @@ func (c *FundingRequest) String() string {
}
return fmt.Sprintf("\n--- Begin FundingRequest ---\n") +
fmt.Sprintf("ReservationID:\t\t\t%d\n", c.ReservationID) +
fmt.Sprintf("ChannelType:\t\t\t%x\n", c.ChannelType) +
fmt.Sprintf("RequesterFundingAmount:\t\t%s\n", c.RequesterFundingAmount.String()) +
fmt.Sprintf("RequesterReserveAmount:\t\t%s\n", c.RequesterReserveAmount.String()) +

@ -11,6 +11,7 @@ var (
//funding request
fundingRequest = &FundingRequest{
ReservationID: uint64(12345678),
ChannelType: uint8(0),
RequesterFundingAmount: btcutil.Amount(100000000),
RequesterReserveAmount: btcutil.Amount(131072),
@ -26,8 +27,8 @@ var (
ChangePkScript: changePkScript,
Inputs: inputs,
}
fundingRequestSerializedString = "000000000005f5e1000000000008f0d1804132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e20000000000012d68700000006000010e0001976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
fundingRequestSerializedMessage = "0709110b000000c8000000e4000000000005f5e1000000000008f0d1804132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e20000000000012d68700000006000010e0001976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
fundingRequestSerializedString = "0000000000bc614e000000000005f5e1000000000008f0d1804132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e20000000000012d68700000006000010e0001976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
fundingRequestSerializedMessage = "0709110b000000c8000000ec0000000000bc614e000000000005f5e1000000000008f0d1804132b6b48371f7b022a16eacb9b2b0ebee134d4102f977808cb9577897582d7524b562691e180953dd0008eb44e09594c539d6daee00000000000200000000000000004e20000000000012d68700000006000010e0001976a914e8048c0fb75bdecc91ebfb99c174f4ece29ffbd488ac1976a914238ee44bb5c8c1314dd03974a17ec6c406fdcb8388ac02e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8550000000001ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b00000001"
)
func TestFundingRequestEncodeDecode(t *testing.T) {

@ -14,10 +14,17 @@ const MessageHeaderSize = 12
const MaxMessagePayload = 1024 * 1024 * 32 // 32MB
const (
//Funding channel open
CmdFundingRequest = uint32(200)
CmdFundingResponse = uint32(210)
CmdFundingSignAccept = uint32(220)
CmdFundingSignComplete = uint32(230)
//Close channel
CmdCloseRequest = uint32(300)
CmdCloseComplete = uint32(310)
//HTLC payment
)
//Every message has these functions:
@ -53,7 +60,7 @@ type messageHeader struct {
//NOTE(j): We don't need to worry about the magic overlapping with
//bitcoin since this is inside encrypted comms anyway, but maybe we
//should use the XOR (^wire.TestNet3) just in case???
magic wire.BitcoinNet
magic wire.BitcoinNet //which Blockchain Technology(TM) to use
command uint32
length uint32
}