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

Cannot get logs from HRC20 transactions #1

Open
mattlockyer opened this issue Dec 11, 2019 · 10 comments
Open

Cannot get logs from HRC20 transactions #1

mattlockyer opened this issue Dec 11, 2019 · 10 comments

Comments

@mattlockyer
Copy link
Contributor

mattlockyer commented Dec 11, 2019

This issue is tracking the lack of logs returned by Harmony Core SDK + RPC calls from the core protocol.

Specifically, the absence of logs for transactions.

See #2 for issues related directly to SDK / RPC

When calling directly via RPC by using the transaction id:

TXID=0xf6fa4d7912bc40c632627e52040b4af632f52f5c79d9b4648ca9a03cad2f4384
curl -X POST http://localhost:9500 -H 'Content-Type: application/json' -d '{
    "jsonrpc":"2.0",
    "method":"hmy_getTransactionReceipt",
    "params":["'$TXID'"],
    "id":1
}'

The response has no logs and an odd logsBloom value:

    gasUsed: 51338,
    logs: [],
    logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
    shardID: 0,
    ...

Will be uploading an example and some tests to HRC repo shortly.

@flicker-harmony
Copy link

As we discussed with Matt, Dennis, might even go on core level, because when getTransactionReceipt is performed it uses core GetReceipts method https://github.com/harmony-one/harmony/blob/master/internal/hmyapi/transactionpool.go#L283 which just wraps core GetReceiptsByHash method https://github.com/harmony-one/harmony/blob/master/core/blockchain.go#L720 which is pretty straightforward on how it should fetch tx logs.

@flicker-harmony
Copy link

I compared it with Ethereum implementation for https://github.com/ethereum/go-ethereum/blob/master/core/blockchain.go#L758 GetReceipts, Log and Receipt struct and they look almost identical with not significant changes. But still Receipts returned with no logs for txs or they incorrectly formed at the beggining when transaction is added to block. Need to debug core level.

@flicker-harmony
Copy link

https://github.com/harmony-one/harmony/blob/master/internal/hmyapi/filters/api.go#L272 this is proper method to fetch blocks which uses FilterCriteria as param.https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs how it works for Ethereum. It subscribes to logs for smart contract or just returns past logs for it.

@flicker-harmony
Copy link

Harmony-SDK uses that here https://github.com/harmony-one/sdk/blob/master/packages/harmony-network/src/subscriptions/LogSub.ts and https://github.com/harmony-one/sdk/blob/master/packages/harmony-contract/src/events/event.ts.
But @mattlockyer said that he couldn't even connect by websockets using those methods. So SDK might be badly connected with blockchain API. And Monetha and others don't use this hmy_getLogs method properly.

@flicker-harmony
Copy link

Still it doesn't answer question why logs on hmy_getTransactionReceipt are not returned and why they not fetched from core. blockchain API simply forwards it from core.

@flicker-harmony
Copy link

How can we debug it @mattlockyer @denniswon @john-harmony. Any engineer can set some debug utils logging at blockchain core method GetReceiptsByHash and see if len of logs fetched for some block when using hmy_getTransactionReceipt not zero. If it's zero then really discuss with core engineers and set up milestone to develop and debug this issue because in that case it's not gonna be fast fix.

@mattlockyer
Copy link
Contributor Author

Debugging the core protocol at:
https://github.com/harmony-one/harmony/blob/37935bb29f8bef8b582a0dd7c1fd3587de2235ba/core/rawdb/accessors_chain.go#L290

I added the following:

image

Using a deployment of https://github.com/harmony-one/HRC/blob/master/build/contracts/HarmonyERC20.json

I called the transfer function, which emits an event (it should be in the logs)!

Here are the logs after 1 contract deployment and transfer:

image

And after a second contract deployment and HRC20 transfer:

image

In both cases there are NEVER any logs for the receipts...

There are differences between Ethereum:
https://github.com/ethereum/go-ethereum/blob/d90d1db609c8d77baa422d49bd371207c06b4711/core/rawdb/accessors_chain.go#L476

And Harmony's implementation:
https://github.com/harmony-one/harmony/blob/37935bb29f8bef8b582a0dd7c1fd3587de2235ba/core/rawdb/accessors_chain.go#L290

My conclusion would be that there's something mis-matched in how we store and retrieve the logs.

This may also explain why every TX has a logsBloom of some length but filled with zeros...

@john-harmony
Copy link
Contributor

@LeoHChen your thoughts?

@flicker-harmony
Copy link

@john-harmony @mattlockyer @LeoHChen as it's not properly processed very deep at core level probably we should give a task to dedicated core engineer to work on that but we might be out of hands now

@mattlockyer
Copy link
Contributor Author

Probably in some testing someone commented this line in the core protocol:
https://github.com/harmony-one/harmony/blob/33905bc2edb5cde7859a4cf7d0cb92d65d0c1fcb/core/state_processor.go#L192

Uncommenting this yields the desired result from an HRC20 token transfer:

image

In case this was done purposefully...

We will need someone involved in with the core protocol to uncomment and properly stress test the emission and storage of logs on our network.

@rlan35 @LeoHChen

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

No branches or pull requests

3 participants