mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-18 22:54:25 +01:00
Use dedicated type for error codes
Before this patch we used `int` for error codes. The problem with `int` is that we try to pass it to/from wire and the size of `int` is not defined by the standard. So a sender with 4-byte `int` would write 4 bytes to the wire and a receiver with 2-byte `int` (for example) would read just 2 bytes from the wire. To resolve this: * Introduce an error code type with a known size: `typedef s32 errcode_t`. * Change all error code macros to constants of type `errcode_t`. Constants also play better with gdb - it would visualize the name of the constant instead of the numeric value. * Change all functions that take error codes to take the new type `errcode_t` instead of `int`. * Introduce towire / fromwire functions to send / receive the newly added type `errcode_t` and use it instead of `towire_int()`. In addition: * Remove the now unneeded `towire_int()`. * Replace a hardcoded error code `-2` with a new constant `INVOICE_EXPIRED_DURING_WAIT` (903). Changelog-Changed: The waitinvoice command would now return error code 903 to designate that the invoice expired during wait, instead of the previous -2
This commit is contained in:
committed by
ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent
295ca2a436
commit
55173a56b7
@@ -9,8 +9,10 @@
|
||||
#include <ccan/crypto/siphash24/siphash24.h>
|
||||
#include <ccan/endian/endian.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/errcode.h>
|
||||
#include <common/node_id.h>
|
||||
#include <common/type_to_string.h>
|
||||
#include <common/utils.h>
|
||||
@@ -165,12 +167,12 @@ bool fromwire_bool(const u8 **cursor, size_t *max)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int fromwire_int(const u8 **cursor, size_t *max)
|
||||
errcode_t fromwire_errcode_t(const u8 **cursor, size_t *max)
|
||||
{
|
||||
int ret;
|
||||
errcode_t ret;
|
||||
|
||||
ret = (s32)fromwire_u32(cursor, max);
|
||||
|
||||
if (!fromwire(cursor, max, &ret, sizeof(ret)))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user