-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add a test with a 3Mb ordinals transaction #83
Conversation
input < 0xFDuL -> writeUInt8(input.toUByte(), out) | ||
input < 65535uL -> { | ||
input < 253uL -> writeUInt8(input.toUByte(), out) | ||
input <= 65535uL -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Damn, we should really have exhaustive tests on the varint encoding, like we have in eclair (where we unit test every boundary). This is already implemented in lightning-kmp with the following function, which I find slightly more clear, what do you think?
private fun writeBigSize(input: ULong, out: Output) {
when {
input < 0xfdu -> writeByte(input.toInt(), out)
input < 0x10000u -> {
out.write(0xfd)
writeU16(input.toInt(), out)
}
input < 0x100000000u -> {
out.write(0xfe)
writeU32(input.toInt(), out)
}
else -> {
out.write(0xff)
writeU64(input.toLong(), out)
}
}
}
But I think there's a difference between lightning and bitcoin here, we don't use the same endianness, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes bitcoin is little endian and LN is big endian. With the proposed changes we match what bitcoin core does which is always a good thing :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it a bit confusing that the implementation uses <
for the first case but <=
for the others to be honest...but if that matches the bitcoind
implementation why not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, Bitcoin Core confusingly calls these "compact size unsigned integers" and also sometimes varints
, but CVarint
is something different. I think the lightning-kmp implementation is clearer, though core names the function WriteCompactSize
, so both could lead to naming confusion when comparing to core.
src/commonTest/kotlin/fr/acinq/bitcoin/BtcSerializerTestsCommon.kt
Outdated
Show resolved
Hide resolved
This tx highlighted a bug in how we encoded script size.
cf43565
to
a86fccc
Compare
src/commonTest/kotlin/fr/acinq/bitcoin/BtcSerializerTestsCommon.kt
Outdated
Show resolved
Hide resolved
…n.kt Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
55d5fa9
to
6576181
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I compared to the core code and tested with and without the fixes to double check the tests catch any issues. I only had a question and found an issue with the test.
input < 0xFDuL -> writeUInt8(input.toUByte(), out) | ||
input < 65535uL -> { | ||
input < 253uL -> writeUInt8(input.toUByte(), out) | ||
input <= 65535uL -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference, Bitcoin Core confusingly calls these "compact size unsigned integers" and also sometimes varints
, but CVarint
is something different. I think the lightning-kmp implementation is clearer, though core names the function WriteCompactSize
, so both could lead to naming confusion when comparing to core.
src/commonTest/kotlin/fr/acinq/bitcoin/BtcSerializerTestsCommon.kt
Outdated
Show resolved
Hide resolved
src/commonTest/kotlin/fr/acinq/bitcoin/BtcSerializerTestsCommon.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
small nit:
val v = (1uL shl i)
uses lower case uL
, a few lines down it's an uppercase UL
and a few lines above it's uL
. Both are valid, Kotlin docs say "uL and UL explicitly tag literal as unsigned long"
Ah now I have to fix :) |
This tx highlighted a bug in how we encoded script size.