Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

feat(abci): Utilize geth miner to build blocks #1165

Merged
merged 119 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
56ef836
modularize default handler
Sep 20, 2023
4fe840a
lint
Sep 20, 2023
e15fe01
Merge branch 'main' into top-of-block
Sep 22, 2023
e8966a8
Merge branch 'main' into top-of-block
Sep 25, 2023
f03126f
base fee works
Sep 26, 2023
a57dcdd
hacky works
Sep 26, 2023
79c9c5d
init
Sep 26, 2023
af584a0
reduce some of the race conditions
Sep 26, 2023
a0266c0
reduce keeper interface
Sep 26, 2023
ff4045d
ree
Sep 26, 2023
a897bd3
Merge branch 'main' into dev/geth-txpool
Sep 26, 2023
e79d154
ree
Sep 26, 2023
5b5d25e
remove dead file
Sep 26, 2023
8b8c92e
txpool config
Sep 26, 2023
4fb9a05
update app.toml
Sep 26, 2023
988e340
back fee in sort of a jank way
Sep 26, 2023
def8815
bing bong
Sep 26, 2023
4bdfd42
remove more sleeps
Sep 26, 2023
2293a2a
remove zi sleeps
Sep 26, 2023
8d84ac8
Merge branch 'main' into dev/geth-txpool
Sep 26, 2023
cfe5a93
revert solidity change
Sep 27, 2023
9148aa6
remove waitgroup in handler
Sep 27, 2023
977b3a0
add mockery
Sep 27, 2023
fdf5b21
improve handler
Sep 27, 2023
0b75544
undo contract changes
Sep 27, 2023
9088795
mockery to mage
Sep 27, 2023
cd7ac66
improve test a bit
Sep 27, 2023
54eca2b
fix starting handler
Sep 27, 2023
4a73964
empty data dir
Sep 27, 2023
b33abd5
cleanup in keeper
Sep 27, 2023
0f6c2d2
move store package
Sep 27, 2023
1b91ff5
reconfigure configuration plugin
Sep 27, 2023
3f71005
giga cleanup
Sep 27, 2023
4ad1acf
fix tests
Sep 27, 2023
5554a20
bing bong
Sep 27, 2023
9ffc9dd
lint
Sep 27, 2023
511eb6c
bing bong
Sep 27, 2023
8e7d497
order
Sep 27, 2023
b0d8797
Merge branch 'main' into dev/geth-txpool
Sep 27, 2023
61b8e27
format
Sep 27, 2023
a4a40a3
some cleanup
Sep 27, 2023
065a61a
push
Sep 28, 2023
558edc7
remove chain config test from genesis
Sep 28, 2023
5cb4aff
bing bong
Sep 28, 2023
9353158
update app.tomls
Sep 28, 2023
88d7568
some cleanup
Sep 28, 2023
4b5b391
ree
Sep 28, 2023
d002197
comment as reminder to fix hive tomorrow
Sep 28, 2023
289e54a
merge main
Sep 28, 2023
2e0e42a
merge main
Sep 28, 2023
95cd953
fix config import
Sep 28, 2023
754052a
revert genesis.json to main
Sep 28, 2023
26c6b1e
app.toml
Sep 28, 2023
a217ebf
failed tests to 1 hive
Sep 28, 2023
06302f3
some cleanup
Sep 28, 2023
3565443
fix unit test
Sep 28, 2023
428e82b
fix unit test
Sep 28, 2023
82883ab
lint
Sep 28, 2023
1ea7771
some cleanup
Sep 28, 2023
dcdb207
fix test
Sep 28, 2023
47994fd
lint and fix address codec
Sep 28, 2023
0e0b890
push
Sep 28, 2023
8dea165
fix e2e
Sep 28, 2023
4381be2
fix data race in handler
Sep 29, 2023
4ae8b74
lint
Sep 29, 2023
3b83058
lint
Sep 29, 2023
4faa0df
merge main
Sep 29, 2023
2b390bc
fix nil ptr
Sep 29, 2023
847a697
fix
Sep 29, 2023
f20db1b
remove mocks
Sep 29, 2023
70e77f0
Merge branch 'main' into dev/geth-txpool
Sep 29, 2023
5ea5b5a
mockery from main
Sep 29, 2023
f0911fa
reduce diff
Sep 29, 2023
1f07d6f
merge main
Sep 29, 2023
c264bc9
Merge branch 'main' into dev/geth-txpool
Sep 29, 2023
00425ae
ree
Sep 29, 2023
f6cbc7c
fix test
Sep 29, 2023
02524d7
merge main
Sep 29, 2023
b018231
set mempool on the baseapp
Sep 29, 2023
b66eace
set tx pool
Sep 29, 2023
1866675
ree
Sep 29, 2023
00789c3
remove uneeded code
Oct 1, 2023
65a91fa
Merge branch 'main' into dev/geth-txpool
Oct 1, 2023
45e3175
miner poc
Oct 2, 2023
2106a1e
typos
Oct 2, 2023
efb63cb
remove mock engine
Oct 2, 2023
47b5de7
push
Oct 2, 2023
0cc3e14
lint
Oct 2, 2023
b5a2853
doesnt need cosmos bump anymore
Oct 2, 2023
73d5d24
probably still fails
Oct 2, 2023
97072ad
merge main
Oct 3, 2023
245a1b7
Merge branch 'main' into dev/geth-txpool
Oct 3, 2023
84c0ed3
merge
Oct 3, 2023
785b1dd
begin moving miner
Oct 3, 2023
51605c1
cleanup and remove txp
Oct 3, 2023
d2aa08e
remove unused function from miner
Oct 3, 2023
bd1daa9
add logger to mp
Oct 3, 2023
8bc764f
fix mempool test
Oct 3, 2023
df986e2
remove unused mock
Oct 3, 2023
22132f8
fix merge
Oct 3, 2023
7c62453
fix hive
Oct 3, 2023
c1aad43
Merge branch 'main' into dev/geth-txpool
calbera Oct 4, 2023
3851517
Merge branch 'dev/geth-txpool' into dev/miner-episode-1
calbera Oct 4, 2023
a963038
merge
Oct 4, 2023
cdb66fe
deadcode
Oct 4, 2023
ffcdbbe
merge main
Oct 4, 2023
a96cc8b
l o l
Oct 4, 2023
51e706e
merge main
Oct 5, 2023
b4cb889
add miner config
Oct 5, 2023
cc4a644
lint
Oct 5, 2023
2964ec1
feat(statedb): Move precompile setup around (#1187)
Oct 5, 2023
ede1575
merge main
Oct 6, 2023
0d8e7d5
Merge branch 'main' into dev/miner-episode-1
Oct 6, 2023
69cfe7d
Merge branch 'main' into dev/miner-episode-1
Oct 6, 2023
98a35ef
fix
Oct 6, 2023
fc6dac3
bing bong
Oct 6, 2023
5d03e96
cleanup
Oct 6, 2023
1babef2
merge main
Oct 6, 2023
4ff3e98
cleanup miner a touch
Oct 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 0 additions & 134 deletions cosmos/abci/prepare/prepare.go

This file was deleted.

138 changes: 138 additions & 0 deletions cosmos/miner/miner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
// 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 miner implements the Ethereum miner.
package miner

import (
"context"

abci "github.com/cometbft/cometbft/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/miner"

evmtypes "pkg.berachain.dev/polaris/cosmos/x/evm/types"
"pkg.berachain.dev/polaris/eth/core/types"
)

// emptyHash is a common.Hash initialized to all zeros.
var emptyHash = common.Hash{}

// Miner implements the baseapp.TxSelector interface.
type Miner struct {
*miner.Miner
serializer evmtypes.TxSerializer
currentPayload *miner.Payload
}

// New produces a cosmos miner from a geth miner.
func New(gm *miner.Miner) *Miner {
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved
return &Miner{
Miner: gm,
}
}
calbera marked this conversation as resolved.
Show resolved Hide resolved

// Init sets the transaction serializer.
func (m *Miner) Init(serializer evmtypes.TxSerializer) {
m.serializer = serializer
}
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved

// PrepareProposal implements baseapp.PrepareProposal.
func (m *Miner) PrepareProposal(
ctx sdk.Context, _ *abci.RequestPrepareProposal,
) (*abci.ResponsePrepareProposal, error) {
var txs [][]byte
var err error
if txs, err = m.buildBlock(ctx); err != nil {
return nil, err
}
return &abci.ResponsePrepareProposal{Txs: txs}, err
}
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved

// buildBlock builds and submits a payload, it also waits for the txs
// to resolve from the underying worker.
func (m *Miner) buildBlock(ctx sdk.Context) ([][]byte, error) {
defer m.clearPayload()
if err := m.submitPayloadForBuilding(ctx); err != nil {
return nil, err
}
return m.resolveTxs(), nil
}

// submitPayloadForBuilding submits a payload for building.
func (m *Miner) submitPayloadForBuilding(ctx context.Context) error {
var (
err error
payload *miner.Payload
sCtx = sdk.UnwrapSDKContext(ctx)
)

// Build Payload
if payload, err = m.BuildPayload(m.constructPayloadArgs(sCtx)); err != nil {
sCtx.Logger().Error("failed to build payload", "err", err)
return err
}
m.currentPayload = payload
sCtx.Logger().Info("submitted payload for building")
return nil
}

// constructPayloadArgs builds a payload to submit to the miner.
func (m *Miner) constructPayloadArgs(ctx sdk.Context) *miner.BuildPayloadArgs {
return &miner.BuildPayloadArgs{
Timestamp: uint64(ctx.BlockTime().Unix()),
FeeRecipient: common.Address{}, /* todo: set etherbase */
Random: common.Hash{}, /* todo: generated random */
Withdrawals: make(types.Withdrawals, 0),
BeaconRoot: &emptyHash,
}
}

// resolveTxs resolves the transactions from the payload.
func (m *Miner) resolveTxs() [][]byte {
if m.currentPayload == nil {
return nil
}
envelope := m.currentPayload.ResolveFull()
ethTxBzs := envelope.ExecutionPayload.Transactions
txs := make([][]byte, len(envelope.ExecutionPayload.Transactions))

// encode to sdk.txs and then
for i, ethTxBz := range ethTxBzs {
var tx types.Transaction
if err := tx.UnmarshalBinary(ethTxBz); err != nil {
return nil
}
bz, err := m.serializer.SerializeToBytes(&tx)
if err != nil {
panic(err)
}
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved
txs[i] = bz
}
return txs
}
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved

// clearPayload clears the payload.
func (m *Miner) clearPayload() {
m.currentPayload = nil
}
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved
30 changes: 29 additions & 1 deletion cosmos/cosmos.go → cosmos/miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,32 @@
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package cosmos
package miner

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestMiner(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "cosmos/miner")
}

var _ = Describe("", func() {

var (
// t = GinkgoT()
// txPool *mocks.GethTxPool
// sdkTx *mocks.SdkTx
// mempool *Miner
// ctx = context.Background()
)

BeforeEach(func() {
// mempool = &Miner{}
})

})
itsdevbear marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions cosmos/x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (

func (k *Keeper) BeginBlocker(ctx context.Context) error {
// Prepare the Polaris Ethereum block.
_ = k.polaris.Miner().Prepare(ctx, uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()))
_ = k.polaris.SPMiner().Prepare(ctx, uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()))
return nil
}

func (k *Keeper) EndBlock(ctx context.Context) error {
// Finalize the Polaris Ethereum block.
return k.polaris.Miner().Finalize(ctx)
return k.polaris.SPMiner().Finalize(ctx)
}
2 changes: 2 additions & 0 deletions cosmos/x/evm/keeper/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ func NewHost(
func (h *host) SetupPrecompiles() error {
// Set the query context function for the block and state plugins
pcs := h.pcs().GetPrecompiles()

if err := h.pp.RegisterPrecompiles(pcs); err != nil {
return err
}

h.sp.SetPrecompileLogFactory(pclog.NewFactory(pcs))
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cosmos/x/evm/keeper/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (k *Keeper) ProcessTransaction(
"reset gas meter prior to ethereum state transition")

// Process the transaction and return the EVM's execution result.
receipt, err := k.polaris.Miner().ProcessTransaction(ctx, tx)
receipt, err := k.polaris.SPMiner().ProcessTransaction(ctx, tx)
if err != nil {
k.Logger(sCtx).Error("failed to process transaction", "err", err)
return nil, err
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
>> {"jsonrpc":"2.0","id":1,"method":"eth_getBlockByNumber","params":["0x0",true]}
<< {"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x3b9aca00","difficulty":"0x1","extraData":"0x","gasLimit":"0x4c4b40","gasUsed":"0x0","hash":"0x1fc027d65f820d3eef441ebeec139ebe09e471cf98516dce7b5643ccb27f418c","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x21e","stateRoot":"0x078dc6061b1d8eaa8493384b59c9c65ceb917201221d08b80c4de6770b6ec7e7","timestamp":"0x0","totalDifficulty":"0x1","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[],"withdrawals": null,"withdrawalsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"}}
<< {"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x3b9aca00","difficulty":"0x1","extraData":"0x","gasLimit":"0x4c4b40","gasUsed":"0x0","hash":"0x1fc027d65f820d3eef441ebeec139ebe09e471cf98516dce7b5643ccb27f418c","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x21f","stateRoot":"0x078dc6061b1d8eaa8493384b59c9c65ceb917201221d08b80c4de6770b6ec7e7","timestamp":"0x0","totalDifficulty":"0x1","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[],"withdrawals": [],"withdrawalsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>> {"jsonrpc":"2.0","id":1,"method":"eth_getBlockByNumber","params":["0x3e8",true]}
<< {"jsonrpc":"2.0","id":1,"result":null}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
>> {"jsonrpc":"2.0","id":1,"method":"eth_getBlockByNumber","params":["0x0",true]}
<< {"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x3b9aca00","difficulty":"0x1","extraData":"0x","gasLimit":"0x4c4b40","gasUsed":"0x0","hash":"0x1fc027d65f820d3eef441ebeec139ebe09e471cf98516dce7b5643ccb27f418c","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x21e","stateRoot":"0x078dc6061b1d8eaa8493384b59c9c65ceb917201221d08b80c4de6770b6ec7e7","timestamp":"0x0","totalDifficulty":"0x1","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[],"withdrawals": null,"withdrawalsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"}}
<< {"jsonrpc":"2.0","id":1,"result":{"baseFeePerGas":"0x3b9aca00","difficulty":"0x1","extraData":"0x","gasLimit":"0x4c4b40","gasUsed":"0x0","hash":"0x1fc027d65f820d3eef441ebeec139ebe09e471cf98516dce7b5643ccb27f418c","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0000000000000000","number":"0x0","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x21f","stateRoot":"0x078dc6061b1d8eaa8493384b59c9c65ceb917201221d08b80c4de6770b6ec7e7","timestamp":"0x0","totalDifficulty":"0x1","transactions":[],"transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","uncles":[],"withdrawals": [],"withdrawalsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"}}
Loading