Commit graph

691 commits

Author SHA1 Message Date
Daniel Liu
956767a41e
consensus/XDPoS: remove unused parameters in BlockConsensusVersion, close XFN-02 (#1613) 2025-10-08 13:19:45 +08:00
wit liu
7c5d2a45da
accounts/keystore: use ticker to avoid timer allocations #32732 (#1592) 2025-10-08 12:50:48 +08:00
Daniel Liu
6e8d261e42
all: eliminate zero owner variables (#1587) 2025-10-08 12:38:32 +08:00
wit liu
09b6622165
accounts/keystore: use runtime.AddCleanup #32610 (#1580)
Co-authored-by: cui <cuiweixie@gmail.com>
2025-10-08 12:29:03 +08:00
wit liu
077c4e6a45
accounts/usbwallet/trezor: fix gengerate files (#1577) 2025-10-08 12:27:34 +08:00
wit liu
d9ae317a38
all: format golang files (#1548)
Co-authored-by: wit <wit765765346@gmail>
2025-09-21 19:41:54 +08:00
Daniel Liu
7c69d03a88
accounts/abi/bind/v2: add Address method to BoundContract #32559 (#1518)
Co-authored-by: Mobin Mohanan <47410557+tr1sm0s1n@users.noreply.github.com>
2025-09-21 18:55:42 +08:00
Daniel Liu
b3ae8beb91
accounts/abi: generate TryPack* methods for abigen v2 bindings #31692 (#1424)
1. Fix the error return format.
**todo**: ~~`bindtype` needs more complex logic to fix it.~~
`
if err != nil {
  return nil, err
}
if err == nil {
  return obj, nil
}
`
2. ~~Return pointer type object to avoid copying the whole struct
content.~~
3. Give the panic decision to the user.
4. Fix empty line at the end of function.

**TODO**: ~~fix some related test cases.~~

---------

Co-authored-by: maskpp <maskpp266@gmail.com>
Co-authored-by: Jared Wasinger <j-wasinger@hotmail.com>
2025-09-17 08:24:03 +08:00
Daniel Liu
23acecf6d8
account/abi/bind/v2: fix TestDeploymentWithOverrides #32212 (#1426)
The root cause of the flaky test was a nonce conflict caused by async
contract deployments.

This solution defines a custom deployer with automatic nonce management.

Co-authored-by: steven <wangpeculiar@gmail.com>
2025-09-13 09:50:19 +08:00
Daniel Liu
dd198e0371
accounts/abi/abigen: remove unnecessary test files #31804 (#1421) 2025-09-13 09:44:10 +08:00
Daniel Liu
d87774c6a3
accounts/abi/abigen: safe chain view update #31590 (#1420) 2025-09-13 09:41:35 +08:00
Daniel Liu
ad9003c41e
eth/tracers: live chain tracing with hooks #29189 (#1352)
Here we add a Go API for running tracing plugins within the main block import process.

As an advanced user of geth, you can now create a Go file in eth/tracers/live/, and within
that file register your custom tracer implementation. Then recompile geth and select your tracer
on the command line. Hooks defined in the tracer will run whenever a block is processed.

The hook system is defined in package core/tracing. It uses a struct with callbacks, instead of
requiring an interface, for several reasons:

- We plan to keep this API stable long-term. The core/tracing hook API does not depend on
  on deep geth internals.
- There are a lot of hooks, and tracers will only need some of them. Using a struct allows you
   to implement only the hooks you want to actually use.

All existing tracers in eth/tracers/native have been rewritten to use the new hook system.

This change breaks compatibility with the vm.EVMLogger interface that we used to have.
If you are a user of vm.EVMLogger, please migrate to core/tracing, and sorry for breaking
your stuff. But we just couldn't have both the old and new tracing APIs coexist in the EVM.

---------

Co-authored-by: Sina M <1591639+s1na@users.noreply.github.com>
Co-authored-by: Matthieu Vachon <matthieu.o.vachon@gmail.com>
Co-authored-by: Delweng <delweng@gmail.com>
Co-authored-by: Martin HS <martin@swende.se>
2025-09-09 17:30:56 +08:00
Daniel Liu
be61f66cb2
core/types: remove message #25977 (#1322) 2025-09-09 11:23:47 +08:00
Daniel Liu
343cd1021a
accounts/abi: precompile regex #32301 (#1427)
Co-authored-by: cui <cuiweixie@gmail.com>
2025-09-08 15:36:33 +08:00
Daniel Liu
4fd1e0b04d
accounts/abi/abigen: fix a flaky bind test case NewSingleStructArgument #31501 (#1418)
Co-authored-by: Delweng <delweng@gmail.com>
2025-09-08 15:34:39 +08:00
Daniel Liu
8e8a04d9ce
accounts/abi: include access-list in gas estimation #31394 (#1417)
Simple bugfix to include the access-list in the gas-estimation step of
the ABI bindings code.

Co-authored-by: protolambda <proto@protolambda.com>
2025-09-08 15:33:31 +08:00
Daniel Liu
a85b4ee518
accounts/abi: fix panic when check event with log has empty or nil topics #32503 (#1431)
When the log has empty or nil topics, the generated bindings code will
panic when accessing `log.Topics[0]`, add a check to avoid it.

Co-authored-by: nthumann <nthumanna@gmail.com>
2025-09-06 17:04:33 +08:00
Daniel Liu
b0996a2829
accounts/usbwallet: correct version comparison logic #32417 (#1430)
This PR fixes a bug in the Ledger hardware wallet version validation
logic for EIP-155 transaction signing. The original condition
incorrectly allowed older versions that don't support EIP-155 such as
0.9.9 and 0.1.5 to proceed.

Co-authored-by: Rizky Ikwan <rizzikwann@gmail.com>
2025-09-06 17:03:55 +08:00
Daniel Liu
8c4863a567
accounts/scwallet: fixes nil pointer dereference in scwallet #32186 (#1429)
Fixes #32181

Signed-off-by: kapil <kapilsareen584@gmail.com>
Co-authored-by: Kapil Sareen <kapilsareen584@gmail.com>
2025-09-06 17:03:04 +08:00
Daniel Liu
9b189e1ea3
accounts/abi, accounts/keystore: use reflect.TypeFor #32323 (#1428)
Co-authored-by: cui <cuiweixie@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-09-06 17:01:22 +08:00
Daniel Liu
61fcd420b3
accounts/keystore: update links to documenation #32194 (#1425) 2025-09-03 15:50:18 +08:00
Daniel Liu
aec5f28dab
accounts: fix data race when closing manager #31982 (#1423)
Fixes a data race on the `wallets` slice when closing account Manager.

At the moment, there is a data race between a go-routine calling the
Manager's `Close` function and the background go-routine handling most
operations on the `Manager`. The `Manager`'s `wallets` field is accessed
without proper synchronization.

By moving the closing of wallets from the `Close()` function into the
background thread, this issue can be resolved.

Co-authored-by: Herbert <herbert.jordan.jun@gmail.com>
2025-09-03 15:49:24 +08:00
Daniel Liu
b6f28effa9
accounts/abi: error when packing negative values in unsigned types #31790 (#1422)
This is an alternative approach to
https://github.com/ethereum/go-ethereum/pull/31607 , that doesn't break
backwards-compatibility with abigen.

Note that this does change the behavior of `Argument.Pack`: previously,
packing negative values for a `uint` parameter would cause them to be
represented in signed binary representation via two's complement. Now,
it will fail explicitly in this case.

However, I don't see a reason to support this functionality. The ABI
already explicitly supports signed integers. There's no reason that a
smart contract author would choose to store signed values in a `uint`
afaict.

---------

Co-authored-by: jwasinger <j-wasinger@hotmail.com>
Co-authored-by: MariusVanDerWijden <m.vanderwijden@live.de>
2025-09-03 15:48:44 +08:00
Daniel Liu
4e3bd78545
accounts/usbwallet: full 32bit chainId support for Trezor #17439 (#1419)
This fix allows Trezor to support full 32bit chainId in geth, with the
next version of firmware.

For `chainId > 2147483630` case, Trezor returns signature bit only.
- Trezor returns only signature parity for `chainId > 2147483630` case.
- for `chainId == 2147483630` case, Trezor returns `MAX_UINT32` or `0`,
but it doesn't matter.
  (`2147483630 * 2 + 35` = `4294967295`(`MAX_UINT32`))

chainId | returned signature_v | compatible issue
---------|------------------------|--------------------
0 < chainId <= 255 | chainId * 2 + 35 + v | no issue (firmware `1.6.2`
for Trezor one)
255 < chainId <= 2147483630 | chainId * 2 + 35 + v | ***fixed.***
*firmware `1.6.3`*
chainId > 2147483630 | v | *firmware `1.6.3`*

Please see also: full 32bit chainId support for Trezor
- Trezor one: https://github.com/trezor/trezor-mcu/pull/399 ***merged***
- Trezor model T: https://github.com/trezor/trezor-core/pull/311
***merged***

---------

Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Co-authored-by: HackyMiner <hackyminer@gmail.com>
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
2025-09-03 15:48:01 +08:00
Daniel Liu
05a9e91898
cmd/abigen, accounts/abi/bind: implement abigen version 2 #31379 (#1416)
This PR implements a new version of the abigen utility (v2) which exists
along with the pre-existing v1 version.

Abigen is a utility command provided by go-ethereum that, given a
solidity contract ABI definition, will generate Go code to transact/call
the contract methods, converting the method parameters/results and
structures defined in the contract into corresponding Go types. This is
useful for preventing the need to write custom boilerplate code for
contract interactions.

Methods in the generated bindings perform encoding between Go types and
Solidity ABI-encoded packed bytecode, as well as some action (e.g.
`eth_call` or creating and submitting a transaction). This limits the
flexibility of how the generated bindings can be used, and prevents
easily adding new functionality, as it will make the generated bindings
larger for each feature added.

Abigen v2 was conceived of by the observation that the only
functionality that generated Go bindings ought to perform is conversion
between Go types and ABI-encoded packed data. Go-ethereum already
provides various APIs which in conjunction with conversion methods
generated in v2 bindings can cover all functionality currently provided
by v1, and facilitate all other previously-desired use-cases.

To generate contract bindings using abigen v2, invoke the `abigen`
command with the `--v2` flag. The functionality of all other flags is
preserved between the v2 and v1 versions.

The execution of `abigen --v2` generates Go code containing methods
which convert between Go types and corresponding ABI-encoded data
expected by the contract. For each input-accepting contract method and
the constructor, a "packing" method is generated in the binding which
converts from Go types to the corresponding packed solidity expected by
the contract. If a method returns output, an "unpacking" method is
generated to convert this output from ABI-encoded data to the
corresponding Go types.

For contracts which emit events, an unpacking method is defined for each
event to unpack the corresponding raw log to the Go type that it
represents.

Likewise, where custom errors are defined by contracts, an unpack method
is generated to unpack raw error data into a Go type.

For a smooth user-experience, abigen v2 comes with a number of utility
functions to be used in conjunction with the generated bindings for
performing common contract interaction use-cases. These include:

* filtering for historical logs of a given topic
* watching the chain for emission of logs with a given topic
* contract deployment methods
* Call/Transact methods

https://geth.ethereum.org will be updated to include a new tutorial page
for abigen v2 with full code examples. The page currently exists in a
PR: https://github.com/ethereum/go-ethereum/pull/31390 .

There are also extensive examples of interactions with contract bindings
in [test
cases](cc855c7ede/accounts/abi/bind/v2/lib_test.go)
provided with this PR.

---------

Co-authored-by: jwasinger <j-wasinger@hotmail.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-09-03 15:47:12 +08:00
Daniel Liu
ca8d39b862
accounts/abi: improve unpack performance #31387 (#1415)
Slightly improves performance of abi.Unpack

```
Before
BenchmarkUnpack/0-14   5965714       210.9 ns/op     280 B/op       5 allocs/op
BenchmarkUnpack/1-14   2148283       569.7 ns/op     688 B/op      16 allocs/op

After:
BenchmarkUnpack/0-14  	 7693365	       151.2 ns/op	     136 B/op	       4 allocs/op
BenchmarkUnpack/1-14  	 2261294	       508.9 ns/op	     544 B/op	      15 allocs/op
```

replaces https://github.com/ethereum/go-ethereum/pull/31292 since I was
unable to push to your branch @Exca-DK

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Exca-DK <dawidk.info@gmail.com>
2025-09-03 15:46:23 +08:00
Daniel Liu
47d17e1b97
accounts/usbwallet: fix ledger access for latest firmware and add Ledger Flex #31004 (#1414)
The latest firmware for Ledger Nano S Plus now returns `0x5000` for it's
product ID, which doesn't match any of the product IDs enumerated in
`hub.go`.

This PR removes the assumption about the interfaces exposed, and simply
checks the upper byte for a match.

Also adds support for the `0x0007` / `0x7000` product ID (Ledger Flex).

Co-authored-by: Michael de Hoog <michael.dehoog@coinbase.com>
2025-09-03 15:45:34 +08:00
Daniel Liu
2def2b955b
accounts: fix typo (#1413) 2025-09-03 15:44:49 +08:00
Daniel Liu
34020969ff
all: simplify timestamps to uint64 #19372 (#1318) 2025-08-08 10:33:37 +08:00
JukLee0ira
87ed24a113
all: update to golangci-lint 1.61.0 #30587 (#1181)
Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-07-01 18:10:05 +08:00
Daniel Liu
93c2745b7b
all: disable recording preimage of trie keys #21402 (#1054) 2025-06-17 13:10:47 +08:00
JukLee0ira
b1e08e6642
all: refactor package node #21105 (#923) 2025-04-10 18:52:49 +08:00
Daniel Liu
a8a96a804f accounts/abi/bind: make it possible to wait for tx hash (#30079)
This change adds methods which makes it possible for to wait for a transaction with a specific hash when deploying contracts during abi bind interaction.

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
2025-01-24 16:54:12 +08:00
Daniel Liu
6f37e85e80 accounts/abi: support unpacking solidity errors (#30738)
This PR adds the error fragments to `func (abi ABI) getArguments` which
allows typed decoding of errors.
2025-01-24 16:54:12 +08:00
Daniel Liu
aa164fbbc1 accounts/abi: fix MakeTopics mutation of big.Int inputs (#30785)
However, it also changed the behavior of the function from just
_reading_ the input `*big.Int` via `Bytes()`, to leveraging
`big.U256Bytes` which is documented as being _destructive_:

This change updates `MakeTopics` to not mutate the original, and
also applies the same change in signer/core/apitypes.
2025-01-24 16:54:12 +08:00
Daniel Liu
db3dc1932c accounts/usbwallet: support dynamic tx (#30180)
Adds support non-legacy transaction-signing using ledger

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
2025-01-24 16:54:12 +08:00
Daniel Liu
72e5ee7f17 accounts/abi: golangci-lint 1.61.0 (#30587) 2025-01-24 16:54:12 +08:00
Daniel Liu
ced65923db accounts/abi/bind: check SendTransaction error in tests (#30349)
In few tests the returned error from `SendTransaction` is not being
checked. This PR checks the returned err in tests.

Returning errors also revealed tx in `TestCommitReturnValue` is not
actually being sent, and returns err ` only replay-protected (EIP-155)
transactions allowed over RPC`. Fixed the transaction by using the
`testTx` function.
2025-01-24 16:54:12 +08:00
Daniel Liu
11d3afd849 accounts/abi: handle ABIs with contract type parameter (#30315)
convert parameter of type contract to the basic `address` type
---------

Co-authored-by: Martin HS <martin@swende.se>
2025-01-24 16:54:12 +08:00
Daniel Liu
c6a8f79702 accounts/abi/bind: add accessList support to base bond contract (#30195)
Adding the correct accessList parameter when calling a contract can
reduce gas consumption. However, the current version only allows adding
the accessList manually when constructing the transaction. This PR can
provide convenience for saving gas.
2025-01-24 16:54:12 +08:00
Daniel Liu
5beff83a6d all: remove deprecated protobuf dependencies (#30232)
The package `github.com/golang/protobuf/proto` is deprecated in favor
`google.golang.org/protobuf/proto`. We should update the codes to
recommended package.

Signed-off-by: Icarus Wu <icaruswu66@qq.com>
2025-01-24 16:54:12 +08:00
Daniel Liu
0cbaccd106 accounts/keystore: simplify tests using t.TempDir() (#30150) 2025-01-24 16:54:12 +08:00
Daniel Liu
52ac8ae22b accounts/abi/bind: use embed pkg to split go source template to file (#30098) 2025-01-24 16:54:12 +08:00
Daniel Liu
1fcc36a2dc build: add check for stale generated files (#30037)
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-01-24 16:54:12 +08:00
Daniel Liu
a0a1322d84 accounts/usbwallet/trezor: upgrade to generate with protoc 27.1 (#30058) 2025-01-24 16:54:12 +08:00
Daniel Liu
62895df693 accounts/keystore: use t.TempDir in test (#30052) 2025-01-24 16:54:12 +08:00
Daniel Liu
d2e00672c5 accounts: avoid duplicate regex compilation (#29943)
* fix: Optimize regular initialization

* modify var name

* variable change to private types
2025-01-24 16:54:12 +08:00
Daniel Liu
643c715b43 accounts: fix TestUpdateKeyfileContents (#29867)
Create the directory before NewKeyStore. This ensures the watcher successfully starts on
the first attempt, and waitWatcherStart functions as intended.
2025-01-24 16:54:12 +08:00
Daniel Liu
ef71887d7a accounts, cmd/geth, core: close opened files (#29598)
* fix: open file used up but not closed

* feat: more same case

* feat: accept conversation
2025-01-24 16:54:12 +08:00
Daniel Liu
02a3aa13c1 accounts/abi: fix typos (#29542 #29600) 2025-01-24 16:54:12 +08:00