mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
gossip: Avoid integer count overflow in gossip_store
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
94ef0a7fbf
commit
71ec8193b2
1 changed files with 1 additions and 5 deletions
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#define GOSSIP_STORE_FILENAME "gossip_store"
|
#define GOSSIP_STORE_FILENAME "gossip_store"
|
||||||
#define GOSSIP_STORE_TEMP_FILENAME "gossip_store.tmp"
|
#define GOSSIP_STORE_TEMP_FILENAME "gossip_store.tmp"
|
||||||
#define MAX_COUNT_TO_STALE_RATE 10
|
|
||||||
static u8 gossip_store_version = 0x02;
|
static u8 gossip_store_version = 0x02;
|
||||||
|
|
||||||
struct gossip_store {
|
struct gossip_store {
|
||||||
|
@ -219,8 +218,6 @@ disable:
|
||||||
|
|
||||||
void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg)
|
void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg)
|
||||||
{
|
{
|
||||||
size_t stale;
|
|
||||||
|
|
||||||
/* Only give error message once. */
|
/* Only give error message once. */
|
||||||
if (gs->fd == -1)
|
if (gs->fd == -1)
|
||||||
return;
|
return;
|
||||||
|
@ -232,8 +229,7 @@ void gossip_store_add(struct gossip_store *gs, const u8 *gossip_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
gs->count++;
|
gs->count++;
|
||||||
stale = gs->count - gs->broadcast->count;
|
if (gs->count >= 1000 && gs->count > gs->broadcast->count * 1.25 &&
|
||||||
if (gs->count >= 100 && stale * MAX_COUNT_TO_STALE_RATE > gs->count &&
|
|
||||||
!gs->disable_compaction)
|
!gs->disable_compaction)
|
||||||
gossip_store_compact(gs);
|
gossip_store_compact(gs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue