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

comm: make sure that our version check is reliable #5880

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions common/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,11 @@ common/test/run-bolt12_merkle-json: \
common/base32.o \
common/wireaddr.o


common/test/run-version: \
common/amount.o \
wire/fromwire.o \
wire/towire.o


check-units: $(COMMON_TEST_PROGRAMS:%=unittest/%)
16 changes: 16 additions & 0 deletions common/test/run-version.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "config.h"
#include "../version.c"
#include <common/setup.h>
#include <assert.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
common_setup(argv[0]);

assert(cmp_release_version("v22.11"));
assert(cmp_release_version("v22.11.1"));
assert(cmp_release_version("v22.11.1-6-gdf29990-modded") == false);

common_shutdown();
}
13 changes: 13 additions & 0 deletions common/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <common/version.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Only common/version.c can safely include this. */
# include "version_gen.h"
Expand All @@ -20,3 +21,15 @@ char *version_and_exit(const void *unused UNUSED)
}
exit(0);
}

static bool cmp_release_version(const char *version) {
if (version[0] != 'v')
return false;
return strspn(version+1, ".0123456789") == strlen(version+1);
}

/* Released versions are of form v[year].[month]?(.patch)* */
bool is_released_version(void)
{
return cmp_release_version(version());
}
5 changes: 5 additions & 0 deletions common/version.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#ifndef LIGHTNING_COMMON_VERSION_H
#define LIGHTNING_COMMON_VERSION_H
#include "config.h"
#include <stdbool.h>

char *version_and_exit(const void *unused);
const char *version(void);
/* check if the current version is a release version.
*
* Released versions are of form v[year].[month]?(.patch)* */
bool is_released_version(void);

#define opt_register_version() \
opt_register_early_noarg("--version|-V", version_and_exit, NULL, \
Expand Down
8 changes: 0 additions & 8 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,14 +945,6 @@ static struct migration dbmigrations[] = {
/* FIXME: Remove payments local_offer_id column! */
};

/* Released versions are of form v{num}[.{num}]* */
static bool is_released_version(void)
{
if (version()[0] != 'v')
return false;
return strcspn(version()+1, ".0123456789") == strlen(version()+1);
}

/**
* db_migrate - Apply all remaining migrations from the current version
*/
Expand Down