Skip to content

Commit 498c789

Browse files
committed
pyln-testing: routines to save/restore entire blockchain.
Good for making test snapshots. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 6a81f07 commit 498c789

File tree

1 file changed

+14
-0
lines changed
  • contrib/pyln-testing/pyln/testing

1 file changed

+14
-0
lines changed

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,20 @@ def simple_reorg(self, height, shift=0):
551551
def getnewaddress(self):
552552
return self.rpc.getnewaddress()
553553

554+
def save_blocks(self):
555+
"""Bundle up blocks into an array, for restore_blocks"""
556+
blocks = []
557+
numblocks = self.rpc.getblockcount()
558+
for bnum in range(1, numblocks):
559+
bhash = self.rpc.getblockhash(bnum)
560+
blocks.append(self.rpc.getblock(bhash, False))
561+
return blocks
562+
563+
def restore_blocks(self, blocks):
564+
"""Restore blocks from an array"""
565+
for b in blocks:
566+
self.rpc.submitblock(b)
567+
554568

555569
class ElementsD(BitcoinD):
556570
def __init__(self, bitcoin_dir="/tmp/bitcoind-test", rpcport=None):

0 commit comments

Comments
 (0)