From 69537d4c00ebf633017ae9bfdfc96f6f4b18165f Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Thu, 30 Nov 2023 15:53:30 +0000 Subject: [PATCH] Fix comment out unused functionalities and add LND 0.17.2 to tests --- .github/workflows/integration-tests.yml | 6 +- api/lightning/lnd.py | 13 ++- api/nick_generator/nick_generator.py | 148 ++++++++++++------------ 3 files changed, 87 insertions(+), 80 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 30ca1edb..4cb89558 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -18,12 +18,12 @@ jobs: test: runs-on: ubuntu-latest strategy: - max-parallel: 4 + max-parallel: 2 matrix: python-tag: ['3.11.6-slim-bookworm', '3.12-slim-bookworm'] - lnd-version: ['v0.17.0-beta'] # , 'v0.17.0-beta.rc1'] + lnd-version: ['v0.17.0-beta', 'v0.17.2-beta.rc1'] cln-version: ['v23.08.1'] - ln-vendor: ['LND', 'CLN'] + ln-vendor: ['LND'] #, 'CLN'] steps: - name: 'Checkout' diff --git a/api/lightning/lnd.py b/api/lightning/lnd.py index 6afe5e09..706b4a6b 100644 --- a/api/lightning/lnd.py +++ b/api/lightning/lnd.py @@ -362,12 +362,13 @@ class LNDNode: return status, expiry_height - @classmethod - def resetmc(cls): - routerstub = router_pb2_grpc.RouterStub(cls.channel) - request = router_pb2.ResetMissionControlRequest() - _ = routerstub.ResetMissionControl(request) - return True + # UNUSED + # @classmethod + # def resetmc(cls): + # routerstub = router_pb2_grpc.RouterStub(cls.channel) + # request = router_pb2.ResetMissionControlRequest() + # _ = routerstub.ResetMissionControl(request) + # return True @classmethod def validate_ln_invoice(cls, invoice, num_satoshis, routing_budget_ppm): diff --git a/api/nick_generator/nick_generator.py b/api/nick_generator/nick_generator.py index 9105d37a..3b75c0c6 100755 --- a/api/nick_generator/nick_generator.py +++ b/api/nick_generator/nick_generator.py @@ -34,21 +34,23 @@ class NickGenerator: from .dicts.en.adjectives import adjectives from .dicts.en.adverbs import adverbs from .dicts.en.nouns import nouns - elif lang == "Spanish": - from .dicts.es.adjectives import adjectives - from .dicts.es.adverbs import adverbs - from .dicts.es.nouns import nouns - else: - raise ValueError("Language not implemented.") - if verbose: - print( - f"{lang} SHA256 Nick Generator initialized with:" - + f"\nUp to {len(adverbs)} adverbs." - + f"\nUp to {len(adjectives)} adjectives." - + f"\nUp to {len(nouns)} nouns." - + f"\nUp to {max_num+1} numerics.\n" - ) + # UNUSED + # elif lang == "Spanish": + # from .dicts.es.adjectives import adjectives + # from .dicts.es.adverbs import adverbs + # from .dicts.es.nouns import nouns + # else: + # raise ValueError("Language not implemented.") + # UNUSED + # if verbose: + # print( + # f"{lang} SHA256 Nick Generator initialized with:" + # + f"\nUp to {len(adverbs)} adverbs." + # + f"\nUp to {len(adjectives)} adjectives." + # + f"\nUp to {len(nouns)} nouns." + # + f"\nUp to {max_num+1} numerics.\n" + # ) self.use_adv = use_adv self.use_adj = use_adj @@ -84,11 +86,13 @@ class NickGenerator: # Compute adverb id if self.use_adv: - adv_id = int(nick_id / (self.max_num * num_nouns * num_adj)) - adv = self.adverbs[adv_id] - remainder = nick_id - adv_id * self.max_num * num_nouns * num_adj - if self.verbose: - print(f"Adverb: {adv}, id {adv_id}.") + pass + # UNUSED + # adv_id = int(nick_id / (self.max_num * num_nouns * num_adj)) + # adv = self.adverbs[adv_id] + # remainder = nick_id - adv_id * self.max_num * num_nouns * num_adj + # if self.verbose: + # print(f"Adverb: {adv}, id {adv_id}.") else: adv_id, adv, remainder = 0, "", nick_id @@ -154,69 +158,71 @@ class NickGenerator: nick pool diversity due to max_lenght restrictions. """ + return + # UNUSED + # import random + # import statistics - import random - import statistics + # attempts = [] + # for i in range(num_runs): + # string = str(random.uniform(0, 1_000_000)) + # hash = hashlib.sha256(str.encode(string)).hexdigest() - attempts = [] - for i in range(num_runs): - string = str(random.uniform(0, 1_000_000)) - hash = hashlib.sha256(str.encode(string)).hexdigest() + # _, _, pool_size, tries = self.short_from_SHA256(hash, max_length) + # attempts.append(tries) - _, _, pool_size, tries = self.short_from_SHA256(hash, max_length) - attempts.append(tries) + # median = statistics.median(attempts) + # mean = statistics.mean(attempts) - median = statistics.median(attempts) - mean = statistics.mean(attempts) - - print(f"\nFor max_length of {max_length}:") - print(f"Median loss of entropy factor is {median}.") - print(f"Mean loss of entropy factor is {mean}.") - print( - f"Approximate real pool is {human_format( int(pool_size/(mean+1)))} nicks in size." - ) + # print(f"\nFor max_length of {max_length}:") + # print(f"Median loss of entropy factor is {median}.") + # print(f"Mean loss of entropy factor is {mean}.") + # print( + # f"Approximate real pool is {human_format( int(pool_size/(mean+1)))} nicks in size." + # ) -if __name__ == "__main__": - # Just for code timming - t0 = time.time() +# UNUSED +# if __name__ == "__main__": +# # Just for code timming +# t0 = time.time() - # Hardcoded example text and hashing - nick_lang = "English" # Spanish - hash = hashlib.sha256(b"No one expected such cool nick!!").hexdigest() - max_length = 22 - max_iter = 100_000_000 +# # Hardcoded example text and hashing +# nick_lang = "English" # Spanish +# hash = hashlib.sha256(b"No one expected such cool nick!!").hexdigest() +# max_length = 22 +# max_iter = 100_000_000 - # Initialized nick generator - GenNick = NickGenerator(lang=nick_lang) +# # Initialized nick generator +# GenNick = NickGenerator(lang=nick_lang) - # Generates a short nick with length limit from SHA256 - nick, nick_id, pool_size, iterations = GenNick.short_from_SHA256( - hash, max_length, max_iter - ) +# # Generates a short nick with length limit from SHA256 +# nick, nick_id, pool_size, iterations = GenNick.short_from_SHA256( +# hash, max_length, max_iter +# ) - # Output - print( - f"Nick number {nick_id} has been selected among" - + f" {human_format(pool_size)} possible nicks.\n" - + f"Needed {iterations} iterations to find one " - + f"this short.\nYour nick is {nick} !\n" - ) - print(f"Nick lenght is {len(nick)} characters.") - print(f"Nick landed at height {nick_id/(pool_size+1)} on the pool.") - print(f"Took {time.time()-t0} secs.\n") +# # Output +# print( +# f"Nick number {nick_id} has been selected among" +# + f" {human_format(pool_size)} possible nicks.\n" +# + f"Needed {iterations} iterations to find one " +# + f"this short.\nYour nick is {nick} !\n" +# ) +# print(f"Nick lenght is {len(nick)} characters.") +# print(f"Nick landed at height {nick_id/(pool_size+1)} on the pool.") +# print(f"Took {time.time()-t0} secs.\n") - # Print many nicks - import random +# # Print many nicks +# import random - random.seed(1) +# random.seed(1) - for i in range(100): - string = str(random.uniform(0, 1_000_000)) - hash = hashlib.sha256(str.encode(string)).hexdigest() - print( - GenNick.short_from_SHA256(hash, max_length=max_length, max_iter=max_iter)[0] - ) +# for i in range(100): +# string = str(random.uniform(0, 1_000_000)) +# hash = hashlib.sha256(str.encode(string)).hexdigest() +# print( +# GenNick.short_from_SHA256(hash, max_length=max_length, max_iter=max_iter)[0] +# ) - # Other analysis - GenNick.compute_pool_size_loss(max_length, max_iter, 200) +# # Other analysis +# GenNick.compute_pool_size_loss(max_length, max_iter, 200)