1
0
Fork 0
forked from forks/go-ethereum
Commit graph

15871 commits

Author SHA1 Message Date
crStiv
2547bb28a4
eth/fetcher: Fix flaky TestTransactionForgotten test using mock clock (#31468)
Fixes #31169

The TestTransactionForgotten test was flaky due to real time
dependencies. This PR:

- Replaces real time with mock clock for deterministic timing control
- Adds precise state checks at timeout boundaries
- Verifies underpriced cache states and cleanup
- Improves test reliability by controlling transaction timestamps
- Adds checks for transaction re-enqueueing behavior

The changes ensure consistent test behavior without timing-related
flakiness.

---------

Co-authored-by: Zsolt Felfoldi <zsfelfoldi@gmail.com>
2025-04-10 11:26:35 +02:00
Luis Ayuso
0c2ad07673
core/txpool: allow tx and authority regardless of admission order (#31373)
This PR proposes a change to the authorizations' validation introduced
in commit cdb66c8. These changes make the expected behavior independent
of the order of admission of authorizations, improving the
predictability of the resulting state and the usability of the system
with it.

The current implementation behavior is dependent on the transaction
submission order: This issue is related to authorities and the sender of
a transaction, and can be reproduced respecting the normal nonce rules.

The issue can be reproduced by the two following cases:
**First case**
- Given an empty pool.
- Submit transaction `{ from: B, auths [ A ] }`: is accepted.
- Submit transaction `{ from: A }`: Is accepted: it becomes the one
in-flight transaction allowed.

**Second case**
- Given an empty pool.
- Submit transaction `{ from: A }`:  is accepted
- Submit transaction `{ from: B, auths [ A ] }`: is rejected since there
is already a queued/pending transaction from A.

The expected behavior is that both sequences of events would lead to the
same sets of accepted and rejected transactions.

**Proposed changes** 
The queued/pending transactions issued from any authority of the
transaction being validated have to be counted, allowing one transaction
from accounts submitting an authorization.

- Notice that the expected behavior was explicitly forbidden in the case
"reject-delegation-from-pending-account", I believe that this behavior
conflicts to the definition of the limitation, and it is removed in this
PR. The expected behavior is tested in
"accept-authorization-from-sender-of-one-inflight-tx".
- Replacement tests have been separated to improve readability of the
acceptance test.
- The test "allow-more-than-one-tx-from-replaced-authority" has been
extended with one extra transaction, since the system would always have
accepted one transaction (but not two).
- The test "accept-one-inflight-tx-of-delegated-account" is extended to
clean-up state, avoiding leaking the delegation used into the other
tests. Additionally, replacement check is removed to be tested in its
own test case.

**Expected behavior** 
The expected behavior of the authorizations' validation shall be as
follows:

![image](https://github.com/user-attachments/assets/dbde7a1f-9679-4691-94eb-c197a0cbb823)
Notice that replacement shall be allowed, and behavior shall remain
coherent with the table, according to the replaced transaction.

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
2025-04-09 19:11:24 -06:00
lightclient
60b922fd52
core/txpool: add notice to Clear that is not meant for production code (#31567)
The `Sync(..)` function explicitly says not to rely on in production
code, but it is used in `Clear(..)` so should add a similar mention.
2025-04-09 14:19:28 -06:00
Csaba Kiraly
a7f24c26c0
p2p/nat: fix UPnP port reset (#31566)
Make UPnP more robust

- Once a random port was mapped, we try to stick to it even if a UPnP
refresh fails. Previously we were immediately moving back to try the
default port, leading to frequent ENR changes.

- We were deleting port mappings before refresh as a possible
workaround. This created issues in some UPnP servers. The UPnP (and PMP)
specification is explicit about the refresh requirements, and delete is
clearly not needed (see
https://github.com/ethereum/go-ethereum/pull/30265#issuecomment-2766987859).
From now on we only delete when closing.

- We were trying to add port mappings only once, and then moved on to
random ports. Now we insist a bit more, so that a simple failed request
won't lead to ENR changes.

Fixes https://github.com/ethereum/go-ethereum/issues/31418

---------

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-09 11:28:29 +02:00
Marius van der Wijden
5cc9137c9c
core/vm: optimize push2 opcode (#31267)
During my benchmarks on Holesky, around 10% of all CPU time was spent in
PUSH2
```
ROUTINE ======================== github.com/ethereum/go-ethereum/core/vm.newFrontierInstructionSet.makePush.func1 in github.com/ethereum/go-ethereum/core/vm/instructions.go
    16.38s     20.35s (flat, cum) 10.31% of Total
     740ms      740ms    976:	return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
         .          .    977:		var (
      40ms       40ms    978:			codeLen = len(scope.Contract.Code)
     970ms      970ms    979:			start   = min(codeLen, int(*pc+1))
     200ms      200ms    980:			end     = min(codeLen, start+pushByteSize)
         .          .    981:		)
     670ms      2.39s    982:		a := new(uint256.Int).SetBytes(scope.Contract.Code[start:end])
         .          .    983:
         .          .    984:		// Missing bytes: pushByteSize - len(pushData)
     410ms      410ms    985:		if missing := pushByteSize - (end - start); missing > 0 {
         .          .    986:			a.Lsh(a, uint(8*missing))
         .          .    987:		}
    12.69s     14.94s    988:		scope.Stack.push2(*a)
      10ms       10ms    989:		*pc += size
     650ms      650ms    990:		return nil, nil
         .          .    991:	}
         .          .    992:}
```

Which is quite crazy. We have a handwritten encoder for PUSH1 already,
this PR adds one for PUSH2.

PUSH2 is the second most used opcode as shown here:
https://gist.github.com/shemnon/fb9b292a103abb02d98d64df6fbd35c8 since
it is used by solidity quite significantly. Its used ~20 times as much
as PUSH20 and PUSH32.

# Benchmarks

```
BenchmarkPush/makePush-14         	94196547	        12.27 ns/op	       0 B/op	       0 allocs/op
BenchmarkPush/push-14             	429976924	         2.829 ns/op	       0 B/op	       0 allocs/op
``` 

---------

Co-authored-by: jwasinger <j-wasinger@hotmail.com>
2025-04-08 19:57:45 +02:00
rjl493456442
2e739fce58
core/txpool: add 7702 protection to blobpool (#31526)
This pull request introduces two constraints in the blobPool:

(a) If the sender has a pending authorization or delegation, only one
in-flight
executable transaction can be cached.
(b) If the authority address in a SetCode transaction is already
reserved by
the blobPool, the transaction will be rejected.

These constraints mitigate an attack where an attacker spams the pool
with
numerous blob transactions, evicts other transactions, and then cancels
all
pending blob transactions by draining the sender’s funds if they have a
delegation.

Note, because there is no exclusive lock held between different subpools
when processing transactions, it's totally possible the SetCode
transaction
and blob transactions with conflict sender and authorities are accepted
simultaneously. I think it's acceptable as it's very hard to be
exploited.

---------

Co-authored-by: lightclient <lightclient@protonmail.com>
2025-04-08 07:46:27 -06:00
Ocenka
ec6d104404
eth/remotedb: improve error handling (#31331)
This PR improves error handling in the remotedb package by fixing two
issues:

1. In the `Has` method, we now properly propagate errors instead of
silently returning false. This makes the behavior more predictable and
helps clients better understand when there are connection issues.

2. In the `New` constructor, we add a nil check for the client parameter
to prevent potential panics. This follows Go best practices for
constructor functions.

These changes make the code more robust and follow Go's error handling
idioms without requiring any changes to other parts of the codebase.

Changes:
- Modified `Has` method to return errors instead of silently returning
false
- Added nil check in `New` constructor
- Fixed field name in constructor to match struct definition
2025-04-08 14:44:13 +02:00
Delweng
21b035eb29
cmd/geth: set trie,gc and other cache flags for import chain (#31577)
Signed-off-by: jsvisa <delweng@gmail.com>
2025-04-07 13:16:26 +08:00
Sina M
77dc1acafa
internal/era: random access to header and receipts (#31544)
Co-authored-by: lightclient <lightclient@protonmail.com>

Add GetHeaderByNumber and GetReceiptsByNumber to allow more efficient API request filling from Era files.
2025-04-04 06:07:46 -06:00
Nathan Jo
ff365afc63
p2p/nat: remove forceful port mapping in upnp (#30265)
Here we are modifying the port mapping logic so that existing port
mappings will only be removed when they were previously created by geth.

The AddAnyPortMapping functionality has been adapted to work consistently
between the IGDv1 and IGDv2 backends.
2025-04-04 10:56:55 +02:00
Felföldi Zsolt
9f83e9e673
beacon/blsync: add checkpoint import/export file feature (#31469)
This PR adds a new `--beacon.checkpoint.file` config flag to geth and
blsync which specifies a checkpoint import/export file. If a file with
an existing checkpoint is specified, it is used for initialization
instead of the hardcoded one (except when `--beacon.checkpoint` is also
specified simultaneously). Whenever the client encounters a new valid
finality update with a suitable finalized beacon block root at an epoch
boundary, it saves the block root in hex format to the checkpoint file.
2025-04-03 16:04:11 +02:00
rjl493456442
553183e5de
core, eth, node: use sync write option in pebble (#31519)
Fixes #31499
2025-04-03 16:03:03 +02:00
Felix Lange
49f0d49e89
cmd/devp2p/internal/v5test: log test descriptions (#31551)
This adds the test description text to the output, instead of keeping it
as a Go comment. Logs are visible in the hive UI where these tests run,
while Go comments are not.
2025-04-03 15:58:37 +02:00
Felix Lange
a0620f114c
eth: fix calls to HistoryPruningCutoff (#31552)
These were caused by crossed merges of recent PRs #31414 and #31361
2025-04-03 15:44:07 +02:00
Mobin Mohanan
db9be56bab
build: upgrade to golangci-lint v2 (#31530) 2025-04-03 15:18:35 +02:00
rjl493456442
90d44e715d
core, eth/downloader: implement pruning mode sync (#31414)
This pull request introduces new sync logic for pruning mode. The downloader will now skip
insertion of block bodies and receipts before the configured history cutoff point.

Originally, in snap sync, the header chain and other components (bodies and receipts) were
inserted separately. However, in Proof-of-Stake, this separation is unnecessary since the
sync target is already verified by the CL.

To simplify the process, this pull request modifies `InsertReceiptChain` to insert headers
along with block bodies and receipts together. Besides, `InsertReceiptChain` doesn't have
the notion of reorg, as the common ancestor is always be found before the sync and extra
side chain is truncated at the beginning if they fall in the ancient store. The stale
canonical chain flags will always be rewritten by the new chain. Explicit reorg logic is
no longer required in `InsertReceiptChain`.
2025-04-03 15:16:35 +02:00
antonis19
22c0605b68
eth/protocols/eth: improve over/underflow handling in GetBlockHeaders (#31522) 2025-04-03 12:35:52 +08:00
fuder.eth
e6098437a6
all: fix typos in docs and comments (#31548)
Co-authored-by: lightclient <lightclient@protonmail.com>
2025-04-02 13:52:40 -06:00
owen
82f01f9f24
README: fixup typos (#31540)
Fixes a few typos in readme.
2025-04-02 11:19:25 -06:00
thinkAfCod
d2176f463b
p2p/discover: pass node instead of node ID to TALKREQ handler (#31075)
This is for the implementation of Portal Network in the Shisui client.
Their handler needs access to the node object in order to send further
calls to the requesting node. This is a breaking API change but it
should be fine, since there are basically no known users of TALKREQ
outside of Portal network.

---------

Signed-off-by: thinkAfCod <q315xia@163.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-02 14:56:21 +02:00
thinkAfCod
3e4fbce034
p2p/discover: repeat exact encoding when resending WHOAREYOU packet (#31543)
When resending the WHOAREYOU packet, a new nonce and random IV should not
be generated. The sent packet needs to match the previously-sent one exactly
in order to make the handshake retry work.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-02 13:47:44 +02:00
minh-bq
ee30681a8d
core/txpool: add GetMetadata to transaction pool (#31433)
This is an alternative to #31309

With eth/68, transaction announcement must have transaction type and
size. So in announceTransactions, we need to query the transaction from
transaction pool with its hash. This creates overhead in case of blob
transaction which needs to load data from billy and RLP decode. This
commit creates a lightweight lookup from transaction hash to transaction
size and a function GetMetadata to query transaction type and
transaction size given the transaction hash.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2025-04-02 15:47:56 +08:00
Ng Wei Han
a9e6c8daae
triedb/pathdb: improve perf by separating nodes map (#31306)
This PR refactors the `nodeSet` structure in the path database to use
separate maps for account and storage trie nodes, resulting in
performance improvements. The change maintains the same API while
optimizing the internal data structure.
2025-04-02 15:06:54 +08:00
Delweng
d342f76232
accounts/abi/abigen: fix a flaky bind test case NewSingleStructArgument (#31501)
found the failed testcase here
https://ci.appveyor.com/project/ethereum/go-ethereum/builds/51767091/job/rbjke432c05pufja

add a timeout to wait the tx to be mined.

---------

Signed-off-by: jsvisa <delweng@gmail.com>
Co-authored-by: Jared Wasinger <j-wasinger@hotmail.com>
2025-04-01 16:13:37 +02:00
Felföldi Zsolt
7e3170fb5c
core/filtermaps: add metrics (#31511)
This PR adds metrics related to map rendering and pattern matching to
the `core/filtermaps` package.
2025-04-01 14:29:20 +02:00
Delweng
4add312c8a
cmd: apply snapshot cache flag in the MakeChain (#31534) 2025-04-01 20:10:22 +08:00
John
1bd70ba57a
p2p/nat: improve AddMapping code (#31486)
It introduces a new variable to store the external port returned by the
addAnyPortMapping function and ensures that the correct external port is
returned even in case of an error.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-01 14:07:47 +02:00
Sina M
bc36f2de83
eth, eth/filters: implement API error code for pruned blocks (#31361)
Implements #31275

---------

Co-authored-by: Jared Wasinger <j-wasinger@hotmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-01 13:42:01 +02:00
Felix Lange
f0cdc40ceb version: begin v1.15.8 release cycle reloaded 2025-03-31 18:29:33 +02:00
Felix Lange
827d3fccf7 .travis.yml: remove macos build 2025-03-31 18:27:43 +02:00
Felix Lange
9af88d1100 version: back to v1.15.7, to fix the build 2025-03-31 18:26:56 +02:00
Felix Lange
9c970d80a2 version: begin v1.15.8 release cycle 2025-03-31 15:30:31 +02:00
Felix Lange
82fc77a865 version: release go-ethereum v1.15.7 stable 2025-03-31 15:29:03 +02:00
Felföldi Zsolt
14d576c002
core/filtermaps: hashdb safe delete range (#31525)
This PR adds `rawdb.SafeDeleteRange` and uses it for range deletion in
`core/filtermaps`. This includes deleting the old bloombits database,
resetting the log index database and removing index data for unindexed
tail epochs (which previously weren't properly implemented for the
fallback case).
`SafeDeleteRange` either calls `ethdb.DeleteRange` if the node uses the
new path based state scheme or uses an iterator based fallback method
that safely skips trie nodes in the range if the old hash based state
scheme is used. Note that `ethdb.DeleteRange` also has its own iterator
based fallback implementation in `ethdb/leveldb`. If a path based state
scheme is used and the backing db is pebble (as it is on the majority of
new nodes) then `rawdb.SafeDeleteRange` uses the fast native range
delete.
Also note that `rawdb.SafeDeleteRange` has different semantics from
`ethdb.DeleteRange`, it does not automatically return if the operation
takes a long time. Instead it receives a `stopCallback` that can
interrupt the process if necessary. This is because in the safe mode
potentially a lot of entries are iterated without being deleted (this is
definitely the case when deleting the old bloombits database which has a
single byte prefix) and therefore restarting the process every time a
fixed number of entries have been iterated would result in a quadratic
run time in the number of skipped entries.

When running in safe mode, unindexing an epoch takes about a second,
removing bloombits takes around 10s while resetting a full log index
might take a few minutes. If a range delete operation takes a
significant amount of time then log messages are printed. Also, any
range delete operation can be interrupted by shutdown (tail uinindexing
can also be interrupted by head indexing, similarly to how tail indexing
works). If the last unindexed epoch might have "dirty" index data left
then the indexed map range points to the first valid epoch and
`cleanedEpochsBefore` points to the previous, potentially dirty one. At
startup it is always assumed that the epoch before the first fully
indexed one might be dirty. New tail maps are never rendered and also no
further maps are unindexed before the previous unindexing is properly
cleaned up.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
2025-03-31 14:47:56 +02:00
Marius van der Wijden
ffa315f746
.gitignore: ignore binaries (#31531)
Ignores all hand-built binaries (built with go build, everything built
with make is already ignored)
2025-03-31 09:49:19 +02:00
Felföldi Zsolt
c8a9a9c091
core/filtermaps: revert to unindexed mode in case of indexing error (#31500)
This PR changes log indexer error handling so that if an indexing error
happens then it disables the indexer and reverts to unindexed more
without resetting the database (except in case of a failed database
init).
Resetting the database on the first error would probably be overkill as
a client update might fix this without having to reindex the entire
history. It would also make debugging very hard. On the other hand,
these errors do not resolve themselves automatically so constantly
retrying makes no sense either. With these changes a new attempt to
resume indexing is made every time the client is restarted.
The PR also fixes https://github.com/ethereum/go-ethereum/issues/31491
which originated from the tail indexer trying to resume processing a
failed map renderer.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-03-28 16:17:28 +01:00
rjl493456442
32f36a6749
core/txpool: fix nonce assignment in local tracker (#31496)
Fixes #31494
2025-03-28 12:32:24 +01:00
rekyyang
141968a48b
core/txpool/legacypool: fix data race in checkDelegationLimit (#31475) 2025-03-28 15:16:37 +08:00
Delweng
714fa4f2e6
cmd/geth: update geth subcommand arguments (#31293) 2025-03-28 15:15:13 +08:00
jwasinger
cc273cef0b
Merge pull request #31228 from curvegrid/fix-sim-rollback
eth/catalyst: force sync of txpool before clearing subpools in Rollback
2025-03-27 18:40:15 +01:00
georgehao
6143c350ae
internal/ethapi: CreateAccessList with stateOverrides (#31497)
Add support for state overrides in eth_createAccessList. This will make the method consistent
with other execution methods.

---------

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2025-03-27 12:22:17 +01:00
protolambda
a82303f4e3
accounts/abi: include access-list in gas estimation (#31394)
Simple bugfix to include the access-list in the gas-estimation step of
the ABI bindings code.
2025-03-26 16:14:17 +01:00
VolodymyrBg
a775e68421
eth: downgrade peer removal error to warning level (#31492) 2025-03-26 19:57:08 +08:00
rjl493456442
5b4a743493
core/rawdb: remove LES database stats (#31495)
This removes DB schema for LES related db entries. LES has been non-functional
since the merge.
2025-03-26 12:48:04 +01:00
Delweng
c1ff2d8ba9
core/state: fix double-increment of accountLoaded counter (#31493) 2025-03-26 12:59:40 +08:00
sashabeton
c49aadc4b6
internal/ethapi: exclude 7702 authorities from result in eth_createAccessList (#31336)
closes https://github.com/ethereum/go-ethereum/issues/31335

---------

Co-authored-by: sashabeton <sashabeton2007@gmail.com>
2025-03-25 15:01:21 +01:00
rjl493456442
4dfec7e83e
trie: optimize memory allocation (#30932)
This pull request removes the node copy operation to reduce memory
allocation. Key Changes as below:

**(a) Use `decodeNodeUnsafe` for decoding nodes retrieved from the trie
node reader**

In the current implementation of the MPT, once a trie node blob is
retrieved, it is passed to `decodeNode` for decoding. However,
`decodeNode` assumes the supplied byte slice might be mutated later, so
it performs a deep copy internally before parsing the node.

Given that the node reader is implemented by the path database and the
hash database, both of which guarantee the immutability of the returned
byte slice. By restricting the node reader interface to explicitly
guarantee that the returned byte slice will not be modified, we can
safely replace `decodeNode` with `decodeNodeUnsafe`. This eliminates the
need for a redundant byte copy during each node resolution.

**(b) Modify the trie in place**

In the current implementation of the MPT, a copy of a trie node is
created before any modifications are made. These modifications include:
- Node resolution: Converting the value from a hash to the actual node.
- Node hashing: Tagging the hash into its cache.
- Node commit: Replacing the children with its hash.
- Structural changes: For example, adding a new child to a fullNode or
replacing a child of a shortNode.

This mechanism ensures that modifications only affect the live tree,
leaving all previously created copies unaffected.

Unfortunately, this property leads to a huge memory allocation
requirement. For example, if we want to modify the fullNode for n times,
the node will be copied for n times.

In this pull request, all the trie modifications are made in place. In
order to make sure all previously created copies are unaffected, the
`Copy` function now will deep-copy all the live nodes rather than the
root node itself.

With this change, while the `Copy` function becomes more expensive, it's
totally acceptable as it's not a frequently used one. For the normal
trie operations (Get, GetNode, Hash, Commit, Insert, Delete), the node
copy is not required anymore.
2025-03-25 14:59:44 +01:00
Shude Li
4ff5093df1
all: use fmt.Appendf instead of fmt.Sprintf where possible (#31301) 2025-03-25 14:53:02 +01:00
nethoxa
21d36f7c37
core: process EL requests in GenerateVerkleChain (#31175) 2025-03-25 14:13:05 +01:00
Felix Lange
aa6d0ef5f2 version: begin v1.15.7 release cycle 2025-03-25 12:26:15 +01:00