corda / accounts

Accounts on Corda
Other
36 stars 38 forks source link

Incorrect result with Token intergration using Accounts #83

Closed saraGeorge closed 4 years ago

saraGeorge commented 4 years ago

Hi,

I have executed ConfidentialIntegrationTest provided in the examples folder. I have added another account on both nodes A and B. Hence following is my configuration Node A -> Account A1 and Account A2 Node B -> Account B1 and Account B2

Process 1: Step 1: Issue 100 tokens to A1 and A2 : Expected Balances: A1 - 100, A2 -100 ,B1 -0 ,B2 - 0 Actual Balances : A1 - 100, A2 -100 ,B1 -0 ,B2 - 0

Step 2: Move 25 units from A1 - B1 Expected Balances: A1 - 75, A2 -100 ,B1 -25 ,B2 - 0 Actual Balances : A1 - 75, A2 -100 ,B1 -25 ,B2 - 0

Step 3: Move 30 units from A2 - B2 Expected Balances: A1 - 75, A2 -70 ,B1 -25 ,B2 - 30 Actual Balances : A1 - 75, A2 -70 ,B1 -25 ,B2 - 30

Step 4: Move 25 units from A1 - B1 Expected Balances: A1 - 50, A2 -70 ,B1 -25,25 (50) ,B2 - 30 Actual Balances : A1 - 50, A2 -70 ,B1 -25,25 (50) ,B2 - 30

Process 2: Restart the whole process

Step 1: Issue 100 tokens to A1 and A2 : Expected Balances: A1 - 100, A2 -100 ,B1 -0 ,B2 - 0 Actual Balances : A1 - 100, A2 -100 ,B1 -0 ,B2 - 0

Step 2: Move 25 units from A1 - B1 Expected Balances: A1 - 75, A2 -100 ,B1 -25 ,B2 - 0 Actual Balances : A1 - 75, A2 -100 ,B1 -25 ,B2 - 0

Step 3: Move 25 units from A1 - B1 Expected Balances: A1 - 50, A2 -70 ,B1 -25,25 (50) ,B2 - 30 Actual Balances : A1 - 75, A2 -75 ,B1 -25,25 (50) ,B2 - 0

Step 4: Move 30 units from A2 - B2 Expected Balances: A1 - 75, A2 -70 ,B1 -25 ,B2 - 30 Actual Balances : A1 - 75, A2 -45 ,B1 -25 ,B2 - 30

As you can see transfer happens in an alternate fashion from the accounts in Node A. I have also executed the same test by explicitly by specifying public key of the Account instead of using the Node's Legal identity. I have found it to behave in the same manner.

Can somebody please explain what is going on in the above scenario? Is there anyway to mitigate this error and ensure that the tokens are indeed deducted from the expected accounts.

Thanks in advance

roger-that-dev commented 4 years ago

Thanks for the post. Are you sure you are selecting the tokens from the correct account when spending? If you don't specify an account via VaultQueryCriteria then your node probably will select tokens belonging to other accounts, or if you have specified the wrong account, then tokens will be selected from that account only. Also, perhaps the issue could be that the public keys you are using were not allocated to the correct/expected accounts initially. I've tested this and it works when I've done the above but perhaps there is a subtle edge case we missed. Do you have any code you can post ?

saraGeorge commented 4 years ago

Adding VaultQueryCriteria solves the problem. Thanks

roger-that-dev commented 4 years ago

Boom! - good stuff. Cheers