In Corda 3.2, when using the Cordform task, I might define a validating notary as follows:
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
directory "./build/nodes"
node {
name "O=Notary,L=London,C=GB"
notary = [validating : true]
p2pPort 10002
rpcSettings {
address("localhost:10003")
adminAddress("localhost:10043")
}
cordapps = [ ]
}
}
How do I define a validating notary when using the node driver?
When using the node driver, you use the notarySpecs parameter to define the notaries to create on the network:
fun main(args: Array<String>) {
val validatingNotarySpec = NotarySpec(CordaX500Name("ValidatingNotary", "London", "GB"), true)
val nonValidatingNotarySpec = NotarySpec(CordaX500Name("NonValidatingNotary", "London", "GB"), false)
val notarySpecs = listOf(validatingNotarySpec, nonValidatingNotarySpec)
driver(DriverParameters(notarySpecs = notarySpecs)) {
// Driver logic.
}
}
By default, you will get a single validating notary with the name CordaX500Name("Notary Service", "Zurich", "CH").
Related
Problem:
I am trying Corda official documentation hello word application. After Deploying CorDapp I issued
start IOUFlow iouValue: 99, otherParty: "O=PartyB,L=New York,C=US"
This command on Party A. After doing that I tried to check the ledger state by issuing this command on Party A and B.
run vaultQuery contractStateType: com.template.states.IOUState
But it gives the same output as the notary like this.
states: []
statesMetadata: []
totalStatesAvailable: -1
stateTypes: "UNCONSUMED"
otherResults: []
But Output should be like this.
states:
- state:
data:
value: 99
lender: "C=GB,L=London,O=PartyA"
borrower: "C=US,L=New York,O=PartyB"
participants:
- "C=GB,L=London,O=PartyA"
- "C=US,L=New York,O=PartyB"
contract: "com.template.contract.IOUContract"
notary: "C=GB,L=London,O=Notary"
encumbrance: null
constraint:
attachmentId: "F578320232CAB87BB1E919F3E5DB9D81B7346F9D7EA6D9155DC0F7BA8E472552"
ref:
txhash: "5CED068E790A347B0DD1C6BB5B2B463406807F95E080037208627565E6A2103B"
index: 0
statesMetadata:
- ref:
txhash: "5CED068E790A347B0DD1C6BB5B2B463406807F95E080037208627565E6A2103B"
index: 0
contractStateClassName: "com.template.state.IOUState"
recordedTime: 1506415268.875000000
consumedTime: null
status: "UNCONSUMED"
notary: "C=GB,L=London,O=Notary"
lockId: null
lockUpdateTime: 1506415269.548000000
totalStatesAvailable: -1
stateTypes: "UNCONSUMED"
otherResults: []
This is my build.gradle task deployNodes.
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
nodeDefaults {
projectCordapp {
deploy = true
}
cordapp project(':contracts')
cordapp project(':workflows')
}
directory "./build/nodes"
node {
name "O=Notary,L=London,C=GB"
notary = [validating : true]
p2pPort 10002
rpcSettings {
address("localhost:10003")
adminAddress("localhost:10043")
}
}
node {
name "O=PartyA,L=London,C=GB"
p2pPort 10005
rpcSettings {
address("localhost:10006")
adminAddress("localhost:10046")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
}
node {
name "O=PartyB,L=New York,C=US"
p2pPort 10008
rpcSettings {
address("localhost:10009")
adminAddress("localhost:10049")
}
rpcUsers = [[ user: "user1", "password": "test", "permissions": ["ALL"]]]
}
}
I tried a lot to find out a solution to this problem on the internet but I was unable to do so as I am a newcomer to Corda. Can someone help me to solve this issue? Thank you very much.
If you didn't get anything on the screen, then the flow didn't complete.
Check the logs of your nodes (inside build/nodes/PartyA/logs).
You can also start the node in debug mode (https://docs.corda.net/node-commandline.html#enabling-remote-debugging) and put breakpoints on your code to see where it's failing.
I have created a 3 node Corda network on a Linux instance and can initiate and complete flows between the 3 nodes of the network. However when I added a 4th node to the network on the same Linux Instance, any of the nodes in the existing network are unable to complete flows with the 4th node.
Here is the configuration of an existing node:
myLegalName="O=PartyA,L=Mumbai,C=IN"
p2pAddress="198.136.234.245:10005"
rpcSettings {
address="localhost:10006"
adminAddress="localhost:10046"
}
rpcUsers=[
{
password=test
permissions=[
ALL
]
user=user1
}
]
dataSourceProperties = {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
"dataSource.url" = "jdbc:postgresql://10.0.0.4:5432/postgres"
"dataSource.user" = test2
"dataSource.password" = test2p
}
database = {
transactionIsolationLevel = READ_COMMITTED
schema = test2
}
jarDirs = ['/home/ubuntu/java/postgres']
webAddress="198.136.234.245:10007"
Here is the configuration of a newly added node:
myLegalName="O=PartyB,L=Delhi,C=IN"
p2pAddress="198.136.234.245:10014"
rpcSettings {
address="localhost:10015"
adminAddress="localhost:10055"
}
rpcUsers=[
{
password=test
permissions=[
ALL
]
user=user1
}
]
dataSourceProperties = {
dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"
"dataSource.url" = "jdbc:postgresql://10.0.0.4:5432/postgres"
"dataSource.user" = test5
"dataSource.password" = test5p
}
database = {
transactionIsolationLevel = READ_COMMITTED
schema = test5
}
jarDirs = ['/home/ubuntu/java/postgres']
webAddress="198.136.234.245:10016"
Here's the message in PartyA's log file:
[INFO ] 2019-07-05T13:27:02,457Z [Node thread-1] flow.[ae2549c0-9bfd-4226-9625-653bc79322b0].initiateSession - Initiating flow session with party O=PartyB, L=Delhi, C=IN. Session id for tracing purposes is SessionId(toLong=5939067804807479907). {}
[INFO ] 2019-07-05T13:27:14,277Z [nioEventLoopGroup-2-4] netty.AMQPClient.operationComplete - Failed to connect to 198.136.234.245:10014 {}
...
[INFO ] 2019-07-05T13:27:15,278Z [nioEventLoopGroup-2-5] netty.AMQPClient.run - Retry connect to 198.136.234.245:10014 {}
deployNodes bootstraps the network. In short, the generated nodes know about each other and nothing else. Adding a new node to the network without running deployNodes will leave the original nodes communicating with each other but they will not see the new node. The new node will also not see the original nodes.
To resolve this, you can rebuild your network using deployNodes.
Or, you will need a network map which will handle the distribution of identities as nodes join the network. An implementation can be found here.
Facing this error when trying to connect Corda v3.3 to SQL server 2017.
Could not find method dataSourceProperties() for arguments [build_b58g7zpxmgi2o4qynsvg23rrl$_run_closure7$_closure18$_closure22#6e5d745d] on object of type
net.corda.plugins.Node.
deployNodes code snippet is
dataSourceProperties {
dataSourceClassName ("com.microsoft.sqlserver.jdbc.SQLServerDataSource")
dataSource.url ("jdbc:sqlserver://localhost:1433;databaseName=testdb")
dataSource.user (testuser)
dataSource.password (123)
}
database {
transactionIsolationLevel (READ_COMMITTED)
}
jarDirs = [".../Microsoft JDBC Driver 6.2 for SQL Server/sqljdbc_6.2/enu/"]
You are confusing the syntax of deployNodes with the syntax of the node.conf node configuration file.
If you want to add additional configuration options in deployNodes that will be copied to the node's node.conf file, you need to use extraConfig, as follows:
task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
directory "./build/nodes"
node {
name "O=PartyA,L=London,C=GB"
p2pPort 10007
rpcSettings {
address("localhost:10008")
adminAddress("localhost:10048")
}
cordapps = ["$corda_release_group:corda-finance:$corda_release_version"]
rpcUsers = [[user: "user1", "password": "test", "permissions": ["ALL"]]]
extraConfig = [
dataSourceProperties: [
dataSourceClassName: 'com.microsoft.sqlserver.jdbc.SQLServerDataSource',
dataSource : [
url : 'jdbc:sqlserver://localhost:1433;databaseName=testdb',
user : 'testuser',
password: '123'
]
],
database : [transactionIsolationLevel: 'READ_COMMITTED'],
jarDirs : ['.../Microsoft JDBC Driver 6.2 for SQL Server/sqljdbc_6.2/enu/']
]
}
}
I want to add the security property to my node configuration using Gradle. I'm trying to do something like the below:
node {
name "O=Bank_A,L=New York,C=US"
p2pPort 10005
rpcSettings {
address("localhost:10006")
adminAddress("localhost:10046")
}
h2Port 9005
cordapps = [
"$project.group:bank-abc:$project.version",
"$project.group:shared-contracts-states:$project.version",
"$corda_release_group:corda-finance:$corda_release_version"
]
security = {
authService = {
dataSource = {
type = "DB"
passwordEncryption = "SHIRO_1_CRYPT"
connection = {
jdbcUrl = "jdbc:h2:tcp://10.0.75.1:9014/node"
username = "some user"
password = "some pass"
driverClassName = "org.h2.Driver"
}
}
}
}
}
when I execute gradlew deployNodes. I get the below error:
What went wrong:
A problem occurred evaluating root project 'tbs-term-reciprocal-dapp'.
Could not set unknown property 'security' for object of type net.corda.plugins.Node.
In order to add security config, you need to use extraConfig within your node's Gradle script.
Taking your example, the extraConfig will look like this:
extraConfig = [
security : [
authService : [
dataSource : [
type: "DB",
passwordEncryption: "SHIRO_1_CRYPT",
connection : [
jdbcUrl: "jdbc:h2:tcp://10.0.75.1:9014/node",
username: "sa",
password: "",
driverClassName: "org.h2.Driver"
]
]
]
]
]
I'm deploying a corda network using two different machines: in the first I'm deploying a notary and an oracle service using the following configuration:
Notary
myLegalName="O=Notary,L=London,C=GB"
keyStorePassword : "cordacadevpass"
trustStorePassword : "trustpass"
p2pAddress="machine-ip1:10004"
notary : {
validating : false
}
devMode : true
Oracle
myLegalName="O=Oracle,L=London,C=GB"
keyStorePassword : "cordacadevpass"
trustStorePassword : "trustpass"
p2pAddress="machine-ip1:10001"
rpcSettings {
address="0.0.0.0:10002"
adminAddress="0.0.0.0:10003"
}
rpcUsers=[
{
password=test
permissions=[
ALL
]
user=user1
}
]
devMode : true
In the second I'm deploying the following party node:
Party
myLegalName="O=Party,L=London,C=GB"
keyStorePassword : "cordacadevpass"
trustStorePassword : "trustpass"
p2pAddress="machine-ip2:10001"
rpcSettings {
address="0.0.0.0:10002"
adminAddress="0.0.0.0:10003"
}
rpcUsers=[
{
password=test
permissions=[
ALL
]
user=user1
}
]
devMode : true
Once Party starts a flow building a transaction it fails raising this exception:
java.lang.IllegalStateException: Need to specify a notary for the state, or set a default one on TransactionBuilder
at net.corda.core.transactions.TransactionBuilder.addOutputState(TransactionBuilder.kt:172)
at net.corda.core.transactions.TransactionBuilder.addOutputState$default(TransactionBuilder.kt:171)
The call function is :
override fun call(): SignedTransaction {
val notary = serviceHub.networkMapCache.getNotary(CordaX500Name("Notary", "London", "GB"))!!
val issueState = CashOwningState(amount, ourIdentity)
val issueCommand = Command(
CashIssueContract.Commands.Issue(),
issueState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary).withItems(
StateAndContract(issueState, CashIssueContract.TEST_CONTRACT_ID),
issueCommand)
txBuilder.verify(serviceHub)
val fullySignedTx = serviceHub.signInitialTransaction(txBuilder)
return subFlow(FinalityFlow(fullySignedTx, FINALIZING_TX.childProgressTracker()))
}
It seems that the Notary is found in the network, but the CordApp doesn't recognize it as a notary.
This is not an issue of the CorDapp not recognising the notary. The only place this exception is thrown is here:
#JvmOverloads
fun addOutputState(state: ContractState, contract: ContractClassName, constraint: AttachmentConstraint = AutomaticHashConstraint): TransactionBuilder {
checkNotNull(notary) { "Need to specify a notary for the state, or set a default one on TransactionBuilder initialisation" }
addOutputState(state, contract, notary!!, constraint = constraint)
return this
}
When instantiating a TransactionBuilder by passing in a notary, no check is performed for whether the party being passed is in fact a notary.
You must be trying to add an output state to a TransactionBuilder without a notary somewhere else in your code.