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: ethrpc: implement EthBlock and EthTx structs #9287

Merged
merged 7 commits into from
Sep 12, 2022

Conversation

ychiaoli18
Copy link
Contributor

Related Issues

ref-fvm #854

Proposed Changes

  • implement EthBlock and EthTx structs
  • implement the following methods
    • eth_getBlockByHash
    • eth_getBlockByNumber
    • eth_getTransactionByHash

Additional Info

Checklist

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

  • All commits have a clear commit message.
  • The PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, INTERFACE BREAKING CHANGE, CONSENSUS BREAKING, build, chore, ci, docs,perf, refactor, revert, style, test
    • area: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps
  • This PR has tests for new functionality or change in behaviour
  • If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or Discussion Tutorials.
  • CI is green

@ychiaoli18 ychiaoli18 requested a review from a team as a code owner September 12, 2022 01:51
Copy link
Contributor

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

looks fine for now.

api/eth_types.go Outdated
)

var (
// TODO: need to determine based on build params
Copy link
Contributor

Choose a reason for hiding this comment

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

put this in build/params to do this.

api/eth_types.go Outdated
Comment on lines 22 to 33
const (
CHAIN_ID_MAINNET = 314
CHAIN_ID_BUILDERNET = 3141
CHAIN_ID_WALLABY = 31415
CHAIN_ID_CALIBRATION = 314159
CHAIN_ID_BUTTERFLY = 3141592
CHAIN_ID_LOCAL = 31415926
)

var (
// TODO: need to determine based on build params
CHAIN_ID_CURRENT = CHAIN_ID_MAINNET
Copy link
Member

Choose a reason for hiding this comment

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

We need to solve this before merge. Should be trivial? Just add the appropriate const to the params_ file for the corresponding network?

From: fromEthAddr,
To: toEthAddr,
Value: api.EthBigInt(msg.Value),
Type: api.EthInt(2),
Copy link
Member

Choose a reason for hiding this comment

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

I assume this indicates it's an EIP-1559 tx -- we should add a constant for this.

Copy link
Contributor Author

@ychiaoli18 ychiaoli18 Sep 12, 2022

Choose a reason for hiding this comment

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

Yes, 2 means it's an EIP-1559 tx

api/eth_types.go Outdated
Comment on lines 22 to 33
const (
CHAIN_ID_MAINNET = 314
CHAIN_ID_BUILDERNET = 3141
CHAIN_ID_WALLABY = 31415
CHAIN_ID_CALIBRATION = 314159
CHAIN_ID_BUTTERFLY = 3141592
CHAIN_ID_LOCAL = 31415926
)

var (
// TODO: need to determine based on build params
CHAIN_ID_CURRENT = CHAIN_ID_MAINNET
Copy link
Member

Choose a reason for hiding this comment

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

We'll want these consts to be defined in build/params_{network}.go files.

Comment on lines +75 to +84
replaced := strings.Replace(s, "0x", "", -1)
if len(replaced)%2 == 1 {
replaced = "0" + replaced
}

i := new(mathbig.Int)
i.SetString(replaced, 16)

*e = EthBigInt(big.NewFromGo(i))
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why not to use the encoding/hex package? https://pkg.go.dev/encoding/hex

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's likely that the underlying string is a big int, so it's easier to parse the string directly using the standard big.Int library.

Comment on lines +162 to +163
type TempEthCall EthCall
var params TempEthCall
Copy link
Member

Choose a reason for hiding this comment

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

Why is this type dance necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Otherwise decoding with json.Unmarshal will create an infinite loop and cause stack overflow. (json.Unmarshal -> EthCall.UnmarshalJSON -> json.Unmarshal -> EthCall.UnmarshalJSON -> ...)

Comment on lines +244 to +266
for _, blkMsg := range blkMsgs {
for _, msg := range append(blkMsg.BlsMessages, blkMsg.SecpkMessages...) {
msgLookup, err := a.StateAPI.StateSearchMsg(ctx, types.EmptyTSK, msg.Cid(), api.LookbackNoLimit, true)
if err != nil {
return api.EthBlock{}, nil
}
gasUsed += msgLookup.Receipt.GasUsed

if fullTxInfo {
tx, err := a.ethTxFromFilecoinMessageLookup(ctx, msgLookup)
if err != nil {
return api.EthBlock{}, nil
}
block.Transactions = append(block.Transactions, tx)
} else {
hash, err := api.EthHashFromCid(msg.Cid())
if err != nil {
return api.EthBlock{}, err
}
block.Transactions = append(block.Transactions, hash.String())
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure there's any other way of doing it other than loading every single receipt and adding the gas used, like you're doing here. The problem is two-fold: (a) deferred execution due to tipsets, (b) execution tipset does not broadcast the total gas used in the chain data structure (like the Ethereum block does).

Copy link
Member

Choose a reason for hiding this comment

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

@arajasek ideas here would be welcome.

Comment on lines +303 to +316
fromEthAddr, err := api.EthAddressFromFilecoinIDAddress(fromFilIdAddr)
if err != nil {
return api.EthTx{}, err
}

toFilAddr, err := a.StateAPI.StateLookupID(ctx, msg.From, types.EmptyTSK)
if err != nil {
return api.EthTx{}, err
}

toEthAddr, err := api.EthAddressFromFilecoinIDAddress(toFilAddr)
if err != nil {
return api.EthTx{}, err
}
Copy link
Member

Choose a reason for hiding this comment

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

In the future we will want these addresses to preferentially be f4 addresses when there is one.

}

tx := api.EthTx{
ChainID: api.EthInt(api.CHAIN_ID_CURRENT),
Copy link
Member

Choose a reason for hiding this comment

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

Once you move this to build/params_{network}.go, you won't have to track the current chain ID here.

Copy link
Member

@raulk raulk left a comment

Choose a reason for hiding this comment

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

This is good to merge and iterate on on the experimental branch. We will still make quite a few changes, and the full JSON-RPC API isn't expected until Iron r04.

@raulk raulk merged commit 8bbc55e into experimental/fvm-m2 Sep 12, 2022
@raulk raulk deleted the kevin/feat/ethrpc-block-tx branch September 12, 2022 21:46
adlrocha referenced this pull request in consensus-shipyard/lotus Oct 13, 2022
vyzo pushed a commit that referenced this pull request Nov 9, 2022
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.

3 participants