-
Notifications
You must be signed in to change notification settings - Fork 95
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
Finish Rosetta Endpoints #1050
Conversation
…web-node into rosetta-block-endpoints
…tta-block-endpoints
…web-node into rosetta-block-endpoints
There was a problem hiding this 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
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: No longer applies. When account not present, just return a balance of RosettaCouldNotRetrieveBalance
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/Util.hs
Outdated
-> T.Text | ||
-> ExceptT RosettaFailure Handler Decimal | ||
getHistoricalLookupBalance cr bh k = do | ||
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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! 😎
There was a problem hiding this comment.
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:
readCoinAccount |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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 inUtil
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/Rosetta/Util.hs
Outdated
-> T.Text | ||
-> ExceptT RosettaFailure Handler Decimal | ||
getHistoricalLookupBalance cr bh k = do | ||
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key |
There was a problem hiding this comment.
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
nonGenesisTransaction' | ||
logs _crReqKey _crTxId rosettaTransaction initial rest target | ||
|
||
nonGenesisTransaction' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
-> T.Text | ||
-> ExceptT RosettaFailure Handler Decimal | ||
getHistoricalLookupBalance cr bh k = do | ||
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key |
There was a problem hiding this comment.
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/Rosetta/Util.hs
Outdated
-> T.Text | ||
-> ExceptT RosettaFailure Handler Decimal | ||
getHistoricalLookupBalance cr bh k = do | ||
someHist <- liftIO $ (_pactHistoricalLookup cr) bh d key |
There was a problem hiding this comment.
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:
readCoinAccount |
…-node into rosetta-block-endpoints
Co-authored-by: Emily Pillmore <emily@kadena.io>
…tta-block-endpoints
…eb-node into rosetta-block-endpoints
There was a problem hiding this 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. 👍
fundTx
.Future Work: