Commit graph

2470 commits

Author SHA1 Message Date
Arran Schlosberg
380aa319f9
refactor!: consolidate params and types payload access (#84)
## Why this should be merged

There are 3 places at which we perform the same, sensitive logic to
access registered payloads and as we modify more types this is likely to
expand. (e.g. `types.Header`).

## How this works

Introduces `pseudo.Accessor` to abstract the reusable code.

## How this was tested

Existing unit tests. Note that the `types.StateAccount` tests needed a
minor refactor to provide the assertions with access to the
`ExtraPayloads[T]` without introducing generic types anywhere.
2024-12-09 18:32:15 +00:00
Arran Schlosberg
d71677f141
refactor: consolidate once-only registration of extras (#85)
## Why this should be merged

Consolidates duplicated logic. Similar rationale to #84.

## How this works

New `register.AtMostOnce[T]` type is responsible for limiting calls to
`Register()`.

## How this was tested

Existing unit tests of `params`. Note that the equivalent functionality
in `types` wasn't tested but now is.
2024-12-09 17:43:59 +00:00
Arran Schlosberg
c2f1269ba3
feat!: types.ExtraPayloads supports SlimAccount (#79)
## Why this should be merged

Provides access to extra payloads registered on `types.SlimAccount`, not
just on regular `types.StateAccount`. This is a breaking syntax change
to have the method reflect the behaviour.

## How this works

Modify existing method to accept the `ExtraPayloadCarrier` interface
instead of `*StateAccount`. The interface is implemented by both
`*StateAccount` and `*SlimAccount`.

## How this was tested

Covered by existing testing.
2024-11-29 08:02:03 -08:00
Arran Schlosberg
3a754099bf
feat: state.SnapshotTree interface for drop-in replacement (#77)
## Why this should be merged

Allows for a drop-in replacement of `snapshot.Tree` (i.e. one that uses
block hashes instead of state roots). This is intended as a temporary
solution while we investigate having the state root affected by the
block hash to remove path ambiguity.

## How this works

Introduction of:
1. `state.SnapshotTree` interface to match methods required on
`snapshot.Tree` as used by `state.StateDB`; and
2. `stateconf` package for variadic options plumbed by
`StateDB.Commit()` through to `SnapshotTree.Update()`.

Although variadic (to maintain function call-signature compatibility)
only the `stateconf.WithUpdatePayload(any)` is expected to be used.
Recipients of the options can access the payload with
`stateconf.ExtractUpdatePayload()`.

## How this was tested

Unit test demonstrating propagation of `stateconf.UpdateOption` payload.
2024-11-26 17:22:13 +00:00
Arran Schlosberg
4feb960086
feat(core/state): async trie prefetching (#76)
## Why this should be merged

Performs trie prefetching concurrently, required for equivalent
performance with `coreth` / `subnet-evm` implementations.

## How this works

`StateDB.StartPrefetcher()` accepts variadic options (for backwards
compatibility of function signatures). An option to specify a
`WorkerPool` is provided which, if present, is used to call
`Trie.Get{Account,Storage}()`; the pool is responsible for concurrency
but does not need to be able to wait on the work as that is handled by
this change.

## How this was tested

Unit test demonstrating hand-off of work to a `WorkerPool` as well as
API-guaranteed ordering of events.
2024-11-26 08:01:47 -08:00
Arran Schlosberg
44068c8bab
refactor: abstract options package (#74)
## Why this should be merged

Simplifies the creation and application of variadic options; this is
also applicable to many of my other WIP branches (e.g. `snapshot`).

## How this works

See `libevm/options/options.go`, which is very simple.

## How this was tested

Existing tests of `vm.PrecompileEnvironment.Call()`, which itself uses
refactored options.
2024-11-21 13:59:51 -08:00
Arran Schlosberg
41a2592b8c
chore: post-rename cleanup + libevm intro (#68)
## Why this should be merged

Cleans up loose ends after renaming the Go module. Also adds an
introduction to the README to explain the purpose of libevm.

## How this works

The changed hash in the workflow is just a fix (although a no-op). The
spaces after the copyright headers are to stop them from [showing up in
documentation](https://pkg.go.dev/github.com/ava-labs/libevm@v1.13.14-0.1.0-rc.1/params).

## How this was tested

n/a
2024-10-30 09:51:41 -04:00
Arran Schlosberg
12b8aa5c2e
fix: pre-state tracer logging storage after call from precompile (#64)
## Why this should be merged

Fixes tracing when a stateful precompile calls another contract that
itself accesses storage.

## How this works

The pre-state tracer from `eth/tracers/native` doesn't implement
`CaptureEnter()` (entry of a new context), instead relying on
`CaptureState()` (per-opcode tracing) to detect that a new contract has
been entered. In doing so, it [maintains an
invariant](cb7eb89341/eth/tracers/native/prestate.go (L160))
that is expected when `CaptureState(vm.SLOAD, ...)` is called—breaking
the invariant results in a panic due to a nil map.

The fix involves (a) maintaining the invariant as part of
`CaptureEnter()` (previously a no-op); and (b) calling said method
inside `vm.PrecompileEnvironment.Call()`. The latter has the added
benefit of properly handling all tracing involving an outbound call from
precompiles.

## How this was tested

New integration test demonstrates that the tracer can log the retrieved
storage value.

---------

Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org>
2024-10-29 17:26:29 +11:00
Arran Schlosberg
cb7eb89341
fix: state.stateObject.empty() with extra payload (#62)
## Why this should be merged

Fixes invariant broken by introduction of `types.StateAccountExtra`.

## How this works

`state.stateObject.empty()` now also requires that the underlying
account's `Extra` field carries the zero value if a type is registered,
or is itself nil.

## How this was tested

New unit test.

---------

Co-authored-by: Darioush Jalali <darioush.jalali@avalabs.org>
2024-10-28 11:34:19 -07:00
Arran Schlosberg
4410f807c2
Merge branch 'auto-rename-module_source-2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1_workflow-c1fc594f020d23958b641a4e5a856b6e52c49d3bece94b95594864db16c1b0fc-main' into arr4n/rename-module 2024-10-17 13:07:28 +11:00
github-actions[bot]
0b56af5a01
[AUTO] rename Go module + update internal import paths
Workflow: c1fc594f020d23958b641a4e5a856b6e52c49d3bece94b95594864db16c1b0fc on branch main
2024-10-17 01:49:47 +00:00
Arran Schlosberg
77c55715f6
feat: state.{Get,Set}Extra[SA any](*StateDB,types.ExtraPayloads,...) (#48)
* feat: `state.{Get,Set}Extra[SA any](*StateDB,types.ExtraPayloads,...)`

* test: `GetExtra()` at each point in `CreateAccount()` + `SetExtra()` lifecycle

* test: reverting extras to snapshot

* test: `GetExtra()` after `StateDB.Copy()` and writes to original
2024-10-09 07:06:32 -07:00
Arran Schlosberg
51cd795878
fix: vm.WithUNSAFECallerAddressProxying under DELEGATECALL (#50)
* fix: `vm.WithUNSAFECallerAddressProxying` under `DELEGATECALL`

* test: `vm.WithUNSAFECallerAddressProxying()` effect on outgoing caller addr

* chore: mark `eth/tracers/js` test flaky

* feat: `vm.PrecompileEnvironment.IncomingCallType()`

* chore: minor documentation edit

* doc: `PrecompileEnvironment` example for determining actual caller

* chore: placate the linter
2024-10-07 12:46:14 +01:00
Arran Schlosberg
5ec080f75d
test: StateAccount.Extra via trie.StateTrie.{Update,Get}Account() (#45)
* refactor: abstract `testonly` package

* test: `StateAccount.Extra` via `trie.StateTrie.{Update,Get}Account()`

* chore: `types.TestOnlyClearRegisteredExtras()` at beginning of tests

This is a purely defensive approach in case future tests forget to clean up.

* chore: placate the linter
2024-10-02 09:45:02 -07:00
Arran Schlosberg
f0ae9c50eb
feat: types.StateAccount pseudo-generic payload (#44)
Some of the changes in the full commit history were merged into `libevm` as part of #43 in `336a289` and then merged back into this branch as `5b15698`. Cherry-picking commits was not possible as some touched both halves of the changes; the squash-merges will, however, make this convoluted history irrelevant.

* feat: `types.StateAccount` pseudo-generic payload

* feat: registration of `StateAccount` payload type

* chore: mark `eth/tracers/logger` flaky

* chore: copyright header + `gci`

* test: lock default `types.SlimAccount` RLP encoding

* feat: `vm.SlimAccount.Extra` from `StateAccount` equiv

* chore: placate the linter

* test: `pseudo.Type.EncodeRLP()`

* test: `pseudo.Type.DecodeRLP()`

* fix: `pseudo.Type.DecodeRLP()` with non-pointer type

* feat: `pseudo.Type.IsZero()` and `Type.Equal(*Type)`

* feat: `types.StateAccountExtra.DecodeRLP()`

* fix: remove unnecessary `StateAccountExtra.clone()`

* refactor: readability

* feat: `pseudo.Type.Format()` implements `fmt.Formatter`
2024-10-02 16:00:13 +01:00
Arran Schlosberg
210f8ab8e1
feat: vm.PrecompiledStatefulContract can make CALLs (#40)
* feat: `vm.PrecompiledStatefulContract` can make `CALL`s

* fix: caller propagation

* feat: precompile can override default caller in `Call()`

* refactor: `WithUNSAFEForceDelegate()` replaces `WithCaller()`

* refactor: `WithUNSAFECallerAddressProxying()` instead of `ForceDelegate`

This matches the pattern used by `ava-labs/coreth` `NativeAssetCall`.

* refactor: `type callType` replaces `rwInheritance` + `delegation` types

* refactor: abstract return-data-proxy contract bytecode

* doc: fix comments from `46346f51`

* fix: `PrecompileEnvironment.Addresses()` for all call types

* chore: readability, linting & mark upstream test flaky

* test: `PrecompileEnvironment.Call()`

* refactor: improved {read,maintain}ability

* doc: fix `evmCallArgs` example

* test: `PrecompileEnvironment.Call()` input data

* fix: write protection for non-zero call value
2024-09-30 17:26:50 +01:00
Arran Schlosberg
f1dba53688
feat: params.RulesHooks.ActivePrecompiles override (#39) 2024-09-26 15:36:07 +01:00
Arran Schlosberg
99a755f040
feat!: vm.Hooks.OverrideEVMResetArgs() receives params.Rules (#38)
* feat!: `vm.Hooks.OverrideEVMResetArgs()` receives `params.Rules`

* test: propagation of `params.Rules`
2024-09-26 15:35:54 +01:00
Arran Schlosberg
53ef0712af
feat: override EVM.Reset() args (#36) 2024-09-25 15:03:36 +01:00
Arran Schlosberg
dc619990f5
doc: licensing of libevm additions and modifications (#34)
* doc: licensing of libevm extensions and modifications

* chore: add license headers via linter

* chore: `golangci-lint run --fix`

* chore: `golangci-lint run --fix`

* chore: fix `libevm/libevm.go` header

* chore: `s/extensions/additions/`

* chore: add missing headers
2024-09-19 21:38:26 +00:00
Arran Schlosberg
1a6dd02a18
feat: override vm.NewEVM() args (#35)
* feat: override `vm.NewEVM()` args

* test: `vm.Hooks.OverrideNewEVMArgs`

* refactor: use `NewEVMArgs struct` in hook

* chore: `gci`

* fix: clear `vm.Hooks` at end of test
2024-09-19 16:54:52 -04:00
Arran Schlosberg
81e109afcc
feat: PrecompileEnvironment.ChainConfig() (#32) 2024-09-18 12:29:56 -04:00
Arran Schlosberg
df1338920b
feat: vm.MutableStack wrapper (#31)
* feat: `vm.MutableStack` wrapper

* refactor: use `require.Empty()`
2024-09-18 12:29:39 -04:00
Arran Schlosberg
ab357e0279
feat: vm.PrecompileEnvironment access to block info (#27) 2024-09-17 13:08:42 -04:00
Arran Schlosberg
c5da3ca99e
refactor!: gas consumption for stateful precompiles (#26)
* refactor!: gas consumption for stateful precompiles

* chore: remove receiver & arg names on `statefulPrecompile.RequiredGas()`

* doc: `vm.statefulPrecompile`
2024-09-17 12:58:59 -04:00
Arran Schlosberg
38eaaab96c
feat!: RulesHooks.CanCreateContract() accepts and returns gas (#28)
* refactor!: `RulesHooks.CanCreateContract()` via `defer`

`TestCanCreateContract` is unchanged and merely moved to the appropriate file.

* feat!: `RulesHooks.CanCreateContract()` accepts and returns gas

* chore: move `TestCanCreateContract` to original file

Simplifies code review

* chore: pacify linter

* refactor!: revert to non-deferred call (not at start)
2024-09-17 12:14:17 -04:00
Arran Schlosberg
58f38836c0
feat: read-only stateful precompiles (#20)
* feat: read-only argument to stateful precompiles

* refactor: group `PrecompiledStatefulRun()` args except input

* test: read-only status of all `EVM.*Call*()` methods

* feat: `PrecompileEnvironment.ReadOnlyStateDB()`

* doc: warning about allowing recursive calling

* test: precompile call from within read-only env

* refactor: introduce `{inherit,force}ReadOnly` consts

* fix: `nolint` verbose if statement
2024-09-14 10:45:18 +01:00
Arran Schlosberg
04543ea837
chore: golangci-lint CI workflow (#16)
* chore: `golangci-lint` CI workflow

* fix: make `golangci-lint` happy

* chore: bump `actions/{checkout,setup-go}` versions

* chore: overhaul `.golanci.yml` config

* fix: all linter issues

* chore: exclude non-libevm linters + change deprecated option

* fix: add overflow check in example

* fix: try again; different local version?

* chore: this is trying my patience

* chore: enable `gci` and fix ordering

* chore: mark `ethclient/gethclient` test as flaky

* chore: mark `eth/catalyst` test as flaky
2024-09-12 20:31:04 +01:00
Arran Schlosberg
72744cebe7
refactor: abstract hookstest.Register() out of hookstest.Stub.Register() (#12) 2024-09-11 17:52:14 +01:00
Arran Schlosberg
5429fd87c8
chore: squash arr4n/libevm into libevm (#7)
* feat: pseudo-generic extra payloads in `params.ChainConfig` and `params.Rules`

* feat: `params.ExtraPayloadGetter` for end-user type safety

* refactor: payloads only available through `params.ExtraPayloadGetter`

* chore: make `libevm/examples/extraparams` a `params` testable example

* doc: `libevm/pseudo` package comments and improved readability

* doc: `params.*Extra*` comments and improved readability

* doc: `params.ExtraPayloadGetter` comments and improved readability

* doc: `params/config.libevm_test.go` comments and improved readability

* refactor: simplify `params.ChainConfig.UnmarshalJSON()`

* refactor: abstract new/nil-pointer creation into `pseudo.Constructor`s

* feat: precompile override via `params.Extras` hooks

* doc: flesh out `PrecompileOverride()` in example

* doc: complete commentary and improve readability

* refactor: `ChainConfig.Hooks()` + `Rules` equivalent

* chore: rename precompiles test file in keeping with geth equivalent

* feat: stateful precompiles + allowlist hooks

The allowlist hooks are included in this commit because they allow for the same functionality as stateful precompiles in `ava-labs/coreth` and `ava-labs/subnet-evm`.

* fix: `StateTransition.canExecuteTransaction()` used `msg.From` instead of `To`

* test: `params.RulesHooks.CanCreateContract` integration

* test: `params.RulesHooks.CanExecuteTransaction` integration

* test: `vm.NewStatefulPrecompile()` integration

* refactor: simplify test of `CanCreateContract`

* refactor: abstract generation of random `Address`/`Hash` values

* doc: full documentation + readability refactoring/renaming

* fix: remove circular dependency in tests
2024-09-10 19:20:32 +01:00
Roberto Bayardo
51b479e564
core/txpool: elevate the 'already reserved' error into a constant (#29095)
declare the 'already reserved' error in errors.go
2024-02-27 13:27:50 +02:00
Delweng
45a272c7b9
core/txpool: no need to log loud rotate if no local txs (#29083)
* core/txpool: no need to run rotate if no local txs

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

* Revert "core/txpool: no need to run rotate if no local txs"

This reverts commit 17fab17388.

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

* use Debug if todo is empty

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

---------

Signed-off-by: jsvisa <delweng@gmail.com>
2024-02-26 18:34:45 +02:00
Péter Szilágyi
63aaac8100
core/txpool/blobpool: reduce default database cap for rollout (#29090)
xcore/txpool/blobpool: reduce default database cap for rollout
2024-02-26 14:27:56 +02:00
Roberto Bayardo
32d4d6e616
core/txpool: reject blob txs with blob fee cap below the minimum (#29081)
* make blobpool reject blob transactions with fee below the minimum

* core/txpool: some minot nitpick polishes and unified error formats

* core/txpool: do less big.Int constructions with the min blob cap

---------

Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2024-02-26 11:06:52 +02:00
colin
b9ca38b735
core/txpool: fix typo (#29036)
* fix typos

* address comments
2024-02-21 10:00:01 +02:00
buddho
bba3fa9af9
core,eth,internal: fix typo (#29024) 2024-02-20 19:42:48 +08:00
buddho
7f5e96dc6c
core/txpool: fix typo (#29031) 2024-02-20 12:08:56 +02:00
Péter Szilágyi
f4852b8ddc
core/txpool, eth, miner: retrieve plain and blob txs separately (#29026)
* core/txpool, eth, miner: retrieve plain and blob txs separately

* core/txpool: fix typo, no farming

* miner: farm all the typos

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

---------

Co-authored-by: Martin HS <martin@swende.se>
2024-02-20 11:37:23 +02:00
Martin HS
ac0ff04460
core/vm, params: ensure order of forks, prevent overflow (#29023)
This PR fixes an overflow which can could happen if inconsistent blockchain rules were configured. Additionally, it tries to prevent such inconsistencies from occurring by making sure that merge cannot be enabled unless previous fork(s) are also enabled.
2024-02-19 16:29:59 +01:00
Péter Szilágyi
6fb0d0992b
core/txpool, miner: speed up blob pool pending retrievals (#29008)
* core/txpool, miner: speed up blob pool pending retrievals

* miner: fix test merge issue

* eth: same same

* core/txpool/blobpool: speed up blobtx creation in benchmark a bit

* core/txpool/blobpool: fix linter

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
2024-02-19 15:59:40 +02:00
cui
5d984796af
core: using math.MaxUint64 instead of 0xffffffffffffffff (#29022) 2024-02-19 13:03:58 +01:00
Péter Szilágyi
593e303485
core/txpool, eth, miner: pre-filter dynamic fees during pending tx retrieval (#29005)
* core/txpool, eth, miner: pre-filter dynamic fees during pending tx retrieval

* miner: fix typo

* core/txpool: handle init-error in blobpool without panicing

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
2024-02-17 13:37:14 +02:00
Sina Mahmoodi
95741b1844
core: move genesis alloc types to core/types (#29003)
We want to use these types in public user-facing APIs, so they shouldn't be in core.

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-02-16 19:05:33 +01:00
Péter Szilágyi
3c30de219f
core/txpool/blobpool: update the blob db with corruption handling (#29001)
Updates billy to a more recent version which is more robust in the face of corrupt data (e.g. after a hard crash)
2024-02-16 16:33:14 +01:00
colin
a193bb0c73
core/txpool/legacypool: remove a redundant heap.Init (#28910)
Co-authored-by: Martin HS <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
2024-02-15 19:50:17 +01:00
bk
efddedc16c
core/txpool/blobpool: rename variables in comments (#28981)
Co-authored-by: Felix Lange <fjl@twurst.com>
2024-02-15 10:20:10 +01:00
Martin HS
8321fe2fda
tests: fix goroutine leak related to state snapshot generation (#28974)
---------

Co-authored-by: Felix Lange <fjl@twurst.com>
2024-02-14 17:02:56 +01:00
rjl493456442
fe91d476ba
all: remove the dependency from trie to triedb (#28824)
This change removes the dependency from trie package to triedb package.
2024-02-13 14:49:53 +01:00
Ng Wei Han
beb2954fa4
core/txpool/legacypool: use uint256.Int instead of big.Int (#28606)
This change makes the legacy transaction pool use of `uint256.Int` instead of `big.Int`. The changes are made primarily only on the internal functions of legacypool. 

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
2024-02-13 10:10:11 +01:00
Sina Mahmoodi
ac5aa672d3
internal/ethapi: add support for blobs in eth_fillTransaction (#28839)
This change adds support for blob-transaction in certain API-endpoints, e.g. eth_fillTransaction. A follow-up PR will add support for signing such transactions.
2024-02-08 19:53:32 +01:00