Sharing an H2 database
As of Corda 3, each node spins up its own H2 database by default.
However, you can point multiple nodes to a single, stand-alone H2 database as follows:
- Start a standalone H2 instance (e.g.
java -jar ./h2/bin/h2-1.4.196.jar -webAllowOthers -tcpAllowOthers)
- In the
node.conf node configuration file, set dataSource.url = "jdbc:h2:tcp://localhost:9092/~/nodeUniqueDatabaseName", where nodeUniqueDatabaseName is unique to that node
For each nodeUniqueDatabaseName, H2 will create a file nodeUniqueDatabaseName.mv.db in the user's home directory.
You can also set a specific absolute path as well (e.g. dataSource.url = "jdbc:h2:tcp://localhost:9092/~/Users/szymonsztuka/IdeaProjects/corda3/nodeUniqueDatabaseName"). This will create a database file under Users/szymonsztuka/IdeaProjects/corda3/.
Note that this approach is not secure since the h2 server is started with -webAllowOthers -tcpAllowOthers, meaning that anyone can log in and modify the database.
Maintaining data across node builds
The H2 database is discarded when re-running deployNodes, because you are considered to be creating an entirely new set of nodes. If you only want to make changes to the installed CorDapps, you can shut down the node, update its CorDapps (by creating the new CorDapp JARs as described here and copying the CorDapp JARs into its cordapps folder) and restart the node. The new CorDapps will be installed, but the old node data will still be present.