From 7684a47e01b31817cc85fd3ecde2713422302295 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Thu, 22 Aug 2024 16:55:45 -0700 Subject: [PATCH 01/27] Copying over plugeth2 resources --- .circleci/config.yml | 112 +++++++++++++++++++++++++++++++++++++------ README.md | 106 ++++++++++++++++------------------------ SECURITY.md | 15 ++---- circle.yml | 32 ------------- slack-post.sh | 87 +++++++++++++++++++++++++++++++++ 5 files changed, 232 insertions(+), 120 deletions(-) delete mode 100644 circle.yml create mode 100755 slack-post.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index bcac607de9..bee56c5a3d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,20 +1,104 @@ -# Golang CircleCI 2.0 configuration file -# Check https://circleci.com/docs/2.0/language-go/ for more details +orbs: + aws-cli: circleci/aws-cli@1.0.0 #See: https://circleci.com/orbs/registry/orb/circleci/aws-cli -version: 2.1 - -executors: - golang: - docker: - - image: circleci/golang:1.13 - working_directory: /go/src/github.com/ethereum/go-ethereum +version: 2.1 jobs: - build: - executor: golang + test: + docker: + - image: cimg/go:1.22.0 + steps: + - checkout + - run: + name: Prep env + command: | + mkdir -p /home/circleci/go/src + mkdir artifacts + go mod tidy + - run: + name: test rpc + command: go test ./rpc/ + - run: + name: test eth + command: go test ./eth/ + - run: + name: test eth/tracers + command: go test ./eth/tracers/ + - run: + name: test core + command: go test ./core/ + - run: + name: test core/vm + command: go test ./core/vm/ + - run: + name: test core/state + command: go test ./core/state/ + - run: + name: test core/rawdb + command: go test ./core/rawdb/ + build_geth_push: + docker: # run the steps with Docker + - image: cimg/go:1.22.0 # ...with this image as the primary container + # this is where all `steps` will run steps: - - checkout # check out source code to working directory + - checkout + - setup_remote_docker - run: - command: make all + name: Prep env + command: | + mkdir -p /home/circleci/go/src + mkdir artifacts + go mod tidy - run: - command: make test + name: build geth binaries + command: | + sudo apt update + sudo apt install gcc-aarch64-linux-gnu libc6-dev-arm64-cross wget -y + export GOPATH=$HOME/go + export GOARCH=amd64 + go build -o ./artifacts/geth-linux-amd64-${CIRCLE_TAG} ./cmd/geth + CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOARCH=arm64 go build -o ./artifacts/geth-linux-arm64-${CIRCLE_TAG} ./cmd/geth + - run: + name: "Publish Release on GitHub" + command: | + go install github.com/tcnksm/ghr@v0.14.0 + NAME=plugeth2-${CIRCLE_TAG} + VERSION=${CIRCLE_TAG} + ghr -draft -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -name $NAME -delete ${VERSION} ./artifacts/ + - aws-cli/setup: #See: https://circleci.com/orbs/registry/orb/circleci/aws-cli + aws-access-key-id: ACCESS_KEY + aws-secret-access-key: SECRET_ACCESS_KEY + aws-region: AWS_REGION + - run: + name: push to s3 + command: | + aws s3 cp ./artifacts/geth-linux-amd64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/geth-linux-amd64 --acl=public-read + aws s3 cp ./artifacts/geth-linux-arm64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/geth-linux-arm64 --acl=public-read + - run: + name: Message Slack + command: | + ./slack-post.sh -w $SLACK_WEBHOOK -m "*plugeth2*:\nTag: $CIRCLE_TAG \n" + +workflows: + version: 2 + test: + jobs: + - test: + filters: + tags: + ignore: /^v.*/ + build_and_test: + jobs: + - test: + filters: + tags: + only: /^v.*/ + branches: + ignore: /.*/ + - build_geth_push: + context: Rivet + requires: + - test + filters: + tags: + only: /^v.*/ diff --git a/README.md b/README.md index df48157217..3d5a51e8d3 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,60 @@ -# Bor Overview -Bor is the Official Golang implementation of the Polygon PoS blockchain. It is a fork of [geth](https://github.com/ethereum/go-ethereum) and is EVM compatible (upto London fork). +# PluGeth -[![API Reference]( -https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/68747470733a2f2f676f646f632e6f72672f6769746875622e636f6d2f676f6c616e672f6764646f3f7374617475732e737667 -)](https://pkg.go.dev/github.com/maticnetwork/bor) -[![Go Report Card](https://goreportcard.com/badge/github.com/maticnetwork/bor)](https://goreportcard.com/report/github.com/maticnetwork/bor) -![MIT License](https://img.shields.io/github/license/maticnetwork/bor) -[![Discord](https://img.shields.io/discord/714888181740339261?color=1C1CE1&label=Polygon%20%7C%20Discord%20%F0%9F%91%8B%20&style=flat-square)](https://discord.com/invite/0xPolygonDevs) -[![Twitter Follow](https://img.shields.io/twitter/follow/0xPolygon.svg?style=social)](https://twitter.com/0xPolygon) +PluGeth is a fork of the [Go Ethereum Client](https://github.com/ethereum/go-ethereum) +(Geth) that implements a plugin architecture, allowing developers to extend +Geth's capabilities in a number of different ways using plugins, rather than +having to create additional, new forks of Geth. -### Installing bor using packaging +Documentation can be found [here](https://plugeth.org). -The easiest way to get started with bor is to install the packages using the command below. Refer to the [releases](https://github.com/maticnetwork/bor/releases) section to find the latest stable version of bor. - - curl -L https://raw.githubusercontent.com/maticnetwork/install/main/bor.sh | bash -s -- v0.4.0 +## Design Goals -The network accepts `mainnet`,`amoy` or `mumbai` and the node type accepts `validator` or `sentry` or `archive`. The installation script does the following things: -- Create a new user named `bor`. -- Install the bor binary at `/usr/bin/bor`. -- Dump the suitable config file (based on the network and node type provided) at `/var/lib/bor` and uses it as the home dir. -- Create a systemd service named `bor` at `/lib/systemd/system/bor.service` which starts bor using the config file as `bor` user. +The upstream Geth client exists primarily to serve as a client for the Ethereum +mainnet, though it also supports a number of popular testnets. Supporting the +Ethereum mainnet is a big enough challenge in its own right that the Geth team +generally avoids changes to support other networks, or to provide features only +a small handful of users would be interested in. -The releases supports both the networks i.e. Polygon Mainnet, Amoy and Mumbai (Testnet) unless explicitly specified. Before the stable release for mainnet, pre-releases will be available marked with `beta` tag for deploying on Mumbai/Amoy (testnet). On sufficient testing, stable release for mainnet will be announced with a forum post. +The result is that many projects have forked Geth. Some implement their own +consensus protocols or alter the behavior of the EVM to support other networks. +Others are designed to extract information from the Ethereum mainnet in ways +the standard Geth client does not support. -### Building from source +PluGeth aims to provide a single Geth fork that developers can choose to extend +rather than forking the Geth project. Out of the box, PluGeth behaves exactly +like upstream Geth, but by installing plugins written in Golang, developers can +extend its functionality in a wide variety of way. -- Install Go (version 1.19 or later) and a C compiler. -- Clone the repository and build the binary using the following commands: - ```shell - make bor - ``` -- Start bor using the ideal config files for validator and sentry provided in the `packaging` folder. - ```shell - ./build/bin/bor server --config ./packaging/templates/mainnet-v1/sentry/sentry/bor/config.toml - ``` -- To build full set of utilities, run: - ```shell - make all - ``` -- Run unit and integration tests - ```shell - make test && make test-integration - ``` +### Submitting Pull Requests -#### Using the new cli +We are eager to include contributions from the community into the project. We ask that pull requests which include new features to be covered by our test plugin found in: `/plugins/test-plugin`. The test design and instructions for use are documented there. If further assistance is needed please get in touch with us. -Post `v0.3.0` release, bor uses a new command line interface (cli). The new-cli (located at `internal/cli`) has been built with keeping the flag usage similar to old-cli (located at `cmd/geth`) with a few notable changes. Please refer to [docs](./docs) section for flag usage guide and example. +### Contact Us -### Documentation +If you're trying to do something that isn't supported by the current plugin system, Reach out to us on [Discord](https://discord.gg/Epf7b7Gr) and we'll help you figure out how to make it work. -- The official documentation for the Polygon PoS chain can be found [here](https://wiki.polygon.technology/docs/pos/getting-started/). It contains all the conceptual and architectural details of the chain along with operational guide for users running the nodes. -- New release announcements and discussions can be found on our [forum page](https://forum.polygon.technology/). -- Polygon improvement proposals can be found [here](https://github.com/maticnetwork/Polygon-Improvement-Proposals/) +## System Requirements -### Contribution guidelines +System requirements will vary depending on which network you are connecting to. +On the Ethereum mainnet, you should have at least 8 GB RAM, 2 CPUs, and 350 GB +of SSD disks. -Thank you for considering helping out with the source code! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes! If you'd like to contribute to bor, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base. +PluGeth relies on Golang's Plugin implementation, which is only supported on +Linux, FreeBSD, and macOS. Windows support is unlikely to be added in the +foreseeable future. -From the outset we defined some guidelines to ensure new contributions only ever enhance the project: +# Licensing Considerations -* Quality: Code in the Polygon project should meet the style guidelines, with sufficient test-cases, descriptive commit messages, evidence that the contribution does not break any compatibility commitments or cause adverse feature interactions, and evidence of high-quality peer-review. Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)). -* Testing: Please ensure that the updated code passes all the tests locally before submitting a pull request. In order to run unit tests, run `make test` and to run integration tests, run `make test-integration`. -* Size: The Polygon project’s culture is one of small pull-requests, regularly submitted. The larger a pull-request, the more likely it is that you will be asked to resubmit as a series of self-contained and individually reviewable smaller PRs. -* Maintainability: If the feature will require ongoing maintenance (e.g. support for a particular brand of database), we may ask you to accept responsibility for maintaining this feature -* Pull requests need to be based on and opened against the `develop` branch. -* PR title should be prefixed with package(s) they modify. - * E.g. "eth, rpc: make trace configs optional" +The Geth codebase is licensed under the LGPL. By linking with Geth, you have an +obligation to enable anyone you provide your plugin binaries to run against +their own modified versions of Geth. Because of how Golang plugins work +running against updated versions of Geth may require recompiling the plugin. -## License +If you plan to license your plugin under the LGPL or a more permissive license, +you should be able to meet these requirements. If you plan to use your plugin +privately without distributing it, you should be fine. If you plan to release +your plugin without making the source available, you may find yourself in +violation of Geth's license unless you can provide a way to relink it against +more recent versions of Geth. -The go-ethereum library (i.e. all code outside of the `cmd` directory) is licensed under the -[GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.en.html), -also included in our repository in the `COPYING.LESSER` file. -The go-ethereum binaries (i.e. all code inside of the `cmd` directory) are licensed under the -[GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html), also -included in our repository in the `COPYING` file. - -## Join our Discord server - -Join Polygon community – share your ideas or just say hi over [on Discord](https://discord.com/invite/0xPolygonDevs). diff --git a/SECURITY.md b/SECURITY.md index d082838a32..e89ae8e512 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,14 +1,9 @@ -# Polygon Technology Security Information +# Security Policy -## Link to vulnerability disclosure details (Bug Bounty) -- Websites and Applications: https://hackerone.com/polygon-technology -- Smart Contracts: https://immunefi.com/bounty/polygon -## Languages that our team speaks and understands. -Preferred-Languages: en -## Security-related job openings at Polygon. -https://polygon.technology/careers +Please see [Releases](https://github.com/openrelayxyz/plugeth/releases) for notes on each release. We recommend using the most recently released version. -## Polygon security contact details -security@polygon.technology +To report security issues in the underlying Geth code code please see Geth's security policy [here](https://github.com/ethereum/go-ethereum/security/policy). + +To report PluGeth specific issues please email [security@rivet.cloud](mailto:security@rivet.cloud). diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 39ff5d83c6..0000000000 --- a/circle.yml +++ /dev/null @@ -1,32 +0,0 @@ -machine: - services: - - docker - -dependencies: - cache_directories: - - "~/.ethash" # Cache the ethash DAG generated by hive for consecutive builds - - "~/.docker" # Cache all docker images manually to avoid lengthy rebuilds - override: - # Restore all previously cached docker images - - mkdir -p ~/.docker - - for img in `ls ~/.docker`; do docker load -i ~/.docker/$img; done - - # Pull in and hive, restore cached ethash DAGs and do a dry run - - go get -u github.com/karalabe/hive - - (cd ~/.go_workspace/src/github.com/karalabe/hive && mkdir -p workspace/ethash/ ~/.ethash) - - (cd ~/.go_workspace/src/github.com/karalabe/hive && cp -r ~/.ethash/. workspace/ethash/) - - (cd ~/.go_workspace/src/github.com/karalabe/hive && hive --docker-noshell --client=NONE --test=. --sim=. --loglevel=6) - - # Cache all the docker images and the ethash DAGs - - for img in `docker images | grep -v "^" | tail -n +2 | awk '{print $1}'`; do docker save $img > ~/.docker/`echo $img | tr '/' ':'`.tar; done - - cp -r ~/.go_workspace/src/github.com/karalabe/hive/workspace/ethash/. ~/.ethash - -test: - override: - # Build Geth and move into a known folder - - make geth - - cp ./build/bin/geth $HOME/geth - - # Run hive and move all generated logs into the public artifacts folder - - (cd ~/.go_workspace/src/github.com/karalabe/hive && hive --docker-noshell --client=go-ethereum:local --override=$HOME/geth --test=. --sim=.) - - cp -r ~/.go_workspace/src/github.com/karalabe/hive/workspace/logs/* $CIRCLE_ARTIFACTS diff --git a/slack-post.sh b/slack-post.sh new file mode 100755 index 0000000000..56f342ee06 --- /dev/null +++ b/slack-post.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +# Usage: slackpost -w -c -u -m [-a ] +# Usage: echo | slackpost -w -c -u [-a ] + +# exit immediately if a command exits with a non-zero status +set -e + +# error if variable referenced before being set +set -u + +# produce failure return code if any command fails in pipe +set -o pipefail + +# accepted values: good, warning, danger +alert_type="" +channel="" +message="" +username="" +webhook_url="" + +# colon after var means it has a value rather than it being a bool flag +while getopts 'a:c:m:u:w:' OPTION; do + case "$OPTION" in + a) + alert_type="$OPTARG" + ;; + c) + channel="$OPTARG" + ;; + m) + message="$OPTARG" + ;; + u) + username="$OPTARG" + ;; + w) + webhook_url="$OPTARG" + ;; + ?) + echo "script usage: $(basename $0) {-c channel} {-m message} {-u username} {-w webhook} [-a alert_type]" >&2 + exit 1 + ;; + esac +done +shift "$(($OPTIND -1))" + +# # exit if channel not provided +# if [[ -z "$channel" ]] +# then +# echo "No channel specified" +# exit 1 +# fi + +# read piped data as message if message argument is not provided +if [[ -z "$message" ]] +then + message=$* + + while IFS= read -r line; do + message="$message$line\n" + done +fi + +# # exit if username not provided +# if [[ -z "$username" ]] +# then +# echo "No username specified" +# exit 1 +# fi + +# exit if webhook not provided +if [[ -z "$webhook_url" ]] +then + echo "No webhook_url specified" + exit 1 +fi + +# escape message text +escapedText=$(echo $message | sed 's/"/\"/g' | sed "s/'/\'/g") + +# create JSON payload +# json="{\"channel\": \"$channel\", \"username\":\"$username\", \"icon_emoji\":\"ghost\", \"attachments\":[{\"color\":\"$alert_type\" , \"text\": \"$escapedText\"}]}" +json="{\"attachments\":[{\"color\":\"$alert_type\" , \"text\": \"$escapedText\"}]}" + +# fire off slack message post +curl -s -d "payload=$json" "$webhook_url" From 10e40af803fc267b225793fa00b4fbbe1e8d50d9 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Thu, 22 Aug 2024 17:04:59 -0700 Subject: [PATCH 02/27] removed build chain from mod and set circle config to bor --- .circleci/config.yml | 10 +++++----- go.mod | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bee56c5a3d..67e15d75d9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -56,8 +56,8 @@ jobs: sudo apt install gcc-aarch64-linux-gnu libc6-dev-arm64-cross wget -y export GOPATH=$HOME/go export GOARCH=amd64 - go build -o ./artifacts/geth-linux-amd64-${CIRCLE_TAG} ./cmd/geth - CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOARCH=arm64 go build -o ./artifacts/geth-linux-arm64-${CIRCLE_TAG} ./cmd/geth + go build -o ./artifacts/bor-linux-amd64-${CIRCLE_TAG} ./cmd/cli + CC=aarch64-linux-gnu-gcc CGO_ENABLED=1 GOARCH=arm64 go build -o ./artifacts/bor-linux-arm64-${CIRCLE_TAG} ./cmd/cli - run: name: "Publish Release on GitHub" command: | @@ -72,12 +72,12 @@ jobs: - run: name: push to s3 command: | - aws s3 cp ./artifacts/geth-linux-amd64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/geth-linux-amd64 --acl=public-read - aws s3 cp ./artifacts/geth-linux-arm64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/geth-linux-arm64 --acl=public-read + aws s3 cp ./artifacts/bor-linux-amd64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/bor-linux-amd64 --acl=public-read + aws s3 cp ./artifacts/bor-linux-arm64-${CIRCLE_TAG} s3://ethercattle-binaries/plugeth2/$CIRCLE_TAG/bor-linux-arm64 --acl=public-read - run: name: Message Slack command: | - ./slack-post.sh -w $SLACK_WEBHOOK -m "*plugeth2*:\nTag: $CIRCLE_TAG \n" + ./slack-post.sh -w $SLACK_WEBHOOK -m "*plugeth-bor2*:\nTag: $CIRCLE_TAG \n" workflows: version: 2 diff --git a/go.mod b/go.mod index e627477b00..4e1ae88971 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/ethereum/go-ethereum go 1.22 -toolchain go1.22.1 - require ( github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.3.2 github.com/BurntSushi/toml v1.4.0 From 441098b58940578238955f0b823c90b980386f36 Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 23 Aug 2024 04:06:59 +0100 Subject: [PATCH 03/27] added xplugeth hooks and injection at triedb --- trie/triedb/hashdb/database.go | 9 ++++++++ trie/triedb/hashdb/xplugeth_hooks.go | 32 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 trie/triedb/hashdb/xplugeth_hooks.go diff --git a/trie/triedb/hashdb/database.go b/trie/triedb/hashdb/database.go index e45ccdba32..6bbc25f7b8 100644 --- a/trie/triedb/hashdb/database.go +++ b/trie/triedb/hashdb/database.go @@ -413,6 +413,11 @@ func (db *Database) Commit(node common.Hash, report bool) error { // outside code doesn't see an inconsistent state (referenced data removed from // memory cache during commit but not yet in persistent storage). This is ensured // by only uncaching existing data when the database write finalizes. + + // begin PluGeth injection + PluginPreTrieCommit(node) + // end PluGeth injection + start := time.Now() batch := db.diskdb.NewBatch() @@ -451,6 +456,10 @@ func (db *Database) Commit(node common.Hash, report bool) error { db.gcnodes, db.gcsize, db.gctime = 0, 0, 0 db.flushnodes, db.flushsize, db.flushtime = 0, 0, 0 + // begin PluGeth injection + PluginPostTrieCommit(node) + // end PluGeth injection + return nil } diff --git a/trie/triedb/hashdb/xplugeth_hooks.go b/trie/triedb/hashdb/xplugeth_hooks.go new file mode 100644 index 0000000000..e938ad6c7f --- /dev/null +++ b/trie/triedb/hashdb/xplugeth_hooks.go @@ -0,0 +1,32 @@ +package hashdb + +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/openrelayxyz/plugeth-utils/core" + "github.com/openrelayxyz/xplugeth" +) + +type preTrieCommit interface { + PreTrieCommit(node core.Hash) +} + +type postTrieCommit interface { + PostTrieCommit(node core.Hash) +} + +func init() { + xplugeth.RegisterHook[preTrieCommit]() + xplugeth.RegisterHook[postTrieCommit]() +} + +func PluginPreTrieCommit(node common.Hash) { + for _, m := range xplugeth.GetModules[preTrieCommit]() { + m.PreTrieCommit(core.Hash(node)) + } +} + +func PluginPostTrieCommit(node common.Hash) { + for _, m := range xplugeth.GetModules[postTrieCommit]() { + m.PostTrieCommit(core.Hash(node)) + } +} From 0b050d5f8ac04de011716be9c5a95551a02f9bd8 Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 23 Aug 2024 16:45:59 +0100 Subject: [PATCH 04/27] write out hook and injection at core/state --- core/state/statedb.go | 4 + core/state/xplugeth_hooks.go | 174 +++++++++++++++++++++++++++++++++++ go.mod | 19 ++-- go.sum | 11 +++ 4 files changed, 199 insertions(+), 9 deletions(-) create mode 100644 core/state/xplugeth_hooks.go diff --git a/core/state/statedb.go b/core/state/statedb.go index 34230f6d06..97b557e247 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1720,6 +1720,10 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er start := time.Now() // Only update if there's a state transition (skip empty Clique blocks) if parent := s.snap.Root(); parent != root { + //begin PluGeth code injection + PluginStateUpdate(root, parent, s.snap, s.trie, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages, codeUpdates) + if _, ok := s.snap.(*pluginSnapshot); !ok && s.snaps != nil { // This if statement (but not its content) was added by PluGeth + //end PluGeth injection if err := s.snaps.Update(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages); err != nil { log.Warn("Failed to update snapshot tree", "from", parent, "to", root, "err", err) } diff --git a/core/state/xplugeth_hooks.go b/core/state/xplugeth_hooks.go new file mode 100644 index 0000000000..69b6e7e795 --- /dev/null +++ b/core/state/xplugeth_hooks.go @@ -0,0 +1,174 @@ +package state + +import ( + "bytes" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state/snapshot" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" + "github.com/openrelayxyz/xplugeth" +) + +var ( + acctCheckTimer = metrics.NewRegisteredTimer("plugeth/statedb/accounts/checks", nil) +) + +type acctChecker struct { + snap snapshot.Snapshot + trie Trie +} + +type acctByHasher interface { + GetAccountByHash(common.Hash) (*types.StateAccount, error) +} + +type stateUpdatePlugin interface { + PluginStateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot, trie Trie, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) +} + +func init() { + xplugeth.RegisterHook[stateUpdatePlugin]() + +} + +func (ac *acctChecker) exists(k common.Hash) bool { + if hadStorage, ok := ac.snapExists(k); ok { + return hadStorage + } + return ac.trieExists(k) +} + +func (ac *acctChecker) snapExists(k common.Hash) (bool, bool) { + acct, err := ac.snap.AccountRLP(k) + if err != nil { + return false, false + } + return len(acct) != 0, true +} + +func (ac *acctChecker) trieExists(k common.Hash) bool { + trie, ok := ac.trie.(acctByHasher) + if !ok { + log.Warn("Couldn't check trie existence, wrong trie type") + return true + } + acct, _ := trie.GetAccountByHash(k) + return acct != nil +} + +func (ac *acctChecker) updated(k common.Hash, v []byte) bool { + if updated, ok := ac.snapUpdated(k, v); ok { + return updated + } + return ac.trieUpdated(k, v) +} + +func PluginStateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot, trie Trie, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) { + checker := &acctChecker{snap, trie} + + filteredDestructs := make(map[common.Hash]struct{}) + for k, v := range destructs { + if _, ok := accounts[k]; ok { + if !checker.hadStorage(k) { + // If an account is in both destructs and accounts, that means it was + // "destroyed" and recreated in the same block. Especially post-cancun, + // that generally means that an account that had ETH but no code got + // replaced by an account that had code. + // + // If there's data in the accounts map, we only need to process this + // account if there are storage slots we need to clear out, so we + // check the account storage for the empty root. If it's empty, we can + // skip this destruct. We need this check to normalize parallel blocks + // with serial blocks, because they report destructs differently. + continue + } + } else { + if !checker.exists(k) { + // If we have a destruct for an account that didn't exist at the previous + // block, we don't need to destruct it. This normalizes the use case of + // CREATE and CREATE2 deployments to empty addresses that revert. + continue + } + } + filteredDestructs[k] = v + } + + filteredAccounts := make(map[common.Hash][]byte) + start := time.Now() + for k, v := range accounts { + if checker.updated(k, v) { + filteredAccounts[k] = v + } + } + acctCheckTimer.UpdateSince(start) + + for _, update := range xplugeth.GetModules[stateUpdatePlugin]() { + update.PluginStateUpdate(blockRoot, parentRoot, snap, trie, filteredDestructs, filteredAccounts, storage, codeUpdates) + } +} + +func (ac *acctChecker) hadStorage(k common.Hash) bool { + if hadStorage, ok := ac.snapHadStorage(k); ok { + return hadStorage + } + return ac.trieHadStorage(k) +} + +func (ac *acctChecker) trieHadStorage(k common.Hash) bool { + trie, ok := ac.trie.(acctByHasher) + if !ok { + log.Warn("Couldn't check trie updates, wrong trie type") + return true + } + acct, err := trie.GetAccountByHash(k) + if err != nil { + return true + } + if acct == nil { + // No account existed at this hash, so it wouldn't have had storage + return false + } + return acct.Root != types.EmptyRootHash +} + +func (ac *acctChecker) snapHadStorage(k common.Hash) (bool, bool) { + acct, err := ac.snap.Account(k) + if err != nil { + return false, false + } + if acct == nil { + // No account existed at this hash, so it wouldn't have had storage + return false, true + } + if len(acct.Root) > 0 && !bytes.Equal(acct.Root, types.EmptyRootHash.Bytes()) { + return true, true + } + return false, true +} + +func (ac *acctChecker) snapUpdated(k common.Hash, v []byte) (bool, bool) { + acct, err := ac.snap.AccountRLP(k) + if err != nil { + return false, false + } + if len(acct) == 0 { + return false, false + } + return !bytes.Equal(acct, v), true +} + +func (ac *acctChecker) trieUpdated(k common.Hash, v []byte) bool { + trie, ok := ac.trie.(acctByHasher) + if !ok { + log.Warn("Couldn't check trie updates, wrong trie type") + return true + } + oAcct, err := trie.GetAccountByHash(k) + if err != nil { + return true + } + return !bytes.Equal(v, types.SlimAccountRLP(*oAcct)) +} diff --git a/go.mod b/go.mod index b21f9e531b..318ec92d93 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.0 + github.com/cockroachdb/pebble v1.1.1 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 - github.com/crate-crypto/go-kzg-4844 v0.7.0 + github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c + github.com/crate-crypto/go-kzg-4844 v1.0.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v0.4.3 + github.com/ethereum/c-kzg-4844 v1.0.0 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -126,8 +126,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cockroachdb/errors v1.11.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +136,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.18.0 // indirect + github.com/getsentry/sentry-go v0.27.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +161,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,6 +229,7 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect + github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index fd04179f86..257416652d 100644 --- a/go.sum +++ b/go.sum @@ -980,6 +980,7 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1018,10 +1019,12 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= +github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1055,8 +1058,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= +github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1125,6 +1130,7 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1176,6 +1182,7 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= +github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1866,6 +1873,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2144,9 +2153,11 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From f2767773981e521a308377bbdb6bec4d9cbb63b3 Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 23 Aug 2024 17:29:35 +0100 Subject: [PATCH 05/27] add xplugeth & plugeth utils packages --- go.mod | 20 +++++++++++--------- go.sum | 13 +++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index b21f9e531b..391ba85405 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.0 + github.com/cockroachdb/pebble v1.1.1 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 - github.com/crate-crypto/go-kzg-4844 v0.7.0 + github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c + github.com/crate-crypto/go-kzg-4844 v1.0.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v0.4.3 + github.com/ethereum/c-kzg-4844 v1.0.0 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -126,8 +126,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cockroachdb/errors v1.11.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +136,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.18.0 // indirect + github.com/getsentry/sentry-go v0.27.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +161,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,6 +229,8 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect + github.com/openrelayxyz/plugeth-utils v1.5.0 // indirect + github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index fd04179f86..6c8c82daef 100644 --- a/go.sum +++ b/go.sum @@ -980,6 +980,7 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1018,10 +1019,12 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= +github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1055,8 +1058,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= +github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1125,6 +1130,7 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1176,6 +1182,7 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= +github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1866,6 +1873,10 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/openrelayxyz/plugeth-utils v1.5.0 h1:4hzAvMKEo5uCnXy5cCHDc7OfXpwAavFNjr3M/ZfTlEA= +github.com/openrelayxyz/plugeth-utils v1.5.0/go.mod h1:COwKAuTZIsCouCOrIDBhvHZqpbOO1Ojgdy5KTvL8mJg= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2144,9 +2155,11 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From 304b90f5eab5edcf0aa43922dc70fb641fa1e627 Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 23 Aug 2024 18:04:14 +0100 Subject: [PATCH 06/27] add hooks and injections at core package --- core/blockchain.go | 36 ++++++++++++++++++++++- core/xplugeth_hooks.go | 65 ++++++++++++++++++++++++++++++++++++++++++ go.mod | 19 ++++++------ go.sum | 11 +++++++ 4 files changed, 121 insertions(+), 10 deletions(-) create mode 100644 core/xplugeth_hooks.go diff --git a/core/blockchain.go b/core/blockchain.go index b1fec32cf3..343e3875bd 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1641,6 +1641,11 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error { // writeBlockWithState writes block, metadata and corresponding state data to the // database. func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB) ([]*types.Log, error) { + //begin PluGeth injection + var interval time.Duration + _ = PluginSetTrieFlushIntervalClone(interval) // this is being called here to engage a testing scenario + //end PluGeth injection + // Calculate the total difficulty of the block ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1) if ptd == nil { @@ -1734,6 +1739,11 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. chosen := current - bc.cacheConfig.TriesInMemory flushInterval := time.Duration(bc.flushInterval.Load()) // If we exceeded time allowance, flush an entire trie to disk + + // begin PluGeth code injection + flushInterval = PluginSetTrieFlushIntervalClone(flushInterval) + // end PluGeth code injection + if bc.gcproc > flushInterval { // If the header is missing (canonical chain behind), we're reorging a low // diff sidechain. Suspend committing until this operation is completed. @@ -1810,7 +1820,18 @@ func (bc *BlockChain) writeBlockAndSetHead(ctx context.Context, block *types.Blo } bc.futureBlocks.Remove(block.Hash()) + //begin PluGeth code injection + ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1) + if ptd == nil { + return NonStatTy, consensus.ErrUnknownAncestor + } + externTd := new(big.Int).Add(block.Difficulty(), ptd) + // end PluGeth code injection + if status == CanonStatTy { + // begin plugeth injection + PluginNewHead(block, block.Hash(), logs, externTd) + // end plugeth injection bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs}) if len(logs) > 0 { @@ -1836,6 +1857,9 @@ func (bc *BlockChain) writeBlockAndSetHead(ctx context.Context, block *types.Blo // BOR } } else { + //begin PluGeth injection + PluginNewSideBlock(block, block.Hash(), logs) + //end PluGeth injection bc.chainSideFeed.Send(ChainSideEvent{Block: block}) bc.chain2HeadFeed.Send(Chain2HeadEvent{ @@ -2668,7 +2692,9 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error { msg = "Large chain reorg detected" logFn = log.Warn } - + //begin PluGeth code injection + PluginReorg(commonBlock, oldChain, newChain) + //end PluGeth code injection logFn(msg, "number", commonBlock.Number(), "hash", commonBlock.Hash(), "drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash()) blockReorgAddMeter.Mark(int64(len(newChain))) @@ -2897,6 +2923,14 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) { bc.logsFeed.Send(logs) } + // begin PluGeth code injection + ptd := bc.GetTd(head.ParentHash(), head.NumberU64()-1) + externTd := ptd + if ptd != nil { + externTd = new(big.Int).Add(head.Difficulty(), ptd) + } + PluginNewHead(head, head.Hash(), logs, externTd) + // end PluGeth code injection bc.chainHeadFeed.Send(ChainHeadEvent{Block: head}) context := []interface{}{ diff --git a/core/xplugeth_hooks.go b/core/xplugeth_hooks.go new file mode 100644 index 0000000000..5ef89ae0ff --- /dev/null +++ b/core/xplugeth_hooks.go @@ -0,0 +1,65 @@ +package core + +import ( + "math/big" + "sync" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/log" + "github.com/openrelayxyz/xplugeth" +) + +type newHeadPlugin interface { + PluginNewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) +} + +type newSideBlockPlugin interface { + PluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) +} + +type reorgPlugin interface { + PluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) +} + +type setTrieFlushIntervalClonePlugin interface { + PluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration +} + +func init() { + xplugeth.RegisterHook[newHeadPlugin]() + xplugeth.RegisterHook[newSideBlockPlugin]() + xplugeth.RegisterHook[reorgPlugin]() + xplugeth.RegisterHook[setTrieFlushIntervalClonePlugin]() +} + +func PluginNewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) { + for _, m := range xplugeth.GetModules[newHeadPlugin]() { + m.PluginNewHead(block, hash, logs, td) + } +} + +func PluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) { + for _, m := range xplugeth.GetModules[newSideBlockPlugin]() { + m.PluginNewSideBlock(block, hash, logs) + } +} + +func PluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) { + for _, m := range xplugeth.GetModules[reorgPlugin]() { + m.PluginReorg(commonBlock, oldChain, newChain) + } +} + +func PluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration { + m := xplugeth.GetModules[setTrieFlushIntervalClonePlugin]() + var snc sync.Once + if len(m) > 1 { + snc.Do(func() { log.Warn("The blockChain flushInterval value is being accessed by multiple plugins") }) + } + for _, m := range m { + flushInterval = m.PluginSetTrieFlushIntervalClone(flushInterval) + } + return flushInterval +} diff --git a/go.mod b/go.mod index b21f9e531b..318ec92d93 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.0 + github.com/cockroachdb/pebble v1.1.1 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 - github.com/crate-crypto/go-kzg-4844 v0.7.0 + github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c + github.com/crate-crypto/go-kzg-4844 v1.0.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v0.4.3 + github.com/ethereum/c-kzg-4844 v1.0.0 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -126,8 +126,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cockroachdb/errors v1.11.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +136,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.18.0 // indirect + github.com/getsentry/sentry-go v0.27.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +161,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,6 +229,7 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect + github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index fd04179f86..257416652d 100644 --- a/go.sum +++ b/go.sum @@ -980,6 +980,7 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1018,10 +1019,12 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= +github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1055,8 +1058,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= +github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1125,6 +1130,7 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1176,6 +1182,7 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= +github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1866,6 +1873,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2144,9 +2153,11 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From 5e4ae14c026577faa1b6f7bda126b41d72a5fbbd Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 26 Aug 2024 14:27:18 +0100 Subject: [PATCH 07/27] make injected function private, removed xplugeth impororts --- core/blockchain.go | 12 ++++++------ core/xplugeth_hooks.go | 32 ++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 343e3875bd..ecb83da8e0 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1643,7 +1643,7 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error { func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB) ([]*types.Log, error) { //begin PluGeth injection var interval time.Duration - _ = PluginSetTrieFlushIntervalClone(interval) // this is being called here to engage a testing scenario + _ = pluginSetTrieFlushIntervalClone(interval) // this is being called here to engage a testing scenario //end PluGeth injection // Calculate the total difficulty of the block @@ -1741,7 +1741,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. // If we exceeded time allowance, flush an entire trie to disk // begin PluGeth code injection - flushInterval = PluginSetTrieFlushIntervalClone(flushInterval) + flushInterval = pluginSetTrieFlushIntervalClone(flushInterval) // end PluGeth code injection if bc.gcproc > flushInterval { @@ -1830,7 +1830,7 @@ func (bc *BlockChain) writeBlockAndSetHead(ctx context.Context, block *types.Blo if status == CanonStatTy { // begin plugeth injection - PluginNewHead(block, block.Hash(), logs, externTd) + pluginNewHead(block, block.Hash(), logs, externTd) // end plugeth injection bc.chainFeed.Send(ChainEvent{Block: block, Hash: block.Hash(), Logs: logs}) @@ -1858,7 +1858,7 @@ func (bc *BlockChain) writeBlockAndSetHead(ctx context.Context, block *types.Blo } } else { //begin PluGeth injection - PluginNewSideBlock(block, block.Hash(), logs) + pluginNewSideBlock(block, block.Hash(), logs) //end PluGeth injection bc.chainSideFeed.Send(ChainSideEvent{Block: block}) @@ -2693,7 +2693,7 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error { logFn = log.Warn } //begin PluGeth code injection - PluginReorg(commonBlock, oldChain, newChain) + pluginReorg(commonBlock, oldChain, newChain) //end PluGeth code injection logFn(msg, "number", commonBlock.Number(), "hash", commonBlock.Hash(), "drop", len(oldChain), "dropfrom", oldChain[0].Hash(), "add", len(newChain), "addfrom", newChain[0].Hash()) @@ -2929,7 +2929,7 @@ func (bc *BlockChain) SetCanonical(head *types.Block) (common.Hash, error) { if ptd != nil { externTd = new(big.Int).Add(head.Difficulty(), ptd) } - PluginNewHead(head, head.Hash(), logs, externTd) + pluginNewHead(head, head.Hash(), logs, externTd) // end PluGeth code injection bc.chainHeadFeed.Send(ChainHeadEvent{Block: head}) diff --git a/core/xplugeth_hooks.go b/core/xplugeth_hooks.go index 5ef89ae0ff..d3249be9c0 100644 --- a/core/xplugeth_hooks.go +++ b/core/xplugeth_hooks.go @@ -12,19 +12,19 @@ import ( ) type newHeadPlugin interface { - PluginNewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) + NewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) } type newSideBlockPlugin interface { - PluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) + NewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) } type reorgPlugin interface { - PluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) + Reorg(commonBlock common.Hash, oldChain, newChain []common.Hash) } type setTrieFlushIntervalClonePlugin interface { - PluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration + SetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration } func init() { @@ -34,32 +34,40 @@ func init() { xplugeth.RegisterHook[setTrieFlushIntervalClonePlugin]() } -func PluginNewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) { +func pluginNewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) { for _, m := range xplugeth.GetModules[newHeadPlugin]() { - m.PluginNewHead(block, hash, logs, td) + m.NewHead(block, hash, logs, td) } } -func PluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) { +func pluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) { for _, m := range xplugeth.GetModules[newSideBlockPlugin]() { - m.PluginNewSideBlock(block, hash, logs) + m.NewSideBlock(block, hash, logs) } } -func PluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) { +func pluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) { + oldChainHashes := make([]common.Hash, len(oldChain)) + for i, block := range oldChain { + oldChainHashes[i] = block.Hash() + } + newChainHashes := make([]common.Hash, len(newChain)) + for i, block := range newChain { + newChainHashes[i] = block.Hash() + } for _, m := range xplugeth.GetModules[reorgPlugin]() { - m.PluginReorg(commonBlock, oldChain, newChain) + m.Reorg(commonBlock.Hash(), oldChainHashes, newChainHashes) } } -func PluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration { +func pluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration { m := xplugeth.GetModules[setTrieFlushIntervalClonePlugin]() var snc sync.Once if len(m) > 1 { snc.Do(func() { log.Warn("The blockChain flushInterval value is being accessed by multiple plugins") }) } for _, m := range m { - flushInterval = m.PluginSetTrieFlushIntervalClone(flushInterval) + flushInterval = m.SetTrieFlushIntervalClone(flushInterval) } return flushInterval } From 23c940cbe4783365dc468156365ed61c8566f897 Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 26 Aug 2024 14:29:17 +0100 Subject: [PATCH 08/27] make injected function private, removed xplugeth impororts --- trie/triedb/hashdb/database.go | 4 ++-- trie/triedb/hashdb/xplugeth_hooks.go | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/trie/triedb/hashdb/database.go b/trie/triedb/hashdb/database.go index 6bbc25f7b8..31fb51a68f 100644 --- a/trie/triedb/hashdb/database.go +++ b/trie/triedb/hashdb/database.go @@ -415,7 +415,7 @@ func (db *Database) Commit(node common.Hash, report bool) error { // by only uncaching existing data when the database write finalizes. // begin PluGeth injection - PluginPreTrieCommit(node) + pluginPreTrieCommit(node) // end PluGeth injection start := time.Now() @@ -457,7 +457,7 @@ func (db *Database) Commit(node common.Hash, report bool) error { db.flushnodes, db.flushsize, db.flushtime = 0, 0, 0 // begin PluGeth injection - PluginPostTrieCommit(node) + pluginPostTrieCommit(node) // end PluGeth injection return nil diff --git a/trie/triedb/hashdb/xplugeth_hooks.go b/trie/triedb/hashdb/xplugeth_hooks.go index e938ad6c7f..c9e6743819 100644 --- a/trie/triedb/hashdb/xplugeth_hooks.go +++ b/trie/triedb/hashdb/xplugeth_hooks.go @@ -2,16 +2,15 @@ package hashdb import ( "github.com/ethereum/go-ethereum/common" - "github.com/openrelayxyz/plugeth-utils/core" "github.com/openrelayxyz/xplugeth" ) type preTrieCommit interface { - PreTrieCommit(node core.Hash) + PreTrieCommit(node common.Hash) } type postTrieCommit interface { - PostTrieCommit(node core.Hash) + PostTrieCommit(node common.Hash) } func init() { @@ -19,14 +18,14 @@ func init() { xplugeth.RegisterHook[postTrieCommit]() } -func PluginPreTrieCommit(node common.Hash) { +func pluginPreTrieCommit(node common.Hash) { for _, m := range xplugeth.GetModules[preTrieCommit]() { - m.PreTrieCommit(core.Hash(node)) + m.PreTrieCommit(node) } } -func PluginPostTrieCommit(node common.Hash) { +func pluginPostTrieCommit(node common.Hash) { for _, m := range xplugeth.GetModules[postTrieCommit]() { - m.PostTrieCommit(core.Hash(node)) + m.PostTrieCommit(node) } } From 742a9ae8f72c868bc97ed39b9ed2578034f5b4e7 Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 26 Aug 2024 14:44:20 +0100 Subject: [PATCH 09/27] make injected function private, removed xplugeth impororts --- core/state/statedb.go | 2 +- core/state/xplugeth_hooks.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 97b557e247..293b9e03e4 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1721,7 +1721,7 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er // Only update if there's a state transition (skip empty Clique blocks) if parent := s.snap.Root(); parent != root { //begin PluGeth code injection - PluginStateUpdate(root, parent, s.snap, s.trie, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages, codeUpdates) + pluginStateUpdate(root, parent, s.snap, s.trie, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages, codeUpdates) if _, ok := s.snap.(*pluginSnapshot); !ok && s.snaps != nil { // This if statement (but not its content) was added by PluGeth //end PluGeth injection if err := s.snaps.Update(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages); err != nil { diff --git a/core/state/xplugeth_hooks.go b/core/state/xplugeth_hooks.go index 69b6e7e795..11a63670d3 100644 --- a/core/state/xplugeth_hooks.go +++ b/core/state/xplugeth_hooks.go @@ -26,7 +26,7 @@ type acctByHasher interface { } type stateUpdatePlugin interface { - PluginStateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot, trie Trie, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) + StateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot, trie Trie, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) } func init() { @@ -66,7 +66,7 @@ func (ac *acctChecker) updated(k common.Hash, v []byte) bool { return ac.trieUpdated(k, v) } -func PluginStateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot, trie Trie, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) { +func pluginStateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot, trie Trie, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) { checker := &acctChecker{snap, trie} filteredDestructs := make(map[common.Hash]struct{}) @@ -105,8 +105,8 @@ func PluginStateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot } acctCheckTimer.UpdateSince(start) - for _, update := range xplugeth.GetModules[stateUpdatePlugin]() { - update.PluginStateUpdate(blockRoot, parentRoot, snap, trie, filteredDestructs, filteredAccounts, storage, codeUpdates) + for _, m := range xplugeth.GetModules[stateUpdatePlugin]() { + m.StateUpdate(blockRoot, parentRoot, snap, trie, filteredDestructs, filteredAccounts, storage, codeUpdates) } } From 0b13242ba6dd5a6bea75056a80b72989217bf190 Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 26 Aug 2024 18:57:30 +0100 Subject: [PATCH 10/27] update setTrieFlushCloneInterval plugin --- core/xplugeth_hooks.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/xplugeth_hooks.go b/core/xplugeth_hooks.go index d3249be9c0..515ff6e7e2 100644 --- a/core/xplugeth_hooks.go +++ b/core/xplugeth_hooks.go @@ -61,12 +61,12 @@ func pluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) { } func pluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration { - m := xplugeth.GetModules[setTrieFlushIntervalClonePlugin]() + modules := xplugeth.GetModules[setTrieFlushIntervalClonePlugin]() var snc sync.Once - if len(m) > 1 { + if len(modules) > 1 { snc.Do(func() { log.Warn("The blockChain flushInterval value is being accessed by multiple plugins") }) } - for _, m := range m { + for _, m := range modules { flushInterval = m.SetTrieFlushIntervalClone(flushInterval) } return flushInterval From 062325dada07cd528a0afcec1fead627dc2cc4b7 Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 26 Aug 2024 19:46:43 +0100 Subject: [PATCH 11/27] write modifyAncients hook & add injection at core/rawdb --- core/rawdb/freezer.go | 3 ++ core/rawdb/freezer_batch.go | 6 +++ core/rawdb/xplugeth_hooks.go | 79 ++++++++++++++++++++++++++++++++++++ go.mod | 19 +++++---- go.sum | 11 +++++ 5 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 core/rawdb/xplugeth_hooks.go diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go index eae6705b68..18ba980fd2 100644 --- a/core/rawdb/freezer.go +++ b/core/rawdb/freezer.go @@ -292,6 +292,9 @@ func (f *Freezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (writeSize if err != nil { return 0, err } + //begin PluGeth code injection + pluginCommitUpdate(item) + //end PluGeth code injection f.frozen.Store(item) return writeSize, nil } diff --git a/core/rawdb/freezer_batch.go b/core/rawdb/freezer_batch.go index fe7ae614af..1484032274 100644 --- a/core/rawdb/freezer_batch.go +++ b/core/rawdb/freezer_batch.go @@ -45,11 +45,17 @@ func newFreezerBatch(f *Freezer) *freezerBatch { // Append adds an RLP-encoded item of the given kind. func (batch *freezerBatch) Append(kind string, num uint64, item interface{}) error { + // begin PluGeth injection + PluginTrackUpdate(num, kind, item) + // end PluGeth injection return batch.tables[kind].Append(num, item) } // AppendRaw adds an item of the given kind. func (batch *freezerBatch) AppendRaw(kind string, num uint64, item []byte) error { + // begin PluGeth injection + PluginTrackUpdate(num, kind, item) + // end PluGeth injection return batch.tables[kind].AppendRaw(num, item) } diff --git a/core/rawdb/xplugeth_hooks.go b/core/rawdb/xplugeth_hooks.go new file mode 100644 index 0000000000..90959ab5c8 --- /dev/null +++ b/core/rawdb/xplugeth_hooks.go @@ -0,0 +1,79 @@ +package rawdb + +import ( + "sync" + + "github.com/ethereum/go-ethereum/log" + "github.com/openrelayxyz/xplugeth" +) + +var ( + freezerUpdates map[uint64]map[string]interface{} + lock sync.Mutex + modifyAncientsInjection *bool + appendRawInjection *bool + appendInjection *bool +) + +type modifyAncientsPlugin interface { + ModifyAncients(uint64, map[string]interface{}) +} + +func init() { + xplugeth.RegisterHook[modifyAncientsPlugin]() +} + +func PluginTrackUpdate(num uint64, kind string, value interface{}) { + + if appendRawInjection != nil { + called := true + appendRawInjection = &called + } + + if appendInjection != nil { + called := true + appendInjection = &called + } + + lock.Lock() + defer lock.Unlock() + if freezerUpdates == nil { + freezerUpdates = make(map[uint64]map[string]interface{}) + } + update, ok := freezerUpdates[num] + if !ok { + update = make(map[string]interface{}) + freezerUpdates[num] = update + } + update[kind] = value +} + +func pluginCommitUpdate(num uint64) { + if modifyAncientsInjection != nil { + called := true + modifyAncientsInjection = &called + } + + lock.Lock() + defer lock.Unlock() + if freezerUpdates == nil { + freezerUpdates = make(map[uint64]map[string]interface{}) + } + min := ^uint64(0) + for i := range freezerUpdates { + if min > i { + min = i + } + } + for i := min; i < num; i++ { + update, ok := freezerUpdates[i] + defer func(i uint64) { delete(freezerUpdates, i) }(i) + if !ok { + log.Warn("Attempting to commit untracked block", "num", i) + continue + } + for _, m := range xplugeth.GetModules[modifyAncientsPlugin]() { + m.ModifyAncients(i, update) + } + } +} diff --git a/go.mod b/go.mod index b21f9e531b..318ec92d93 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.0 + github.com/cockroachdb/pebble v1.1.1 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 - github.com/crate-crypto/go-kzg-4844 v0.7.0 + github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c + github.com/crate-crypto/go-kzg-4844 v1.0.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v0.4.3 + github.com/ethereum/c-kzg-4844 v1.0.0 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -126,8 +126,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/cockroachdb/errors v1.11.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cockroachdb/errors v1.11.3 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +136,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.18.0 // indirect + github.com/getsentry/sentry-go v0.27.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +161,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,6 +229,7 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect + github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index fd04179f86..257416652d 100644 --- a/go.sum +++ b/go.sum @@ -980,6 +980,7 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1018,10 +1019,12 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= +github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= +github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1055,8 +1058,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= +github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1125,6 +1130,7 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1176,6 +1182,7 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= +github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1866,6 +1873,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= +github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2144,9 +2153,11 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From 061ff1c07da4057ad79f3e7e14c19d0d332c9930 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Tue, 10 Sep 2024 13:12:09 -0700 Subject: [PATCH 12/27] Initial commit of xplugeth injection and hooks in internal/cli/server/ --- go.mod | 1 + go.sum | 2 + internal/cli/server/server.go | 23 ++++++++ internal/cli/server/xplugeth_hooks.go | 74 +++++++++++++++++++++++++ internal/cli/server/xplugeth_imports.go | 7 +++ 5 files changed, 107 insertions(+) create mode 100644 internal/cli/server/xplugeth_hooks.go create mode 100644 internal/cli/server/xplugeth_imports.go diff --git a/go.mod b/go.mod index b21f9e531b..6a73e64cc3 100644 --- a/go.mod +++ b/go.mod @@ -67,6 +67,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/naoina/toml v0.1.1 github.com/olekukonko/tablewriter v0.0.5 + github.com/openrelayxyz/xplugeth v0.0.0-build-test2 github.com/pelletier/go-toml v1.9.5 github.com/peterh/liner v1.2.2 github.com/protolambda/bls12-381-util v0.1.0 diff --git a/go.sum b/go.sum index fd04179f86..1a09edf0a7 100644 --- a/go.sum +++ b/go.sum @@ -1866,6 +1866,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2 h1:zq75jb0VNgUTiVvyM+O7fe/89bgeLxgUNXvycu09rMw= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2/go.mod h1:JcModBzVLMJN2oaIk4kO+rN9ia5Ve3r3QhbA6bjrlfs= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index 34015e23a5..31b57e15d9 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -40,6 +40,9 @@ import ( "github.com/ethereum/go-ethereum/metrics/prometheus" "github.com/ethereum/go-ethereum/node" + "github.com/openrelayxyz/xplugeth" + xtypes "github.com/openrelayxyz/xplugeth/types" + // Force-load the tracer engines to trigger registration _ "github.com/ethereum/go-ethereum/eth/tracers/js" _ "github.com/ethereum/go-ethereum/eth/tracers/native" @@ -131,6 +134,10 @@ func NewServer(config *Config, opts ...serverOption) (*Server, error) { } } + //begin xplugeth injection + xplugeth.Initialize() + //end xplugeth injection + // load the chain genesis if err = config.loadChain(); err != nil { return nil, err @@ -283,11 +290,23 @@ func NewServer(config *Config, opts ...serverOption) (*Server, error) { // Set the node instance srv.node = stack + // begin xplugeth injection + xplugeth.StoreSingleton[*node.Node](stack) + xplugeth.StoreSingleton[xtypes.Backend](srv.backend.APIBackend) + pluginInitializeNode() + stack.RegisterAPIs(pluginGetAPIs()) + // end xplugeth injection + // start the node if err := srv.node.Start(); err != nil { return nil, err } + //begin xplugeth injection + pluginBlockchain() + //end xplugeth injection + + return srv, nil } @@ -306,6 +325,10 @@ func (s *Server) Stop() { log.Error("Failed to shutdown open telemetry tracer") } } + + //begin xplugeth injection + defer pluginOnShutdown() + //end xplugeth injection } func (s *Server) setupMetrics(config *TelemetryConfig, serviceName string) error { diff --git a/internal/cli/server/xplugeth_hooks.go b/internal/cli/server/xplugeth_hooks.go new file mode 100644 index 0000000000..06af22fdbe --- /dev/null +++ b/internal/cli/server/xplugeth_hooks.go @@ -0,0 +1,74 @@ +package server + +import ( + "github.com/openrelayxyz/xplugeth" + "github.com/openrelayxyz/xplugeth/types" + + "github.com/ethereum/go-ethereum/node" + "github.com/ethereum/go-ethereum/rpc" +) + +type initializer interface { + InitializeNode(*node.Node, types.Backend) +} +type shutdown interface { + Shutdown() +} +type blockchain interface { + Blockchain() +} +type getAPIs interface { + GetAPIs(*node.Node, types.Backend) []rpc.API +} + +func init() { + xplugeth.RegisterHook[initializer]() + xplugeth.RegisterHook[shutdown]() + xplugeth.RegisterHook[blockchain]() + xplugeth.RegisterHook[getAPIs]() +} + +func pluginInitializeNode() { + stack, ok := xplugeth.GetSingleton[*node.Node]() + if !ok { + panic("*node.Node singleton not set, xplugeth InitializeNode") + } + backend, ok := xplugeth.GetSingleton[types.Backend]() + if !ok { + panic("types.Backend singleton not set, xplugeth Initializenode") + } + for _, init := range xplugeth.GetModules[initializer]() { + init.InitializeNode(stack, backend) + } +} + +func pluginGetAPIs() []rpc.API { + result := []rpc.API{} + + stack, ok := xplugeth.GetSingleton[*node.Node]() + if !ok { + panic("*node.Node singleton not set, xplugeth GetAPIs") + } + backend, ok := xplugeth.GetSingleton[types.Backend]() + if !ok { + panic("types.Backend singleton not set xplugeth GetAPIs") + } + + for _, a := range xplugeth.GetModules[getAPIs]() { + result = append(result, a.GetAPIs(stack, backend)...) + } + + return result +} + +func pluginOnShutdown() { + for _, shutdown := range xplugeth.GetModules[shutdown]() { + shutdown.Shutdown() + } +} + +func pluginBlockchain() { + for _, b := range xplugeth.GetModules[blockchain]() { + b.Blockchain() + } +} diff --git a/internal/cli/server/xplugeth_imports.go b/internal/cli/server/xplugeth_imports.go new file mode 100644 index 0000000000..e0dc7a60a1 --- /dev/null +++ b/internal/cli/server/xplugeth_imports.go @@ -0,0 +1,7 @@ +package server + +// +build example_plugin + +import ( + _ "github.com/openrelayxyz/xplugeth/plugins/example" +) \ No newline at end of file From 7f9d9e3f4414302d57d28a3e156a53f556f03246 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Tue, 10 Sep 2024 15:34:00 -0700 Subject: [PATCH 13/27] Modified mod and sum to enable building --- go.mod | 20 ++++++++++---------- go.sum | 13 ++----------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 318ec92d93..6a73e64cc3 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.1 + github.com/cockroachdb/pebble v1.1.0 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c - github.com/crate-crypto/go-kzg-4844 v1.0.0 + github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 + github.com/crate-crypto/go-kzg-4844 v0.7.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v1.0.0 + github.com/ethereum/c-kzg-4844 v0.4.3 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -67,6 +67,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/naoina/toml v0.1.1 github.com/olekukonko/tablewriter v0.0.5 + github.com/openrelayxyz/xplugeth v0.0.0-build-test2 github.com/pelletier/go-toml v1.9.5 github.com/peterh/liner v1.2.2 github.com/protolambda/bls12-381-util v0.1.0 @@ -126,8 +127,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/cockroachdb/errors v1.11.3 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +137,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.27.0 // indirect + github.com/getsentry/sentry-go v0.18.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +162,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.12 // indirect - github.com/tklauser/numcpus v0.6.1 // indirect + github.com/tklauser/go-sysconf v0.3.11 // indirect + github.com/tklauser/numcpus v0.6.0 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,7 +230,6 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect - github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index 257416652d..1a09edf0a7 100644 --- a/go.sum +++ b/go.sum @@ -980,7 +980,6 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1019,12 +1018,10 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= -github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= -github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1058,10 +1055,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= -github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= -github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1130,7 +1125,6 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= -github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1182,7 +1176,6 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= -github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1873,8 +1866,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2 h1:zq75jb0VNgUTiVvyM+O7fe/89bgeLxgUNXvycu09rMw= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2/go.mod h1:JcModBzVLMJN2oaIk4kO+rN9ia5Ve3r3QhbA6bjrlfs= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2153,11 +2146,9 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= -github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= -github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From 573b5a4eecbe2db9ad7cfc92d151ecebb7953491 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Tue, 10 Sep 2024 15:51:32 -0700 Subject: [PATCH 14/27] Adjusted mod and sum to allow for building --- go.mod | 20 ++++++++++---------- go.sum | 13 ++----------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 318ec92d93..6a73e64cc3 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.1 + github.com/cockroachdb/pebble v1.1.0 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c - github.com/crate-crypto/go-kzg-4844 v1.0.0 + github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 + github.com/crate-crypto/go-kzg-4844 v0.7.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v1.0.0 + github.com/ethereum/c-kzg-4844 v0.4.3 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -67,6 +67,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/naoina/toml v0.1.1 github.com/olekukonko/tablewriter v0.0.5 + github.com/openrelayxyz/xplugeth v0.0.0-build-test2 github.com/pelletier/go-toml v1.9.5 github.com/peterh/liner v1.2.2 github.com/protolambda/bls12-381-util v0.1.0 @@ -126,8 +127,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/cockroachdb/errors v1.11.3 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +137,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.27.0 // indirect + github.com/getsentry/sentry-go v0.18.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +162,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.12 // indirect - github.com/tklauser/numcpus v0.6.1 // indirect + github.com/tklauser/go-sysconf v0.3.11 // indirect + github.com/tklauser/numcpus v0.6.0 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,7 +230,6 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect - github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index 257416652d..1a09edf0a7 100644 --- a/go.sum +++ b/go.sum @@ -980,7 +980,6 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1019,12 +1018,10 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= -github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= -github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1058,10 +1055,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= -github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= -github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1130,7 +1125,6 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= -github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1182,7 +1176,6 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= -github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1873,8 +1866,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2 h1:zq75jb0VNgUTiVvyM+O7fe/89bgeLxgUNXvycu09rMw= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2/go.mod h1:JcModBzVLMJN2oaIk4kO+rN9ia5Ve3r3QhbA6bjrlfs= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2153,11 +2146,9 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= -github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= -github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From ed4304aec9a8df4e2b67ca8d4014d28939b45b31 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Tue, 10 Sep 2024 17:03:59 -0700 Subject: [PATCH 15/27] updated mod and sum to allow for building --- go.mod | 20 ++++++++++---------- go.sum | 13 ++----------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 318ec92d93..6a73e64cc3 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.1 + github.com/cockroachdb/pebble v1.1.0 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c - github.com/crate-crypto/go-kzg-4844 v1.0.0 + github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 + github.com/crate-crypto/go-kzg-4844 v0.7.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v1.0.0 + github.com/ethereum/c-kzg-4844 v0.4.3 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -67,6 +67,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/naoina/toml v0.1.1 github.com/olekukonko/tablewriter v0.0.5 + github.com/openrelayxyz/xplugeth v0.0.0-build-test2 github.com/pelletier/go-toml v1.9.5 github.com/peterh/liner v1.2.2 github.com/protolambda/bls12-381-util v0.1.0 @@ -126,8 +127,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/cockroachdb/errors v1.11.3 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +137,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.27.0 // indirect + github.com/getsentry/sentry-go v0.18.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +162,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.12 // indirect - github.com/tklauser/numcpus v0.6.1 // indirect + github.com/tklauser/go-sysconf v0.3.11 // indirect + github.com/tklauser/numcpus v0.6.0 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,7 +230,6 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect - github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index 257416652d..1a09edf0a7 100644 --- a/go.sum +++ b/go.sum @@ -980,7 +980,6 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1019,12 +1018,10 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= -github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= -github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1058,10 +1055,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= -github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= -github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1130,7 +1125,6 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= -github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1182,7 +1176,6 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= -github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1873,8 +1866,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2 h1:zq75jb0VNgUTiVvyM+O7fe/89bgeLxgUNXvycu09rMw= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2/go.mod h1:JcModBzVLMJN2oaIk4kO+rN9ia5Ve3r3QhbA6bjrlfs= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2153,11 +2146,9 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= -github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= -github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From ada583db4c933d79bf9e02284df4bd33f8c4f8c3 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Tue, 10 Sep 2024 17:04:29 -0700 Subject: [PATCH 16/27] Adjustments to stateupdate injections as well as adding pluginSnapshot type. --- core/state/statedb.go | 28 ++++++++++++++++++---------- core/state/xplugeth_hooks.go | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index 293b9e03e4..9cea3d845c 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1643,6 +1643,11 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er nodes = trienode.NewMergedNodeSet() codeWriter = s.db.DiskDB().NewBatch() ) + + // begin PluGeth injection + codeUpdates := make(map[common.Hash][]byte) + // end PluGeth injection + // Handle all state deletions first incomplete, err := s.handleDestruction(nodes) if err != nil { @@ -1657,6 +1662,9 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er // Write any contract code associated with the state object if obj.code != nil && obj.dirtyCode { rawdb.WriteCode(codeWriter, common.BytesToHash(obj.CodeHash()), obj.code) + // begin PluGeth injection + codeUpdates[common.BytesToHash(obj.CodeHash())] = obj.code + // end PluGeth injection obj.dirtyCode = false } // Write any storage changes in the state object to its storage trie @@ -1724,18 +1732,18 @@ func (s *StateDB) Commit(block uint64, deleteEmptyObjects bool) (common.Hash, er pluginStateUpdate(root, parent, s.snap, s.trie, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages, codeUpdates) if _, ok := s.snap.(*pluginSnapshot); !ok && s.snaps != nil { // This if statement (but not its content) was added by PluGeth //end PluGeth injection - if err := s.snaps.Update(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages); err != nil { - log.Warn("Failed to update snapshot tree", "from", parent, "to", root, "err", err) - } - // Keep 128 diff layers in the memory, persistent layer is 129th. - // - head layer is paired with HEAD state - // - head-1 layer is paired with HEAD-1 state - // - head-127 layer(bottom-most diff layer) is paired with HEAD-127 state - if err := s.snaps.Cap(root, 128); err != nil { - log.Warn("Failed to cap snapshot tree", "root", root, "layers", 128, "err", err) + if err := s.snaps.Update(root, parent, s.convertAccountSet(s.stateObjectsDestruct), s.accounts, s.storages); err != nil { + log.Warn("Failed to update snapshot tree", "from", parent, "to", root, "err", err) + } + // Keep 128 diff layers in the memory, persistent layer is 129th. + // - head layer is paired with HEAD state + // - head-1 layer is paired with HEAD-1 state + // - head-127 layer(bottom-most diff layer) is paired with HEAD-127 state + if err := s.snaps.Cap(root, 128); err != nil { + log.Warn("Failed to cap snapshot tree", "root", root, "layers", 128, "err", err) + } } } - if metrics.EnabledExpensive { s.SnapshotCommits += time.Since(start) } diff --git a/core/state/xplugeth_hooks.go b/core/state/xplugeth_hooks.go index 11a63670d3..16ae025883 100644 --- a/core/state/xplugeth_hooks.go +++ b/core/state/xplugeth_hooks.go @@ -1,6 +1,7 @@ package state import ( + "fmt" "bytes" "time" @@ -16,6 +17,26 @@ var ( acctCheckTimer = metrics.NewRegisteredTimer("plugeth/statedb/accounts/checks", nil) ) +type pluginSnapshot struct { + root common.Hash +} + +func (s *pluginSnapshot) Root() common.Hash { + return s.root +} + +func (s *pluginSnapshot) Account(hash common.Hash) (*types.SlimAccount, error) { + return nil, fmt.Errorf("not implemented") +} + +func (s *pluginSnapshot) AccountRLP(hash common.Hash) ([]byte, error) { + return nil, fmt.Errorf("not implemented") +} + +func (s *pluginSnapshot) Storage(accountHash, storageHash common.Hash) ([]byte, error) { + return nil, fmt.Errorf("not implemented") +} + type acctChecker struct { snap snapshot.Snapshot trie Trie From 70f3d9a79a17ef423664fc55d603a26b8e480c1f Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Tue, 10 Sep 2024 17:15:53 -0700 Subject: [PATCH 17/27] Adjustments to mod and sum to enable building --- go.mod | 21 ++++++++++----------- go.sum | 15 ++------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 391ba85405..6a73e64cc3 100644 --- a/go.mod +++ b/go.mod @@ -16,16 +16,16 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.3 github.com/cespare/cp v1.1.1 github.com/cloudflare/cloudflare-go v0.97.0 - github.com/cockroachdb/pebble v1.1.1 + github.com/cockroachdb/pebble v1.1.0 github.com/consensys/gnark-crypto v0.12.1 github.com/cosmos/cosmos-sdk v0.50.6 - github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c - github.com/crate-crypto/go-kzg-4844 v1.0.0 + github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 + github.com/crate-crypto/go-kzg-4844 v0.7.0 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/deckarep/golang-set/v2 v2.6.0 github.com/dop251/goja v0.0.0-20240516125602-ccbae20bcec2 github.com/emirpasic/gods v1.18.1 - github.com/ethereum/c-kzg-4844 v1.0.0 + github.com/ethereum/c-kzg-4844 v0.4.3 github.com/fatih/color v1.17.0 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fsnotify/fsnotify v1.7.0 @@ -67,6 +67,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/naoina/toml v0.1.1 github.com/olekukonko/tablewriter v0.0.5 + github.com/openrelayxyz/xplugeth v0.0.0-build-test2 github.com/pelletier/go-toml v1.9.5 github.com/peterh/liner v1.2.2 github.com/protolambda/bls12-381-util v0.1.0 @@ -126,8 +127,8 @@ require ( github.com/aws/smithy-go v1.20.2 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/cockroachdb/errors v1.11.3 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cockroachdb/errors v1.11.1 // indirect github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect github.com/cockroachdb/redact v1.1.5 // indirect github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect @@ -136,7 +137,7 @@ require ( github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect - github.com/getsentry/sentry-go v0.27.0 // indirect + github.com/getsentry/sentry-go v0.18.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/gogo/protobuf v1.3.2 // indirect @@ -161,8 +162,8 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/tklauser/go-sysconf v0.3.12 // indirect - github.com/tklauser/numcpus v0.6.1 // indirect + github.com/tklauser/go-sysconf v0.3.11 // indirect + github.com/tklauser/numcpus v0.6.0 // indirect github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect @@ -229,8 +230,6 @@ require ( github.com/montanaflynn/stats v0.7.0 // indirect github.com/naoina/go-stringutil v0.1.0 // indirect github.com/oapi-codegen/runtime v1.0.0 // indirect - github.com/openrelayxyz/plugeth-utils v1.5.0 // indirect - github.com/openrelayxyz/xplugeth v0.0.0-build-test1 // indirect github.com/posener/complete v1.2.3 // indirect github.com/rakyll/statik v0.1.7 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect diff --git a/go.sum b/go.sum index 6c8c82daef..1a09edf0a7 100644 --- a/go.sum +++ b/go.sum @@ -980,7 +980,6 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927/go.mod h1:h/aW8ynjgkuj+NQRlZcDbAbM1ORAbXjXX77sX7T289U= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= @@ -1019,12 +1018,10 @@ github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaY github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.11.1 h1:xSEW75zKaKCWzR3OfxXUxgrk/NtT4G1MiOv5lWZazG8= github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4MIpiWMSNRfxw= -github.com/cockroachdb/errors v1.11.3/go.mod h1:m4UIW4CDjx+R5cybPsNrRbreomiFqt8o1h1wUVazSd8= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE= github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs= github.com/cockroachdb/pebble v1.1.0 h1:pcFh8CdCIt2kmEpK0OIatq67Ln9uGDYY3d5XnE0LJG4= github.com/cockroachdb/pebble v1.1.0/go.mod h1:sEHm5NOXxyiAoKWhoFxT8xMgd/f3RA6qUqQ1BXKrh2E= -github.com/cockroachdb/pebble v1.1.1/go.mod h1:4exszw1r40423ZsmkG/09AFEG83I0uDgfujJdbL6kYU= github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30= github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg= github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 h1:zuQyyAKVxetITBuuhv3BI9cMrmStnpT18zmgmTxunpo= @@ -1058,10 +1055,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= -github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= -github.com/crate-crypto/go-kzg-4844 v1.0.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -1130,7 +1125,6 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/ethereum/c-kzg-4844 v0.4.3 h1:Mpg+qsE1XyDAc03LyDfJsr8oxrt7mN7HX6wJIlB2880= github.com/ethereum/c-kzg-4844 v0.4.3/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= -github.com/ethereum/c-kzg-4844 v1.0.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0= github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64= @@ -1182,7 +1176,6 @@ github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 h1:BAIP2Gihuqh github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46/go.mod h1:QNpY22eby74jVhqH4WhDLDwxc/vqsern6pW+u2kbkpc= github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0= github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= -github.com/getsentry/sentry-go v0.27.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -1873,10 +1866,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/openrelayxyz/plugeth-utils v1.5.0 h1:4hzAvMKEo5uCnXy5cCHDc7OfXpwAavFNjr3M/ZfTlEA= -github.com/openrelayxyz/plugeth-utils v1.5.0/go.mod h1:COwKAuTZIsCouCOrIDBhvHZqpbOO1Ojgdy5KTvL8mJg= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1 h1:UDvlVM2NEWQJAhePclzfvjwhCGw+kphiEOcrBUZ+KTA= -github.com/openrelayxyz/xplugeth v0.0.0-build-test1/go.mod h1:PWTTbtM0rA/TtDmkHyicDHhi4kk8ByFHVEwX8U6134Q= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2 h1:zq75jb0VNgUTiVvyM+O7fe/89bgeLxgUNXvycu09rMw= +github.com/openrelayxyz/xplugeth v0.0.0-build-test2/go.mod h1:JcModBzVLMJN2oaIk4kO+rN9ia5Ve3r3QhbA6bjrlfs= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= @@ -2155,11 +2146,9 @@ github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk1 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= -github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= -github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= From 2cb5d65eed174b97748f5296fffddb40e945bcbf Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Thu, 10 Oct 2024 17:59:39 -0700 Subject: [PATCH 18/27] refactored xplugeth_hook files to internal interface version --- core/rawdb/xplugeth_hooks.go | 63 +++++++++++++++------------- core/state/xplugeth_hooks.go | 17 +++----- core/xplugeth_hooks.go | 39 ++++------------- trie/triedb/hashdb/xplugeth_hooks.go | 21 +++------- 4 files changed, 53 insertions(+), 87 deletions(-) diff --git a/core/rawdb/xplugeth_hooks.go b/core/rawdb/xplugeth_hooks.go index 90959ab5c8..c4624fc90a 100644 --- a/core/rawdb/xplugeth_hooks.go +++ b/core/rawdb/xplugeth_hooks.go @@ -2,39 +2,24 @@ package rawdb import ( "sync" + "reflect" + + "github.com/openrelayxyz/xplugeth" + "github.com/openrelayxyz/xplugeth/hooks/modifyancients" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" - "github.com/openrelayxyz/xplugeth" + "github.com/ethereum/go-ethereum/rlp" + ) var ( freezerUpdates map[uint64]map[string]interface{} lock sync.Mutex - modifyAncientsInjection *bool - appendRawInjection *bool - appendInjection *bool ) -type modifyAncientsPlugin interface { - ModifyAncients(uint64, map[string]interface{}) -} - -func init() { - xplugeth.RegisterHook[modifyAncientsPlugin]() -} - func PluginTrackUpdate(num uint64, kind string, value interface{}) { - if appendRawInjection != nil { - called := true - appendRawInjection = &called - } - - if appendInjection != nil { - called := true - appendInjection = &called - } - lock.Lock() defer lock.Unlock() if freezerUpdates == nil { @@ -49,11 +34,7 @@ func PluginTrackUpdate(num uint64, kind string, value interface{}) { } func pluginCommitUpdate(num uint64) { - if modifyAncientsInjection != nil { - called := true - modifyAncientsInjection = &called - } - + lock.Lock() defer lock.Unlock() if freezerUpdates == nil { @@ -65,6 +46,7 @@ func pluginCommitUpdate(num uint64) { min = i } } + for i := min; i < num; i++ { update, ok := freezerUpdates[i] defer func(i uint64) { delete(freezerUpdates, i) }(i) @@ -72,8 +54,31 @@ func pluginCommitUpdate(num uint64) { log.Warn("Attempting to commit untracked block", "num", i) continue } - for _, m := range xplugeth.GetModules[modifyAncientsPlugin]() { - m.ModifyAncients(i, update) + if len(xplugeth.GetModules[modifyancients.ModifyAncientsPlugin]()) > 0 { + var keys []string + for k := range update { + keys = append(keys, k) + } + if headeri, ok := update[ChainFreezerHeaderTable]; ok { + var h types.Header + switch v := headeri.(type) { + case []byte: + err := rlp.DecodeBytes(v, &h) + if err != nil { + log.Error("error decoding header, commit update", "err", err) + continue + } + case *types.Header: + log.Error("second case") + h = *v + default: + log.Error("header of unknown type", "type", reflect.TypeOf(headeri)) + continue + } + for _, m := range xplugeth.GetModules[modifyancients.ModifyAncientsPlugin]() { + m.ModifyAncients(num, &h) + } + } } } } diff --git a/core/state/xplugeth_hooks.go b/core/state/xplugeth_hooks.go index 16ae025883..5b58a140d9 100644 --- a/core/state/xplugeth_hooks.go +++ b/core/state/xplugeth_hooks.go @@ -5,12 +5,14 @@ import ( "bytes" "time" + "github.com/openrelayxyz/xplugeth" + "github.com/openrelayxyz/xplugeth/hooks/stateupdates" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state/snapshot" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/metrics" - "github.com/openrelayxyz/xplugeth" ) var ( @@ -46,15 +48,6 @@ type acctByHasher interface { GetAccountByHash(common.Hash) (*types.StateAccount, error) } -type stateUpdatePlugin interface { - StateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot, trie Trie, destructs map[common.Hash]struct{}, accounts map[common.Hash][]byte, storage map[common.Hash]map[common.Hash][]byte, codeUpdates map[common.Hash][]byte) -} - -func init() { - xplugeth.RegisterHook[stateUpdatePlugin]() - -} - func (ac *acctChecker) exists(k common.Hash) bool { if hadStorage, ok := ac.snapExists(k); ok { return hadStorage @@ -126,8 +119,8 @@ func pluginStateUpdate(blockRoot, parentRoot common.Hash, snap snapshot.Snapshot } acctCheckTimer.UpdateSince(start) - for _, m := range xplugeth.GetModules[stateUpdatePlugin]() { - m.StateUpdate(blockRoot, parentRoot, snap, trie, filteredDestructs, filteredAccounts, storage, codeUpdates) + for _, m := range xplugeth.GetModules[stateupdates.StateUpdatePlugin]() { + m.StateUpdate(blockRoot, parentRoot, filteredDestructs, filteredAccounts, storage, codeUpdates) } } diff --git a/core/xplugeth_hooks.go b/core/xplugeth_hooks.go index 515ff6e7e2..99339825ad 100644 --- a/core/xplugeth_hooks.go +++ b/core/xplugeth_hooks.go @@ -5,43 +5,22 @@ import ( "sync" "time" + "github.com/openrelayxyz/xplugeth" + "github.com/openrelayxyz/xplugeth/hooks/blockchain" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" - "github.com/openrelayxyz/xplugeth" ) -type newHeadPlugin interface { - NewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) -} - -type newSideBlockPlugin interface { - NewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) -} - -type reorgPlugin interface { - Reorg(commonBlock common.Hash, oldChain, newChain []common.Hash) -} - -type setTrieFlushIntervalClonePlugin interface { - SetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration -} - -func init() { - xplugeth.RegisterHook[newHeadPlugin]() - xplugeth.RegisterHook[newSideBlockPlugin]() - xplugeth.RegisterHook[reorgPlugin]() - xplugeth.RegisterHook[setTrieFlushIntervalClonePlugin]() -} - func pluginNewHead(block *types.Block, hash common.Hash, logs []*types.Log, td *big.Int) { - for _, m := range xplugeth.GetModules[newHeadPlugin]() { + for _, m := range xplugeth.GetModules[blockchain.NewHeadPlugin]() { m.NewHead(block, hash, logs, td) } } func pluginNewSideBlock(block *types.Block, hash common.Hash, logs []*types.Log) { - for _, m := range xplugeth.GetModules[newSideBlockPlugin]() { + for _, m := range xplugeth.GetModules[blockchain.NewSideBlockPlugin]() { m.NewSideBlock(block, hash, logs) } } @@ -55,18 +34,18 @@ func pluginReorg(commonBlock *types.Block, oldChain, newChain types.Blocks) { for i, block := range newChain { newChainHashes[i] = block.Hash() } - for _, m := range xplugeth.GetModules[reorgPlugin]() { + for _, m := range xplugeth.GetModules[blockchain.ReorgPlugin]() { m.Reorg(commonBlock.Hash(), oldChainHashes, newChainHashes) } } func pluginSetTrieFlushIntervalClone(flushInterval time.Duration) time.Duration { - modules := xplugeth.GetModules[setTrieFlushIntervalClonePlugin]() + m := xplugeth.GetModules[blockchain.SetTrieFlushIntervalClonePlugin]() var snc sync.Once - if len(modules) > 1 { + if len(m) > 1 { snc.Do(func() { log.Warn("The blockChain flushInterval value is being accessed by multiple plugins") }) } - for _, m := range modules { + for _, m := range m { flushInterval = m.SetTrieFlushIntervalClone(flushInterval) } return flushInterval diff --git a/trie/triedb/hashdb/xplugeth_hooks.go b/trie/triedb/hashdb/xplugeth_hooks.go index c9e6743819..046131e985 100644 --- a/trie/triedb/hashdb/xplugeth_hooks.go +++ b/trie/triedb/hashdb/xplugeth_hooks.go @@ -1,31 +1,20 @@ package hashdb import ( - "github.com/ethereum/go-ethereum/common" "github.com/openrelayxyz/xplugeth" -) + "github.com/openrelayxyz/xplugeth/hooks/triecommit" -type preTrieCommit interface { - PreTrieCommit(node common.Hash) -} - -type postTrieCommit interface { - PostTrieCommit(node common.Hash) -} - -func init() { - xplugeth.RegisterHook[preTrieCommit]() - xplugeth.RegisterHook[postTrieCommit]() -} + "github.com/ethereum/go-ethereum/common" +) func pluginPreTrieCommit(node common.Hash) { - for _, m := range xplugeth.GetModules[preTrieCommit]() { + for _, m := range xplugeth.GetModules[triecommit.PreTrieCommit]() { m.PreTrieCommit(node) } } func pluginPostTrieCommit(node common.Hash) { - for _, m := range xplugeth.GetModules[postTrieCommit]() { + for _, m := range xplugeth.GetModules[triecommit.PostTrieCommit]() { m.PostTrieCommit(node) } } From 2c26e7414ffc3a59fc39d07b95858c9ad2674b66 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Thu, 10 Oct 2024 18:00:34 -0700 Subject: [PATCH 19/27] Added plugins config environment variable parser --- internal/cli/server/server.go | 2 +- internal/cli/server/xplugeth_hooks.go | 50 ++++++++++++++++----------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index 31b57e15d9..786a90dc1e 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -135,7 +135,7 @@ func NewServer(config *Config, opts ...serverOption) (*Server, error) { } //begin xplugeth injection - xplugeth.Initialize() + xplugeth.Initialize(pluginsConfig()) //end xplugeth injection // load the chain genesis diff --git a/internal/cli/server/xplugeth_hooks.go b/internal/cli/server/xplugeth_hooks.go index 06af22fdbe..d8ff7bd58b 100644 --- a/internal/cli/server/xplugeth_hooks.go +++ b/internal/cli/server/xplugeth_hooks.go @@ -1,31 +1,41 @@ package server import ( + "os" + "path/filepath" + "github.com/openrelayxyz/xplugeth" "github.com/openrelayxyz/xplugeth/types" + "github.com/openrelayxyz/xplugeth/hooks/apis" + "github.com/openrelayxyz/xplugeth/hooks/initialize" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" ) -type initializer interface { - InitializeNode(*node.Node, types.Backend) -} -type shutdown interface { - Shutdown() -} -type blockchain interface { - Blockchain() -} -type getAPIs interface { - GetAPIs(*node.Node, types.Backend) []rpc.API +func isValidPath(path string) bool { + cleanPath := filepath.Clean(path) + + fileInfo, err := os.Stat(cleanPath) + if err != nil { + return false + } + return fileInfo.IsDir() } -func init() { - xplugeth.RegisterHook[initializer]() - xplugeth.RegisterHook[shutdown]() - xplugeth.RegisterHook[blockchain]() - xplugeth.RegisterHook[getAPIs]() + +func pluginsConfig() string { + pluginsConfigEnv := os.Getenv("PLUGINS_CONFIG") + + if pluginsConfigEnv != "" && isValidPath(pluginsConfigEnv) { + log.Error("path provided", "path", pluginsConfigEnv) + return pluginsConfigEnv + } else { + log.Error("plugins config path not provided or invalid") + return "" + } + } func pluginInitializeNode() { @@ -37,7 +47,7 @@ func pluginInitializeNode() { if !ok { panic("types.Backend singleton not set, xplugeth Initializenode") } - for _, init := range xplugeth.GetModules[initializer]() { + for _, init := range xplugeth.GetModules[initialize.Initializer]() { init.InitializeNode(stack, backend) } } @@ -54,7 +64,7 @@ func pluginGetAPIs() []rpc.API { panic("types.Backend singleton not set xplugeth GetAPIs") } - for _, a := range xplugeth.GetModules[getAPIs]() { + for _, a := range xplugeth.GetModules[apis.GetAPIs]() { result = append(result, a.GetAPIs(stack, backend)...) } @@ -62,13 +72,13 @@ func pluginGetAPIs() []rpc.API { } func pluginOnShutdown() { - for _, shutdown := range xplugeth.GetModules[shutdown]() { + for _, shutdown := range xplugeth.GetModules[initialize.Shutdown]() { shutdown.Shutdown() } } func pluginBlockchain() { - for _, b := range xplugeth.GetModules[blockchain]() { + for _, b := range xplugeth.GetModules[initialize.Blockchain]() { b.Blockchain() } } From b59248022e154f72ee7970aaabe9ecf3774cd653 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Thu, 10 Oct 2024 18:01:21 -0700 Subject: [PATCH 20/27] upgraded mod and sum to reflect xplugeth v0.1.0 --- go.mod | 3 ++- go.sum | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6a73e64cc3..851735bef2 100644 --- a/go.mod +++ b/go.mod @@ -67,7 +67,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 github.com/naoina/toml v0.1.1 github.com/olekukonko/tablewriter v0.0.5 - github.com/openrelayxyz/xplugeth v0.0.0-build-test2 + github.com/openrelayxyz/xplugeth v0.1.0 github.com/pelletier/go-toml v1.9.5 github.com/peterh/liner v1.2.2 github.com/protolambda/bls12-381-util v0.1.0 @@ -205,6 +205,7 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/go-redsync/redsync/v4 v4.0.4 // indirect + github.com/go-yaml/yaml v2.1.0+incompatible // indirect github.com/goccy/go-json v0.10.3 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect diff --git a/go.sum b/go.sum index 1a09edf0a7..5d79961bff 100644 --- a/go.sum +++ b/go.sum @@ -1251,6 +1251,8 @@ github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4 github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= github.com/go-test/deep v1.1.0/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= +github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o= +github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= github.com/go-zookeeper/zk v1.0.2/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= @@ -1866,8 +1868,8 @@ github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJK github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/openrelayxyz/xplugeth v0.0.0-build-test2 h1:zq75jb0VNgUTiVvyM+O7fe/89bgeLxgUNXvycu09rMw= -github.com/openrelayxyz/xplugeth v0.0.0-build-test2/go.mod h1:JcModBzVLMJN2oaIk4kO+rN9ia5Ve3r3QhbA6bjrlfs= +github.com/openrelayxyz/xplugeth v0.1.0 h1:HSrX0NMUcXUKHDATytsNCp+dkWyBH/dlBw9Jh74+A+w= +github.com/openrelayxyz/xplugeth v0.1.0/go.mod h1:OLIeeTdTo1NJ5JKqzclNoqn+O5wqKf/Z6zWdCF6cFG8= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= From 211e35b462df79cc68b442b5c3f42d2110c31170 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Fri, 11 Oct 2024 10:41:04 -0700 Subject: [PATCH 21/27] changed logging level in internal/cli/server/xplugeth_hooks pluginsConfig() --- internal/cli/server/xplugeth_hooks.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/cli/server/xplugeth_hooks.go b/internal/cli/server/xplugeth_hooks.go index d8ff7bd58b..490484694c 100644 --- a/internal/cli/server/xplugeth_hooks.go +++ b/internal/cli/server/xplugeth_hooks.go @@ -27,15 +27,14 @@ func isValidPath(path string) bool { func pluginsConfig() string { pluginsConfigEnv := os.Getenv("PLUGINS_CONFIG") - + if pluginsConfigEnv != "" && isValidPath(pluginsConfigEnv) { - log.Error("path provided", "path", pluginsConfigEnv) + log.Info("plugins config path provided", "path", pluginsConfigEnv) return pluginsConfigEnv - } else { - log.Error("plugins config path not provided or invalid") - return "" - } + } + log.Info("plugins config path not provided or invalid") + return "" } func pluginInitializeNode() { From 87dd70a5c7cc0534734fb39d3ec95482880c8bde Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Fri, 11 Oct 2024 14:09:33 -0700 Subject: [PATCH 22/27] Added disablePlugins function --- internal/cli/server/server.go | 4 +++- internal/cli/server/xplugeth_hooks.go | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index 786a90dc1e..ffb36c176b 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -135,7 +135,9 @@ func NewServer(config *Config, opts ...serverOption) (*Server, error) { } //begin xplugeth injection - xplugeth.Initialize(pluginsConfig()) + if !disablePlugins() { + xplugeth.Initialize(pluginsConfig()) + } //end xplugeth injection // load the chain genesis diff --git a/internal/cli/server/xplugeth_hooks.go b/internal/cli/server/xplugeth_hooks.go index 490484694c..7e97e9bdc4 100644 --- a/internal/cli/server/xplugeth_hooks.go +++ b/internal/cli/server/xplugeth_hooks.go @@ -3,6 +3,7 @@ package server import ( "os" "path/filepath" + "strings" "github.com/openrelayxyz/xplugeth" "github.com/openrelayxyz/xplugeth/types" @@ -24,6 +25,19 @@ func isValidPath(path string) bool { return fileInfo.IsDir() } +func disablePlugins() bool { + val := os.Getenv("DISABLE_PLUGINS") + if len(val) > 0 { + truthyValues := []string{"true", "1", "yes", "y"} + for _, truthy := range truthyValues { + if strings.EqualFold(val, truthy) { + return true + } + } + } + return false +} + func pluginsConfig() string { pluginsConfigEnv := os.Getenv("PLUGINS_CONFIG") @@ -32,7 +46,7 @@ func pluginsConfig() string { log.Info("plugins config path provided", "path", pluginsConfigEnv) return pluginsConfigEnv } - + log.Info("plugins config path not provided or invalid") return "" } From f784482dae183f5efdc9578c0173bc89e0fe7db8 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Fri, 11 Oct 2024 14:18:10 -0700 Subject: [PATCH 23/27] Added logging for initialize xplugeth --- internal/cli/server/server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/cli/server/server.go b/internal/cli/server/server.go index ffb36c176b..a2d74ddd92 100644 --- a/internal/cli/server/server.go +++ b/internal/cli/server/server.go @@ -137,6 +137,7 @@ func NewServer(config *Config, opts ...serverOption) (*Server, error) { //begin xplugeth injection if !disablePlugins() { xplugeth.Initialize(pluginsConfig()) + log.Info("xplugeth initialized") } //end xplugeth injection From d8fc46b2b5e353fede2d8ced5bb4df6a9e2ca7c2 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Thu, 17 Oct 2024 14:06:44 -0700 Subject: [PATCH 24/27] Added subscription hook and injection --- rpc/service.go | 4 + rpc/xplugeth_subscription.go | 147 +++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 rpc/xplugeth_subscription.go diff --git a/rpc/service.go b/rpc/service.go index 95dd3afc31..d791d65db3 100644 --- a/rpc/service.go +++ b/rpc/service.go @@ -68,6 +68,10 @@ func (r *serviceRegistry) registerName(name string, rcvr interface{}) error { return fmt.Errorf("service %T doesn't have any suitable methods/subscriptions to expose", rcvr) } + // begin PluGeth code injection + pluginExtendedCallbacks(callbacks, rcvrVal) + // end PluGeth code injection + r.mu.Lock() defer r.mu.Unlock() diff --git a/rpc/xplugeth_subscription.go b/rpc/xplugeth_subscription.go new file mode 100644 index 0000000000..f426a746c0 --- /dev/null +++ b/rpc/xplugeth_subscription.go @@ -0,0 +1,147 @@ +package rpc + +import ( + "context" + "reflect" + "github.com/ethereum/go-ethereum/log" +) + +// Is t context.Context or *context.Context? +func isContextType(t reflect.Type) bool { + for t.Kind() == reflect.Ptr { + t = t.Elem() + } + return t == contextType +} + +func isChanType(t reflect.Type) bool { + // Pointers to channels are weird, but whatever + for t.Kind() == reflect.Ptr { + t = t.Elem() + } + // Make sure we have a channel + if t.Kind() != reflect.Chan { + return false + } + // Make sure it is a receivable channel + return (t.ChanDir() & reflect.RecvDir) == reflect.RecvDir +} + +func isChanPubsub(methodType reflect.Type) bool { + if methodType.NumIn() < 2 || methodType.NumOut() != 2 { + return false + } + return isContextType(methodType.In(1)) && + isChanType(methodType.Out(0)) && + isErrorType(methodType.Out(1)) +} + +func callbackifyChanPubSub(receiver, fn reflect.Value) *callback { + c := &callback{rcvr: receiver, errPos: 1, isSubscribe: true} + fntype := fn.Type() + // Skip receiver and context.Context parameter (if present). + firstArg := 0 + if c.rcvr.IsValid() { + firstArg++ + } + if fntype.NumIn() > firstArg && fntype.In(firstArg) == contextType { + c.hasCtx = true + firstArg++ + } + // Add all remaining parameters. + c.argTypes = make([]reflect.Type, fntype.NumIn()-firstArg) + for i := firstArg; i < fntype.NumIn(); i++ { + c.argTypes[i-firstArg] = fntype.In(i) + } + + retFnType := reflect.FuncOf(append([]reflect.Type{receiver.Type(), contextType}, c.argTypes...), []reflect.Type{reflect.PointerTo(subscriptionType), errorType}, false) + +// // What follows uses reflection to construct a dynamically typed function equivalent to: +// func(receiver , cctx context.Context, args ...) (*rpc.Subscription, error) { +// notifier, supported := NotifierFromContext(cctx) +// if !supported { return Subscription{}, ErrNotificationsUnsupported} +// ctx, cancel := context.WithCancel(context.Background()) +// ch, err := fn() +// if err != nil { return Subscription{}, err } +// rpcSub := notifier.CreateSubscription() +// go func() { +// select { +// case v, ok := <- ch: +// if !ok { return } +// notifier.Notify(rpcSub.ID, v) +// case <-rpcSub.Err(): +// cancel() +// return +// case <-notifier.Closed(): +// cancel() +// return +// } +// }() +// return rpcSub, nil +// } +// + + c.fn = reflect.MakeFunc(retFnType, func(args []reflect.Value) ([]reflect.Value) { + notifier, supported := NotifierFromContext(args[1].Interface().(context.Context)) + if !supported { + return []reflect.Value{reflect.Zero(subscriptionType), reflect.ValueOf(ErrNotificationsUnsupported)} + } + ctx, cancel := context.WithCancel(context.Background()) + + args[1] = reflect.ValueOf(ctx) + out := fn.Call(args) + if !out[1].IsNil() { + // This amounts to: if err != nil { return nil, err } + cancel() + return []reflect.Value{reflect.Zero(subscriptionType), out[1]} + } + // Geth's provided context is done once we've returned the subscription id. + // This new context will cancel when the notifier closes. + + rpcSub := notifier.CreateSubscription() + go func() { + defer cancel() + defer log.Info("Plugin subscription goroutine closed") + selectCases := []reflect.SelectCase{ + {Dir: reflect.SelectRecv, Chan: out[0]}, + {Dir: reflect.SelectRecv, Chan: reflect.ValueOf(rpcSub.Err())}, + // {Dir: reflect.SelectRecv, Chan: reflect.ValueOf(notifier.Closed())}, + } + for { + chosen, val, recvOK := reflect.Select(selectCases) + switch chosen { + case 0: // val, ok := <-ch + if !recvOK { + return + } + if err := notifier.Notify(rpcSub.ID, val.Interface()); err != nil { + log.Warn("Subscription notification failed", "id", rpcSub.ID, "err", err) + } + case 1: + return + // case 2: + // cancel() + // return + } + } + }() + return []reflect.Value{reflect.ValueOf(rpcSub), reflect.Zero(errorType)} + }) + return c +} + + +func pluginExtendedCallbacks(callbacks map[string]*callback, receiver reflect.Value) { + typ := receiver.Type() + for m := 0; m < typ.NumMethod(); m++ { + method := typ.Method(m) + if method.PkgPath != "" { + continue // method not exported + } + if isChanPubsub(method.Type) { + cb := callbackifyChanPubSub(receiver, method.Func) + name := formatName(method.Name) + callbacks[name] = cb + } + } +} \ No newline at end of file From f563de2946e4033b2619cebc08e615047c014357 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Sat, 19 Oct 2024 13:46:57 -0700 Subject: [PATCH 25/27] Added utility function to core/state/xplugeth_hooks --- core/state/xplugeth_hooks.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/state/xplugeth_hooks.go b/core/state/xplugeth_hooks.go index 5b58a140d9..1044d233af 100644 --- a/core/state/xplugeth_hooks.go +++ b/core/state/xplugeth_hooks.go @@ -23,6 +23,11 @@ type pluginSnapshot struct { root common.Hash } +// This function is being brought over from foundation to enable our producer plugin to work agnostically across networks. +func (s *StateDB) GetTrie() Trie { + return s.trie +} + func (s *pluginSnapshot) Root() common.Hash { return s.root } From defcef8e1cd1f6c2a39d4d22f10e558af0545792 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Mon, 21 Oct 2024 16:48:23 -0700 Subject: [PATCH 26/27] Added xplugeth_imports to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 7405ea2675..d1b43f1eb3 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,6 @@ dist logs/ tests/spec-tests/ + +# xplugeth_imports +/internal/cli/server/xplugeth_hooks.go From 9a37cee7c0233d0fd267c217f6e41b0f4ec4b746 Mon Sep 17 00:00:00 2001 From: Philip Morlier Date: Mon, 28 Oct 2024 12:17:11 -0700 Subject: [PATCH 27/27] refactored implementation of pluginStateUpdate injection --- core/state/statedb.go | 20 ++++++++++++++++++-- core/state/xplugeth_hooks.go | 26 -------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/core/state/statedb.go b/core/state/statedb.go index e477651906..56d5479737 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -206,7 +206,6 @@ func New(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB, error) if sdb.snaps != nil { sdb.snap = sdb.snaps.Snapshot(root) } - return sdb, nil } @@ -1661,6 +1660,7 @@ func (s *StateDB) commit(deleteEmptyObjects bool) (*stateUpdate, error) { return nodes.Merge(set) } ) + // Given that some accounts could be destroyed and then recreated within // the same block, account deletions must be processed first. This ensures // that the storage trie nodes deleted during destruction and recreated @@ -1767,6 +1767,19 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateU if err != nil { return nil, err } + + // begin PluGeth injection + codeUpdates := make(map[common.Hash][]byte) + for _, code := range ret.codes { + if len(code.blob) > 0 { + // Empty code may or may not be included in this list by Geth based on + // factors I'm not certain of, so to normalize our pending batches, + // exclude empty blobs. + codeUpdates[code.hash] = code.blob + } + } + // end PluGeth injection + // Commit dirty contract code if any exists if db := s.db.DiskDB(); db != nil && len(ret.codes) > 0 { batch := db.NewBatch() @@ -1780,8 +1793,11 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateU if !ret.empty() { // If snapshotting is enabled, update the snapshot tree with this new version if s.snap != nil { + //begin PluGeth code injection + pluginStateUpdate(ret.root, ret.originRoot, s.snap, s.trie, ret.destructs, ret.accounts, ret.storages, codeUpdates) + //end PluGeth code injection s.snap = nil - + start := time.Now() if err := s.snaps.Update(ret.root, ret.originRoot, ret.destructs, ret.accounts, ret.storages); err != nil { log.Warn("Failed to update snapshot tree", "from", ret.originRoot, "to", ret.root, "err", err) diff --git a/core/state/xplugeth_hooks.go b/core/state/xplugeth_hooks.go index 1044d233af..0b84fcbfdf 100644 --- a/core/state/xplugeth_hooks.go +++ b/core/state/xplugeth_hooks.go @@ -1,7 +1,6 @@ package state import ( - "fmt" "bytes" "time" @@ -19,31 +18,6 @@ var ( acctCheckTimer = metrics.NewRegisteredTimer("plugeth/statedb/accounts/checks", nil) ) -type pluginSnapshot struct { - root common.Hash -} - -// This function is being brought over from foundation to enable our producer plugin to work agnostically across networks. -func (s *StateDB) GetTrie() Trie { - return s.trie -} - -func (s *pluginSnapshot) Root() common.Hash { - return s.root -} - -func (s *pluginSnapshot) Account(hash common.Hash) (*types.SlimAccount, error) { - return nil, fmt.Errorf("not implemented") -} - -func (s *pluginSnapshot) AccountRLP(hash common.Hash) ([]byte, error) { - return nil, fmt.Errorf("not implemented") -} - -func (s *pluginSnapshot) Storage(accountHash, storageHash common.Hash) ([]byte, error) { - return nil, fmt.Errorf("not implemented") -} - type acctChecker struct { snap snapshot.Snapshot trie Trie