How to reparse Counterparty DB on Federated Node?

In case you suffer from a sudden system failure, Sqlite DB may end up in inconsistent state.

2014-12-30-T19:50:31+0000 [ERROR] Unhandled Exception
Traceback (most recent call last):
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/counterpartyd.py", line 656, in <module>
    db = database.get_connection(read_only=False)
  File "/home/xcp/counterpartyd_build/dist/counterpartyd/lib/database.py", line 87, in get_connection
    raise exceptions.DatabaseError('Integrity check failed.')
lib.exceptions.DatabaseError: Integrity check failed.

For stand-alone counterparty-server, stop counterparty-server and then reparse the correct (mainnet or testnet) database.

On Counterblock Federated Node, use this format:

sudo su -s /bin/bash -c 'counterparty-server reparse' xcpd

For testnet, you can add --config-file /home/xcp/.config/counterparty/server.testnet.conf to the reparse command to let the CLI know it needs to use database specified in particular config file (a testnet database, for example).

After that you can restart counterparty-server for the correct network.

You can also download a new DB (see below and http://counterparty.io/docs/federated_node/ for details).

After reparse is finished, you can start service again.

Alternative Approach: Download Recent Database from the Web or Another Server

If your DB can’t be fixed, or reparse takes too long, you can download a recent copy from the Web or another server.

Stop the service, move the corrupt DB elsewhere, go to the location of your corrupt DB (mainnet or testnet), download a good Counterparty Sqlite DB, decompress it and give it correct ownership. Then you can start the service again. It should catch up within less than 1 hour.

ubuntu@ubuntu:/home/xcp/.config/counterpartyd$ sudo gunzip counterpartyd-db.latest.tar.gz
ubuntu@ubuntu:/home/xcp/.config/counterpartyd$ sudo tar xfv counterpartyd-db.latest.tar
counterpartyd.9.db
counterpartyd.9.testnet.db
ubuntu@ubuntu:/home/xcp/.config/counterpartyd$ sudo dir -la
total 837764
drwxr-xr-x 2 xcpd xcp 4096 Dec 31 07:50 .
drwxr-xr-x 6 root root 4096 Dec 19 03:00 ..
-rw-r--r-- 1 ubuntu ubuntu 428346368 Dec 29 11:45 counterpartyd.9.db
-rw-r--r-- 1 ubuntu ubuntu 148480 Dec 3 02:32 counterpartyd.9.testnet.db
-rw-rw---- 1 xcpd xcp 225 Dec 29 19:57 counterpartyd.conf
-rw-r--r-- 1 root root 428503040 Dec 30 11:35 counterpartyd-db.latest.tar
ubuntu@ubuntu:/home/xcp/.config/counterpartyd$ sudo chown xcpd:xcp *.*
ubuntu@ubuntu:/home/xcp/.config/counterpartyd$ dir -la
total 837764
drwxr-xr-x 2 xcpd xcp 4096 Dec 31 07:50 .
drwxr-xr-x 6 root root 4096 Dec 19 03:00 ..
-rw-r--r-- 1 xcpd xcp 428346368 Dec 29 11:45 counterpartyd.9.db
-rw-r--r-- 1 xcpd xcp 148480 Dec 3 02:32 counterpartyd.9.testnet.db
-rw-rw---- 1 xcpd xcp 225 Dec 29 19:57 counterpartyd.conf
-rw-r--r-- 1 xcpd xcp 428503040 Dec 30 11:35 counterpartyd-db.latest.tar
ubuntu@ubuntu:/home/xcp/.config/counterpartyd$