forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 5
chore: logging #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
chore: logging #151
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b6d5cdb
chore: log registration of extras + precompile overriding
ARR4N a8e6668
test: `log.TypeOf()`
ARR4N 28c96d4
refactor: log type registration at `Info`
ARR4N 9ffcbdb
test: `TypeOf([typed nil])`
ARR4N 6211140
feat(log): `type Lazy func() slog.Value`
ARR4N 9e862fa
chore: lazily log differences in active precompiles
ARR4N 3996f8a
refactor: precise error message in `Lazy` test
ARR4N 4c699c8
feat: minimal `set` package
ARR4N d3101d1
chore: log `RulesAllowlistHooks` blocking only
ARR4N 87e1ff7
refactor(log): `TypeOf` returns a `Lazy`
ARR4N 888e350
chore: log from+to when tx blocked
ARR4N c0cd552
refactor: abstract `vm.EVM.canCreateContract()` hook wrapper
ARR4N a1aad6f
doc(log): correct `Lazy` comment
ARR4N 570fb7a
chore(ci): mark `eth/tracers/internal/tracetest` flaky
ARR4N bf67df4
chore: use lowercase log-attribute keys
ARR4N File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2025 the libevm authors. | ||
// | ||
// The libevm additions to go-ethereum are free software: you can redistribute | ||
// them and/or modify them under the terms of the GNU Lesser General Public License | ||
// as published by the Free Software Foundation, either version 3 of the License, | ||
// or (at your option) any later version. | ||
// | ||
// The libevm additions are distributed in the hope that they will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
package vm | ||
|
||
import ( | ||
"github.com/ava-labs/libevm/common" | ||
"github.com/ava-labs/libevm/libevm" | ||
"github.com/ava-labs/libevm/log" | ||
) | ||
|
||
// canCreateContract is a convenience wrapper for calling the | ||
// [params.RulesHooks.CanCreateContract] hook. | ||
func (evm *EVM) canCreateContract(caller ContractRef, contractToCreate common.Address, gas uint64) (remainingGas uint64, _ error) { | ||
addrs := &libevm.AddressContext{Origin: evm.Origin, Caller: caller.Address(), Self: contractToCreate} | ||
gas, err := evm.chainRules.Hooks().CanCreateContract(addrs, gas, evm.StateDB) | ||
|
||
// NOTE that this block only performs logging and that all paths propagate | ||
// `(gas, err)` unmodified. | ||
if err != nil { | ||
log.Debug( | ||
"Contract creation blocked by libevm hook", | ||
"origin", addrs.Origin, | ||
"caller", addrs.Caller, | ||
"contract", addrs.Self, | ||
"hooks", log.TypeOf(evm.chainRules.Hooks()), | ||
"reason", err, | ||
) | ||
} | ||
|
||
return gas, err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2025 the libevm authors. | ||
// | ||
// The libevm additions to go-ethereum are free software: you can redistribute | ||
// them and/or modify them under the terms of the GNU Lesser General Public License | ||
// as published by the Free Software Foundation, either version 3 of the License, | ||
// or (at your option) any later version. | ||
// | ||
// The libevm additions are distributed in the hope that they will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
// Package set provides a generic implementation of a set. | ||
package set | ||
|
||
// A Set is a generic set implementation. | ||
type Set[T comparable] map[T]struct{} | ||
|
||
// From returns a Set containing the elements. | ||
func From[T comparable](elements ...T) Set[T] { | ||
s := make(Set[T], len(elements)) | ||
for _, e := range elements { | ||
s[e] = struct{}{} | ||
} | ||
return s | ||
} | ||
|
||
// Sub returns the elements in `s` that aren't in `t`. | ||
func (s Set[T]) Sub(t Set[T]) Set[T] { | ||
return s.alsoIn(t, false) | ||
} | ||
|
||
// Intersect returns the intersection of `s` and `t`. | ||
func (s Set[T]) Intersect(t Set[T]) Set[T] { | ||
return s.alsoIn(t, true) | ||
} | ||
|
||
func (s Set[T]) alsoIn(t Set[T], inBoth bool) Set[T] { | ||
res := make(Set[T]) | ||
for el := range s { | ||
if _, ok := t[el]; ok == inBoth { | ||
res[el] = struct{}{} | ||
} | ||
} | ||
return res | ||
} | ||
|
||
// Slice returns the elements of `s` as a slice. | ||
func (s Set[T]) Slice() []T { | ||
sl := make([]T, 0, len(s)) | ||
for el := range s { | ||
sl = append(sl, el) | ||
} | ||
return sl | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2025 the libevm authors. | ||
// | ||
// The libevm additions to go-ethereum are free software: you can redistribute | ||
// them and/or modify them under the terms of the GNU Lesser General Public License | ||
// as published by the Free Software Foundation, either version 3 of the License, | ||
// or (at your option) any later version. | ||
// | ||
// The libevm additions are distributed in the hope that they will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
package set | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSub(t *testing.T) { | ||
for _, tt := range [][3][]int{ // start, sub, want | ||
{{}, {}, {}}, | ||
{{0}, {}, {0}}, | ||
{{}, {0}, {}}, | ||
{{0, 1}, {0}, {1}}, | ||
{{0, 1}, {1}, {0}}, | ||
} { | ||
in, sub := tt[0], tt[1] | ||
want := tt[2] | ||
got := From(in...).Sub(From(sub...)).Slice() | ||
assert.Equalf(t, want, got, "Set(%v).Sub(%v)", in, sub) | ||
} | ||
} | ||
|
||
func TestIntersect(t *testing.T) { | ||
for _, tt := range [][3][]int{ // L, R, intersection | ||
{{}, {}, {}}, | ||
{{0}, {}, {}}, | ||
{{0}, {0}, {0}}, | ||
{{0, 1}, {0}, {0}}, | ||
{{0, 1}, {1}, {1}}, | ||
} { | ||
want := tt[2] | ||
|
||
for i := 0; i <= 1; i++ { // commutativity | ||
lhs, rhs := tt[i], tt[1-i] | ||
got := From(lhs...).Intersect(From(rhs...)).Slice() | ||
assert.Equalf(t, want, got, "Set(%v).Intersect(%v)", lhs, rhs) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2025 the libevm authors. | ||
// | ||
// The libevm additions to go-ethereum are free software: you can redistribute | ||
// them and/or modify them under the terms of the GNU Lesser General Public License | ||
// as published by the Free Software Foundation, either version 3 of the License, | ||
// or (at your option) any later version. | ||
// | ||
// The libevm additions are distributed in the hope that they will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
// General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License | ||
// along with the go-ethereum library. If not, see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
package log | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/exp/slog" | ||
) | ||
|
||
// A Lazy function defers its execution until logging is performed. | ||
type Lazy func() slog.Value | ||
|
||
var _ slog.LogValuer = Lazy(nil) | ||
|
||
// LogValue implements the [slog.LogValuer] interface. | ||
func (l Lazy) LogValue() slog.Value { | ||
return l() | ||
} | ||
|
||
// TypeOf returns a Lazy function that reports the concrete type of `v` as | ||
// determined with the `%T` [fmt] verb. | ||
func TypeOf(v any) Lazy { | ||
return Lazy(func() slog.Value { | ||
return slog.StringValue(fmt.Sprintf("%T", v)) | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than not being exported, this is now identical to the
geth@v1.13.14
implementation.