sei-protocol / sei-chain

Apache License 2.0
2.67k stars 797 forks source link

refactor: Use geths hydrate tx #1654

Closed jewei1997 closed 1 month ago

jewei1997 commented 1 month ago

Describe your changes and provide context

replace our hydrate tx's with geth's implementation. Geth has a more robust implementation that handles different tx types https://github.com/sei-protocol/go-ethereum/pull/26/files#diff-fd44fe26ff1757fd0d84daed80b66438a1891eb9112a0d03d3858b3a6bd4ebd7R1354-R1426

old legacy tx data (notice how it has maxFeePerGas and maxPriorityFeePerGas which are eip1559 attributes):

$ cast tx 0x9446f57fc50b3f474b005e002c730fa183f957328f538bbaeb59369a6eb29260 -r http://127.0.0.1:8545 --json | jq
{
  "hash": "0x9446f57fc50b3f474b005e002c730fa183f957328f538bbaeb59369a6eb29260",
  "nonce": "0x0",
  "blockHash": "0xf59e823d004837a0d550ac10fcc00297a4d04063ae76dbb6b93a8a85d602730e",
  "blockNumber": "0x7",
  "transactionIndex": "0x1",
  "from": "0xf87a299e6bc7beba58dbbe5a5aa21d49bcd16d52",
  "to": "0xe6a25499327abb2dd5cc7685c8ebe2d804f72638",
  "value": "0x0",
  "gasPrice": "0xe8d4a51000",
  "gas": "0x54ea",
  "maxFeePerGas": "0xe8d4a51000",
  "maxPriorityFeePerGas": "0xe8d4a51000",
  "input": "0x40c10f19000000000000000000000000f87a299e6bc7beba58dbbe5a5aa21d49bcd16d520000000000000000000000000000000000000000000000000000000000000001",
  "r": "0x8458ca8c2f91eb7437879d30b54fabb3b86b7f8c6ca546c9afa23d490502a8e",
  "s": "0x263d803b0349dc9518d294cd1c88a34f1fc50a7bbe291a7d65d56079f8af1d07",
  "v": "0x15c809",
  "chainId": "0xae3f3",
  "type": "0x0",
  "accessList": null
}

new legacy tx data:

$ cast tx 0xd931ead6c57c8c4ec1a5b968ca25156ba6e4933a71aca84d7eda0b04cc55e0eb -r http://127.0.0.1:8545 --json | jq
{
  "hash": "0xd931ead6c57c8c4ec1a5b968ca25156ba6e4933a71aca84d7eda0b04cc55e0eb",
  "nonce": "0x2",
  "blockHash": "0x95444f610e870d0d3a94e6c43354947063932ae6aa3f898451babc39cf865a49",
  "blockNumber": "0x59",
  "transactionIndex": "0x0",
  "from": "0xf87a299e6bc7beba58dbbe5a5aa21d49bcd16d52",
  "to": "0xe6a25499327abb2dd5cc7685c8ebe2d804f72638",
  "value": "0x0",
  "gasPrice": "0x3b9aca00",
  "gas": "0x54ea",
  "input": "0x40c10f19000000000000000000000000f87a299e6bc7beba58dbbe5a5aa21d49bcd16d520000000000000000000000000000000000000000000000000000000000000001",
  "r": "0xde8fc70270330a613b7a4a5e0b026cd29dd099bd0730e720f727069038da3316",
  "s": "0x4017a174861f3784fb57e22063757f57c1a55f463a2be66fbcb5124551eae3c3",
  "v": "0x15c809",
  "chainId": "0xae3f3",
  "type": "0x0"
}

old eip1559 tx:

