datastore.py: update to meet new datastore builtin PR.

The new datastore PR now has a generation count; this passes
the tests against that now.

Also copies tests from c-lightning, and adds ugprade test.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-08-03 14:58:58 +09:30
committed by Christian Decker
parent 941c1b7141
commit 2ec769e05b
3 changed files with 236 additions and 33 deletions

View File

@@ -2,6 +2,7 @@
from pyln.client import Plugin, RpcError
import shelve
import os
from collections import namedtuple
plugin = Plugin()
@@ -10,12 +11,12 @@ plugin = Plugin()
def unload_store(plugin):
"""When we have a real store, we transfer our contents into it"""
try:
datastore = shelve.open('datastore.dat', 'r')
datastore = shelve.open('datastore_v1.dat', 'r')
except:
return
plugin.log("Emptying store into main store!", level='unusual')
for k, d in datastore.items():
plugin.log("Emptying store into main store (resetting generations!)", level='unusual')
for k, (g, d) in datastore.items():
try:
plugin.rpc.datastore(k, d.hex())
except RpcError as e:
@@ -23,7 +24,7 @@ def unload_store(plugin):
level='broken')
datastore.close()
plugin.log("Erasing our store", level='unusual')
os.unlink('datastore.dat')
os.unlink('datastore_v1.dat')
@plugin.init()