Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use signed amounts in RBF messages #15

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions 01-messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ All data fields are unsigned big-endian unless otherwise specified.
* [Appendix A: BigSize Test Vectors](#appendix-a-bigsize-test-vectors)
* [Appendix B: Type-Length-Value Test Vectors](#appendix-b-type-length-value-test-vectors)
* [Appendix C: Message Extension](#appendix-c-message-extension)
* [Appendix D: Signed Integers Test Vectors](#appendix-d-signed-integers-test-vectors)
* [Acknowledgments](#acknowledgments)
* [References](#references)
* [Authors](#authors)
Expand Down Expand Up @@ -220,9 +221,16 @@ receiver to parse individual elements from `value`.
Various fundamental types are referred to in the message specifications:

* `byte`: an 8-bit byte
* `i8`: an 8-bit signed integer
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use s not i, as it's better to do opposites in specs (unsigned vs signed -> u vs s)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in cf62b5a

I find it a bit weird, as i32/i64 seems to be the standard way in programming languages to refer to signed integers and I've never seen s32/s64 anywhere, but I don't really mind!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah s seems a bit strange but no big deal honestly.

* `u16`: a 2 byte unsigned integer
* `i16`: a 2 byte signed integer
* `u32`: a 4 byte unsigned integer
* `i32`: a 4 byte signed integer
* `u64`: an 8 byte unsigned integer
* `i64`: an 8 byte signed integer
t-bast marked this conversation as resolved.
Show resolved Hide resolved

Signed integers use standard big-endian two's complement representation
(see test vectors [below](#appendix-d-signed-integers-test-vectors)).

Inside TLV records which contain a single value, leading zeros in
integers can be omitted:
Expand Down Expand Up @@ -968,6 +976,108 @@ Note that when messages are signed, the _extension_ is part of the signed bytes.
Nodes should store the _extension_ bytes even if they don't understand them to
be able to correctly verify signatures.

## Appendix D: Signed Integers Test Vectors

The following test vector show how signed integers (`i8`, `i16`, `i32`
and `i64`) are encoded using big-endian two's complement.

```json
[
{
"value": 0,
"bytes": "00"
},
{
"value": 42,
"bytes": "2a"
},
{
"value": -42,
"bytes": "d6"
},
{
"value": 127,
"bytes": "7f"
},
{
"value": -128,
"bytes": "80"
},
{
"value": 128,
"bytes": "0080"
},
{
"value": -129,
"bytes": "ff7f"
},
{
"value": 15000,
"bytes": "3a98"
},
{
"value": -15000,
"bytes": "c568"
},
{
"value": 32767,
"bytes": "7fff"
},
{
"value": -32768,
"bytes": "8000"
},
{
"value": 32768,
"bytes": "00008000"
},
{
"value": -32769,
"bytes": "ffff7fff"
},
{
"value": 21000000,
"bytes": "01406f40"
},
{
"value": -21000000,
"bytes": "febf90c0"
},
{
"value": 2147483647,
"bytes": "7fffffff"
},
{
"value": -2147483648,
"bytes": "80000000"
},
{
"value": 2147483648,
"bytes": "0000000080000000"
},
{
"value": -2147483649,
"bytes": "ffffffff7fffffff"
},
{
"value": 500000000000,
"bytes": "000000746a528800"
},
{
"value": -500000000000,
"bytes": "ffffff8b95ad7800"
},
{
"value": 9223372036854775807,
"bytes": "7fffffffffffffff"
},
{
"value": -9223372036854775808,
"bytes": "8000000000000000"
}
]
```

## Acknowledgments

[ TODO: (roasbeef); fin ]
Expand Down
4 changes: 2 additions & 2 deletions 02-peer-protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ completed.
2. types:
1. type: 0 (`funding_output_contribution`)
2. data:
* [`tu64`:`satoshis`]
* [`i64`:`satoshis`]

#### Requirements

Expand Down Expand Up @@ -497,7 +497,7 @@ not contributing to the funding output.
2. types:
1. type: 0 (`funding_output_contribution`)
2. data:
* [`tu64`:`satoshis`]
* [`i64`:`satoshis`]

#### Requirements

Expand Down