Browse Source

lnaddr: 15x speedup for lndecode

benchmarked with:

```
import time
import electrum
from electrum.lnaddr import lndecode

electrum.constants.set_testnet()

inv = "lntb4m1p00zfpppp597ely08ffhk8n3emeswukt0y3qfvt3sj3ufkhnaatlrswj2xvwuqsp5vu3ezu44ka8arvgda44yalysp3k3edlvg56cjkk5lvu4e4anmdssdq2v9ekgctnvscqzynxqyz5vq9qypqsqrzjqv8shunq4nda8mw2mpxhtz8v03wlgug7sln2yvqklxym35ayz3erqxct8vqqqcqqqqqqqqlgqqqqqqgq9qrzjqdxvvgt048y4htef7r63r4ha9kctz3d6l3za0053ahe597wgrkc4gxct8cqqqfsqqqqqqqlgqqqqqqgq9qrzjqwyx8nu2hygyvgc02cwdtvuxe0lcxz06qt3lpsldzcdr46my5epmjxct8vqqqdcqqqqqqqlgqqqqqqgq9qrzjqf56jn5txtqqtepnd0ahg0qg5m5mavfajsx403rem9wgu6rue0de7xct8vqqqtgqqqqqqqlgqqqq86qq9qrzjq027z73uyyl7fy8pkrpcn7x0el82pz3fw974p2052de4uz4j5lqqxx49tuqqqwgqqqqqqqqqqqqqqqqqpurzjqfj34n62wztqjxl59w4drxekg04rrrtf08mdestwhtky84ds7ja0yxct8sqqq3qqqqqqqqlgqqqqqqgq9qrzjqd872t5c5r5a8ssmwelpkdccsyn9mrr40rpp7khad4jr3kssxj9nvx49vgqqqnqqqqqqqqlgqqqq05qqgcxwu0ervh6atmqmqv7pmenhmc207gncyj0mcxedpwm8f56y2yl3qpq6mzjak37ddmeayd9unektmffv5rq8dvlpgq00rmmdalda73yhgqep0zuz"

def f():
  for _ in range(100):
    addr = lndecode(inv)

t0 = time.monotonic()
f()
t1 = time.monotonic()
print(f"{t1-t0:.4f}")
```
patch-4
SomberNight 4 years ago
parent
commit
d7597d96d0
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 8
      electrum/lnaddr.py

8
electrum/lnaddr.py

@ -63,12 +63,12 @@ def unshorten_amount(amount) -> Decimal:
else:
return Decimal(amount)
_INT_TO_BINSTR = {a: '0' * (5-len(bin(a)[2:])) + bin(a)[2:] for a in range(32)}
# Bech32 spits out array of 5-bit values. Shim here.
def u5_to_bitarray(arr):
ret = bitstring.BitArray()
for a in arr:
ret += bitstring.pack("uint:5", a)
return ret
b = ''.join(_INT_TO_BINSTR[a] for a in arr)
return bitstring.BitArray(bin=b)
def bitarray_to_u5(barr):
assert barr.len % 5 == 0

Loading…
Cancel
Save