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

Finish Rosetta Endpoints #1050

Merged
merged 57 commits into from
Jun 18, 2020
Merged

Finish Rosetta Endpoints #1050

merged 57 commits into from
Jun 18, 2020

Conversation

LindaOrtega
Copy link
Contributor

@LindaOrtega LindaOrtega commented May 14, 2020

  • Add /account/balance endpoint (merge Adds /account/balance endpoint #1047 into this one and close)
  • Add /block endpoint
  • Add /block/transaction endpoint
  • Finish up /network/options (add enumeration of operation statuses and types allowed)
  • Refactor helper functions to Rosetta Utils module
  • Investigate how continuations and rollbacks affect coin accounts. Findings: We already see this in fundTx.
  • Address review comments
  • Add unit test to check logic of matching logs to all block transactions
  • Add unit test to check logic for matching logs to single transaction
  • Add unit test to check conversion from KDA to Rosetta Amount
  • Add unit test to check validating networkId correctly
  • Fix failing txLog history test
  • Merge in /mempool endpoint once merged into master
  • Verify that Rosetta Transaction Id being parsed and created in standard way across endpoints
  • Successfully run rosetta validator on local development node db
  • Adds historical balance lookup internal API using similar approach to Pact block history query #1046
  • Fix account address sanitization

Future Work:

  • Add gas price and gas limit in metadata for /mempool/transaction and transaction in general.
  • When creating Operations figure out how to efficiently add "related operations" (an optional Rosetta field in the Operation type). Already including TxId and operation id is generated based on the order the logs appeared in.
  • Investigate how Rosetta validator tool handles continuations and cross-chain transactions. Especially if cross-chain wrapped inside of another function.
  • Add Rosetta endpoint tests #1073
  • Enable Rosetta config #1072
  • Add Show instances to Rosetta types for better debugging: Add Show instances rosetta#9

@LindaOrtega LindaOrtega marked this pull request as ready for review May 20, 2020 18:08
Copy link
Member

@emilypi emilypi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First past done, but I need to stare at the algorithm for txlogs some more before approval

src/Chainweb/Rosetta/RestAPI.hs Outdated Show resolved Hide resolved
RosettaError 7 "Historical account balance lookup is not supported." False
rosettaError RosettaPactExceptionThrown =
RosettaError 7 "A pact exception was thrown" False
rosettaError RosettaPactErrorThrown = RosettaError 8 "Transaction failed with a pact error" False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it spec that Rosetta be mixed up with Pact like this? Why would Rosetta care if a tx failed? That's still a valid tx to the blockchain.

Copy link
Contributor Author

@LindaOrtega LindaOrtega May 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only thrown when looking up account balance fails with a pact error, which (assuming I constructed the local command correctly) should only happen if the account doesn't exist. I changed it to something more user friendly: RosettaCouldNotRetrieveBalance No longer applies. When account not present, just return a balance of 0.0.

@emilypi
The only time a specific "Pact" rosetta error thrown is via RosettaPactExceptionThrown. This is thrown by getTxLogs and getHistoricalLookupBalance, when the internal pact API throws an error. Not sure if this should be encapsulated into another less specific Rosetta Error.

src/Chainweb/Rosetta/RestAPI/Server.hs Outdated Show resolved Hide resolved
@LindaOrtega LindaOrtega changed the title Add /block endpoints Finish Rosetta Endpoints May 21, 2020
@LindaOrtega LindaOrtega mentioned this pull request Jun 9, 2020
2 tasks
-> T.Text
-> ExceptT RosettaFailure Handler Decimal
getHistoricalLookupBalance cr bh k = do
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key
Copy link
Contributor Author

@LindaOrtega LindaOrtega Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be subject to sql injection? Is it okay to use the bare text submitted by the user when its going to be used to form sql statements (sql statement used: https://github.com/kadena-io/chainweb-node/pull/1050/files#diff-1cee5293be7515e25b6f00d33b117ac5R333-R339)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a concern. @emilypi is there Haskell code (as opposed to the pact code in coin) for validating account IDs somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, in the future you should consider possibly making _pactHistoricalLookup return the last two transactions (since your SQL is already a LIMIT 1 affair). Why? Because we can do deltas with that! 😎

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we have haskell code for this. We only validate decimal inputs iirc, but we can definitely write that or reuse this code if we have access to a pact db handel:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slpopejoy regarding returning the last two transactions, I've made an issue for it here: #1078

@slpopejoy and @emilypi regarding the potential sql injection via account address: I've added the following code to check that the account address is a valid Pact Name (since I believe row keys need to be valid Name correct?)
https://github.com/kadena-io/chainweb-node/pull/1050/files#diff-04e165a290c33e67270413e0ae8c3d85R515-R519

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I need to reconsider this approach. It throws an errors with "address": "POTENT AF MINER" on mainnet. This seems to be to strict

Copy link
Contributor

@sirlensalot sirlensalot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow what a huge effort! The two things I wish were less complex but seems unavoidable at this point:

  • The fork-checking for the PartialBlockId stuff. I can't really see around it, but Checkpointer is already at the "current fork" so if somehow we could just send that straight to Checkpointer you wouldn't have to bother.
  • The heuristics for assembling the txlog triples. No idea what would be a better way there ...
    Finally the indirection I noted, you don't have to change it but I find the code in Util a little hard to follow. Fine to leave it for now in interests of delivery.

Requesting changes mainly for the genesis block check stuff in checkpointer.

src/Chainweb/Pact/Backend/RelationalCheckpointer.hs Outdated Show resolved Hide resolved
-> T.Text
-> ExceptT RosettaFailure Handler Decimal
getHistoricalLookupBalance cr bh k = do
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's a concern. @emilypi is there Haskell code (as opposed to the pact code in coin) for validating account IDs somewhere?

src/Chainweb/Rosetta/Util.hs Outdated Show resolved Hide resolved
nonGenesisTransaction'
logs _crReqKey _crTxId rosettaTransaction initial rest target

nonGenesisTransaction'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not seeing why there's the function indirection here (getXXX) arguments since this is only used once, is that for tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also same comment as above regarding polymorphism and roles of a and b, it makes it hard to understand what is being accomplished here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got rid of the getXXX indirection. And yes part of the indirection was there for the tests because debugging is easier with Either String rosettaTx. But I added the conversion of the Either String rosettaTx to the matchLogs function.

@slpopejoy @emilypi I tried to simplify the matching logic and cut down on the polymorphism. See this commit for exactly what changed: ee355f5

src/Chainweb/Rosetta/Util.hs Outdated Show resolved Hide resolved
src/Chainweb/Rosetta/Util.hs Outdated Show resolved Hide resolved
src/Chainweb/Rosetta/Util.hs Show resolved Hide resolved
-> T.Text
-> ExceptT RosettaFailure Handler Decimal
getHistoricalLookupBalance cr bh k = do
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, in the future you should consider possibly making _pactHistoricalLookup return the last two transactions (since your SQL is already a LIMIT 1 affair). Why? Because we can do deltas with that! 😎

src/Chainweb/Pact/Backend/InMemoryCheckpointer.hs Outdated Show resolved Hide resolved
-> T.Text
-> ExceptT RosettaFailure Handler Decimal
getHistoricalLookupBalance cr bh k = do
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe we have haskell code for this. We only validate decimal inputs iirc, but we can definitely write that or reuse this code if we have access to a pact db handel:

@LindaOrtega LindaOrtega requested a review from emilypi June 15, 2020 18:49
Copy link
Contributor

@larskuhtz larskuhtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do a full review, but checked that there are not adverse effects for other chainweb components. 👍

@emilypi emilypi merged commit d75df80 into master Jun 18, 2020
@emilypi emilypi deleted the rosetta-block-endpoints branch June 18, 2020 18:21
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

Successfully merging this pull request may close these issues.

5 participants