Skip to content

Feat/pbss#2

Closed
cffls wants to merge 65 commits into
developfrom
feat/pbss
Closed

Feat/pbss#2
cffls wants to merge 65 commits into
developfrom
feat/pbss

Conversation

@cffls
Copy link
Copy Markdown
Owner

@cffls cffls commented Aug 28, 2023

Description

Test

Changes

  • Bugfix (non-breaking change that solves an issue)
  • Hotfix (change that solves an urgent issue, and requires immediate attention)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)

Breaking changes

Please complete this section if any breaking changes have been made, otherwise delete it

Checklist

  • I have added at least 2 reviewer or the whole pos-v1 team
  • I have added sufficient documentation in code
  • I will be resolving comments - if any - by pushing each fix in a separate commit and linking the commit hash in the comment reply

Cross repository changes

  • This PR requires changes to heimdall
    • In case link the PR here:
  • This PR requires changes to matic-cli
    • In case link the PR here:

Testing

  • I have added unit tests
  • I have added tests to CI
  • I have tested this code manually on local environment
  • I have tested this code manually on remote devnet using express-cli
  • I have tested this code manually on mumbai
  • I have created new e2e tests into express-cli

Manual tests

Please complete this section with the steps you performed if you ran manual tests for this functionality, otherwise delete it

Additional comments

Please post additional comments in this section if you have them, otherwise delete it

cffls and others added 30 commits August 8, 2023 17:39
* core, trie: rework trie database

* trie: fix comment
* trie: add node type common package

In trie/types package, a few node wrappers are defined, which will be used
in both trie package, trie/snap package, etc. Therefore, a standalone common
package is created to put these stuffs.

* trie: rename trie/types to trie/trienode
…27049)

* core/types, params: add blob transaction type, RLP encoded for now

* all: integrate Cancun (and timestamp based forks) into MakeSigner

* core/types: fix 2 back-and-forth type refactors

* core: fix review comment

* core/types: swap blob tx type id to 0x03
* all: port boring changes from pbss

* core, trie: address comments from martin

* trie: minor fixes

* core/rawdb: update comment

* core, eth, tests, trie: address comments

* tests, trie: add extra check when update trie database

* trie/triedb/hashdb: degrade the error to warning
…7147)

* all: remove notion of trusted checkpoints in the post-merge world

* light: remove unused function

* eth/ethconfig, les: remove unused config option

