-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
type TempEthCall EthCall | ||
var params TempEthCall |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 -> ...)
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()) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
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 | ||
} |
There was a problem hiding this comment.
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.
node/impl/full/eth.go
Outdated
} | ||
|
||
tx := api.EthTx{ | ||
ChainID: api.EthInt(api.CHAIN_ID_CURRENT), |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Co-authored-by: Raúl Kripalani <[email protected]>
Co-authored-by: Raúl Kripalani <[email protected]>
Related Issues
ref-fvm #854
Proposed Changes
Additional Info
Checklist
Before you mark the PR ready for review, please make sure that:
<PR type>: <area>: <change being made>
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, testarea
: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps