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

feat: add support for eth_getBlockReceipts #12478

Conversation

virajbhartiya
Copy link
Member

Related Issues

Fixes #12429

Proposed Changes

Implimented eth_getBlockReceipts method which accepts a block number and returns all the transaction receipts for it

Additional Info

QuickNode
Infura

Checklist

Before you mark the PR ready for review, please make sure that:

@virajbhartiya
Copy link
Member Author

As far as my understanding of deferred execution, it refers to the scheduling or delaying of actions within the Filecoin protocol in smart contracts or while processing messages. Also, Filecoin nodes maintain a replicated state machine, and state transitions may be deferred while validation of proofs or consensus confirmations haven't been met.

For chain forks, it occur when two or more valid blocks are mined at the same height but from different miners, creating divergent chains. I am still reading about the Expected Consensus mechanism but it chooses which fork to go forward with based on which chain has the highest aggregate power of the miners that have contributed to that chain.

api/api_full.go Outdated Show resolved Hide resolved
chain/events/filter/event.go Outdated Show resolved Hide resolved
gateway/node.go Outdated Show resolved Hide resolved
node/impl/full/eth.go Outdated Show resolved Hide resolved
events := make([]*filter.CollectedEvent, 0, len(executedMsgs))
for _, em := range executedMsgs {
for _, ev := range em.Events() {
addr, err := address.NewIDAddress(uint64(ev.Emitter))
Copy link
Member

Choose a reason for hiding this comment

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

We're going to need to check this, does it produce what we want? I suspect not, you'll find out if you compare the output in the itests with EthGetTransactionReceipt I think.

there's a translation layer inside the event subsystem to go from id addresses to robust addresses, you can see it in action here:

if !found {
var ok bool
addr, ok = resolver(ctx, ev.Emitter, te.rctTs)
if !ok {
// not an address we will be able to match against
continue
}
addressLookups[ev.Emitter] = addr
}
if !f.matchAddress(addr) {

The resolver itself is

AddressResolver: func(ctx context.Context, emitter abi.ActorID, ts *types.TipSet) (address.Address, bool) {
idAddr, err := address.NewIDAddress(uint64(emitter))
if err != nil {
return address.Undef, false
}
actor, err := sm.LoadActor(ctx, idAddr, ts)
if err != nil || actor.DelegatedAddress == nil {
return idAddr, true
}
return *actor.DelegatedAddress, true
},

You could just potentially use the resolver in EventFilterManager to do this, it's exposed as AddressResolver, just be sure to cache the look-ups like CollectEvents does because you're likely to have a lot of duplicates in a single set.

Comment on lines 1064 to 1066
// Invoke a function to ensure there is a transaction
_, _, err := client.EVM().InvokeContractByFuncName(ctx, client.DefaultKey.Address, contractAddr, "someFunction()", []byte{})
require.NoError(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

you might need to check out the other uses of SimpleCoin to make sure you interact with it appropriately, I think we're failing here

Copy link
Member Author

Choose a reason for hiding this comment

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

inputData, err := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000066162636465660000000000000000000000000000000000000000000000000000")
require.NoError(t, err)

// Invoke the sendCoin function to ensure there is a transaction
_, _, err = client.EVM().InvokeContractByFuncName(ctx, client.DefaultKey.Address, contractAddr, "sendCoin(address,uint256)", inputData)
require.NoError(t, err) // Ensure the function call is successful

Is this the correct implementation for it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Had a chat with @virajbhartiya and he will use the MultipleEvents contract to generate events here and test this out.

Copy link
Member Author

@virajbhartiya virajbhartiya Sep 19, 2024

Choose a reason for hiding this comment

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

I was learning about Cid in IPFS, and from what I understand, it's a unique identifier created by hashing the contents of a file stored on IPFS. This makes the file immutable, as any change to the content generates a new Cid. IPFS uses the MultiHash protocol go generate a Cid. Cid functions as a content-based address, allowing nodes to locate the file on the network. It’s similar to how domain names function in web2, but instead of pointing to a location, it points directly to the data itself. Am I going in the right direction? @aarshkshah1992

itests/eth_filter_test.go Outdated Show resolved Hide resolved
@rvagg
Copy link
Member

rvagg commented Sep 18, 2024

Getting very close I think!

fwiw you can run the itests locally but they're best done specifically targeted, e.g. go test ./itests/fevm_test.go -run TestEthGetBlockReceipts -v. It should be quick enough to run on most machines. You should try it out on the ones you're modifying to see how close you are. Currently I need to Approve and Run CI for you here as a first-time contributor, unfortunately.

@rjan90 rjan90 mentioned this pull request Sep 18, 2024
51 tasks
@virajbhartiya
Copy link
Member Author

I have made the changes suggested above, and also implemented MultipleEvents in the test, can you please give it a look @aarshkshah1992 @rvagg

@aarshkshah1992 aarshkshah1992 changed the base branch from master to feat/eth-block-get-receipts-api September 23, 2024 10:53
@aarshkshah1992
Copy link
Contributor

@virajbhartiya Merging this into a feature branch and taking it over to fill in the missing bits. Looks mostly good here.

Thanks for all your hard work here !

@aarshkshah1992 aarshkshah1992 merged commit e6474f5 into filecoin-project:feat/eth-block-get-receipts-api Sep 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ☑️ Done (Archive)
Development

Successfully merging this pull request may close these issues.

Support eth_getBlockReceipts
4 participants