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

Add owner/creator to LinearState to allow ordering by "mine" records first #7139

Open
adamturski opened this issue Mar 31, 2022 · 5 comments
Labels

Comments

@adamturski
Copy link

LinearState has a list of participants which will be automatically notified about changes etc.
Let's say that I have 2 nodes and on both nodes I created 2 states and shared them between nodes, by adding both parties on their participants list, for example:
PARTY_A: state1 (PARTY_A, PARTY_B)
PARTY_B: state2 (PARTY_B, PARTY_A)
PARTY_A: state3 (PARTY_A, PARTY_B)
PARTY_B: state4 (PARTY_B, PARTY_A)

let's say that states implement PersistableState, meaning that in DB both nodes has vault_states records [state1, state2, state3, state4].

My need is now to get all RELEVANT (where my party is on participants list) states but order them by putting mine records first, e.g.
state1 (originally created by PARTY_A)
state3 (originally created by PARTY_A)
state2 (originally created by PARTY_B)
state4 (originally created by PARTY_B)

How can I achieve that? Is it even possible? I was able to achieve that but my solution looks hacky.

@r3jirabot
Copy link

Automatically created Jira issue: CORDA-4240

@adelel1
Copy link
Collaborator

adelel1 commented Apr 14, 2022

HI, If you have a custom schema for your state you could add an issuer column and store the issuer in that column. Then use this to determine which states are yours.

@adamturski
Copy link
Author

@adelel1 Issuer column is not enough to achieve "sorting by mine first" because you cannot pass your Party to "ORDER BY" clause. With issuer column only it would be possible to sort by issuer name which is not the same as take mine states first/last.
In my implementation I had to add "issuer: Party" on a state and a flag "ourState: Boolean" on a persistent state which is calculated comparing issuer column and current party from a flow.

In the end I think that something like issuer/creator/owner should be part of the LinearState, just to know who created that state.

@adelel1
Copy link
Collaborator

adelel1 commented Apr 27, 2022

HI, Your workaround seems reasonable. To add issuer to linear state would be an enhancement request. There is an internal Jira ticket CORDA-4240 created to track this.

@adamturski
Copy link
Author

@adelel1 One of the problem with my solution is that inside of a XState I'm extracting something from flow, in this case current Party. It is not perfect, because ideally I would like to get account, but since I'm in context of a contract.jar I cannot use anything from workflows.jar.

override fun generateMappedObject(schema: MappedSchema): PersistentState {
  val currentParty = FlowLogic.currentTopLevel?.serviceHub?.myInfo?.legalIdentities?.first()
  val isOurState = hostParty.equals(currentParty)
  return XPersistentState(
    ...
    ourState = isOurState
  )
)

I saw one of the ticket (https://r3-cev.atlassian.net/browse/CORDA-4229) which was suggesting to move state to persistent state migration to workflows. That would be perfect because then we could use workflow stuff.

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

No branches or pull requests

4 participants