issue in consuming existing data after re-build and deploy nodes - corda

i created one transaction using . After that i made some changes in code and build and deploy the nodes successfully. I tried to consume previously created data to create new data. But it led to Contract constraints failed error. But i didn’t get any error at the time of creating new data and consuming the same to create another transaction at that instance.

TransactionVerificationException.ContractConstraintRejection
This exception is thrown when you have existing states in the vault and you updated the contract code and redeployed.
Every time at the node startup CorDapp Jar are scanned and Jar which has Contract classes are uploaded to attachment storage, and the hash of the Jar used as Attachment ID to attach the contract to a transaction.
Now, consider, you have a first fresh version of CorDapp - Attachment ID is: 3B6CA18330500C738455444115C49769D54074CE3CFFB194D8943F34494DB0A4
To create State on vault, you build the transaction, Corda auto-attach the contract using Attachment ID given above.
Then, consider, you changed the code and re-ployed the CorDapp, now jar hash changed, new Attachment ID is: F054BA8C1A67BAABF58539F8718B8A62DC770157D9F1D01434B86E73AD2A9217
My finding, when you create any new the transaction, Corda uses new/recent Attachment ID to attach specified contract.
For example, You want to update State already present on vault.
a. You created a transaction which has one input and it's output state.
b. You sent this transaction for verification.
c. There is check verifies that input state contract Attachment Id and current transaction Attachment Id must be same.
d. But right now input state pointing to old Attachment ID and transaction pointing new Attachment ID. Here check fails and throws a TransactionVerificationException.ContractConstraintRejection exception.

Related

Is Corda support state deletion scenario?

Is corda support state deletion scenario when don't need to use some state (in both dev/prod)
Because I face exception when start node like "class not found exception", It's happen when I delete state class in project and use same old persistence file.
I think it because of state class already insert in VAULT_STATES and it can't find that class when start node.
I expect to have some method that provide state deletion.
More info
In Dev side I delete persistence file and of course it's work, but I just worry about Production side.
As of Corda 3, if a node has a state stored as part of a transaction in its transaction storage or in its vault, the node needs to keep the state's class definition on its classpath permanently.
You can delete old transactions and states directly via the node's database, but only if the transactions are not required for transaction resolution. You would do this by dropping rows from the NODE_TRANSACTIONS and VAULT_STATES tables in the node's database (as well as any custom tables defined by the state's schemas if it is a QueryableState). However, if the deleted transactions are later required as part of transaction resolution, your node will throw an error.
Future versions of Corda may provide a mechanism to delete old or "non-current" states and transactions. You can find a discussion of what this process may look like here: https://groups.io/g/corda-dev/topic/20405353.
For development purposes you can simply just delete the persistence.mv.db file which is the entire H2 database. This will reset your corda node.
Of course don't do that for any production use.

Can I create Corda Custom Data Tables?

Reference code :-
GIT clone url :- git clone https://github.com/corda/cordapp-tutorial
Release M14 :- git checkout -b release-M14.0
I am little bit confused about how the data flows in Corda. I have some database releated queries:
Whether the database structure is fixed or we can add our custom tables in it?
Where can I see the data flowing in tables, when I do a cash transaction which I can see in VAULT_CASH_BALANCES
table in my H2 database client but apart from cash I am unable to see any details of my other transactiosn i.e. if I
save a string then I am unable to get the information, I only get the transaction Id for that.
Is it possible to get entire data flow diagram?
Do the Node and Vault tables created every time when I build a code?
You can define how each state type is stored in the node by implementing the QueryableState interface. Each state type that implements QueryableState will have its own custom database table.
See https://github.com/corda/cordapp-tutorial/blob/master/kotlin-source/src/main/kotlin/com/example/state/IOUState.kt for an example. Since the IOU state implements a schema (in the Kotlin version of the CorDapp), you can see the sender, recipient and value from the H2 interface for each IOU state.
In the current implementation, the node's data is stored in the persistence.mv.db file of the deployed node. This will be wiped whenever you run gradlew deployNodes. However, if you simply create an updated CorDapp jar by running gradlew jar, you can then copy the updated CorDapp jar from build/libs into each node's plugins folder, and the node will use the new plugin.

How to create Corda Custom Data Tables

Reference code:
Git clone URL: git clone https://github.com/corda/cordapp-tutorial
Release M14: git checkout -b release-M14.0
I am little bit confused about how the data flows in Corda. I have some database related queries:
Is the database structure fixed or can we add our custom tables in it?
Where can I see the data flowing in tables? When I do a cash transaction, I can see it in the AULT_CASH_BALANCES table in my H2 database client, but apart from cash I am unable to see any details of my other transactions, i.e., if I save a string then I am unable to get the information, I only get the transaction ID for that.
Is it possible to get entire data flow diagram?
Are the Node and Vault tables created every time when I build a code?
You can define how each state type is stored in the node by implementing the QueryableState interface. Each state type that implements QueryableState will have its own custom database table.
See https://github.com/corda/cordapp-tutorial/blob/master/kotlin-source/src/main/kotlin/com/example/state/IOUState.kt for an example. Since the IOU state implements a schema (in the Kotlin version of the CorDapp), you can see the sender, recipient and value from the H2 interface for each IOU state.
In the current implementation, the node's data is stored in the persistence.mv.db file of the deployed node. This will be wiped whenever you run gradlew deployNodes. However, if you simply create an updated CorDapp jar by running gradlew jar, you can then copy the updated CorDapp jar from build/libs into each node's plugins folder, and the node will use the new plugin.

How to add another regulatory node and add some functionality to it in corda DLT?

I would like to add a new Notary/Regulatory node in my Cordapp application ,
which should perform some extra validation checks when transaction
is completed between two parties.
so that notary/regulatory will be finally checks for some things and stamp the transaction.
There are two options here:
Instead of using the default FinalityFlow to notarise, broadcast and record transactions, you can implement your own flow that performs some additional validation before the notarisation step. The limitation here is that the checks are not part of the notary service.
Create your own custom notary. Here, the custom validation checks happen within the notary service. The ability to do this is a recent change to the codebase, as such the documentation has not been updated to reflect the changes, however the source docs can be found on github:
Instructions for creating a custom notary service: https://github.com/corda/corda/blob/9e563f9b98b79a308d68ecb01c80ce61df048310/docs/source/tutorial-custom-notary.rst
Sample custom notary service code: https://github.com/corda/corda/blob/9e563f9b98b79a308d68ecb01c80ce61df048310/docs/source/example-code/src/main/kotlin/net/corda/docs/CustomNotaryTutorial.kt
As Roger notes, you could customise FinalityFlow/implement your own notary.
An alternative would be:
Add a new node to the network representing some regulator
Write the contract rules so that the regulator is a required signer on transactions
Have the regulator do additional checking of the transaction in their flow before signing

Get a value which is being inserted in DB via an HTTP request and later being used in another transaction

JMeter Version: 2.9
Test Scenario:
To test purchase order creation process.
In the process, an HTTP request generates a temp id for the purchase being made and stores it into the DB. Later this tempid gets fethced from the DB and used in the purchase closure step.
Could anyone suggest how to get this temp id value from the DB and reuse the same later in the JMeter test plan in the purchase closure step.
If the value is stored in the DB only and doesn't appear anywhere in DOM (page source) the only way to get it is using JDBC Sampler (or JDBC Post Processor wrapped in Transaction Controller if you don't want extra sampler in your results and extra time being tracked to HTTP Request).
You'll need to know database URL, credentials, etc. and have a proper JDBC driver somewhere in JMeter classpath - download the JDBC driver for your database and drop it to /lib folder of your JMeter installation.

Resources