{
  "hash": "0x60bc0089ce60661bcd980a5563d71bd35172bfbb89c473c0fbbde18c2e72eee5",
  "nonce": "0x1",
  "blockHash": "0x49b1d9bb9451b7d2d61c8e759ea8c5ebfc814cf1ee538d4e6126d445f1b095fb",
  "blockNumber": "0x139",
  "transactionIndex": "0x0",
  "from": "0xf87a299e6bc7beba58dbbe5a5aa21d49bcd16d52",
  "to": "0xe6a25499327abb2dd5cc7685c8ebe2d804f72638",
  "value": "0x0",
  "gasPrice": "0x3b9aca00",
  "gas": "0x54ea",
  "maxFeePerGas": "0x3b9aca00",
  "maxPriorityFeePerGas": "0x3b9aca00",
  "input": "0x40c10f19000000000000000000000000f87a299e6bc7beba58dbbe5a5aa21d49bcd16d520000000000000000000000000000000000000000000000000000000000000001",
  "r": "0x50a84b936a60dbee4013fb73504150e41d52937ff494dcffe05970c56755b668",
  "s": "0x25a57bb846d5bd43cb326a26c048cd28c1a847cd77191c7f4c1d1aaacecc8f9b",
  "v": "0x0",
  "yParity": "0x0",
  "chainId": "0xae3f3",
  "accessList": [],
  "type": "0x2"
}

new eip1559 tx (pretty much the same):

{
  "hash": "0xc9ea7d7c64ad33411191ebab208f4d8caee42f898725abb57b7bc5bc0338984a",
  "nonce": "0x0",
  "blockHash": "0x04b288c19f57e35d716caf5c269c1c35e2ed687384582d5a2c6db424f27e5e0d",
  "blockNumber": "0xe",
  "transactionIndex": "0x0",
  "from": "0xf87a299e6bc7beba58dbbe5a5aa21d49bcd16d52",
  "to": "0xe6a25499327abb2dd5cc7685c8ebe2d804f72638",
  "value": "0x0",
  "gasPrice": "0x3b9aca00",
  "gas": "0x54ea",
  "maxFeePerGas": "0x3b9aca00",
  "maxPriorityFeePerGas": "0x3b9aca00",
  "input": "0x40c10f19000000000000000000000000f87a299e6bc7beba58dbbe5a5aa21d49bcd16d520000000000000000000000000000000000000000000000000000000000000001",
  "r": "0x2e78ee34f5b5d7a210e54600b712e43e0e45482a6f370563fc40114468b10dcf",
  "s": "0x79489c5b39ad580a3922cb2339fe0a47ecb4d099950c39196367f5d22c98f39c",
  "v": "0x0",
  "yParity": "0x0",
  "chainId": "0xae3f3",
  "accessList": [],
  "type": "0x2"
}

Testing performed to validate your change

existing tests

codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 92.85714% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 61.39%. Comparing base (3cd4736) to head (3c355d3).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654/graphs/tree.svg?width=650&height=150&src=pr&token=DG7ZZJ3PVV&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol)](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol) ```diff @@ Coverage Diff @@ ## main #1654 +/- ## ========================================== - Coverage 61.58% 61.39% -0.19% ========================================== Files 367 367 Lines 26629 26572 -57 ========================================== - Hits 16399 16315 -84 - Misses 9137 9168 +31 + Partials 1093 1089 -4 ``` | [Files](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol) | Coverage Δ | | |---|---|---| | [evmrpc/block.go](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654?src=pr&el=tree&filepath=evmrpc%2Fblock.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol#diff-ZXZtcnBjL2Jsb2NrLmdv) | `68.75% <100.00%> (+0.72%)` | :arrow_up: | | [evmrpc/utils.go](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654?src=pr&el=tree&filepath=evmrpc%2Futils.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol#diff-ZXZtcnBjL3V0aWxzLmdv) | `65.32% <ø> (-10.72%)` | :arrow_down: | | [evmrpc/tx.go](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654?src=pr&el=tree&filepath=evmrpc%2Ftx.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol#diff-ZXZtcnBjL3R4Lmdv) | `67.11% <92.30%> (+0.91%)` | :arrow_up: | | [evmrpc/txpool.go](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654?src=pr&el=tree&filepath=evmrpc%2Ftxpool.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol#diff-ZXZtcnBjL3R4cG9vbC5nbw==) | `73.80% <88.88%> (+0.63%)` | :arrow_up: | ... and [4 files with indirect coverage changes](https://app.codecov.io/gh/sei-protocol/sei-chain/pull/1654/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sei-protocol)