* les: make linter happy

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
Adds an optional config parameter to eth_call which allows users to override block context fields (same functionality that was added to traceCall in #24871)

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
* light: use atomic type

* light: use a suitable name for the stopped switch in LightChain
* eth: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

* consensus: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

---------

Signed-off-by: jsvisa <delweng@gmail.com>
ethclient accepts certain negative block number values as specifiers for the "pending",
"safe" and "finalized" block. In case of "pending", the value accepted by ethclient (-1)
did not match rpc.PendingBlockNumber (-2).

This wasn't really a problem, but other values accepted by ethclient did match the
definitions in package rpc, and it's weird to have this one special case where they don't.

To fix it, we decided to change the values of the constants rather than changing ethclient.
The constant values are not otherwise significant. This is a breaking API change, but we
believe not a dangerous one.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
…sts (#27178)

* all: remove ethash pow, only retain shims needed for consensus and tests

* all: thank you linter

* all: disallow launching Geth in legacy PoW mode

* cmd/env/internal/t8ntool: remove dangling ethash flag
This change splits up the multiple API functions / namespaces currently defined in the eth package into different per-namespace files.
This change implements async log retrievals via feeding logs in channels, instead of returning slices. This is a first step to implement #15063.  

---------

Signed-off-by: jsvisa <delweng@gmail.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
Drop the notions of uncles, and disables activities while syncing

-  Disable activities (e.g. generate pending state) while node is syncing,
-  Disable empty block submission (but empty block is still kept for payload building),
-  Drop uncle notion since (ethash is already deprecated)
…mplementation (#27310)

Deserialize hex keys early to shortcut on invalid input, and re-use the account storageTrie for each proof for each proof in the account, preventing repeated deep-copying of the trie.

Closes #27308

 --------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
* core: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

* console: replace noarg fmt.Errorf with errors.New

Signed-off-by: jsvisa <delweng@gmail.com>

* core: go autoimport

Signed-off-by: jsvisa <delweng@gmail.com>

* core: dry

Signed-off-by: jsvisa <delweng@gmail.com>

---------

Signed-off-by: jsvisa <delweng@gmail.com>
Fixes a discrepancy between source and generated files, which was introduced when ExcessDataGas was added in ethereum/go-ethereum#27046.
This removes the feature where top nodes of the proof can be elided.
It was intended to be used by the LES server, to save bandwidth 
when the client had already fetched parts of the state and only needed
some extra nodes to complete the proof. Alas, it never got implemented
in the client.
* core: crypto: implement BLOBHASH and pointEval precompile

* core: crypto: fixed nitpicks, moved precompile return value

* core/vm: fix review comments
* cryto/kzg4844: pull in the C and Go libs for KZG cryptography

* go.mod: pull in the KZG libraries

* crypto/kzg4844: add basic becnhmarks for ballpark numbers

* cmd, crypto: integrate both CKZG and GoKZG all the time, add flag

* cmd/utils, crypto/kzg4844: run library init on startup

* crypto/kzg4844: make linter happy

* crypto/kzg4844: push missing file

* crypto/kzg4844: fully disable CKZG but leave in the sources

* build, crypto/kzg4844, internal: link CKZG by default and with portable mode

* crypto/kzg4844: drop verifying the trusted setup in gokzg

* internal/build: yolo until it works?

* cmd/utils: make flag description friendlier

Co-authored-by: Martin Holst Swende <martin@swende.se>

* crypto/ckzg: no need for double availability check

* build: tiny flag cleanup nitpick

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
fixes bug which caused the zero-address to be ignored during an iterative state-dump.

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
This changes the journal logic to mark the state object dirty immediately when it
is reset. 

We're mostly adding this change to appease the fuzzer. Marking it dirty immediately
makes no difference in practice because accounts will always be modified by EVM
right after creation.
The state availability is checked during the creation of a state reader.

-    In hash-based database, if the specified root node does not exist on disk disk, then
    the state reader won't be created and an error will be returned.

-    In path-based database, if the specified state layer is not available, then the
    state reader won't be created and an error will be returned.

This change also contains a stricter semantics regarding the `Commit` operation: once it has been performed, the trie is no longer usable, and certain operations will return an error.
Dan Laine and others added 11 commits August 16, 2023 14:33
Co-authored-by: Felix Lange <fjl@twurst.com>
* go.mod: update kzg libraries to use big-endian

* go.sum: ran go mod tidy

* core/testdata/precompiles: fix blob verification test

* core/testdata/precompiles: fix blob verification test
It is usually best to set GOMAXPROCS to the number of available CPU cores. However, setting
it like that does not work well when the process is quota-limited to a certain number of CPUs.
The automaxprocs library configures GOMAXPROCS, taking such limits into account.
* cmd/evm: make evm blocktest output logs if so instructed

* Apply suggestions from code review

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>

---------

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
implements the ability to run several state-tests in one instance. By not providing a statetest path to the `evm statetest` command, the path(s) will instead be read from `stdin`.
This updates the reference tests to the latest version and also adds logic
to process EIP-4844 blob transactions into the state transition. We are now
passing most Cancun fork tests.

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Felix Lange <fjl@twurst.com>
* params, trie: add verkle fork management + upgrade go-verkle

* remove the two verkle files

* core, eth, params: add missing function

* Gary's feedback

* remove trie/utils/verkle.go

* add verkle block override

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
Dan Laine and others added 8 commits September 5, 2023 15:44
Co-authored-by: Felix Lange <fjl@twurst.com>
Also adds Address.Less for sorting use in other packages.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
* all: implement path-based state scheme

* all: edits from review

* core/rawdb, trie/triedb/pathdb: review changes

* core, light, trie, eth, tests: reimplement pbss history

* core, trie/triedb/pathdb: track block number in state history

* trie/triedb/pathdb: add history documentation

* core, trie/triedb/pathdb: address comments from Peter's review

Important changes to list:

- Cache trie nodes by path in clean cache
- Remove root->id mappings when history is truncated

* trie/triedb/pathdb: fallback to disk if unexpect node in clean cache

* core/rawdb: fix tests

* trie/triedb/pathdb: rename metrics, change clean cache key

* trie/triedb: manage the clean cache inside of disk layer

* trie/triedb/pathdb: move journal function

* trie/triedb/path: fix tests

* trie/triedb/pathdb: fix journal

* trie/triedb/pathdb: fix history

* trie/triedb/pathdb: try to fix tests on windows

* core, trie: address comments

* trie/triedb/pathdb: fix test issues

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
This change adds the ability to perform reads from freezer without size limitation. This can be useful in cases where callers are certain that out-of-memory will not happen (e.g. reading only a few elements).

The previous API was designed to behave both optimally and secure while servicing a request from a peer, whereas this change should _not_ be used when an untrusted peer can influence the query size.
* all: activate pbss

* core/rawdb: fix compilation error

* cma, core, eth, les, trie: address comments

* cmd, core, eth, trie: polish code

* core, cmd, eth: address comments

* cmd, core, eth, les, light, tests: address comment

* cmd/utils: shorten log message

* trie/triedb/pathdb: limit node buffer size to 1gb

* cmd/utils: fix opening non-existing db

* cmd/utils: rename flag name

* cmd, core: group chain history flags and fix tests

* core, eth, trie: fix memory leak in snapshot generation

* cmd, eth, internal: deprecate flags

* all: enable state tests for pathdb, fixes

* cmd, core: polish code

* trie/triedb/pathdb: limit the node buffer size to 256mb

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 4, 2023

This PR is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions Bot added the Stale label Oct 4, 2023
@github-actions
Copy link
Copy Markdown

This PR was closed because it has been stalled for 35 days with no activity.

@github-actions github-actions Bot closed this Oct 19, 2023
cffls pushed a commit that referenced this pull request Jun 13, 2025
This PR is #2 of a 3-part series that implements the new log index
intended to replace core/bloombits.
Based on ethereum/go-ethereum#31079
Replaces ethereum/go-ethereum#30370

This part replaces the old bloombits based log search logic in
`eth/filters` to use the new `core/filtermaps` logic.

FilterMaps data structure explanation:
https://gist.github.com/zsfelfoldi/a60795f9da7ae6422f28c7a34e02a07e

Log index generator code overview:
https://gist.github.com/zsfelfoldi/97105dff0b1a4f5ed557924a24b9b9e7

Search pattern matcher code overview:
https://gist.github.com/zsfelfoldi/5981735641c956afb18065e84f8aff34

Note that the possibility of a tree hashing scheme and remote proof
protocol are mentioned in the documents above but they are not exactly
specified yet. These specs are WIP and will be finalized after the local
log indexer/filter code is finalized and merged.

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
cffls pushed a commit that referenced this pull request Apr 27, 2026
)

* consensus/bor: refactor Finalize to add better checks for state-sync

* consensus/bor: refactor tests

* consensus/bor: resolve small comment for test

* consensus/bor: type check before setting state-syncs
cffls added a commit that referenced this pull request May 1, 2026
…rnal review

An external reviewer found six issues in V2's correctness/operability
surface. Fixes for each, plus targeted regression tests.

#1 (CRITICAL) — V2 swallowed ApplyMessage errors. applyMessage at
core/parallel_state_processor.go:735 ignored execErr when result==nil,
so a tx with a consensus-level error (bad nonce, intrinsic gas under-
flow, insufficient upfront gas, blob fork-gating violation, etc.)
settled as a zero-gas successful no-op. Serial returns the error and
aborts the block (state_processor.go:222). V2 now records execErr on
the PDB, the settle path skips the tx, and Process surfaces the error
to BlockChain so it can fall back to serial — same behaviour as the
panicked-PDB path. Test: TestV2StateProcessor_ApplyMessageErrorFailsBlock.

#2 (CRITICAL) — SelfDestruct not published to MVStore. FlushToMVStore
wrote nonces, storage, code, created, balance deltas, but never the
destructed set. Cross-tx readers saw destroyed accounts as still alive
with stale code/storage/nonce. Pre-EIP-6780 chains: tx B reading a
just-destroyed account got base-state values; SetStorageDirectWithOrigins
at settle time would resurrect the account. Fix: publish destructions
under SuicidePath (the same flag V1 already uses on its MVHashMap), and
gate Exist/GetCode/GetCodeHash/GetState/GetCommittedState/GetNonce on
priorDestructed so cross-tx reads return defaults. priorDestructed is
cached per-tx so the four getters share one MVStore lookup per address.
Test: TestPDB_CrossTxSelfDestructVisibility.

#3 (HIGH) — V2 receipts had zero BlockHash. buildV2Receipt didn't set
BlockHash and passed common.Hash{} to GetLogs. Receipt-trie consensus
was unaffected (BlockHash is not in the consensus encoding) but RPC
consumers got 0x000…0 for blockHash on V2-processed blocks. Thread
block.Hash() through ExecuteV2BlockSTM → newV2SettleFn → buildV2Receipt
and into GetLogs. Test: TestV2StateProcessor_ReceiptHasBlockHash.

#4 (HIGH) — V2 executor ignored cancellation. core/blockstm/v2_executor.go
had no context plumbing, so when serial won the parallel-vs-serial
race and BlockChain called cancel(), V2 ran to completion (~50–200ms)
before the import could continue; if V2 hung, the import couldn't
return. Add ctx.Context to ExecuteV2BlockSTM, plumb it through to the
dispatcher and validation loop, check at task-boundary and validation
boundaries. Updated the misleading "<1ms" comment in blockchain.go.
Test: TestExecuteV2BlockSTM_HonoursCancellation.

#5 (MEDIUM) — numWorkers <= 0 deadlocked the executor. The dispatcher
window collapsed to 0 and the very first task waited forever on an
execDone channel no worker would close (v2_executor.go:355). Clamp
to runtime.NumCPU() in NewV2StateProcessor with a comment explaining
the failure mode. Test: TestNewV2StateProcessor_ClampsNumWorkers.

0xPolygon#6 (LOW, comment-only) — Biased pathdb cache lock removal. The Has →
Set race exists but is benign because reader.Node hash-checks every
cache hit (Verkle-only noHashCheck doesn't apply to Bor). The previous
comment claimed "self-corrects on the next disk read" — actually it
self-corrects via the hash check in reader.go:72. Tightened the
comment.

Verified: ./core/, ./core/state/, ./core/blockstm/ tests pass; the V2
backbone TestV2BlockSTMAllBlocks passes (165s).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cffls added a commit that referenced this pull request May 4, 2026
A second pass of external review surfaced three issues missed by the
prior round.

#1 (CRITICAL) — selfdestruct over-applied as a permanent same-block
tombstone. priorDestructed used to be a monotonic boolean: once any
prior tx wrote SuicidePath for addr, every subsequent read of addr
returned the destroyed view. That diverges from serial when a later
same-block tx recreates addr (CREATE2 / SetCode / value transfer):
serial sees the recreated empty/new account, V2 still saw the
tombstone, and validation could not catch it because the SuicidePath
read remained stable.

Replace with priorDestructedAt + priorCreatedAt, both returning the
tx index of the most recent SuicidePath / CreatePath writer (or -1).
Each getter now compares its own MVStore writer's tx index against
the most recent suicide:
  - GetNonce / GetCode / GetCodeHash / GetState / GetCommittedState:
    honor the path-specific writer only when its index > suicideIdx,
    otherwise treat as wiped by the destruction.
  - Exist: returns the side of the most recent ordering event,
    falling back to the balance-recreation path when destruction was
    most recent (matches serial's "value transfer recreates" rule).

Test: TestPDB_CrossTxSelfDestructThenRecreate exercises both an
explicit recreate (CreateAccount writes CreatePath) and an implicit
recreate (value transfer with no CreatePath write — Exist's balance
fallback must still report true). Both subtests fail without the fix.

#2 (HIGH) — V2 cancellation could still hang under mid-flight cancel.
runValidationLoop's pre-loop ctx check caught a pre-cancelled context
but the dispatcher could exit between iterations, leaving execDone[i]
unclosed; validateOne's `<-x.execDone[i]` would block forever.
Workers and re-exec goroutines blocked on waitForTx / waitForFinal
would also hang because those did plain `<-execDone` / `<-completionCh`.
Result: BlockChain.ProcessBlock's synchronous wait for the losing
processor stalls forever if V2 is the loser.

Fix: thread ctx.Done() into waitForTx, waitForFinal, and validateOne's
execDone read. The validation loop now exits via either pre-loop or
in-loop cancellation; in-flight workers and re-exec goroutines drain
out via the new ctx-aware waits. Helpers tolerate a nil ctx (existing
unit tests don't construct a v2ExecCtx with one).

Test: TestExecuteV2BlockSTM_MidFlightCancellation queues 32 txs,
spawns ExecuteV2BlockSTM in a goroutine, cancels after 2ms, asserts
return within 10s. Without the fix, the test hangs.

#3 (MEDIUM) — biased pathdb cache stays poisoned until natural
eviction after a stale Has→Set race. The previous comment claimed the
hash check in reader.Node made stale blobs harmless, but a stale blob
caused Node to error out without evicting; the next read of that key
hit the same stale entry and errored again, until the entry was
evicted by capacity pressure.

Fix: on locCleanCache hash mismatch, reader.Node now evicts the
offending entry from the disk layer's cache (via a parentLayer walk
to reach the disk layer) and retries the read once. The cache
self-heals immediately instead of returning errors until eviction.
Worst case is one extra disk fetch per stale-blob occurrence.

V2 backbone (TestV2BlockSTMAllBlocks) and full ./core/state/,
./core/blockstm/, ./trie/, ./triedb/pathdb/ test suites pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.