Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty account_to_state_refs table #85

Closed
adelrustum opened this issue Jan 14, 2020 · 7 comments
Closed

Empty account_to_state_refs table #85

adelrustum opened this issue Jan 14, 2020 · 7 comments

Comments

@adelrustum
Copy link

adelrustum commented Jan 14, 2020

Corda Open Source 4.3
Tokens 1.1-RC01
Accounts 1.0
Confidential Identities 1.0

I assume that when you assign (e.g. issue, transfer) a state (e.g. FungibleToken) to an account; a new entry should appear in the account_to_state_refs table.
I noticed that this table is empty in my case, I assign FungibleTokens to accounts; I tested it with H2 and Postgres, locally and on GCP. In all cases, the table was empty.
Roger Willis mentioned that they tested this table and they didn't have any problems with it.
I create a repo (for a different issue), but I was able to recreate the issue in it; so please have a look: https://github.com/adelRestom/tokens-sdk-issue-172
Follow these steps to reproduce:

  • Deploy the nodes: ./gradlew deployNodes
  • Browse to the nodes (Notary, Mint, and Wallet): cd build/nodes/
  • Start all nodes (Notary, Mint, and Wallet): java -jar corda.jar
  • Inside Mint terminal Mint tokens: start MintFixedToken. This will mint 800.867681.
  • Inside Mint terminal Issue tokens: start IssueFixedToken. This will issue 0.867681 to an Account123 on Wallet node.
  • Open the H2 database: cd /bin/h2/bin, sh h2.sh, the DB port for Wallet node is 10091

You will see that the account is created inside accounts table, and the token is inside fungible_token table, but the account_to_state_refs table is empty.

The logs didn't show any errors.

@adelrustum
Copy link
Author

Please hold-off from investigating this for a bit; I have one idea that I want to test before I waste your time.

@roger-that-dev
Copy link

Can you query the vault specifying the account IDs of the accounts you want to return states for? E.g.

QueryCriteria.VaultQueryCriteria(externalIds = listOf(accountId))

Does it return the expected states? If so, there are no problems.

@roger-that-dev
Copy link

Also see these tests in the main Corda repo where this functionality is tested:

https://github.com/corda/corda/blob/4dd51de5c1d14901ce143502c21b87ac0863543f/node/src/test/kotlin/net/corda/node/services/vault/ExternalIdMappingTest.kt

The tests are run for every build in the Corda repo and don't seem to be failing.

@roger-that-dev
Copy link

I created my own flow in your project called QueryToken which looks like this:

@StartableByRPC
public class QueryToken extends FlowLogic<List<FungibleToken>> {
    private final ProgressTracker progressTracker = new ProgressTracker();

    @Override
    public ProgressTracker getProgressTracker() {
        return progressTracker;
    }

    private final String accountId;

    public QueryToken(String accountId) {
        this.accountId = accountId;
    }

    @Override
    @Suspendable
    public List<FungibleToken> call() throws FlowException {
        UUID uuid = UUID.fromString(accountId);
        QueryCriteria.VaultQueryCriteria vaultQueryCriteria = new QueryCriteria.VaultQueryCriteria().withExternalIds(Collections.singletonList(uuid));
        List<FungibleToken> states = getServiceHub().getVaultService()
                .queryBy(FungibleToken.class, vaultQueryCriteria)
                .getStates()
                .stream()
                .map(stateAndRef -> stateAndRef.getState().getData())
                .collect(Collectors.toList());
        return states;
    }
}

Then I ran it from the shell of the wallet node and I get:

Wed Jan 15 13:18:01 GMT 2020>>> start QueryToken accountId: 0ddc7c9f-1f1a-4760-a041-3ba555d84d5e

 ✅   Starting
➡️   Done
Flow completed with result: [0.867681 TokenType(tokenIdentifier='MyToken', fractionDigits=6) issued by Mint held by DLBPVBSf8JRBKZqc]

Wed Jan 15 13:18:09 GMT 2020>>> 

Which leads me to believe this is all working as expected. I.e. the mapping table is working as expected.

@adelrustum
Copy link
Author

Thanx Roger for looking into this; I never had an issue querying the vault by accounts inside my flows. My only observation is that when I use a SQL editor (e.g. pgAdmin) and I query that table; it's always empty.

@roger-that-dev
Copy link

Ah, that's because it's a view created by Liquibase at run-time. Cheers

@adelrustum
Copy link
Author

Makes sense now. Thanx Roger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants