From 759c0b0b3c2f64b5c23605ce9a4edb9530748120 Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Tue, 9 Jan 2024 22:13:40 -0500 Subject: [PATCH] fix(miner): Fix issue seen in prepare proposal (#1396) ## Summary by CodeRabbit - **New Features** - Introduced a new proposal system for validators to propose and process blocks. - Enhanced the EVMKeeper interface to support blockchain setup and state plugin factory retrieval. - Added a new interface for ABCI requests with methods for transaction and blockchain state retrieval. - Implemented a state plugin factory for creating and managing state plugins. - Updated the blockchain interface to manage state plugins more effectively. - **Improvements** - Removed unnecessary methods from the App interface to streamline blockchain interactions. - Updated Miner type to integrate with the Ethereum miner and state plugin factory. - Enhanced the Keeper type in EVM module to support new host chain interactions. - Modified the blockchain and chain writer interfaces to include state parameters in various methods. - **Bug Fixes** - Fixed issues in genesis state handling by correctly utilizing the state plugin factory. - Adjusted EndBlock and PrepareCheckState functions in the EVM module to align with the Cosmos-SDK lifecycle. - **Documentation** - Translated project introductory information and core principles to Korean. - **Refactor** - Updated various Go files to use the new Go version 1.21.6. - Simplified the chain and miner modules by removing redundant fields and imports. - Refined the EVM module to better manage gas metering and state overrides. - **Chores** - Updated Go version in workflow actions and Dockerfiles for consistent build environments. --------- Co-authored-by: ocnc Co-authored-by: Cal Bera --- .github/workflows/codeql.yml | 2 +- .github/workflows/daily.yml | 2 +- .github/workflows/e2e.yml | 8 +- .github/workflows/pipeline.yml | 2 +- build/scripts/main.mk | 2 +- build/tools/go.mod | 4 +- build/tools/go.sum | 12 +- .../distribution_testing_helper.abigen.go | 2 +- cosmos/go.mod | 14 +- cosmos/go.sum | 28 +-- cosmos/runtime/abci/proposal.go | 148 +++++++++++++++ cosmos/runtime/abci/types.go | 37 ++++ cosmos/runtime/chain/abci.go | 34 +--- cosmos/runtime/chain/chain.go | 38 +--- cosmos/runtime/chain/interfaces.go | 6 +- cosmos/runtime/miner/abci.go | 29 +-- cosmos/runtime/miner/interfaces.go | 11 +- cosmos/runtime/miner/miner.go | 19 +- cosmos/runtime/runtime.go | 59 ++++-- cosmos/x/evm/genesis_test.go | 9 +- cosmos/x/evm/keeper/abci.go | 8 +- cosmos/x/evm/keeper/genesis.go | 5 +- cosmos/x/evm/keeper/host.go | 16 +- cosmos/x/evm/keeper/keeper.go | 23 +-- cosmos/x/evm/keeper/processor.go | 21 +-- cosmos/x/evm/plugins/state/factory.go | 177 ++++++++++++++++++ cosmos/x/evm/plugins/state/plugin.go | 38 ++-- e2e/localnet/go.mod | 6 +- e2e/localnet/go.sum | 12 +- e2e/localnet/network/fixture_test.go | 2 +- e2e/localnet/network/node_test.go | 2 +- e2e/precompile/go.mod | 6 +- e2e/precompile/go.sum | 12 +- e2e/precompile/utils.go | 2 +- e2e/testapp/app.go | 2 +- e2e/testapp/docker/base.Dockerfile | 2 +- e2e/testapp/go.mod | 8 +- e2e/testapp/go.sum | 16 +- eth/core/chain.go | 28 ++- eth/core/chain_resources.go | 8 +- eth/core/chain_writer.go | 58 ++++-- eth/core/host.go | 15 +- eth/core/mock/state_plugin.mock.go | 81 ++++++++ eth/core/precompile/method_validation.go | 2 +- eth/core/state/interfaces.go | 2 - eth/core/state/modes.go | 32 ++++ eth/eth.go | 28 +-- eth/go.mod | 12 +- eth/go.sum | 24 +-- eth/polar/backend.go | 4 + go.work.sum | 8 +- lib/go.mod | 6 +- lib/go.sum | 12 +- 53 files changed, 806 insertions(+), 338 deletions(-) create mode 100644 cosmos/runtime/abci/proposal.go create mode 100644 cosmos/runtime/abci/types.go create mode 100644 cosmos/x/evm/plugins/state/factory.go create mode 100644 eth/core/state/modes.go diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 4accdacdb..b438f7260 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -34,7 +34,7 @@ # fail-fast: false # matrix: # language: ["go"] -# versions: [1.21.5] +# versions: [1.21.6] # # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # # Use only 'java' to analyze code written in Java, Kotlin or both # # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both diff --git a/.github/workflows/daily.yml b/.github/workflows/daily.yml index 93ae26711..b810ef107 100644 --- a/.github/workflows/daily.yml +++ b/.github/workflows/daily.yml @@ -8,7 +8,7 @@ jobs: docs: strategy: matrix: - go-version: [1.21.5] + go-version: [1.21.6] python-version: [3.11.5] runs-on: ubuntu-latest steps: diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 988572ef3..459b117f7 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -36,7 +36,7 @@ jobs: matrix: docker-type: [base] # Changed docker-version to docker-type for consistency with the Makefile os: [polaris-linux-latest] - go-version: [1.21.5] + go-version: [1.21.6] arch: [amd64] # Changed go-arch to arch for consistency with the Makefile image-name: ["polard/base:v0.0.0"] export-name: [base-image] @@ -76,7 +76,7 @@ jobs: namespace: [cosmos] docker-type: [localnet] # Changed docker-version to docker-type for consistency with the Makefile os: [polaris-linux-latest] - go-version: [1.21.5] + go-version: [1.21.6] arch: [amd64] # Changed go-arch to arch for consistency with the Makefile base-image: [base-image] image-name: ["polard/localnet:v0.0.0"] @@ -123,7 +123,7 @@ jobs: strategy: matrix: os: [polaris-linux-latest] - go-version: [1.21.5] + go-version: [1.21.6] base-image: [base-image] runs-on: ${{ matrix.os }} steps: @@ -153,7 +153,7 @@ jobs: matrix: namespace: ["e2e", "localnet"] os: [polaris-linux-latest] - go-version: [1.21.5] + go-version: [1.21.6] base-image: [localnet] runs-on: ${{ matrix.os }} steps: diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index b908331a5..8da3819da 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -36,7 +36,7 @@ jobs: matrix: args: ["build", "lint", "test-unit-race", "test-unit-cover"] os: [polaris-linux-latest] - go-version: [1.21.5] + go-version: [1.21.6] runs-on: ${{ matrix.os }} steps: - name: Checkout diff --git a/build/scripts/main.mk b/build/scripts/main.mk index 5ab13396f..7ce19d130 100644 --- a/build/scripts/main.mk +++ b/build/scripts/main.mk @@ -65,7 +65,7 @@ proto-build: # Variables DOCKER_TYPE ?= base ARCH ?= arm64 -GO_VERSION ?= 1.21.5 +GO_VERSION ?= 1.21.6 IMAGE_NAME ?= polard IMAGE_VERSION ?= v0.0.0 BASE_IMAGE ?= polard/base:$(IMAGE_VERSION) diff --git a/build/tools/go.mod b/build/tools/go.mod index 3bd20829d..183709d69 100644 --- a/build/tools/go.mod +++ b/build/tools/go.mod @@ -9,7 +9,7 @@ require ( github.com/golangci/golangci-lint v1.55.2 github.com/google/addlicense v1.1.1 github.com/matryer/moq v0.3.2 - github.com/onsi/ginkgo/v2 v2.13.0 + github.com/onsi/ginkgo/v2 v2.13.2 github.com/securego/gosec/v2 v2.18.2 github.com/vektra/mockery/v2 v2.34.1 ) @@ -106,7 +106,7 @@ require ( github.com/gin-gonic/gin v1.9.1 // indirect github.com/go-chi/chi/v5 v5.0.10 // indirect github.com/go-critic/go-critic v0.9.0 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/locales v0.14.1 // indirect diff --git a/build/tools/go.sum b/build/tools/go.sum index 4e11fd1d0..24fae0e78 100644 --- a/build/tools/go.sum +++ b/build/tools/go.sum @@ -292,8 +292,8 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= @@ -661,14 +661,14 @@ github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vv github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= -github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0= diff --git a/contracts/bindings/testing/distribution_testing_helper.abigen.go b/contracts/bindings/testing/distribution_testing_helper.abigen.go index ba531a50d..2fdb247bb 100644 --- a/contracts/bindings/testing/distribution_testing_helper.abigen.go +++ b/contracts/bindings/testing/distribution_testing_helper.abigen.go @@ -32,7 +32,7 @@ var ( // DistributionWrapperMetaData contains all meta data concerning the DistributionWrapper contract. var DistributionWrapperMetaData = &bind.MetaData{ ABI: "[{\"type\":\"constructor\",\"inputs\":[{\"name\":\"_distributionprecompile\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_stakingprecompile\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"delegate\",\"inputs\":[{\"name\":\"_validator\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"payable\"},{\"type\":\"function\",\"name\":\"distribution\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"contractIDistributionModule\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getWithdrawEnabled\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"setWithdrawAddress\",\"inputs\":[{\"name\":\"_withdrawAddress\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"staking\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"contractIStakingModule\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"withdrawRewards\",\"inputs\":[{\"name\":\"_delegatorAddress\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_validatorAddress\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"error\",\"name\":\"ZeroAddress\",\"inputs\":[]}]", - Bin: "0x608060405234801561000f575f80fd5b50604051610bf8380380610bf8833981810160405281019061003191906101b2565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614801561009757505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b156100ce576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b815f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050506101f0565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61018182610158565b9050919050565b61019181610177565b811461019b575f80fd5b50565b5f815190506101ac81610188565b92915050565b5f80604083850312156101c8576101c7610154565b5b5f6101d58582860161019e565b92505060206101e68582860161019e565b9150509250929050565b6109fb806101fd5f395ff3fe608060405260043610610054575f3560e01c806339cc4c86146100585780633ab1a494146100825780634cf088d9146100be5780635c19a95c146100e85780635ee58efc14610104578063e20981ca1461012e575b5f80fd5b348015610063575f80fd5b5061006c610156565b604051610079919061042e565b60405180910390f35b34801561008d575f80fd5b506100a860048036038101906100a391906104b2565b6101e9565b6040516100b5919061042e565b60405180910390f35b3480156100c9575f80fd5b506100d261028a565b6040516100df9190610538565b60405180910390f35b61010260048036038101906100fd91906104b2565b6102af565b005b34801561010f575f80fd5b5061011861034f565b6040516101259190610571565b60405180910390f35b348015610139575f80fd5b50610154600480360381019061014f919061058a565b610372565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166339cc4c866040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101c0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101e491906105f2565b905090565b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633ab1a494836040518263ffffffff1660e01b8152600401610243919061062c565b6020604051808303815f875af115801561025f573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061028391906105f2565b9050919050565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663026e402b82346040518363ffffffff1660e01b815260040161030b92919061065d565b6020604051808303815f875af1158015610327573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061034b91906105f2565b5050565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663562c67a483836040518363ffffffff1660e01b81526004016103cc929190610684565b5f604051808303815f875af11580156103e7573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061040f919061097e565b505050565b5f8115159050919050565b61042881610414565b82525050565b5f6020820190506104415f83018461041f565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61048182610458565b9050919050565b61049181610477565b811461049b575f80fd5b50565b5f813590506104ac81610488565b92915050565b5f602082840312156104c7576104c6610450565b5b5f6104d48482850161049e565b91505092915050565b5f819050919050565b5f6105006104fb6104f684610458565b6104dd565b610458565b9050919050565b5f610511826104e6565b9050919050565b5f61052282610507565b9050919050565b61053281610518565b82525050565b5f60208201905061054b5f830184610529565b92915050565b5f61055b82610507565b9050919050565b61056b81610551565b82525050565b5f6020820190506105845f830184610562565b92915050565b5f80604083850312156105a05761059f610450565b5b5f6105ad8582860161049e565b92505060206105be8582860161049e565b9150509250929050565b6105d181610414565b81146105db575f80fd5b50565b5f815190506105ec816105c8565b92915050565b5f6020828403121561060757610606610450565b5b5f610614848285016105de565b91505092915050565b61062681610477565b82525050565b5f60208201905061063f5f83018461061d565b92915050565b5f819050919050565b61065781610645565b82525050565b5f6040820190506106705f83018561061d565b61067d602083018461064e565b9392505050565b5f6040820190506106975f83018561061d565b6106a4602083018461061d565b9392505050565b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6106f5826106af565b810181811067ffffffffffffffff82111715610714576107136106bf565b5b80604052505050565b5f610726610447565b905061073282826106ec565b919050565b5f67ffffffffffffffff821115610751576107506106bf565b5b602082029050602081019050919050565b5f80fd5b5f80fd5b5f80fd5b61077781610645565b8114610781575f80fd5b50565b5f815190506107928161076e565b92915050565b5f80fd5b5f67ffffffffffffffff8211156107b6576107b56106bf565b5b6107bf826106af565b9050602081019050919050565b5f5b838110156107e95780820151818401526020810190506107ce565b5f8484015250505050565b5f6108066108018461079c565b61071d565b90508281526020810184848401111561082257610821610798565b5b61082d8482856107cc565b509392505050565b5f82601f830112610849576108486106ab565b5b81516108598482602086016107f4565b91505092915050565b5f6040828403121561087757610876610766565b5b610881604061071d565b90505f61089084828501610784565b5f83015250602082015167ffffffffffffffff8111156108b3576108b261076a565b5b6108bf84828501610835565b60208301525092915050565b5f6108dd6108d884610737565b61071d565b90508083825260208201905060208402830185811115610900576108ff610762565b5b835b8181101561094757805167ffffffffffffffff811115610925576109246106ab565b5b8086016109328982610862565b85526020850194505050602081019050610902565b5050509392505050565b5f82601f830112610965576109646106ab565b5b81516109758482602086016108cb565b91505092915050565b5f6020828403121561099357610992610450565b5b5f82015167ffffffffffffffff8111156109b0576109af610454565b5b6109bc84828501610951565b9150509291505056fea26469706673582212202590bdf94ae0cff454c85441d1e0d4dc612df3a7a9aa99b451964c4d8a3b55de64736f6c63430008170033", + Bin: "0x608060405234801561000f575f80fd5b50604051610bf8380380610bf8833981810160405281019061003191906101b2565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614801561009757505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b156100ce576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b815f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050506101f0565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61018182610158565b9050919050565b61019181610177565b811461019b575f80fd5b50565b5f815190506101ac81610188565b92915050565b5f80604083850312156101c8576101c7610154565b5b5f6101d58582860161019e565b92505060206101e68582860161019e565b9150509250929050565b6109fb806101fd5f395ff3fe608060405260043610610054575f3560e01c806339cc4c86146100585780633ab1a494146100825780634cf088d9146100be5780635c19a95c146100e85780635ee58efc14610104578063e20981ca1461012e575b5f80fd5b348015610063575f80fd5b5061006c610156565b604051610079919061042e565b60405180910390f35b34801561008d575f80fd5b506100a860048036038101906100a391906104b2565b6101e9565b6040516100b5919061042e565b60405180910390f35b3480156100c9575f80fd5b506100d261028a565b6040516100df9190610538565b60405180910390f35b61010260048036038101906100fd91906104b2565b6102af565b005b34801561010f575f80fd5b5061011861034f565b6040516101259190610571565b60405180910390f35b348015610139575f80fd5b50610154600480360381019061014f919061058a565b610372565b005b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166339cc4c866040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101c0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101e491906105f2565b905090565b5f805f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16633ab1a494836040518263ffffffff1660e01b8152600401610243919061062c565b6020604051808303815f875af115801561025f573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061028391906105f2565b9050919050565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663026e402b82346040518363ffffffff1660e01b815260040161030b92919061065d565b6020604051808303815f875af1158015610327573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061034b91906105f2565b5050565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663562c67a483836040518363ffffffff1660e01b81526004016103cc929190610684565b5f604051808303815f875af11580156103e7573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061040f919061097e565b505050565b5f8115159050919050565b61042881610414565b82525050565b5f6020820190506104415f83018461041f565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61048182610458565b9050919050565b61049181610477565b811461049b575f80fd5b50565b5f813590506104ac81610488565b92915050565b5f602082840312156104c7576104c6610450565b5b5f6104d48482850161049e565b91505092915050565b5f819050919050565b5f6105006104fb6104f684610458565b6104dd565b610458565b9050919050565b5f610511826104e6565b9050919050565b5f61052282610507565b9050919050565b61053281610518565b82525050565b5f60208201905061054b5f830184610529565b92915050565b5f61055b82610507565b9050919050565b61056b81610551565b82525050565b5f6020820190506105845f830184610562565b92915050565b5f80604083850312156105a05761059f610450565b5b5f6105ad8582860161049e565b92505060206105be8582860161049e565b9150509250929050565b6105d181610414565b81146105db575f80fd5b50565b5f815190506105ec816105c8565b92915050565b5f6020828403121561060757610606610450565b5b5f610614848285016105de565b91505092915050565b61062681610477565b82525050565b5f60208201905061063f5f83018461061d565b92915050565b5f819050919050565b61065781610645565b82525050565b5f6040820190506106705f83018561061d565b61067d602083018461064e565b9392505050565b5f6040820190506106975f83018561061d565b6106a4602083018461061d565b9392505050565b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6106f5826106af565b810181811067ffffffffffffffff82111715610714576107136106bf565b5b80604052505050565b5f610726610447565b905061073282826106ec565b919050565b5f67ffffffffffffffff821115610751576107506106bf565b5b602082029050602081019050919050565b5f80fd5b5f80fd5b5f80fd5b61077781610645565b8114610781575f80fd5b50565b5f815190506107928161076e565b92915050565b5f80fd5b5f67ffffffffffffffff8211156107b6576107b56106bf565b5b6107bf826106af565b9050602081019050919050565b5f5b838110156107e95780820151818401526020810190506107ce565b5f8484015250505050565b5f6108066108018461079c565b61071d565b90508281526020810184848401111561082257610821610798565b5b61082d8482856107cc565b509392505050565b5f82601f830112610849576108486106ab565b5b81516108598482602086016107f4565b91505092915050565b5f6040828403121561087757610876610766565b5b610881604061071d565b90505f61089084828501610784565b5f83015250602082015167ffffffffffffffff8111156108b3576108b261076a565b5b6108bf84828501610835565b60208301525092915050565b5f6108dd6108d884610737565b61071d565b90508083825260208201905060208402830185811115610900576108ff610762565b5b835b8181101561094757805167ffffffffffffffff811115610925576109246106ab565b5b8086016109328982610862565b85526020850194505050602081019050610902565b5050509392505050565b5f82601f830112610965576109646106ab565b5b81516109758482602086016108cb565b91505092915050565b5f6020828403121561099357610992610450565b5b5f82015167ffffffffffffffff8111156109b0576109af610454565b5b6109bc84828501610951565b9150509291505056fea2646970667358221220d470139c4b771c066c702ac9cc8ef914f3867f9779239e96fcc44723dcd6f0d964736f6c63430008170033", } // DistributionWrapperABI is the input ABI used to generate the binding from. diff --git a/cosmos/go.mod b/cosmos/go.mod index 9fcd25c22..96eeeea35 100644 --- a/cosmos/go.mod +++ b/cosmos/go.mod @@ -7,7 +7,7 @@ replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // We replace `go-ethereum` with `polaris-geth` in order include our required changes. - github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b + github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0 // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 @@ -24,9 +24,9 @@ require ( cosmossdk.io/store v1.0.1 cosmossdk.io/x/evidence v0.0.0-20231103111158-e83a20081ced cosmossdk.io/x/tx v0.12.0 - github.com/berachain/polaris/contracts v0.0.4-alpha - github.com/berachain/polaris/eth v0.0.4-alpha - github.com/berachain/polaris/lib v0.0.4-alpha + github.com/berachain/polaris/contracts v0.0.4-alpha.0.20240109235613-943fac740e5e + github.com/berachain/polaris/eth v0.0.3-alpha.0.20240109235613-943fac740e5e + github.com/berachain/polaris/lib v0.0.4-alpha.0.20240109235613-943fac740e5e github.com/btcsuite/btcd v0.23.2 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cometbft/cometbft v0.38.2 @@ -38,8 +38,8 @@ require ( github.com/ethereum/go-ethereum v1.13.7 github.com/golang/mock v1.6.0 github.com/grpc-ecosystem/grpc-gateway v1.16.0 - github.com/onsi/ginkgo/v2 v2.13.0 - github.com/onsi/gomega v1.28.1 + github.com/onsi/ginkgo/v2 v2.13.2 + github.com/onsi/gomega v1.29.0 github.com/spf13/cast v1.5.1 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 @@ -115,7 +115,7 @@ require ( github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect diff --git a/cosmos/go.sum b/cosmos/go.sum index c42d05592..c8844e421 100644 --- a/cosmos/go.sum +++ b/cosmos/go.sum @@ -112,14 +112,14 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b h1:wrzTIsCeIUh3wgSDXCvXKfwJA7G1SYIQccl7UhBexBY= -github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= -github.com/berachain/polaris/contracts v0.0.4-alpha h1:CyiElDqABwa4tIrC8j/D7dd21dRqGEV6yZjZsVD13nE= -github.com/berachain/polaris/contracts v0.0.4-alpha/go.mod h1:Sm1T+tIQGuP0wEJnF/TlgZiJ+NPHgOZWO7vAz7FkwVs= -github.com/berachain/polaris/eth v0.0.4-alpha h1:N0xvT/1Cu6LB5/ZMdttfjiH8CF2bWUgHfp71FIiFdpY= -github.com/berachain/polaris/eth v0.0.4-alpha/go.mod h1:i2ORG5xO2uktxaQcyRAM/40gin/pGS/3MzujhwfGXI4= -github.com/berachain/polaris/lib v0.0.4-alpha h1:5ob1YtUD6qx35yfwcOKyOOuU6/OgtXMRk0eQrsjCSsw= -github.com/berachain/polaris/lib v0.0.4-alpha/go.mod h1:08kBE9vqIO1PREtvM99uI2Sq/bjxjSQ5rYXM9k8wAYs= +github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0 h1:jGah7o6k6xytfTFH7hIKmfJZOPnAhCb9bmCb+lRS4Bk= +github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= +github.com/berachain/polaris/contracts v0.0.4-alpha.0.20240109235613-943fac740e5e h1:gqjyQkuYHRUKX3AQNNACItHx5qvbKdY7MQDjmzMU/Oo= +github.com/berachain/polaris/contracts v0.0.4-alpha.0.20240109235613-943fac740e5e/go.mod h1:Sm1T+tIQGuP0wEJnF/TlgZiJ+NPHgOZWO7vAz7FkwVs= +github.com/berachain/polaris/eth v0.0.3-alpha.0.20240109235613-943fac740e5e h1:1x0Km420lsYhe4Rl9hyLa01tHxK8/Sib2wM1nx4V2VQ= +github.com/berachain/polaris/eth v0.0.3-alpha.0.20240109235613-943fac740e5e/go.mod h1:x1J2V2lu8GxOBCO71PW42pxD0/U1M4SluNL/cuKe2FA= +github.com/berachain/polaris/lib v0.0.4-alpha.0.20240109235613-943fac740e5e h1:GFuC+25z3zWb2jrBsqaI0RkBRkwB45eMnZGGqcBK+78= +github.com/berachain/polaris/lib v0.0.4-alpha.0.20240109235613-943fac740e5e/go.mod h1:bP/AxNoKhjMIt+WI7rh/ULHZoFIUSlZKsaFUZ2jUXHI= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s= github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= @@ -389,8 +389,8 @@ github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= @@ -788,14 +788,14 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108 github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= -github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= diff --git a/cosmos/runtime/abci/proposal.go b/cosmos/runtime/abci/proposal.go new file mode 100644 index 000000000..4929a3f4d --- /dev/null +++ b/cosmos/runtime/abci/proposal.go @@ -0,0 +1,148 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package abci + +import ( + "time" + + "cosmossdk.io/log" + + "github.com/berachain/polaris/cosmos/runtime/chain" + "github.com/berachain/polaris/cosmos/runtime/miner" + + cometabci "github.com/cometbft/cometbft/abci/types" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// ProposalProvider is a struct that provides the abci functions required +// for validators to propose blocks and validators/full nodes to process +// said proposals. +type ProposalProvider struct { + logger log.Logger + preBlocker sdk.PreBlocker + beginBlocker sdk.BeginBlocker + wrappedMiner *miner.Miner + wrappedBlockchain *chain.WrappedBlockchain + + // TODO: refactor validator commands out of the wbc and miner. + // valCmdProcessor *ValidatorCommands + // *eth.ExecutionLayer +} + +// NewProposalProvider creates a new ProposalProvider instance. +// It takes a miner.Miner and a chain.WrappedBlockchain as +// arguments and returns a pointer to the initialized ProposalProvider. +func NewProposalProvider( + preBlocker sdk.PreBlocker, beginBlocker sdk.BeginBlocker, + wrappedMiner *miner.Miner, wrappedBlockchain *chain.WrappedBlockchain, + logger log.Logger, +) *ProposalProvider { + return &ProposalProvider{ + preBlocker: preBlocker, + beginBlocker: beginBlocker, + wrappedMiner: wrappedMiner, + wrappedBlockchain: wrappedBlockchain, + logger: logger, + } +} + +// PrepareProposal is responsible for preparing a proposal for the next block. +// It takes a context and a RequestPrepareProposal, simulates finalizing the block, +// and if successful, delegates the proposal preparation to the wrapped miner. +// It returns a ResponsePrepareProposal and an error if any occurs during the process. +func (pp *ProposalProvider) PrepareProposal( + ctx sdk.Context, req *cometabci.RequestPrepareProposal, +) (*cometabci.ResponsePrepareProposal, error) { + var ( + start = time.Now() + height = ctx.BlockHeight() + ) + + pp.logger.Info( + "entering prepare proposal", + "timestamp", start, "height", height) + defer func() { + pp.logger.Info( + "exiting prepare proposal", + "timestamp", time.Now(), + "duration", time.Since(start), + "height", height) + }() + + if err := pp.simulateFinalizeBlock(ctx, req); err != nil { + return nil, err + } + + return pp.wrappedMiner.PrepareProposal(ctx, req) +} + +// ProcessProposal processes the incoming proposal. +// It takes a context and a RequestProcessProposal, simulates finalizing the block, +// and if successful, delegates the proposal processing to the wrapped blockchain. +// It returns a ResponseProcessProposal and an error if any occurs during the process. +func (pp *ProposalProvider) ProcessProposal( + ctx sdk.Context, req *cometabci.RequestProcessProposal, +) (*cometabci.ResponseProcessProposal, error) { + var ( + start = time.Now() + height = ctx.BlockHeight() + ) + + pp.logger.Info( + "entering process proposal", + "timestamp", start, "height", height) + defer func() { + pp.logger.Info( + "exiting process proposal", + "timestamp", time.Now(), + "duration", time.Since(start), + "height", height) + }() + + if err := pp.simulateFinalizeBlock(ctx, req); err != nil { + return nil, err + } + + return pp.wrappedBlockchain.ProcessProposal(ctx, req) +} + +// simulateFinalizeBlock simulates the execution of a block. +// We have to run the PreBlocker && BeginBlocker to get the chain into the state +// it'll be in when the EVM transaction actually runs. +func (pp *ProposalProvider) simulateFinalizeBlock(ctx sdk.Context, req abciRequest) error { + if _, err := pp.preBlocker(ctx, &cometabci.RequestFinalizeBlock{ + Txs: req.GetTxs(), + Time: req.GetTime(), + Misbehavior: req.GetMisbehavior(), + Height: req.GetHeight(), + NextValidatorsHash: req.GetNextValidatorsHash(), + ProposerAddress: req.GetProposerAddress(), + }); err != nil { + return err + } + + if _, err := pp.beginBlocker(ctx); err != nil { + return err + } + + return nil +} diff --git a/cosmos/runtime/abci/types.go b/cosmos/runtime/abci/types.go new file mode 100644 index 000000000..c77113557 --- /dev/null +++ b/cosmos/runtime/abci/types.go @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package abci + +import ( + "time" + + cometabci "github.com/cometbft/cometbft/abci/types" +) + +type abciRequest interface { + // add your methods here + GetTxs() [][]byte + GetTime() time.Time + GetMisbehavior() []cometabci.Misbehavior + GetHeight() int64 + GetNextValidatorsHash() []byte + GetProposerAddress() []byte +} diff --git a/cosmos/runtime/chain/abci.go b/cosmos/runtime/chain/abci.go index 19622c13a..5393f56d1 100644 --- a/cosmos/runtime/chain/abci.go +++ b/cosmos/runtime/chain/abci.go @@ -23,8 +23,6 @@ package chain import ( "fmt" - storetypes "cosmossdk.io/store/types" - evmtypes "github.com/berachain/polaris/cosmos/x/evm/types" abci "github.com/cometbft/cometbft/abci/types" @@ -42,31 +40,6 @@ func (wbc *WrappedBlockchain) ProcessProposal( err error ) - // We have to run the PreBlocker && BeginBlocker to get the chain into the state - // it'll be in when the EVM transaction actually runs. - if _, err = wbc.app.PreBlocker(ctx, &abci.RequestFinalizeBlock{ - Txs: req.Txs, - Time: req.Time, - Misbehavior: req.Misbehavior, - Height: req.Height, - NextValidatorsHash: req.NextValidatorsHash, - ProposerAddress: req.ProposerAddress, - }); err != nil { - return &abci.ResponseProcessProposal{ - Status: abci.ResponseProcessProposal_REJECT, - }, err - } else if _, err = wbc.app.BeginBlocker(ctx); err != nil { - return &abci.ResponseProcessProposal{ - Status: abci.ResponseProcessProposal_REJECT, - }, err - } - - ctx.GasMeter().RefundGas(ctx.GasMeter().GasConsumed(), "process proposal") - ctx.BlockGasMeter().RefundGas(ctx.BlockGasMeter().GasConsumed(), "process proposal") - ctx = ctx.WithKVGasConfig(storetypes.GasConfig{}). - WithTransientKVGasConfig(storetypes.GasConfig{}). - WithGasMeter(storetypes.NewInfiniteGasMeter()) - // Pull an execution payload out of the proposal. var envelope *engine.ExecutionPayloadEnvelope for _, tx := range req.Txs { @@ -101,8 +74,11 @@ func (wbc *WrappedBlockchain) ProcessProposal( }, err } - // Insert the block into the chain. - if err = wbc.InsertBlockWithoutSetHead(ctx, block); err != nil { + spf := wbc.StatePluginFactory() + spf.SetInsertChainContext(ctx) + + // Insert the block into the chain.å + if err = wbc.InsertBlockWithoutSetHead(block); err != nil { ctx.Logger().Error("failed to insert block", "err", err) return &abci.ResponseProcessProposal{ Status: abci.ResponseProcessProposal_REJECT, diff --git a/cosmos/runtime/chain/chain.go b/cosmos/runtime/chain/chain.go index 2edb6c3ec..095afa7c2 100644 --- a/cosmos/runtime/chain/chain.go +++ b/cosmos/runtime/chain/chain.go @@ -21,50 +21,22 @@ package chain import ( - "context" - "github.com/berachain/polaris/eth/core" - - ethtypes "github.com/ethereum/go-ethereum/core/types" ) // WrappedBlockchain is a struct that wraps the core blockchain with additional // application context. type WrappedBlockchain struct { - core.Blockchain // chain is the core blockchain. - app App // App is the application context. - + core.Blockchain // chain is the core blockchain. + app txDecoder // App is the application context. } // New creates a new instance of WrappedBlockchain with the provided core blockchain // and application context. -func New(chain core.Blockchain, app App) *WrappedBlockchain { +func New(chain core.Blockchain, app txDecoder) *WrappedBlockchain { return &WrappedBlockchain{Blockchain: chain, app: app} } -// WriteGenesisState writes the genesis state to the blockchain. -// It uses the provided context as the application context. -func (wbc *WrappedBlockchain) WriteGenesisState( - ctx context.Context, genState *core.Genesis, -) error { - wbc.PreparePlugins(ctx) - return wbc.WriteGenesisBlock(genState.ToBlock()) -} - -// InsertBlockAndSetHead inserts a block into the blockchain and sets -// it as the head. It uses the provided context as the application context. -func (wbc *WrappedBlockchain) InsertBlockAndSetHead( - ctx context.Context, block *ethtypes.Block, -) error { - wbc.PreparePlugins(ctx) - return wbc.Blockchain.InsertBlockAndSetHead(block) -} - -// InsertBlockWithoutSetHead inserts a block into the blockchain without setting it -// as the head. It uses the provided context as the application context. -func (wbc *WrappedBlockchain) InsertBlockWithoutSetHead( - ctx context.Context, block *ethtypes.Block, -) error { - wbc.PreparePlugins(ctx) - return wbc.Blockchain.InsertBlockWithoutSetHead(block) +func (wbc *WrappedBlockchain) SetBlockchain(chain core.Blockchain) { + wbc.Blockchain = chain } diff --git a/cosmos/runtime/chain/interfaces.go b/cosmos/runtime/chain/interfaces.go index a60d5d6d1..5702a374d 100644 --- a/cosmos/runtime/chain/interfaces.go +++ b/cosmos/runtime/chain/interfaces.go @@ -21,13 +21,9 @@ package chain import ( - abci "github.com/cometbft/cometbft/abci/types" - sdk "github.com/cosmos/cosmos-sdk/types" ) -type App interface { - BeginBlocker(sdk.Context) (sdk.BeginBlock, error) - PreBlocker(sdk.Context, *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) +type txDecoder interface { TxDecode(txBz []byte) (sdk.Tx, error) } diff --git a/cosmos/runtime/miner/abci.go b/cosmos/runtime/miner/abci.go index 4a6eb6b82..e04c162fd 100644 --- a/cosmos/runtime/miner/abci.go +++ b/cosmos/runtime/miner/abci.go @@ -22,8 +22,6 @@ package miner import ( - storetypes "cosmossdk.io/store/types" - abci "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -45,31 +43,8 @@ func (m *Miner) PrepareProposal( ethGasUsed uint64 ) - // We have to run the PreBlocker && BeginBlocker to get the chain into the state - // it'll be in when the EVM transaction actually runs. - if _, err = m.app.PreBlocker(ctx, &abci.RequestFinalizeBlock{ - Txs: req.Txs, - Time: req.Time, - Misbehavior: req.Misbehavior, - Height: req.Height, - NextValidatorsHash: req.NextValidatorsHash, - ProposerAddress: req.ProposerAddress, - }); err != nil { - return nil, err - } else if _, err = m.app.BeginBlocker(ctx); err != nil { - return nil, err - } - - ctx.GasMeter().RefundGas(ctx.GasMeter().GasConsumed(), "prepare proposal") - ctx.BlockGasMeter().RefundGas(ctx.BlockGasMeter().GasConsumed(), "prepare proposal") - ctx = ctx.WithKVGasConfig(storetypes.GasConfig{}). - WithTransientKVGasConfig(storetypes.GasConfig{}). - WithGasMeter(storetypes.NewInfiniteGasMeter()) - - // We have to prime the state plugin. - if err = m.keeper.SetLatestQueryContext(ctx); err != nil { - return nil, err - } + // Set the mining context for the state plugin factory. + m.spf.SetLatestMiningContext(ctx) // Trigger the geth miner to build a block. if payloadEnvelopeBz, ethGasUsed, err = m.buildBlock(ctx); err != nil { diff --git a/cosmos/runtime/miner/interfaces.go b/cosmos/runtime/miner/interfaces.go index fdecb2b7c..24818de68 100644 --- a/cosmos/runtime/miner/interfaces.go +++ b/cosmos/runtime/miner/interfaces.go @@ -23,9 +23,7 @@ package miner import ( "context" - evmkeeper "github.com/berachain/polaris/cosmos/x/evm/keeper" - - abci "github.com/cometbft/cometbft/abci/types" + "github.com/berachain/polaris/eth/core" sdk "github.com/cosmos/cosmos-sdk/types" @@ -39,16 +37,15 @@ type ( ToSdkTxBytes(*engine.ExecutionPayloadEnvelope, uint64) ([]byte, error) } - App interface { - BeginBlocker(sdk.Context) (sdk.BeginBlock, error) - PreBlocker(sdk.Context, *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) + TxDecoder interface { TxDecode(txBytes []byte) (sdk.Tx, error) } // EVMKeeper is an interface that defines the methods needed for the EVM setup. EVMKeeper interface { // Setup initializes the EVM keeper. - Setup(evmkeeper.WrappedBlockchain) error + Setup(core.Blockchain) error SetLatestQueryContext(context.Context) error + GetHost() core.PolarisHostChain } ) diff --git a/cosmos/runtime/miner/miner.go b/cosmos/runtime/miner/miner.go index 384472dcc..eb8f053e5 100644 --- a/cosmos/runtime/miner/miner.go +++ b/cosmos/runtime/miner/miner.go @@ -28,6 +28,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/berachain/polaris/eth" + "github.com/berachain/polaris/eth/core" "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/telemetry" @@ -40,9 +41,9 @@ import ( // Miner implements the baseapp.TxSelector interface. type Miner struct { - eth.Miner - app App - keeper EVMKeeper + miner eth.Miner + app TxDecoder + spf core.StatePluginFactory valTxSelector baseapp.TxSelector serializer EnvelopeSerializer allowedValMsgs map[string]sdk.Msg @@ -50,11 +51,13 @@ type Miner struct { } // New produces a cosmos miner from a geth miner. -func New(gm eth.Miner, app App, keeper EVMKeeper, allowedValMsgs map[string]sdk.Msg) *Miner { +func New( + miner eth.Miner, app TxDecoder, spf core.StatePluginFactory, allowedValMsgs map[string]sdk.Msg, +) *Miner { return &Miner{ - Miner: gm, - keeper: keeper, + miner: miner, app: app, + spf: spf, allowedValMsgs: allowedValMsgs, valTxSelector: baseapp.NewDefaultTxSelector(), } @@ -90,7 +93,7 @@ func (m *Miner) submitPayloadForBuilding(ctx context.Context) error { ) // Build Payload - if payload, err = m.BuildPayload(m.constructPayloadArgs(sCtx)); err != nil { + if payload, err = m.miner.BuildPayload(m.constructPayloadArgs(sCtx)); err != nil { sCtx.Logger().Error("failed to build payload", "err", err) return err } @@ -103,7 +106,7 @@ func (m *Miner) submitPayloadForBuilding(ctx context.Context) error { func (m *Miner) constructPayloadArgs(ctx sdk.Context) *miner.BuildPayloadArgs { return &miner.BuildPayloadArgs{ Timestamp: uint64(ctx.BlockTime().Unix()), - FeeRecipient: m.Etherbase(), + FeeRecipient: m.miner.Etherbase(), Random: common.Hash{}, /* todo: generated random */ Withdrawals: make(ethtypes.Withdrawals, 0), BeaconRoot: &emptyHash, diff --git a/cosmos/runtime/runtime.go b/cosmos/runtime/runtime.go index dbe7921fe..20d959971 100644 --- a/cosmos/runtime/runtime.go +++ b/cosmos/runtime/runtime.go @@ -28,19 +28,19 @@ import ( storetypes "cosmossdk.io/store/types" libtx "github.com/berachain/polaris/cosmos/lib/tx" + polarabci "github.com/berachain/polaris/cosmos/runtime/abci" antelib "github.com/berachain/polaris/cosmos/runtime/ante" "github.com/berachain/polaris/cosmos/runtime/chain" "github.com/berachain/polaris/cosmos/runtime/comet" "github.com/berachain/polaris/cosmos/runtime/miner" "github.com/berachain/polaris/cosmos/runtime/txpool" - evmkeeper "github.com/berachain/polaris/cosmos/x/evm/keeper" evmtypes "github.com/berachain/polaris/cosmos/x/evm/types" "github.com/berachain/polaris/eth" "github.com/berachain/polaris/eth/consensus" "github.com/berachain/polaris/eth/core" "github.com/berachain/polaris/eth/node" - abci "github.com/cometbft/cometbft/abci/types" + cometabci "github.com/cometbft/cometbft/abci/types" "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" @@ -54,8 +54,10 @@ import ( // EVMKeeper is an interface that defines the methods needed for the EVM setup. type EVMKeeper interface { // Setup initializes the EVM keeper. - Setup(evmkeeper.WrappedBlockchain) error + Setup(core.Blockchain) error + GetStatePluginFactory() core.StatePluginFactory SetLatestQueryContext(context.Context) error + GetHost() core.PolarisHostChain } // CosmosApp is an interface that defines the methods needed for the Cosmos setup. @@ -65,14 +67,18 @@ type CosmosApp interface { SetMempool(mempool.Mempool) SetAnteHandler(sdk.AnteHandler) TxDecode(txBz []byte) (sdk.Tx, error) - BeginBlocker(sdk.Context) (sdk.BeginBlock, error) - PreBlocker(sdk.Context, *abci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) + CommitMultiStore() storetypes.CommitMultiStore + PreBlocker(sdk.Context, *cometabci.RequestFinalizeBlock) (*sdk.ResponsePreBlock, error) + BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) } // Polaris is a struct that wraps the Polaris struct from the polar package. // It also includes wrapped versions of the Geth Miner and TxPool. type Polaris struct { *eth.ExecutionLayer + // ProposalProvider is a wrapped version of the ProposalProvider component. + ProposalProvider *polarabci.ProposalProvider + // WrappedMiner is a wrapped version of the Miner component. WrappedMiner *miner.Miner // WrappedTxPool is a wrapped version of the Mempool component. @@ -85,6 +91,7 @@ type Polaris struct { // New creates a new Polaris runtime from the provided dependencies. func New( + app CosmosApp, cfg *eth.Config, logger cosmoslog.Logger, host core.PolarisHostChain, @@ -95,6 +102,16 @@ func New( logger: logger, } + ctx := sdk.Context{}. + WithMultiStore(app.CommitMultiStore()). + WithBlockHeight(0). + WithGasMeter(storetypes.NewInfiniteGasMeter()). + WithBlockGasMeter(storetypes.NewInfiniteGasMeter()). + WithEventManager(sdk.NewEventManager()) + host.GetStatePluginFactory().SetLatestQueryContext( + ctx, + ) + p.ExecutionLayer, err = eth.New( "geth", cfg, host, engine, cfg.Node.AllowUnprotectedTxs, ethlog.NewLogger(newEthHandler(logger)), @@ -103,7 +120,11 @@ func New( panic(err) } - p.WrappedTxPool = txpool.New(p.Blockchain(), p.TxPool(), cfg.Polar.LegacyTxPool.Lifetime) + p.WrappedTxPool = txpool.New( + p.ExecutionLayer.Backend().Blockchain(), + p.ExecutionLayer.Backend().TxPool(), + cfg.Polar.LegacyTxPool.Lifetime, + ) return p } @@ -115,12 +136,23 @@ func (p *Polaris) Build( app CosmosApp, cosmHandler sdk.AnteHandler, ek EVMKeeper, allowedValMsgs map[string]sdk.Msg, ) error { // Wrap the geth miner and txpool with the cosmos miner and txpool. - p.WrappedMiner = miner.New(p.Miner(), app, ek, allowedValMsgs) - p.WrappedBlockchain = chain.New(p.Blockchain(), app) + p.WrappedMiner = miner.New( + p.ExecutionLayer.Backend().Miner(), app, + ek.GetHost().GetStatePluginFactory(), + allowedValMsgs, + ) + p.WrappedBlockchain = chain.New( + p.ExecutionLayer.Backend().Blockchain(), app, + ) + p.ProposalProvider = polarabci.NewProposalProvider( + app.PreBlocker, app.BeginBlocker, + p.WrappedMiner, p.WrappedBlockchain, + p.logger.With("module", "polaris-proposal-provider"), + ) app.SetMempool(p.WrappedTxPool) - app.SetPrepareProposal(p.WrappedMiner.PrepareProposal) - app.SetProcessProposal(p.WrappedBlockchain.ProcessProposal) + app.SetPrepareProposal(p.ProposalProvider.PrepareProposal) + app.SetProcessProposal(p.ProposalProvider.ProcessProposal) if err := ek.Setup(p.WrappedBlockchain); err != nil { return err @@ -150,7 +182,7 @@ func (p *Polaris) SetupServices(clientCtx client.Context) error { }) // Register the sync status provider with Polaris. - p.RegisterSyncStatusProvider(comet.NewSyncProvider(clientCtx)) + p.ExecutionLayer.Backend().RegisterSyncStatusProvider(comet.NewSyncProvider(clientCtx)) // Start the services. TODO: move to place race condition is solved. return p.StartServices() @@ -162,7 +194,7 @@ func (p *Polaris) SetupServices(clientCtx client.Context) error { func (p *Polaris) RegisterLifecycles(lcs []node.Lifecycle) { // Register the services with polaris. for _, lc := range lcs { - p.ExecutionLayer.RegisterLifecycle(lc) + p.ExecutionLayer.Stack().RegisterLifecycle(lc) } } @@ -189,7 +221,8 @@ func (p *Polaris) StartServices() error { func (p *Polaris) LoadLastState(cms storetypes.CommitMultiStore, appHeight uint64) error { cmsCtx := sdk.Context{}. WithMultiStore(cms). + WithBlockHeight(int64(appHeight)). WithGasMeter(storetypes.NewInfiniteGasMeter()). WithBlockGasMeter(storetypes.NewInfiniteGasMeter()).WithEventManager(sdk.NewEventManager()) - return p.Blockchain().LoadLastState(cmsCtx, appHeight) + return p.Backend().Blockchain().LoadLastState(cmsCtx, appHeight) } diff --git a/cosmos/x/evm/genesis_test.go b/cosmos/x/evm/genesis_test.go index 2a1292200..e3f007121 100644 --- a/cosmos/x/evm/genesis_test.go +++ b/cosmos/x/evm/genesis_test.go @@ -114,21 +114,24 @@ var _ = Describe("Genesis", func() { Expect(bp.GetHeaderByNumber(0)).To(Equal(expectedHeader)) }) It("should have the correct balances", func() { - sp := k.Host.GetStatePlugin() + spf := k.Host.GetStatePluginFactory() + sp := spf.NewPluginFromContext(ctx) for addr, acc := range ethGen.Alloc { balance := sp.GetBalance(addr) Expect(balance).To(Equal(acc.Balance)) } }) It("should have the correct code", func() { - sp := k.Host.GetStatePlugin() + spf := k.Host.GetStatePluginFactory() + sp := spf.NewPluginFromContext(ctx) for addr, acc := range ethGen.Alloc { code := sp.GetCode(addr) Expect(code).To(Equal(acc.Code)) } }) It("should have the correct hash", func() { - sp := k.Host.GetStatePlugin() + spf := k.Host.GetStatePluginFactory() + sp := spf.NewPluginFromContext(ctx) for addr, acc := range ethGen.Alloc { for key, expectedHash := range acc.Storage { actualHash := sp.GetState(addr, key) diff --git a/cosmos/x/evm/keeper/abci.go b/cosmos/x/evm/keeper/abci.go index 66fe83dae..7414534cc 100644 --- a/cosmos/x/evm/keeper/abci.go +++ b/cosmos/x/evm/keeper/abci.go @@ -27,12 +27,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// Precommit runs on the Cosmo-SDK lifecycle Precommit(). +// EndBlock runs on the Cosmos-SDK lifecycle EndBlock() during ABCI Finalize. func (k *Keeper) EndBlock(ctx context.Context) error { // Verify that the EVM block was written. // TODO: Set/GetHead to set and get the canonical head. blockNum := uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) - block := k.wrappedChain.GetBlockByNumber(blockNum) + block := k.chain.GetBlockByNumber(blockNum) if block == nil { return fmt.Errorf( "evm block %d failed to process", blockNum, @@ -45,8 +45,8 @@ func (k *Keeper) EndBlock(ctx context.Context) error { return nil } -// SetLatestQueryContext runs on the Cosmos-SDK lifecycle SetLatestQueryContext(). +// SetLatestQueryContext runs on the Cosmos-SDK lifecycle PrepareCheckState() during ABCI Commit. func (k *Keeper) SetLatestQueryContext(ctx context.Context) error { - k.sp.Prepare(ctx) + k.spf.SetLatestQueryContext(ctx) return nil } diff --git a/cosmos/x/evm/keeper/genesis.go b/cosmos/x/evm/keeper/genesis.go index c118f5c45..32802c049 100644 --- a/cosmos/x/evm/keeper/genesis.go +++ b/cosmos/x/evm/keeper/genesis.go @@ -31,7 +31,7 @@ import ( // InitGenesis is called during the InitGenesis. func (k *Keeper) InitGenesis(ctx sdk.Context, genState *core.Genesis) error { // TODO: Feels jank as fuck lol, but it works. - genState.Config = k.wrappedChain.Config() + genState.Config = k.chain.Config() // Initialize all the plugins. for _, plugin := range k.Host.GetAllPlugins() { @@ -44,7 +44,8 @@ func (k *Keeper) InitGenesis(ctx sdk.Context, genState *core.Genesis) error { } // Insert to chain. - return k.wrappedChain.WriteGenesisState(ctx, genState) + k.spf.SetGenesisContext(ctx) + return k.chain.WriteGenesisBlockWithContext(ctx, genState.ToBlock()) } // ExportGenesis returns the exported genesis state. diff --git a/cosmos/x/evm/keeper/host.go b/cosmos/x/evm/keeper/host.go index 725a490a2..82c9f61f6 100644 --- a/cosmos/x/evm/keeper/host.go +++ b/cosmos/x/evm/keeper/host.go @@ -40,10 +40,11 @@ var _ core.PolarisHostChain = (*Host)(nil) type Host struct { // The various plugins that are are used to implement core.PolarisHostChain. - bp block.Plugin - hp historical.Plugin - pp precompile.Plugin - sp state.Plugin + bp block.Plugin + hp historical.Plugin + pp precompile.Plugin + sp state.Plugin + spf *state.SPFactory pcs func() *ethprecompile.Injector } @@ -68,6 +69,7 @@ func NewHost( // historical plugin requires block plugin. h.hp = historical.NewPlugin(&cfg.Polar.Chain, h.bp, nil, storeKey) + h.spf = state.NewSPFactory(ak, storeKey, qc) return h } @@ -81,6 +83,7 @@ func (h *Host) SetupPrecompiles() error { } h.sp.SetPrecompileLogFactory(pclog.NewFactory(pcs)) + h.spf.SetPrecompileLogFactory(pclog.NewFactory(pcs)) return nil } @@ -99,9 +102,8 @@ func (h *Host) GetPrecompilePlugin() core.PrecompilePlugin { return h.pp } -// GetStatePlugin returns the state plugin. -func (h *Host) GetStatePlugin() core.StatePlugin { - return h.sp +func (h *Host) GetStatePluginFactory() core.StatePluginFactory { + return h.spf } // GetAllPlugins returns all the plugins. diff --git a/cosmos/x/evm/keeper/keeper.go b/cosmos/x/evm/keeper/keeper.go index eeccd16dc..82a3abda5 100644 --- a/cosmos/x/evm/keeper/keeper.go +++ b/cosmos/x/evm/keeper/keeper.go @@ -21,8 +21,6 @@ package keeper import ( - "context" - "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -33,25 +31,14 @@ import ( ethprecompile "github.com/berachain/polaris/eth/core/precompile" sdk "github.com/cosmos/cosmos-sdk/types" - - ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/params" ) -type WrappedBlockchain interface { - PreparePlugins(context.Context) - Config() *params.ChainConfig - WriteGenesisState(context.Context, *core.Genesis) error - InsertBlockAndSetHead(context.Context, *ethtypes.Block) error - GetBlockByNumber(uint64) *ethtypes.Block -} - type Keeper struct { // host represents the host chain *Host // provider is the struct that houses the Polaris EVM. - wrappedChain WrappedBlockchain + chain core.Blockchain } // NewKeeper creates new instances of the polaris Keeper. @@ -74,11 +61,15 @@ func NewKeeper( } } -func (k *Keeper) Setup(wrappedChain WrappedBlockchain) error { - k.wrappedChain = wrappedChain +func (k *Keeper) Setup(chain core.Blockchain) error { + k.chain = chain return k.SetupPrecompiles() } +func (k *Keeper) GetHost() core.PolarisHostChain { + return k.Host +} + // Logger returns a module-specific logger. func (k *Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With(types.ModuleName) diff --git a/cosmos/x/evm/keeper/processor.go b/cosmos/x/evm/keeper/processor.go index 1a3d44bbb..7c111e6f0 100644 --- a/cosmos/x/evm/keeper/processor.go +++ b/cosmos/x/evm/keeper/processor.go @@ -25,8 +25,6 @@ import ( "fmt" "time" - storetypes "cosmossdk.io/store/types" - evmtypes "github.com/berachain/polaris/cosmos/x/evm/types" "github.com/cosmos/cosmos-sdk/telemetry" @@ -36,8 +34,9 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" ) -const () - +// ProcessPayloadEnvelope uses Geth's beacon engine API to build a block from a execution payload +// request. It is called by Cosmos-SDK during ABCI DeliverTx phase (1 cosmos tx to build the entire +// eth block). func (k *Keeper) ProcessPayloadEnvelope( ctx context.Context, msg *evmtypes.WrappedPayloadEnvelope, ) (*evmtypes.WrappedPayloadEnvelopeResponse, error) { @@ -52,8 +51,8 @@ func (k *Keeper) ProcessPayloadEnvelope( blockGasMeter := sCtx.BlockGasMeter() // Reset GasMeter to 0. - gasMeter.RefundGas(gasMeter.GasConsumed(), "reset before evm block") - blockGasMeter.RefundGas(blockGasMeter.GasConsumed(), "reset before evm block") + // + // TODO: we need to remove this next re-genesis. defer gasMeter.RefundGas(gasMeter.GasConsumed(), "reset after evm") defer blockGasMeter.RefundGas(blockGasMeter.GasConsumed(), "reset after evm") @@ -66,14 +65,14 @@ func (k *Keeper) ProcessPayloadEnvelope( return nil, err } - // Prepare should be moved to the blockchain? THIS IS VERY HOOD YES NEEDS TO BE MOVED. - ctx = sCtx.WithKVGasConfig(storetypes.GasConfig{}). - WithTransientKVGasConfig(storetypes.GasConfig{}) - // Record how long it takes to insert the new block into the chain. defer telemetry.ModuleMeasureSince(evmtypes.ModuleName, time.Now(), evmtypes.MetricKeyInsertBlockAndSetHead) - if err = k.wrappedChain.InsertBlockAndSetHead(ctx, block); err != nil { + + // Set the finalize block context on the state plugin factory. + k.spf.SetFinalizeBlockContext(ctx) + // Insert the finalized block and set the chain head. + if err = k.chain.InsertBlockAndSetHeadWithContext(ctx, block); err != nil { return nil, err } diff --git a/cosmos/x/evm/plugins/state/factory.go b/cosmos/x/evm/plugins/state/factory.go new file mode 100644 index 000000000..c42b892df --- /dev/null +++ b/cosmos/x/evm/plugins/state/factory.go @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package state + +import ( + "context" + "errors" + + storetypes "cosmossdk.io/store/types" + + "github.com/berachain/polaris/cosmos/x/evm/plugins/state/events" + "github.com/berachain/polaris/eth/core" + "github.com/berachain/polaris/eth/core/state" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ core.StatePluginFactory = (*SPFactory)(nil) + +type SPFactory struct { + // keepers used for balance and account information. + ak AccountKeeper + storeKey storetypes.StoreKey + plf events.PrecompileLogFactory + + // Contexts for state plugins + genesisContext sdk.Context // "genesis" ---> set in InitGenesis + minerBuildContext sdk.Context // "miner" -----> set in PrepareProposal + insertChainContext sdk.Context // "insert" ----> set in ProcessProposal + finalizeBlockContext sdk.Context // "finalize" --> set in Finalize + latestQueryContext sdk.Context // "latest" ----> set in PrepareCheckState + + // Query function for getting the context at a given height. + qfn func() func(height int64, prove bool) (sdk.Context, error) // "historical" +} + +// NewSPFactory creates a new SPFactory instance with the provided AccountKeeper, +// store key, query function, and PrecompileLogFactory. +func NewSPFactory( + ak AccountKeeper, + storeKey storetypes.StoreKey, + qfn func() func(height int64, prove bool) (sdk.Context, error), +) *SPFactory { + return &SPFactory{ + ak: ak, + storeKey: storeKey, + qfn: qfn, + } +} + +// NewPluginFromContext creates a new Plugin instance using the current SPFactory's +// configuration and the provided context. +func (spf *SPFactory) NewPluginWithMode(mode state.Mode) core.StatePlugin { + p := NewPlugin(spf.ak, spf.storeKey, spf.qfn, spf.plf) + switch mode { + case state.Genesis: + p.Reset(spf.genesisContext) + case state.Miner: + p.Reset(spf.minerBuildContext) + case state.Insert: + p.Reset(spf.insertChainContext) + case state.Finalize: + p.Reset(spf.finalizeBlockContext) + case state.Latest: + fallthrough + default: + p.Reset(spf.latestQueryContext) + } + return p +} + +// NewPluginWithContext creates a new StatePlugin instance using the provided context. +// It initializes the plugin with the current SPFactory's account keeper, store key, +// query function, and precompile log factory, then resets the plugin's context to the +// one provided. +func (spf *SPFactory) NewPluginFromContext(ctx context.Context) core.StatePlugin { + p := NewPlugin(spf.ak, spf.storeKey, spf.qfn, spf.plf) + p.Reset(ctx) + return p +} + +// NewPluginAtBlockNumber creates a new StatePlugin instance using the provided block. +func (spf *SPFactory) NewPluginAtBlockNumber(blockNumber uint64) (core.StatePlugin, error) { + var ctx sdk.Context + // Ensure the query context function is set. + if spf.qfn == nil { + return nil, errors.New("no query context function set in host chain") + } + + // // NOTE: the PreBlock and BeginBlock state changes will not have been applied to the state + // // at this point. + // // This is kind of bad since queries from JSON-RPC (i.e eth_call estimateGas etc.) + // // won't be able to do this + // // ontop of a state that has these updates for the block. + // // TODO: Fix this. + int64Number := int64(blockNumber) + // TODO: the GTE may be hiding a larger issue with the timing of the NewHead channel stuff. + // Investigate and hopefully remove this GTE. + if int64Number >= spf.latestQueryContext.BlockHeight() { + // TODO: Manager properly + if spf.latestQueryContext.MultiStore() == nil { + ctx = spf.latestQueryContext.WithEventManager(sdk.NewEventManager()) + } else { + ctx, _ = spf.latestQueryContext.CacheContext() + } + } else { + // Get the query context at the given height. + var err error + ctx, err = spf.qfn()(int64Number, false) + if err != nil { + return nil, err + } + } + + return spf.NewPluginFromContext(ctx), nil + // // Create a State Plugin with the requested chain height. + // sp := NewPlugin(p.ak, p.storeKey, p.qfn, p.plf) + + // // TODO: Manager properly + // if p.latestQueryContext.MultiStore() != nil { + // sp.Reset(ctx) + // } + // // return sp, nil + // ctx, err := spf.qfn()(int64(blockNumber), false) + // if err != nil { + // return nil, err + // } +} + +// SetGenesisContext updates the SPFactory's genesis context to the provided context. +func (spf *SPFactory) SetGenesisContext(ctx context.Context) { + spf.genesisContext = sdk.UnwrapSDKContext(ctx) +} + +// SetMiningContext updates the SPFactory's minerBuildContext to the provided context. +func (spf *SPFactory) SetLatestMiningContext(ctx context.Context) { + spf.minerBuildContext = sdk.UnwrapSDKContext(ctx) +} + +// SetInsertChainContext updates the SPFactory's insertChainContext to the provided context. +func (spf *SPFactory) SetInsertChainContext(ctx context.Context) { + spf.insertChainContext = sdk.UnwrapSDKContext(ctx) +} + +// SetFinalizeBlockContext updates the SPFactory's finalizeBlockContext to the provided context. +func (spf *SPFactory) SetFinalizeBlockContext(ctx context.Context) { + spf.finalizeBlockContext = sdk.UnwrapSDKContext(ctx) +} + +// SetLatestQueryContext updates the SPFactory's latestQueryContext to the provided context. +// This context will be used for subsequent state queries. +func (spf *SPFactory) SetLatestQueryContext(ctx context.Context) { + spf.latestQueryContext = sdk.UnwrapSDKContext(ctx) +} + +// SetPrecompileLogFactory sets the PrecompileLogFactory in the SPFactory. +func (spf *SPFactory) SetPrecompileLogFactory(plf events.PrecompileLogFactory) { + spf.plf = plf +} diff --git a/cosmos/x/evm/plugins/state/plugin.go b/cosmos/x/evm/plugins/state/plugin.go index b6a38bf95..bfd0200ec 100644 --- a/cosmos/x/evm/plugins/state/plugin.go +++ b/cosmos/x/evm/plugins/state/plugin.go @@ -106,15 +106,17 @@ type plugin struct { // keepers used for balance and account information. ak AccountKeeper - // qfn allows for querying state a historical height. - latestQueryContext sdk.Context - qfn func() func(height int64, prove bool) (sdk.Context, error) - // dbErr stores any error that is returned from state modifications on the underlying // keepers. dbErr error mu sync.Mutex + + stateCtx context.Context + + // lqc is used for fullfilling + lqc sdk.Context + qfn func() func(height int64, prove bool) (sdk.Context, error) } // NewPlugin returns a plugin with the given context and keepers. @@ -138,12 +140,6 @@ func (p *plugin) SetPrecompileLogFactory(plf events.PrecompileLogFactory) { p.plf = plf } -// Prepare sets up the context on the state plugin for use in JSON-RPC calls. -// Prepare implements `core.StatePlugin`. -func (p *plugin) Prepare(ctx context.Context) { - p.latestQueryContext = sdk.UnwrapSDKContext(ctx) -} - // Reset sets up the state plugin for execution of a new transaction. It sets up the snapshottable // multi store so that Cosmos KV store changes can revert according to the EVM. // @@ -521,6 +517,16 @@ func (p *plugin) IterateBalances(fn func(common.Address, *big.Int) bool) { // Historical State // ============================================================================= +func (p *plugin) SetStateOverride(ctx context.Context) { + p.stateCtx = ctx +} + +func (p *plugin) GetOverridenState() core.StatePlugin { + sp := NewPlugin(p.ak, p.storeKey, p.qfn, p.plf) + sp.Reset(p.stateCtx) + return sp +} + // StateAtBlockNumber implements `core.StatePlugin`. func (p *plugin) StateAtBlockNumber(number uint64) (core.StatePlugin, error) { var ctx sdk.Context @@ -535,16 +541,15 @@ func (p *plugin) StateAtBlockNumber(number uint64) (core.StatePlugin, error) { // won't be able to do this // ontop of a state that has these updates for the block. // TODO: Fix this. - int64Number := int64(number) // TODO: the GTE may be hiding a larger issue with the timing of the NewHead channel stuff. // Investigate and hopefully remove this GTE. - if int64Number >= p.latestQueryContext.BlockHeight() { + if int64Number >= p.lqc.BlockHeight() { // TODO: Manager properly - if p.latestQueryContext.MultiStore() == nil { - ctx = p.latestQueryContext.WithEventManager(sdk.NewEventManager()) + if p.lqc.MultiStore() == nil { + ctx = p.lqc.WithEventManager(sdk.NewEventManager()) } else { - ctx, _ = p.latestQueryContext.CacheContext() + ctx, _ = p.lqc.CacheContext() } } else { // Get the query context at the given height. @@ -557,8 +562,9 @@ func (p *plugin) StateAtBlockNumber(number uint64) (core.StatePlugin, error) { // Create a State Plugin with the requested chain height. sp := NewPlugin(p.ak, p.storeKey, p.qfn, p.plf) + // TODO: Manager properly - if p.latestQueryContext.MultiStore() != nil { + if p.lqc.MultiStore() != nil { sp.Reset(ctx) } return sp, nil diff --git a/e2e/localnet/go.mod b/e2e/localnet/go.mod index 9d15677bb..9203b54f7 100644 --- a/e2e/localnet/go.mod +++ b/e2e/localnet/go.mod @@ -6,8 +6,8 @@ require ( github.com/berachain/polaris/contracts v0.0.4-alpha github.com/docker/docker v24.0.7+incompatible github.com/ethereum/go-ethereum v1.13.7 - github.com/onsi/ginkgo/v2 v2.13.0 - github.com/onsi/gomega v1.28.1 + github.com/onsi/ginkgo/v2 v2.13.2 + github.com/onsi/gomega v1.29.0 github.com/ory/dockertest v3.3.5+incompatible ) @@ -32,7 +32,7 @@ require ( github.com/ethereum/c-kzg-4844 v0.4.0 // indirect github.com/fjl/memsize v0.0.1 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gogo/protobuf v1.3.2 // indirect diff --git a/e2e/localnet/go.sum b/e2e/localnet/go.sum index a9d7325c4..fbb4a52e7 100644 --- a/e2e/localnet/go.sum +++ b/e2e/localnet/go.sum @@ -86,8 +86,8 @@ 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.25.0 h1:q6Eo+hS+yoJlTO3uu/azhQadsD8V+jQn2D8VvX1eOyI= github.com/getsentry/sentry-go v0.25.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= @@ -174,10 +174,10 @@ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7P github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= -github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= -github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0= diff --git a/e2e/localnet/network/fixture_test.go b/e2e/localnet/network/fixture_test.go index 4b32354c0..987fabe8c 100644 --- a/e2e/localnet/network/fixture_test.go +++ b/e2e/localnet/network/fixture_test.go @@ -58,7 +58,7 @@ var _ = Describe("JSON RPC tests", func() { "goodcontainer", "8545/tcp", "8546/tcp", - "1.21.5", + "1.21.6", )) Expect(tf).ToNot(BeNil()) client = tf.EthClient() diff --git a/e2e/localnet/network/node_test.go b/e2e/localnet/network/node_test.go index e5b0866bf..2636fe4f2 100644 --- a/e2e/localnet/network/node_test.go +++ b/e2e/localnet/network/node_test.go @@ -50,7 +50,7 @@ var _ = Describe("ContainerizedNode", func() { "8545/tcp", "8546/tcp", []string{ - "GO_VERSION=1.21.5", + "GO_VERSION=1.21.6", "BASE_IMAGE=polard/base:v0.0.0", }, ) diff --git a/e2e/precompile/go.mod b/e2e/precompile/go.mod index 65bad524f..7df2a67fe 100644 --- a/e2e/precompile/go.mod +++ b/e2e/precompile/go.mod @@ -8,8 +8,8 @@ require ( github.com/cosmos/cosmos-sdk v0.50.3-0.20231218145840-3ea39a32bb46 github.com/cosmos/gogoproto v1.4.11 github.com/ethereum/go-ethereum v1.13.7 - github.com/onsi/ginkgo/v2 v2.13.0 - github.com/onsi/gomega v1.28.1 + github.com/onsi/ginkgo/v2 v2.13.2 + github.com/onsi/gomega v1.29.0 ) require ( @@ -83,7 +83,7 @@ require ( github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/validator/v10 v10.15.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect diff --git a/e2e/precompile/go.sum b/e2e/precompile/go.sum index 94054d51c..1d1c8e565 100644 --- a/e2e/precompile/go.sum +++ b/e2e/precompile/go.sum @@ -337,8 +337,8 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= @@ -718,15 +718,15 @@ github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vv github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= -github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= diff --git a/e2e/precompile/utils.go b/e2e/precompile/utils.go index 146d0521e..d6a33e0c7 100644 --- a/e2e/precompile/utils.go +++ b/e2e/precompile/utils.go @@ -34,7 +34,7 @@ const ( containerName = "goodcontainer" polardHTTPAddress = "8545/tcp" polardWSAddress = "8546/tcp" - goVersion = "1.21.5" + goVersion = "1.21.6" ) // NewPolarisFixtureConfig returns a polaris fixture config. diff --git a/e2e/testapp/app.go b/e2e/testapp/app.go index caf2ccd2b..22a1990e2 100644 --- a/e2e/testapp/app.go +++ b/e2e/testapp/app.go @@ -190,7 +190,7 @@ func NewPolarisApp( // Build the app using the app builder. app.App = appBuilder.Build(db, traceStore, baseAppOptions...) - app.Polaris = polarruntime.New( + app.Polaris = polarruntime.New(app, evmconfig.MustReadConfigFromAppOpts(appOpts), app.Logger(), app.EVMKeeper.Host, nil, ) diff --git a/e2e/testapp/docker/base.Dockerfile b/e2e/testapp/docker/base.Dockerfile index 4edfd61a2..baaea4a05 100644 --- a/e2e/testapp/docker/base.Dockerfile +++ b/e2e/testapp/docker/base.Dockerfile @@ -18,7 +18,7 @@ ### Stage 0 - Build Arguments ### ####################################################### -ARG GO_VERSION=1.21.5 +ARG GO_VERSION=1.21.6 ARG GOARCH=amd64 ARG GOOS=linux ARG NAME=polaris-cosmos diff --git a/e2e/testapp/go.mod b/e2e/testapp/go.mod index 29881e9f6..3474957d0 100644 --- a/e2e/testapp/go.mod +++ b/e2e/testapp/go.mod @@ -7,7 +7,7 @@ replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // We replace `go-ethereum` with `polaris-geth` in order include our required changes. - github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b + github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0 // Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 @@ -33,8 +33,8 @@ require ( github.com/cometbft/cometbft v0.38.2 github.com/cosmos/cosmos-db v1.0.0 github.com/cosmos/cosmos-sdk v0.50.3-0.20231218145840-3ea39a32bb46 - github.com/onsi/ginkgo/v2 v2.13.0 - github.com/onsi/gomega v1.28.1 + github.com/onsi/ginkgo/v2 v2.13.2 + github.com/onsi/gomega v1.29.0 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.16.0 ) @@ -123,7 +123,7 @@ require ( github.com/go-kit/kit v0.12.0 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect diff --git a/e2e/testapp/go.sum b/e2e/testapp/go.sum index 60c6929a7..684a276cf 100644 --- a/e2e/testapp/go.sum +++ b/e2e/testapp/go.sum @@ -273,8 +273,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b h1:wrzTIsCeIUh3wgSDXCvXKfwJA7G1SYIQccl7UhBexBY= -github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= +github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0 h1:jGah7o6k6xytfTFH7hIKmfJZOPnAhCb9bmCb+lRS4Bk= +github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= github.com/berachain/polaris/contracts v0.0.4-alpha h1:CyiElDqABwa4tIrC8j/D7dd21dRqGEV6yZjZsVD13nE= github.com/berachain/polaris/contracts v0.0.4-alpha/go.mod h1:Sm1T+tIQGuP0wEJnF/TlgZiJ+NPHgOZWO7vAz7FkwVs= github.com/berachain/polaris/cosmos v0.0.4-alpha h1:f3/mKhVM56a5n2+m25Fhj2cJivESbF/ps8hNqUAaRVw= @@ -555,8 +555,8 @@ github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= @@ -998,14 +998,14 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108 github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= -github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= diff --git a/eth/core/chain.go b/eth/core/chain.go index fd5d01e48..664ae04cb 100644 --- a/eth/core/chain.go +++ b/eth/core/chain.go @@ -27,7 +27,6 @@ import ( "sync/atomic" "github.com/berachain/polaris/eth/consensus" - "github.com/berachain/polaris/eth/core/state" "github.com/berachain/polaris/eth/core/types" "github.com/ethereum/go-ethereum/common" @@ -49,28 +48,27 @@ var _ Blockchain = (*blockchain)(nil) // Blockchain interface defines the methods that a blockchain must have. type Blockchain interface { - PreparePlugins(ctx context.Context) + preparePlugins(ctx context.Context) ChainReader ChainWriter ChainSubscriber ChainResources + StatePluginFactory() StatePluginFactory core.ChainContext } // blockchain is the canonical, persistent object that operates the Polaris EVM. type blockchain struct { // the host chain plugins that the Polaris EVM is running on. - bp BlockPlugin - hp HistoricalPlugin - pp PrecompilePlugin - sp StatePlugin + bp BlockPlugin + hp HistoricalPlugin + pp PrecompilePlugin + spf StatePluginFactory engine consensus.Engine processor core.Processor validator core.Validator - // statedb is the state database that is used to manage state during transactions. - statedb state.StateDB // vmConfig is the configuration used to create the EVM. vmConfig *vm.Config @@ -117,7 +115,7 @@ func NewChain( bp: host.GetBlockPlugin(), hp: host.GetHistoricalPlugin(), pp: host.GetPrecompilePlugin(), - sp: host.GetStatePlugin(), + spf: host.GetStatePluginFactory(), config: config, vmConfig: &vm.Config{}, receiptsCache: lru.NewCache[common.Hash, ethtypes.Receipts](defaultCacheSize), @@ -129,7 +127,6 @@ func NewChain( logger: log.Root(), engine: engine, } - bc.statedb = state.NewStateDB(bc.sp, bc.pp) bc.processor = core.NewStateProcessor(bc.config, bc, bc.engine) bc.validator = core.NewBlockValidator(bc.config, bc, bc.engine) // TODO: hmm... @@ -142,14 +139,11 @@ func NewChain( func (bc *blockchain) LoadLastState(ctx context.Context, number uint64) error { // ctx here is the one created from app.CommitMultistore(). - bc.PreparePlugins(ctx) - bc.sp.Prepare(ctx) - + bc.preparePlugins(ctx) return bc.loadLastState(number) } -func (bc *blockchain) PreparePlugins(ctx context.Context) { - bc.sp.Reset(ctx) +func (bc *blockchain) preparePlugins(ctx context.Context) { bc.bp.Prepare(ctx) if bc.hp != nil { bc.hp.Prepare(ctx) @@ -170,3 +164,7 @@ func (bc *blockchain) loadLastState(number uint64) error { bc.currentBlock.Store(b) return nil } + +func (bc *blockchain) StatePluginFactory() StatePluginFactory { + return bc.spf +} diff --git a/eth/core/chain_resources.go b/eth/core/chain_resources.go index 535d63ce1..38d649544 100644 --- a/eth/core/chain_resources.go +++ b/eth/core/chain_resources.go @@ -41,6 +41,7 @@ type ChainResources interface { // state snapshots StateAtBlockNumber(uint64) (state.StateDB, error) StateAt(root common.Hash) (state.StateDB, error) + GetOverridenState() (state.StateDB, error) // state for tracing StateAtBlock( @@ -62,10 +63,15 @@ func (bc *blockchain) StateAt(common.Hash) (state.StateDB, error) { return nil, errors.New("StateAt is not implemented in polaris due state root") } +// Used by geth miner to build the block (can rename to GetMinerState). +func (bc *blockchain) GetOverridenState() (state.StateDB, error) { + return state.NewStateDB(bc.spf.NewPluginWithMode(state.Miner), bc.pp), nil +} + // StateAtBlockNumber returns a statedb configured to read what the state of the blockchain is/was // at a given block number. func (bc *blockchain) StateAtBlockNumber(number uint64) (state.StateDB, error) { - sp, err := bc.sp.StateAtBlockNumber(number) + sp, err := bc.spf.NewPluginAtBlockNumber(number) if err != nil { return nil, err } diff --git a/eth/core/chain_writer.go b/eth/core/chain_writer.go index 0f1bc4a37..795d87f6a 100644 --- a/eth/core/chain_writer.go +++ b/eth/core/chain_writer.go @@ -35,34 +35,55 @@ import ( // ChainWriter defines methods that are used to perform state and block transitions. type ChainWriter interface { LoadLastState(context.Context, uint64) error + WriteGenesisBlockWithContext(ctx context.Context, block *ethtypes.Block) error WriteGenesisBlock(block *ethtypes.Block) error + InsertBlockAndSetHeadWithContext( + ctx context.Context, block *ethtypes.Block, + ) error InsertBlockAndSetHead(block *ethtypes.Block) error InsertBlockWithoutSetHead(block *ethtypes.Block) error WriteBlockAndSetHead(block *ethtypes.Block, receipts []*ethtypes.Receipt, logs []*ethtypes.Log, state state.StateDB, emitHeadEvent bool) (status core.WriteStatus, err error) } +// WriteGenesisBlockWithContext inserts the genesis block +// into the blockchain using the given context for receipts and logs. +func (bc *blockchain) WriteGenesisBlockWithContext( + ctx context.Context, block *ethtypes.Block) error { + // Get the state with the latest finalize block context + bc.preparePlugins(ctx) + return bc.WriteGenesisBlock(block) +} + // WriteGenesisBlock inserts the genesis block into the blockchain. func (bc *blockchain) WriteGenesisBlock(block *ethtypes.Block) error { + // Get the state with the latest finalize block context. + sp := bc.spf.NewPluginWithMode(state.Genesis) + state := state.NewStateDB(sp, bc.pp) + // TODO: add more validation here. if block.NumberU64() != 0 { return errors.New("not the genesis block") } - _, err := bc.WriteBlockAndSetHead(block, nil, nil, nil, true) + _, err := bc.WriteBlockAndSetHead(block, nil, nil, state, true) return err } // InsertBlockWithoutSetHead inserts a block into the blockchain without setting it as the head. func (bc *blockchain) InsertBlockWithoutSetHead(block *ethtypes.Block) error { + // Get the state with the latest insert chain context. + sp := bc.spf.NewPluginWithMode(state.Insert) + state := state.NewStateDB(sp, bc.pp) + // Call the private method to insert the block without setting it as the head. - _, _, err := bc.insertBlockWithoutSetHead(block) + _, _, err := bc.insertBlockWithoutSetHead(block, state) // Return any error that might have occurred. return err } // insertBlockWithoutSetHead inserts a block into the blockchain without setting it as the head. func (bc *blockchain) insertBlockWithoutSetHead( - block *ethtypes.Block, + block *ethtypes.Block, state state.StateDB, ) ([]*ethtypes.Receipt, []*ethtypes.Log, error) { // Validate that we are about to insert a valid block. // If the block number is greater than 1, @@ -75,14 +96,14 @@ func (bc *blockchain) insertBlockWithoutSetHead( } // Process the incoming EVM block. - receipts, logs, usedGas, err := bc.processor.Process(block, bc.statedb, *bc.vmConfig) + receipts, logs, usedGas, err := bc.processor.Process(block, state, *bc.vmConfig) if err != nil { log.Error("failed to process block", "num", block.NumberU64(), "err", err) return nil, nil, err } // ValidateState validates the statedb post block processing. - if err = bc.validator.ValidateState(block, bc.statedb, receipts, usedGas); err != nil { + if err = bc.validator.ValidateState(block, state, receipts, usedGas); err != nil { log.Error("invalid state after processing block", "num", block.NumberU64(), "err", err) return nil, nil, err } @@ -90,15 +111,30 @@ func (bc *blockchain) insertBlockWithoutSetHead( return receipts, logs, nil } +// InsertBlockAndSetHeadWithContext inserts the genesis block +// into the blockchain using the given context for receipts and logs. +// It also sets the head of the blockchain to the given block. +func (bc *blockchain) InsertBlockAndSetHeadWithContext( + ctx context.Context, block *ethtypes.Block, +) error { + // Get the state with the latest finalize block context + bc.preparePlugins(ctx) + return bc.InsertBlockAndSetHead(block) +} + // InsertBlockAndSetHead inserts a block into the blockchain and sets the head. func (bc *blockchain) InsertBlockAndSetHead(block *ethtypes.Block) error { - receipts, logs, err := bc.insertBlockWithoutSetHead(block) + // Get the state with the latest finalize block context. + sp := bc.spf.NewPluginWithMode(state.Finalize) + state := state.NewStateDB(sp, bc.pp) + + receipts, logs, err := bc.insertBlockWithoutSetHead(block, state) if err != nil { return err } // We can just immediately finalize the block. It's okay in this context. if _, err = bc.WriteBlockAndSetHead( - block, receipts, logs, nil, true); err != nil { + block, receipts, logs, state, true); err != nil { log.Error("failed to write block", "num", block.NumberU64(), "err", err) return err } @@ -108,10 +144,10 @@ func (bc *blockchain) InsertBlockAndSetHead(block *ethtypes.Block) error { // WriteBlockAndSetHead sets the head of the blockchain to the given block and finalizes the block. func (bc *blockchain) WriteBlockAndSetHead( block *ethtypes.Block, receipts []*ethtypes.Receipt, logs []*ethtypes.Log, - _ state.StateDB, emitHeadEvent bool, + state state.StateDB, emitHeadEvent bool, ) (core.WriteStatus, error) { // Write the block to the store. - if err := bc.writeBlockWithState(block, receipts); err != nil { + if err := bc.writeBlockWithState(block, receipts, state); err != nil { return core.NonStatTy, err } currentBlock := bc.currentBlock.Load() @@ -176,7 +212,7 @@ func (bc *blockchain) WriteBlockAndSetHead( // writeBlockWithState writes the block along with its state (receipts and logs) // into the blockchain. func (bc *blockchain) writeBlockWithState( - block *ethtypes.Block, receipts []*ethtypes.Receipt, + block *ethtypes.Block, receipts []*ethtypes.Receipt, state state.StateDB, ) error { // In Polaris since we are using single block finality. // Finalized == Current == Safe. All are the same. @@ -195,7 +231,7 @@ func (bc *blockchain) writeBlockWithState( // Commit all cached state changes into underlying memory database. // In Polaris this is a no-op. - _, err = bc.statedb.Commit(block.NumberU64(), bc.config.IsEIP158(block.Number())) + _, err = state.Commit(block.NumberU64(), bc.config.IsEIP158(block.Number())) if err != nil { return err } diff --git a/eth/core/host.go b/eth/core/host.go index 826bdee74..41d51b675 100644 --- a/eth/core/host.go +++ b/eth/core/host.go @@ -21,6 +21,8 @@ package core import ( + "context" + "github.com/berachain/polaris/eth/core/precompile" "github.com/berachain/polaris/eth/core/state" "github.com/berachain/polaris/eth/core/types" @@ -39,7 +41,7 @@ type PolarisHostChain interface { // GetPrecompilePlugin returns the OPTIONAL `PrecompilePlugin` of the Polaris host chain. GetPrecompilePlugin() PrecompilePlugin // GetStatePlugin returns the `StatePlugin` of the Polaris host chain. - GetStatePlugin() StatePlugin + GetStatePluginFactory() StatePluginFactory } // ============================================================================= @@ -68,6 +70,17 @@ type ( state.Plugin // StateAtBlockNumber returns the state at the given block height. StateAtBlockNumber(uint64) (StatePlugin, error) + SetStateOverride(ctx context.Context) + GetOverridenState() StatePlugin + } + + StatePluginFactory interface { + NewPluginAtBlockNumber(uint64) (StatePlugin, error) + NewPluginWithMode(state.Mode) StatePlugin + NewPluginFromContext(context.Context) StatePlugin + SetLatestQueryContext(ctx context.Context) + SetLatestMiningContext(ctx context.Context) + SetInsertChainContext(ctx context.Context) } ) diff --git a/eth/core/mock/state_plugin.mock.go b/eth/core/mock/state_plugin.mock.go index 2f635e1fa..3633fe824 100644 --- a/eth/core/mock/state_plugin.mock.go +++ b/eth/core/mock/state_plugin.mock.go @@ -67,6 +67,9 @@ var _ core.StatePlugin = &StatePluginMock{} // GetNonceFunc: func(address common.Address) uint64 { // panic("mock out the GetNonce method") // }, +// GetOverridenStateFunc: func() core.StatePlugin { +// panic("mock out the GetOverridenState method") +// }, // GetStateFunc: func(address common.Address, hash common.Hash) common.Hash { // panic("mock out the GetState method") // }, @@ -94,6 +97,9 @@ var _ core.StatePlugin = &StatePluginMock{} // SetStateFunc: func(address common.Address, hash1 common.Hash, hash2 common.Hash) { // panic("mock out the SetState method") // }, +// SetStateOverrideFunc: func(ctx context.Context) { +// panic("mock out the SetStateOverride method") +// }, // SetStorageFunc: func(addr common.Address, storage map[common.Hash]common.Hash) { // panic("mock out the SetStorage method") // }, @@ -158,6 +164,9 @@ type StatePluginMock struct { // GetNonceFunc mocks the GetNonce method. GetNonceFunc func(address common.Address) uint64 + // GetOverridenStateFunc mocks the GetOverridenState method. + GetOverridenStateFunc func() core.StatePlugin + // GetStateFunc mocks the GetState method. GetStateFunc func(address common.Address, hash common.Hash) common.Hash @@ -185,6 +194,9 @@ type StatePluginMock struct { // SetStateFunc mocks the SetState method. SetStateFunc func(address common.Address, hash1 common.Hash, hash2 common.Hash) + // SetStateOverrideFunc mocks the SetStateOverride method. + SetStateOverrideFunc func(ctx context.Context) + // SetStorageFunc mocks the SetStorage method. SetStorageFunc func(addr common.Address, storage map[common.Hash]common.Hash) @@ -272,6 +284,9 @@ type StatePluginMock struct { // Address is the address argument value. Address common.Address } + // GetOverridenState holds details about calls to the GetOverridenState method. + GetOverridenState []struct { + } // GetState holds details about calls to the GetState method. GetState []struct { // Address is the address argument value. @@ -327,6 +342,11 @@ type StatePluginMock struct { // Hash2 is the hash2 argument value. Hash2 common.Hash } + // SetStateOverride holds details about calls to the SetStateOverride method. + SetStateOverride []struct { + // Ctx is the ctx argument value. + Ctx context.Context + } // SetStorage holds details about calls to the SetStorage method. SetStorage []struct { // Addr is the addr argument value. @@ -365,6 +385,7 @@ type StatePluginMock struct { lockGetCommittedState sync.RWMutex lockGetContext sync.RWMutex lockGetNonce sync.RWMutex + lockGetOverridenState sync.RWMutex lockGetState sync.RWMutex lockPrepare sync.RWMutex lockRegistryKey sync.RWMutex @@ -374,6 +395,7 @@ type StatePluginMock struct { lockSetCode sync.RWMutex lockSetNonce sync.RWMutex lockSetState sync.RWMutex + lockSetStateOverride sync.RWMutex lockSetStorage sync.RWMutex lockSnapshot sync.RWMutex lockStateAtBlockNumber sync.RWMutex @@ -852,6 +874,33 @@ func (mock *StatePluginMock) GetNonceCalls() []struct { return calls } +// GetOverridenState calls GetOverridenStateFunc. +func (mock *StatePluginMock) GetOverridenState() core.StatePlugin { + if mock.GetOverridenStateFunc == nil { + panic("StatePluginMock.GetOverridenStateFunc: method is nil but StatePlugin.GetOverridenState was just called") + } + callInfo := struct { + }{} + mock.lockGetOverridenState.Lock() + mock.calls.GetOverridenState = append(mock.calls.GetOverridenState, callInfo) + mock.lockGetOverridenState.Unlock() + return mock.GetOverridenStateFunc() +} + +// GetOverridenStateCalls gets all the calls that were made to GetOverridenState. +// Check the length with: +// +// len(mockedStatePlugin.GetOverridenStateCalls()) +func (mock *StatePluginMock) GetOverridenStateCalls() []struct { +} { + var calls []struct { + } + mock.lockGetOverridenState.RLock() + calls = mock.calls.GetOverridenState + mock.lockGetOverridenState.RUnlock() + return calls +} + // GetState calls GetStateFunc. func (mock *StatePluginMock) GetState(address common.Address, hash common.Hash) common.Hash { if mock.GetStateFunc == nil { @@ -1159,6 +1208,38 @@ func (mock *StatePluginMock) SetStateCalls() []struct { return calls } +// SetStateOverride calls SetStateOverrideFunc. +func (mock *StatePluginMock) SetStateOverride(ctx context.Context) { + if mock.SetStateOverrideFunc == nil { + panic("StatePluginMock.SetStateOverrideFunc: method is nil but StatePlugin.SetStateOverride was just called") + } + callInfo := struct { + Ctx context.Context + }{ + Ctx: ctx, + } + mock.lockSetStateOverride.Lock() + mock.calls.SetStateOverride = append(mock.calls.SetStateOverride, callInfo) + mock.lockSetStateOverride.Unlock() + mock.SetStateOverrideFunc(ctx) +} + +// SetStateOverrideCalls gets all the calls that were made to SetStateOverride. +// Check the length with: +// +// len(mockedStatePlugin.SetStateOverrideCalls()) +func (mock *StatePluginMock) SetStateOverrideCalls() []struct { + Ctx context.Context +} { + var calls []struct { + Ctx context.Context + } + mock.lockSetStateOverride.RLock() + calls = mock.calls.SetStateOverride + mock.lockSetStateOverride.RUnlock() + return calls +} + // SetStorage calls SetStorageFunc. func (mock *StatePluginMock) SetStorage(addr common.Address, storage map[common.Hash]common.Hash) { if mock.SetStorageFunc == nil { diff --git a/eth/core/precompile/method_validation.go b/eth/core/precompile/method_validation.go index 443b78720..081877e5d 100644 --- a/eth/core/precompile/method_validation.go +++ b/eth/core/precompile/method_validation.go @@ -35,7 +35,7 @@ import ( // validateArg uses reflection to verify the implementation arg matches the ABI arg. // -//nolint:gocognit // todo refactor. +//nolint:gocognit // required for reflect. func validateArg(implMethodVar reflect.Value, abiMethodVar reflect.Value) error { implMethodVarType := implMethodVar.Type() abiMethodVarType := abiMethodVar.Type() diff --git a/eth/core/state/interfaces.go b/eth/core/state/interfaces.go index 032e22bb2..6e41115ba 100644 --- a/eth/core/state/interfaces.go +++ b/eth/core/state/interfaces.go @@ -34,8 +34,6 @@ import ( type Plugin interface { // Plugin implements `libtypes.Controllable`. libtypes.Controllable[string] - // Prepare prepares the state with the given `context`. - libtypes.Preparable // Reset resets the state with the given `context`. libtypes.Resettable // Plugin implements `libtypes.Cloneable`. diff --git a/eth/core/state/modes.go b/eth/core/state/modes.go new file mode 100644 index 000000000..894c5aa92 --- /dev/null +++ b/eth/core/state/modes.go @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2023, Berachain Foundation. All rights reserved. +// Use of this software is govered by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package state + +// Mode is the type of state requested from the host chain. +type Mode uint8 + +const ( + Genesis Mode = iota + Miner + Insert + Finalize + Latest +) diff --git a/eth/eth.go b/eth/eth.go index 821af3350..64145f217 100644 --- a/eth/eth.go +++ b/eth/eth.go @@ -145,17 +145,6 @@ func newGethExecutionLayer( }, nil } -// RegisterSyncStatusProvider registers a sync status provider to the backend of the -// execution layer. -func (el *ExecutionLayer) RegisterSyncStatusProvider(provider polar.SyncStatusProvider) { - el.backend.RegisterSyncStatusProvider(provider) -} - -// RegisterLifecycle registers a lifecycle to the networking stack of the execution layer. -func (el *ExecutionLayer) RegisterLifecycle(lifecycle node.Lifecycle) { - el.stack.RegisterLifecycle(lifecycle) -} - // Start starts the networking stack of the execution layer. // It returns an error if the start operation fails. func (el *ExecutionLayer) Start() error { @@ -168,17 +157,12 @@ func (el *ExecutionLayer) Close() error { return el.stack.Close() } -// Miner returns the miner interface of the backend of the execution layer. -func (el *ExecutionLayer) Miner() Miner { - return el.backend.Miner() -} - -// TxPool returns the transaction pool interface of the backend of the execution layer. -func (el *ExecutionLayer) TxPool() TxPool { - return el.backend.TxPool() +// Backend returns the Polaris backend associated with the execution layer. +func (el *ExecutionLayer) Backend() *polar.Polaris { + return el.backend } -// Blockchain returns the blockchain interface of the backend of the execution layer. -func (el *ExecutionLayer) Blockchain() pcore.Blockchain { - return el.backend.Blockchain() +// Stack returns the NetworkingStack associated with the execution layer. +func (el *ExecutionLayer) Stack() NetworkingStack { + return el.stack } diff --git a/eth/go.mod b/eth/go.mod index 66066ff7b..5e93cfee3 100644 --- a/eth/go.mod +++ b/eth/go.mod @@ -5,16 +5,16 @@ go 1.21 replace ( github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // We replace `go-ethereum` with `polaris-geth` in order include our required changes. - github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b + github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0 ) require ( - github.com/berachain/polaris/contracts v0.0.4-alpha - github.com/berachain/polaris/lib v0.0.4-alpha + github.com/berachain/polaris/contracts v0.0.4-alpha.0.20240109234156-7b6ac78b70bd + github.com/berachain/polaris/lib v0.0.4-alpha.0.20240109234156-7b6ac78b70bd github.com/ethereum/go-ethereum v1.13.7 github.com/holiman/uint256 v1.2.4 - github.com/onsi/ginkgo/v2 v2.13.0 - github.com/onsi/gomega v1.28.1 + github.com/onsi/ginkgo/v2 v2.13.2 + github.com/onsi/gomega v1.29.0 github.com/stretchr/testify v1.8.4 golang.org/x/text v0.14.0 ) @@ -58,7 +58,7 @@ require ( github.com/getsentry/sentry-go v0.25.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-gonic/gin v1.9.1 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect diff --git a/eth/go.sum b/eth/go.sum index 8c906f36c..d4ecb4f7c 100644 --- a/eth/go.sum +++ b/eth/go.sum @@ -12,12 +12,12 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7D github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b h1:wrzTIsCeIUh3wgSDXCvXKfwJA7G1SYIQccl7UhBexBY= -github.com/berachain/polaris-geth v0.0.0-20231219175213-697db469215b/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= -github.com/berachain/polaris/contracts v0.0.4-alpha h1:CyiElDqABwa4tIrC8j/D7dd21dRqGEV6yZjZsVD13nE= -github.com/berachain/polaris/contracts v0.0.4-alpha/go.mod h1:Sm1T+tIQGuP0wEJnF/TlgZiJ+NPHgOZWO7vAz7FkwVs= -github.com/berachain/polaris/lib v0.0.4-alpha h1:5ob1YtUD6qx35yfwcOKyOOuU6/OgtXMRk0eQrsjCSsw= -github.com/berachain/polaris/lib v0.0.4-alpha/go.mod h1:08kBE9vqIO1PREtvM99uI2Sq/bjxjSQ5rYXM9k8wAYs= +github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0 h1:jGah7o6k6xytfTFH7hIKmfJZOPnAhCb9bmCb+lRS4Bk= +github.com/berachain/polaris-geth v0.0.0-20240108202417-27ce389773c0/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA= +github.com/berachain/polaris/contracts v0.0.4-alpha.0.20240109234156-7b6ac78b70bd h1:NnEnR7hHSZGCvMbjzfbrn0eeEI4niUZsJguasYgQeB0= +github.com/berachain/polaris/contracts v0.0.4-alpha.0.20240109234156-7b6ac78b70bd/go.mod h1:Sm1T+tIQGuP0wEJnF/TlgZiJ+NPHgOZWO7vAz7FkwVs= +github.com/berachain/polaris/lib v0.0.4-alpha.0.20240109234156-7b6ac78b70bd h1:hhhMUs6q8QPrPoMMlf4LtKKLfGb6CktEYWR7pjmwCy0= +github.com/berachain/polaris/lib v0.0.4-alpha.0.20240109234156-7b6ac78b70bd/go.mod h1:bP/AxNoKhjMIt+WI7rh/ULHZoFIUSlZKsaFUZ2jUXHI= github.com/bits-and-blooms/bitset v1.11.0 h1:RMyy2mBBShArUAhfVRZJ2xyBO58KCBCtZFShw3umo6k= github.com/bits-and-blooms/bitset v1.11.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= @@ -112,8 +112,8 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= @@ -262,14 +262,14 @@ github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vv github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= -github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= -github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4= github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= diff --git a/eth/polar/backend.go b/eth/polar/backend.go index dfaa9bc9d..e8f405bec 100644 --- a/eth/polar/backend.go +++ b/eth/polar/backend.go @@ -220,3 +220,7 @@ func (pl *Polaris) MinerChain() miner.BlockChain { func (pl *Polaris) Blockchain() core.Blockchain { return pl.blockchain } + +func (pl *Polaris) APIBackend() APIBackend { + return pl.apiBackend +} diff --git a/go.work.sum b/go.work.sum index ecebc0190..6a20e7eef 100644 --- a/go.work.sum +++ b/go.work.sum @@ -334,10 +334,6 @@ github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= -github.com/berachain/polaris/contracts v0.0.4-alpha/go.mod h1:Sm1T+tIQGuP0wEJnF/TlgZiJ+NPHgOZWO7vAz7FkwVs= -github.com/berachain/polaris/cosmos v0.0.4-alpha/go.mod h1:zrJstOjAuaVFiAS56Z9arvQIfMfgz6vr7nzryjYguoc= -github.com/berachain/polaris/eth v0.0.4-alpha/go.mod h1:i2ORG5xO2uktxaQcyRAM/40gin/pGS/3MzujhwfGXI4= -github.com/berachain/polaris/lib v0.0.4-alpha/go.mod h1:08kBE9vqIO1PREtvM99uI2Sq/bjxjSQ5rYXM9k8wAYs= github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bmatcuk/doublestar v1.1.1 h1:YroD6BJCZBYx06yYFEWvUuKVWQn3vLLQAVmDmvTSaiQ= github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= @@ -482,6 +478,7 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 h1:WtGNWLvXpe github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U= github.com/go-latex/latex v0.0.0-20210823091927-c0d11ff05a81/go.mod h1:SX0U8uGpxhq9o2S/CELCSUxEWWAuoCUcVCQWv7G2OCk= github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iaueeTaUgdetzel+U7exyigDYBryyVfV/rZk= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= @@ -755,6 +752,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb github.com/oklog/oklog v0.3.2 h1:wVfs8F+in6nTBMkA7CbRw+zZMIB7nNM825cM1wuzoTk= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0= +github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 h1:lDH9UUVJtmYCjyT0CI4q8xvlXPxeZ0gYCVvWbmPlp88= github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 h1:3snG66yBm59tKhhSPQrQ/0bCrv1LQbKt40LnUPiUxdc= github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU= @@ -1004,6 +1003,7 @@ golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.11.1/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo= gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0= gonum.org/v1/gonum v0.9.3/go.mod h1:TZumC3NeyVQskjXqmyWt4S3bINhy7B4eYwW69EbyX+0= diff --git a/lib/go.mod b/lib/go.mod index 9f7470c16..d02c2de8b 100644 --- a/lib/go.mod +++ b/lib/go.mod @@ -3,12 +3,12 @@ module github.com/berachain/polaris/lib go 1.21 require ( - github.com/onsi/ginkgo/v2 v2.13.0 - github.com/onsi/gomega v1.28.1 + github.com/onsi/ginkgo/v2 v2.13.2 + github.com/onsi/gomega v1.29.0 ) require ( - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.3.0 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/pprof v0.0.0-20230901174712-0191c66da455 // indirect diff --git a/lib/go.sum b/lib/go.sum index c1cfbef5a..54299b8ab 100644 --- a/lib/go.sum +++ b/lib/go.sum @@ -2,8 +2,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= +github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -21,10 +21,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= -github.com/onsi/gomega v1.28.1 h1:MijcGUbfYuznzK/5R4CPNoUP/9Xvuo20sXfEm6XxoTA= -github.com/onsi/gomega v1.28.1/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= +github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= +github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= +github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=