crypto-org-chain / cronos

Cronos is the first Ethereum-compatible blockchain network built on Cosmos SDK technology. Cronos aims to massively scale the DeFi, GameFi, and overall Web3 user community by providing builders with the ability to instantly port apps and crypto assets from other chains while benefiting from low transaction fees, high throughput, and fast finality.
Other
290 stars 236 forks source link

Graphql endpoint #308

Open 0xsimulacra opened 2 years ago

0xsimulacra commented 2 years ago

Is your feature request related to a problem? Please describe.

Making multiple RPC calls to read contract storage data can be slow as the call need to go trough the EVM then converted to JSON format. If we could have a Graphql endpoint that reads directly trough the node database that would make the process faster.

Describe the solution you'd like

Based on this issue, it seems that Tendermint are not planning on supporting it : https://github.com/tendermint/tendermint/issues/3253 I'm talking about mainly supporting something like this: https://eips.ethereum.org/EIPS/eip-1767 In GETH we can start a graphql endpoint with our node by adding the argument --graphql to the geth command.

Describe alternatives you've considered

I made a first attempt to build one on my the node I'm running but I encountered a problem, not only that my knowledge right now would not let me decode effectively and in short time the data store in tx_data.db, state.db and blockstore.db located in the data directory, but as soon that I tried to access that data using python driver of leveldb database, the database apparently got corrupted and the node stopped syncing, I tried to restart it and it just crashed and I got the error : ERR failed to open DB: error="failed to intialize ddatabse: file missing".

Transaction indexing might be another alternative to achieve this solution but I can't figure out how yet. The main languages that I know most are python and javascript but mostly Python: https://docs.tendermint.com/master/app-dev/indexing-transactions.html

Additional context

Someone in the discord told that All I have to do to have something like the one in geth is just to install graphql on top of the node, I figure out that in top of that I needed to implement a resolver, and that's when I went to read the node database to see what I could do and by that action I corrupted the database since golelvedb only allow one process to read it at a time (but that process can have multiple threads, maybe that how geth do it).

Finally, I would like to know if there a possibility to achieve this in cronosd ? or that I should stop trying ? and if there is but no one is working on it, from where can I start please ?

yihuang commented 2 years ago

I think better move to ethermint repo.

0xsimulacra commented 2 years ago

Thanks for your input. You think I can move to ethermint repo and run a cronos node from there ? I imgaine I would need to learn the necessary part from ethermint repo and then learn how to port cronos node tot here ?

yihuang commented 2 years ago

Thanks for your input. You think I can move to ethermint repo and run a cronos node from there ? I imgaine I would need to learn the necessary part from ethermint repo and then learn how to port cronos node tot here ?

I mean the graphql server is best implemented in ethermint codebase, for example start the graphql server in the StartCmd(server/start.go).

0xsimulacra commented 2 years ago

Thanks you greatly for your fast response. I'm sorry, I'm learning different things in the same time and all of them are new to me. So I didn't get your response well.

Do you mean I should go to ethermint, run an ethermint node (which is Evmos now) to get the Grphql server although I'm interested in getting that server for the cronos chain ?

Or was it way of saying that ethermint have this capability and that cronos don't have this capability for now ?

By no mean, "cronosd" offer a way to interact with ethermint out of the box for now, so I also understood that I could look into how it is done in ethermint, add this functionality to cronos and compile it to get an new cronosd ?

yihuang commented 2 years ago

ethermint is the library shared by both cronos and evmos, if we add a feature to ethermint, it'll be available in cronos too.

0xsimulacra commented 2 years ago

This might be a dumb question to ask, so forgive my understanding please.

I've always run the cronos node using the "cronosd" binary provided, this binary doesn't offer access to ethermint or its functionalities as far as I see in the options available.

I now discovered trough some examples that Ethermint should be available under the "build" dir, so I'm now in the process of building the node locally that will hopefully give me access to Ethermint. That being said, is my understanding correct ? if so, is there any build options I should add to the build command so that ethermint is available ?

yihuang commented 2 years ago

ethermint is a depedency library of cronos, part of the cronosd is implemented there, so you need to find ethermint through options, it's internal stuff.

yihuang commented 2 years ago

It's also totally fine to implement it in cronos repo, do you have sth in progress?

0xsimulacra commented 2 years ago

I have nothing yet, I just compiled cronosd from source and all I got was the "cronosd" executable. I guess I'll be looking trough the build option if it gives me anything, next thing is reading the code source of both cronos and ethermint to find those options and see how to takle the problem from there, It was something I was planing to do anyway in the future (understand the evm part of the cosmos then understand cosmos-sdk). Your input was much valuable tough, I'll keep you updated if I get any progress unless you want to colaborate or guide me on this ?