Commit Graph

632 Commits

Author SHA1 Message Date
J1ang
5554ff34a6
feature: support generate parse transaction input bytes codes in abigen (#7593)
feature: support generate parse transaction input bytes codes in
`abigen`.


It's easy to use abigen to generate code that help you parse the event
log and call the payable method with the transactor.

But parsing the transaction call data is missing. You can only send a
transaction with a transactor. This PR aims to generate codes that help
developer parse transaction calldata.

abigen can generate code to parse the transaction call data.    

With this PR, transaction parse codes are generated like this:   

```go
// CollectParams is an auto generated read-only Go binding of transcaction calldata params
type CollectParams struct {
	Param_params INonfungiblePositionManagerCollectParams
}

// Parse Collect method from calldata of a transaction
//
// Solidity: function collect((uint256,address,uint128,uint128) params) payable returns(uint256 amount0, uint256 amount1)
func ParseCollect(calldata []byte) (*CollectParams, error) {
	if len(calldata) <= 4 {
		return nil, fmt.Errorf("invalid calldata input")
	}

	_abi, err := abi.JSON(strings.NewReader(UniswapABI))
	if err != nil {
		return nil, fmt.Errorf("failed to get abi of registry metadata: %w", err)
	}

	out, err := _abi.Methods["collect"].Inputs.Unpack(calldata[4:])
	if err != nil {
		return nil, fmt.Errorf("failed to unpack collect params data: %w", err)
	}

	var paramsResult = new(CollectParams)
	value := reflect.ValueOf(paramsResult).Elem()

	if value.NumField() != len(out) {
		return nil, fmt.Errorf("failed to match calldata with param field number")
	}

	out0 := *abi.ConvertType(out[0], new(INonfungiblePositionManagerCollectParams)).(*INonfungiblePositionManagerCollectParams)

	return &CollectParams{
		Param_params: out0,
	}, nil
}
```


Example of using `Parse` Function above:  


```go
package bin

import (
	"context"
	"fmt"
	"testing"

	"github.com/ledgerwatch/erigon/common/hexutil"
	"github.com/ledgerwatch/erigon/rpc"
	"github.com/ledgerwatch/log/v3"
)

func TestOnParse(t *testing.T) {
	cli, err := rpc.Dial("https://rpc.ankr.com/polygon", log.New(context.Background()))
	if err != nil {
		t.Fatal(err)
	}

	var collectTx struct {
		Input string `json:"input"`
	}
	err = cli.CallContext(context.Background(), &collectTx, "eth_getTransactionByHash", "0x741146cce64d873cfe82ade413651de355a6db92f992e5bfc4e1c58d92f5dd5b")
	if err != nil {
		t.Fatal(err)
	}

	var increaseLiquidityTx struct {
		Input string `json:"input"`
	}
	err = cli.CallContext(context.Background(), &increaseLiquidityTx, "eth_getTransactionByHash", "0x645ff650d7bfb9a74f573af474b9ebee48c3fadc7dac67257a8da6b55c71f338")
	if err != nil {
		t.Fatal(err)
	}

	fmt.Println(collectTx.Input)
	fmt.Println(increaseLiquidityTx.Input)

	collectBytes, _ := hexutil.Decode(collectTx.Input)

	increaseLiquidityBytes, _ := hexutil.Decode(increaseLiquidityTx.Input)

	collectInfo, err := ParseCollect(collectBytes)
	if err != nil {
		t.Fatal(err)
	}

	increaseLiquidityInfo, err := ParseIncreaseLiquidity(increaseLiquidityBytes)
	if err != nil {
		t.Fatal(err)
	}

	fmt.Printf("%+v\n", collectInfo)
	fmt.Printf("%+v\n", increaseLiquidityInfo)
}
```

Output of code above:  


&{Param_params:{TokenId:+894123
Recipient:0x48B8e4ed457da9B64c33Ee50Fd5490614833A37D
Amount0Max:+340282366920938463463374607431768211455
Amount1Max:+340282366920938463463374607431768211455}}
&{Param_params:{TokenId:+891904 Amount0Desired:+331092 Amount1Desired:+0
Amount0Min:+331092 Amount1Min:+0 Deadline:+1685112789}}
2023-05-28 21:11:21 +07:00
Alex Sharov
111db5f655
blockReader in tests - step8 (#7578) 2023-05-25 12:46:11 +07:00
Alex Sharov
31687be599
blockReaders in tests, step4 (#7570) 2023-05-24 15:52:51 +07:00
Alex Sharov
4d0dee6fb0
Introduce BlockWriter object (txsV3 step 0) (#7559) 2023-05-22 15:49:21 +07:00
Alex Sharov
2865b85888
move e2 snapshots management closer to e3: step 1 (#7543)
- always RLock all snapshots - to guarantee consistency
- introduce class View (analog of RoTx and MakeContext)
- move read methods to View object
- View object will be managed by temporal_tx

---------

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
2023-05-22 10:09:46 +07:00
racytech
40947f6c98
eip-4844: adding data_gas to gaspool (#7428)
Adding `data_gas` to gas pool. EIP-4844 gas pool includes data_gas which
is used to fee blob transactions.
2023-05-03 09:02:30 +07:00
Andrew Ashikhmin
1533674dad
Implement EIP-1153 transient storage (#7405)
Port https://github.com/ethereum/go-ethereum/pull/26003

---------

Co-authored-by: Mark Tyneway <mark.tyneway@gmail.com>
2023-05-01 18:26:24 +02:00
racytech
ef71909c34
eip-4844: extensions to compute fees for data blobs (#7328)
Small additions that will be used to compute data blob fees and to
verify transactions for "willingness" to pay for these fees.
2023-04-21 11:07:54 +01:00
Alex Sharov
21d66d6c01
e3: state reader constructor in tests (#7338) 2023-04-19 03:10:33 +00:00
racytech
7aa217f015
eip-4844: setting header's excess_data_gas, verifiying eip-4844 headers (#7308)
In this PR Header's ExcessDataGas is set to the actual value, but it's
still unused. It will be used to compute data fee for eip-4844 data
blobs, logic of which will be added in later PRs. Also eip-4844 header
verification logic added.
2023-04-16 08:12:40 +00:00
racytech
47fd86e4fb
eip-4844: assigned value to excessDataGas, unused packages removed (#7289)
`excessDataGas` has been partially made eip-4844 ready, so instead of
passing nils to functions, now it actually assigned to some value (it is
expected to be nil until cancun update).
2023-04-12 05:45:44 +00:00
Alex Sharov
a42d362cbd
move aura epoch data from chainDB to auraDB. remove epochReader parameter from consensus interface (#7250) 2023-04-04 03:30:07 +00:00
racytech
d67087f7fd
eip-4844: ApplyTransaction now expects excessDataGas (#7233)
Tiny addition to ApplyTransaction. Now it expects excessDataGas param so
the BlockContext can be created with it
2023-04-03 14:30:28 +00:00
Alex Sharov
bd83f85912
e3: enable simulated backend (#7245) 2023-04-03 09:36:31 +00:00
Alex Sharov
04b5c0c67b
e4: small tests preparations (#7220) 2023-03-31 02:19:56 +00:00
Alex Sharov
2161c5ed8c
stop using olddb in simulated backend (#7219) 2023-03-30 03:31:15 +00:00
Alex Sharov
3008c25c9e
e3: enable simulated backed (#7218) 2023-03-30 02:53:06 +00:00
Alex Sharov
592ec1ee0d
e4: step 1 to run tests (#7209) 2023-03-29 14:01:27 +00:00
Alex Sharov
417a437584
Break dependency of ethcfg package to core/consensus/etc... move genesis struct to 'types' package (#7206) 2023-03-29 07:27:06 +00:00
racytech
975e38a800
eip-4844: NewEVMBlockContext now expects excessDataGas (#7203)
Small change in core.NewEVMBlockContext and now it expects
excessDataGas. This will be used in state transition to compute data fee
for eip-4844 data blobs. The logic that computes it will be added in the
next PRs.
2023-03-29 06:39:36 +00:00
Alex Sharov
201572c6f5
enable more linters #954 (#7179) 2023-03-25 05:13:27 +00:00
alex.sharov
6c87d19544 clean 2023-03-23 16:25:26 +07:00
alex.sharov
ab87125d58 save 2023-03-23 16:25:08 +07:00
Alex Sharov
e2c5984a12
attempt to finx bindtest (#7167) 2023-03-23 09:24:25 +00:00
Alex Sharov
b685407175
attempt to fix TestGolangBindings (#7041) 2023-03-07 06:14:35 +00:00
nanevardanyan
ab6239b30f
WIP: cmd, turbo, core, eth: TransactionsV3 flag and persist in new table (#6754) 2023-02-24 18:49:25 +00:00
J1ang
b1fce955ca
fix: replace common package to libcommon package in abigen (#6879)
fix: replace common package to libcommon package in `abigen`.
2023-02-15 02:46:12 +00:00
Alex Sharov
b99e4abb3e
move math big constants to erigon-lib (#6719) 2023-01-27 11:39:34 +07:00
Andrew Ashikhmin
d12fda5cbd
Switch AccessList, IntrinsicGas, SafeAdd/Mul to erigon-lib (#6709)
Reduce code duplication.
2023-01-26 12:26:12 +01:00
Alex Sharov
bad616cb8e
e3: use historyReader constructor in tests (#6677) 2023-01-24 12:43:04 +07:00
hexoscott
7dcbfbc283
reference hash, address, and chain config from lib (#6536) 2023-01-13 18:12:18 +00:00
Andrew Ashikhmin
58893937b0
core/vm: Make INVALID a defined opcode (#6477)
Cherry-pick https://github.com/ethereum/go-ethereum/pull/24017.

* core/vm: Define 0xfe opcode as INVALID

* core/vm: Remove opInvalid as opUndefined handles it

Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>

Co-authored-by: Andrei Maiboroda <andrei@ethereum.org>
Co-authored-by: Alex Beregszaszi <alex@rtfs.hu>
2022-12-30 17:13:54 +01:00
Alex Sharov
4a9c871628
a bit rename 22 to v3 (#6476) 2022-12-30 21:53:42 +07:00
alex.sharov
92c95e6e68 cleanup 2022-12-29 11:02:33 +07:00
alex.sharov
a893899fc2 save 2022-12-29 11:02:11 +07:00
ledgerwatch
0a31f5ac2a
Workaround for the code history of BSC system contracts (#6274)
Works around a flaw in the upgrade logic of the system contracts. Since
they are updated directly, without first being self-destructed and then
re-created, the usual incarnation logic does not get activated, and all
historical records of the code of these contracts are retrieved as the
most recent version. This problem will not exist in erigon3, but until
then, a workaround will be used to access code of such contracts through
a special structure, `SystemContractCodeLookup`

Fixes https://github.com/ledgerwatch/erigon/issues/5865

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2022-12-10 22:41:04 +00:00
Nicolas Gotchac
961a0070cc
Fix trace error in Polygon | Pass Engin to the Base API (#6131)
So there is an issue with tracing certain blocks/transactions on
Polygon, for example:
```
> '{"method": "trace_transaction","params":["0xb198d93f640343a98f90d93aa2b74b4fc5c64f3a649f1608d2bfd1004f9dee0e"],"id":1,"jsonrpc":"2.0"}'
```
gives the error `first run for txIndex 1 error: insufficient funds for
gas * price + value: address 0x10AD27A96CDBffC90ab3b83bF695911426A69f5E
have 16927727762862809 want 17594166808296934`

The reason is that this transaction is from the author of the block,
which doesn't have enough ETH to pay for the gas fee + tx value if he's
not the block author receiving transactions fees.

The issue is that currently the APIs are using `ethash.NewFaker()`
Engine for running traces, etc. which doesn't know how to get the author
for a specific block (which is consensus dependant); as it was noting in
several TODO comments.

The fix is to pass the Engine to the BaseAPI, which can then be used to
create the right Block Context. I chose to split the current Engine
interface in 2, with Reader and Writer, so that the BaseAPI only
receives the Reader one, which might be safer (even though it's only
used for getting the block Author).
2022-12-04 12:17:39 +07:00
Alex Sharov
92e6e56120
Fix test e3 (#6087) 2022-11-20 10:58:20 +07:00
Alex Sharov
93926646f8
e3: prepare downloader for extraction (#6061) 2022-11-16 15:48:23 +03:00
Max Revitt
74308f2500
fix(test): eliminate race conditions (#6019) 2022-11-11 15:22:09 +00:00
Andrew Ashikhmin
dd43d486f3
Enable London in AllEthashProtocolChanges (#5891)
`AllEthashProtocolChanges` should contain all the EIPs accepted by the
core developers into the Ethash consensus, including the
[London](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md)
protocol upgrade.
2022-10-28 17:19:18 +02:00
Andrew Ashikhmin
6a5968e7f0
AuRa service transactions are free (#5873)
and the don't pay baseFee after EIP-1559.

See https://openethereum.github.io/Permissioning.html#gas-price
2022-10-26 13:03:47 +02:00
Alex Sharov
c6faa9fca3
e3: tests (#5776) 2022-10-18 11:53:54 +07:00
Tim Mustafin
70851c35ee
[BSC] support for Moran fork (#5696)
This PR brings support for BSC Moran fork

Co-authored-by: Timur Mustafin <timur@mustafin.dev>
2022-10-11 13:33:32 +01:00
Alex Sharov
ff8fcf8070
erigon3 integration tests fixes (#5625) 2022-10-05 10:59:08 +07:00
Alex Sharov
001c344d66
erigon3 integration test fixes (#5624) 2022-10-05 10:55:08 +07:00
ledgerwatch
11893429f5
cleanup bloombits and filters (#5551)
Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2022-09-27 17:19:59 +01:00
Alex Sharov
cb60382e6d
erigon3: rename "history.v2" to "history.v3" to avoid naming miss-match with "erigon3" (#5519) 2022-09-26 10:54:42 +07:00
Alex Sharov
9fb8a190bc
erigon22: folder snapshots/history (#5351) 2022-09-18 17:41:01 +07:00
ledgerwatch
693017c554
Cleanup Tevm experimental code (#5259)
Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2022-09-01 19:49:29 +01:00