Skip to content

Commit

Permalink
amount: make it work with gcc-4.8.
Browse files Browse the repository at this point in the history
```
In file included from bitcoin/chainparams.h:7:0,from bitcoin/chainparams.c:1:
./common/amount.h:36:11: error: initializer element is not constant
((struct amount_sat){(constant) + AMOUNT_MUST_BE_CONST(constant)})
^
bitcoin/chainparams.c:20:21: note: in expansion of macro ‘AMOUNT_SAT’
.max_funding = AMOUNT_SAT((1 << 24) - 1),
^
./common/amount.h:36:11: error: (near initialization for ‘networks[0].max_funding’)
((struct amount_sat){(constant) + AMOUNT_MUST_BE_CONST(constant)})
^
bitcoin/chainparams.c:20:21: note: in expansion of macro ‘AMOUNT_SAT’
.max_funding = AMOUNT_SAT((1 << 24) - 1),
```

Fixes: #2404
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Feb 27, 2019
1 parent a3bac88 commit 02faadf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
20 changes: 10 additions & 10 deletions bitcoin/chainparams.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const struct chainparams networks[] = {
*...
* - MUST set `funding_satoshis` to less than 2^24 satoshi.
*/
.max_funding = AMOUNT_SAT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
/* "Lightning Charge Powers Developers & Blockstream Store" */
.when_lightning_became_cool = 504500,
.testnet = false},
Expand All @@ -29,8 +29,8 @@ const struct chainparams networks[] = {
.cli = "bitcoin-cli",
.cli_args = "-regtest",
.dust_limit = { 546 },
.max_funding = AMOUNT_SAT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
.when_lightning_became_cool = 1,
.testnet = true},
{.network_name = "testnet",
Expand All @@ -40,8 +40,8 @@ const struct chainparams networks[] = {
.cli = "bitcoin-cli",
.cli_args = "-testnet",
.dust_limit = { 546 },
.max_funding = AMOUNT_SAT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT(0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT((1 << 24) - 1),
.max_payment = AMOUNT_MSAT_INIT(0xFFFFFFFFULL),
.testnet = true},
{.network_name = "litecoin",
.bip173_name = "ltc",
Expand All @@ -50,8 +50,8 @@ const struct chainparams networks[] = {
.cli = "litecoin-cli",
.cli_args = NULL,
.dust_limit = { 100000 },
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT_INIT(60 * 0xFFFFFFFFULL),
.when_lightning_became_cool = 1320000,
.testnet = false},
{.network_name = "litecoin-testnet",
Expand All @@ -61,8 +61,8 @@ const struct chainparams networks[] = {
.cli = "litecoin-cli",
.cli_args = "-testnet",
.dust_limit = { 100000 },
.max_funding = AMOUNT_SAT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT(60 * 0xFFFFFFFFULL),
.max_funding = AMOUNT_SAT_INIT(60 * ((1 << 24) - 1)),
.max_payment = AMOUNT_MSAT_INIT(60 * 0xFFFFFFFFULL),
.when_lightning_became_cool = 1,
.testnet = true}
};
Expand Down
7 changes: 7 additions & 0 deletions common/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ struct amount_msat {
#define AMOUNT_MUST_BE_CONST(c) 0
#endif

/* GCC 4.8.5 (Centos 7.6!) thinks struct casts are not constants, so we
* need to not use a cast for static initializations. */
#define AMOUNT_MSAT_INIT(msat) \
{ .millisatoshis = (msat) }
#define AMOUNT_SAT_INIT(sat) \
{ .satoshis = (sat) }

#define AMOUNT_MSAT(constant) \
((struct amount_msat){(constant) + AMOUNT_MUST_BE_CONST(constant)})

Expand Down
4 changes: 2 additions & 2 deletions onchaind/onchaind.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static bool set_htlc_timeout_fee(struct bitcoin_tx *tx,
const struct bitcoin_signature *remotesig,
const u8 *wscript)
{
static struct amount_sat fee = AMOUNT_SAT(UINT64_MAX);
static struct amount_sat fee = AMOUNT_SAT_INIT(UINT64_MAX);

/* BOLT #3:
*
Expand All @@ -181,7 +181,7 @@ static void set_htlc_success_fee(struct bitcoin_tx *tx,
const struct bitcoin_signature *remotesig,
const u8 *wscript)
{
static struct amount_sat fee = AMOUNT_SAT(UINT64_MAX);
static struct amount_sat fee = AMOUNT_SAT_INIT(UINT64_MAX);

/* BOLT #3:
*
Expand Down

0 comments on commit 02faadf

Please sign in to comment.