Skip to content

Upgrade Guide

Wouter den Bakker edited this page Nov 29, 2019 · 1 revision

Upgrade v1 to v2

Before you upgrade:

  • See the processor changelog and node changelog for breaking changes. If you use smart contracts that are affected by breaking changes do NOT upgrade.
  • If you use the postgres database for other purposes pay special attention to various rights revoked from PUBLIC in the new database setup. Eighter assign these rights to all roles needing them or skip that part of the upgrade script. If skipping be sure to avoid using these rights when writing smart contracts.
  • If you do not want to upgrade the node.js or postgres version make sure to change the version in the docker (compose) file to the one you are currently using.
    • Otherwise make sure your smart-contracts are not affected by the breaking changes for the new node.js and postgres versions.
    • If you are running docker you can use 'docker ps' to find the container id and 'docker exec -it CONTAINER_ID /bin/bash' for a shell in the postgres container. See the postgres documentation for how to upgrade.
  • If you wish to upgrade components one at the time start with the processor, then the node, then the server and finally the client.
    • If you are running a node you can upgrade it independent of the processor, but must be done before new version 2 contracts are created.
  • Consider making a database backup before performing the upgrade.

The upgrade:

  • Follow the Setup for how you want to deploy it.
    • Change the config options to the config you are currently using. Make sure to change the postgres/node.js version in the docker (compose) files to match what you are currently using as well if you do not wish to upgrade them.
    • When building the docker you want to use the --pull and --no-cache arguments to force it to download the latest version.
  • Follow the Shutdown for the component(s) you want to upgrade. If using docker compose follow the same shutdown as docker, so you do not shutdown the database yet.
  • If upgrading the processor run the script below. If upgrading a non-processor node run the script below but replace 'processor' with 'node'.
/* Check if not already upgraded. */
DO $$
BEGIN
	IF (SELECT EXISTS(SELECT 1 FROM information_schema.columns WHERE table_schema = 'basics' AND table_name='contracts' AND column_name = 'validana_version')) THEN
		RAISE EXCEPTION 'Already upgraded.';
	END IF;
END $$;
/* Check if there are no incompatible transactions. */
DO $$
BEGIN
	IF (SELECT EXISTS(SELECT 1 FROM basics.transactions WHERE payload::TEXT = '[]' AND status != 'invalid' AND status != 'new')) THEN
		RAISE EXCEPTION 'Unable to upgrade, incompatible transaction found.';
	END IF;
END $$;
/* Check if no half-processed transactions. */
DO $$
BEGIN
	IF (SELECT EXISTS(SELECT 1 FROM basics.transactions WHERE status = 'processing_accepted' OR status = 'processing_rejected')) THEN
		RAISE EXCEPTION 'Unable to upgrade, incomplete block found, please finish processing the current block and do a graceful shutdown.';
	END IF;
END $$;
/* Give notice if extra1 or extra2 columns are used. */
DO $$
BEGIN
	IF (SELECT EXISTS(SELECT 1 FROM basics.transactions WHERE extra1 IS NOT NULL OR extra2 IS NOT NULL)) THEN
		RAISE NOTICE 'Note that extra1 and extra2 will no longer be used after upgrade.';
	END IF;
END $$;
/* Transfer ownership to the new role. */
DO $$ BEGIN
	IF NOT EXISTS (SELECT * FROM pg_catalog.pg_roles WHERE rolname = 'smartcontract') THEN
		CREATE ROLE smartcontract;
	END IF;
END $$;
REASSIGN OWNED BY processor TO smartcontract;
/* Add contract version column. */
ALTER TABLE basics.contracts ADD COLUMN validana_version SMALLINT NOT NULL DEFAULT 1;
  • If upgrading the processor or a non-processor node now run the Processor Database Setup or Node Database Setup. Make sure to check the script for any options you do not want to use.
  • If you want to upgrade the postgres version now is a good time.
  • If using docker compose you can now shutdown the database docker as well. (docker ps for container id, docker stop CONTAINER_ID to stop it.)
  • Follow the Setup for starting the new version. You may need to use different names if using docker or remove the old containers first with 'docker rm CONTAINER_NAME'.

Clone this wiki locally