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

store and allow retrieval of transaction results #129

Merged
merged 8 commits into from
Jul 1, 2020

Conversation

psq
Copy link
Contributor

@psq psq commented May 30, 2020

This is work in progress, and by no means something to consider merging yet.

Background: as best I could tell, the way to get data about transactions without directly scanning the block database is to use Sidecar. You get a lot of information about each transaction, including all the events emitted (sweet!), but not what the transaction returned, which can be quite useful, and was lacking to implement a client for the Clarity hackaton.

Fortunately, the stacks-node server was emitting this data, so there was not much needed to be added to Sidecar. This PR includes the bare minimum I needed so far, but now I'd like to start a discussion on whether this should be something I should pursue further. See questions below.

With this PR, this lets you write client code like the one for the swapr contract where you get the (list dx dy) values returned by the transaction by just deserializing the content of tx_result which is ClarityValue. (calling this contract method)

Questions:

Bonus question: any doc or pointers on how to setup Postgres anywhere?

@aulneau
Copy link
Contributor

aulneau commented Jun 1, 2020

Hi @psq!

I don't actively work on this project but I do work on other things that consume it directly (stacks-explorer), and first of all I wanted to thank you for this! I was just talking about these features and how they'd be useful to expose within the sidecar. I don't have much to add as far as the architectural aspects of this PR, but wanted to let you know that we'll be able to answer your questions soon.

would you also store a more human readable version (like it is the case for events where both the hex and repr version are available)?

I think it seems to be the case that we are moving toward returning most things with that kind of shape, eg:

{
  hex: ...,
  repr: 'something human readable',
}

I know that in the applications I work on, it's very helpful to have the sidecar handle and deserialization/conversion from clarity values.

For the other stuff, I feel like @zone117x should be able to help out!

@psq
Copy link
Contributor Author

psq commented Jun 2, 2020

@aulneau adding a human readable deserialized field should be fairly easy, will add this while I wait to hear back

@psq
Copy link
Contributor Author

psq commented Jun 2, 2020

hmm, what happened to all the ci tests? Or was it because the last commit was trivial stuff that it didn't trigger? I was hoping to get it to rerun the tests as some are failing locally (faucet, pg) to see if it was better than last time.

@aulneau I changed tx_result to return

{
  hex: '0x0100000000000000000000000000000001',
  repr: '1',
}

instead of returning just the hex value, which should be similar to the way it is done for other CV values.

@CLAassistant
Copy link

CLAassistant commented Jun 29, 2020

CLA assistant check
All committers have signed the CLA.

@zone117x
Copy link
Member

Thanks for working on this @psq! Can you rebase your changes onto latest master? This PR should be good to go once the PR checks are passing, and a datastore unit test for the new field

@psq
Copy link
Contributor Author

psq commented Jun 29, 2020

definitely. The rebase did some very strange things, so I've redone it locally but now I'm getting the same block from the mempool added twice the first time I run a transaction on the node, so will looking at this before pushing a clean set of commits.

@psq psq force-pushed the feature/raw_result branch from 20e63d3 to 412903d Compare June 30, 2020 06:28
@psq psq marked this pull request as ready for review June 30, 2020 06:47
@psq
Copy link
Contributor Author

psq commented Jun 30, 2020

@zone117x I've rebuilt the PR, looks like it should have now.

Not sure what you mean by adding a datastore unit test, as I added support for the raw_result field in datastore-tests.ts to make it lint and pass, but perhaps you have something else in mind?

Also, I have no idea why the npm run build fails on the docket test, as this works fine locally. It looks like it is running on a different version of api-tests.ts as some line numbers do not match... And the test failures on the same file look off as well. Running npm test src/tests/api-tests.ts works fine locally. So any insight you could provide on how to make these tests pass on github would be welcome...

I figured out why the node was sending the tx twice: I was specifying the observer twice, once with an environment variable, and once from the toml file. That didn't use to cause issues, but that was before the mempool txs were added.

src/api/routes/tx.ts Outdated Show resolved Hide resolved
src/api/routes/tx.ts Outdated Show resolved Hide resolved
@zone117x
Copy link
Member

Also, I have no idea why the npm run build fails on the docket test, as this works fine locally. It looks like it is running on a different version of api-tests.ts as some line numbers do not match... And the test failures on the same file look off as well. Running npm test src/tests/api-tests.ts works fine locally. So any insight you could provide on how to make these tests pass on github would be welcome

Not sure what's going on here either. It's working locally for me as well. Might be some kind of caching issue in the github actions, or maybe something wrong with how PRs from forks are handled. I'm going to pull this into another PR for debugging purposes

@zone117x
Copy link
Member

zone117x commented Jun 30, 2020

Ahh I see the issue now. The PR just needs rebased on latest master (another PR was merged yesterday after your last rebase). Then the few test failures will show up locally and look like easy fixes

@zone117x
Copy link
Member

@psq btw I pushed a small fix (f23f586) to your branch for the schema types. The docs/index.d.ts file had manual edits, but this file is auto-generated from contents of docs/**/*.schema.json

@zone117x zone117x added this to the 2020 W25-W27 milestone Jun 30, 2020
@zone117x zone117x self-assigned this Jun 30, 2020
@psq psq force-pushed the feature/raw_result branch from 98168dd to 678acf8 Compare June 30, 2020 20:59
@psq
Copy link
Contributor Author

psq commented Jun 30, 2020

Ahh I see the issue now. The PR just needs rebased on latest master (another PR was merged yesterday after your last rebase). Then the few test failures will show up locally and look like easy fixes

Ah, yes, very good point, it runs the tests after merging with master, not the code in the PR branch. Fixing now.

@psq btw I pushed a small fix (f23f586) to your branch for the schema types. The docs/index.d.ts file had manual edits, but this file is auto-generated from contents of docs/**/*.schema.json

makes sense, thank you.

@codecov
Copy link

codecov bot commented Jun 30, 2020

Codecov Report

Merging #129 into master will increase coverage by 0.15%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #129      +/-   ##
==========================================
+ Coverage   56.87%   57.02%   +0.15%     
==========================================
  Files          40       41       +1     
  Lines        2553     2562       +9     
  Branches      404      406       +2     
==========================================
+ Hits         1452     1461       +9     
  Misses       1098     1098              
  Partials        3        3              
Impacted Files Coverage Δ
src/datastore/common.ts 67.05% <ø> (ø)
src/event-stream/core-node-message.ts 0.00% <ø> (ø)
src/api/controllers/db-controller.ts 59.69% <100.00%> (+0.62%) ⬆️
src/datastore/postgres-store.ts 83.37% <100.00%> (+0.03%) ⬆️
src/migrations/1593415759720_add-txs-raw-result.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 762ea51...8b7d3a7. Read the comment docs.

@psq
Copy link
Contributor Author

psq commented Jun 30, 2020

@zone117x yes, that was it. tests are back to green now 😂

Copy link
Member

@zone117x zone117x left a comment

Choose a reason for hiding this comment

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

Looks great, thank you @psq!

@psq
Copy link
Contributor Author

psq commented Jul 1, 2020

great, thank you for your help on this @zone117x
I don't have write access to the repo, so someone will have to merge it, unless someone else needs to review?

@zone117x zone117x merged commit 916343c into hirosystems:master Jul 1, 2020
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.

4 participants