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

Commit

Permalink
ree
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Oct 27, 2023
1 parent d34a732 commit 562929a
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

replace (
// 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-20231024060913-70d774cdaecb
github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5
// Required at the moment until a bug in the comsos-sdk is fixed.
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
Expand Down
4 changes: 2 additions & 2 deletions cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,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-20231024060913-70d774cdaecb h1:4oWKO5gaauAaOqAuVFz1J0/5+raBtr+SZuFNOU9HQn0=
github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5 h1:qqyoNcIlOSnIuCmofS6HRSrEXcAupPlqgEFtQij35E0=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
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=
Expand Down
4 changes: 4 additions & 0 deletions cosmos/x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func NewKeeper(
}
}

func (k *Keeper) SetCommitStore(s storetypes.CommitMultiStore) {
k.Host.sp.SetCommitStore(s)
}

func (k *Keeper) Setup(chain Blockchain) error {
k.chain = chain
return k.SetupPrecompiles()
Expand Down
58 changes: 32 additions & 26 deletions cosmos/x/evm/plugins/state/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package state

import (
"context"
"errors"
"math/big"
"sync"

Expand Down Expand Up @@ -63,6 +62,7 @@ type Plugin interface {
SetGasConfig(storetypes.GasConfig, storetypes.GasConfig)
// SetPrecompileLogFactory sets the precompile log factory for the plugin.
SetPrecompileLogFactory(events.PrecompileLogFactory)
SetCommitStore(storetypes.CommitMultiStore)
}

// The StatePlugin is a very fun and interesting part of the EVM implementation. But if you want to
Expand Down Expand Up @@ -114,6 +114,8 @@ type plugin struct {
dbErr error

mu sync.Mutex

rms NullCommiter
}

// NewPlugin returns a plugin with the given context and keepers.
Expand Down Expand Up @@ -516,43 +518,29 @@ func (p *plugin) IterateBalances(fn func(common.Address, *big.Int) bool) {
}
}

func (p *plugin) SetCommitStore(s storetypes.CommitMultiStore) {
p.rms = NullCommiter{CommitMultiStore: s}
}

// =============================================================================
// Historical State
// =============================================================================

// StateAtBlockNumber implements `core.StatePlugin`.
func (p *plugin) StateAtBlockNumber(number uint64) (core.StatePlugin, error) {
var ctx sdk.Context
// Ensure the query context function is set.
if p.qfn == nil {
return nil, errors.New("no query context function set in host chain")
}

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() {
// TODO: Manager properly
if p.latestQueryContext.MultiStore() == nil {
ctx = p.latestQueryContext.WithEventManager(sdk.NewEventManager())
} else {
ctx, _ = p.latestQueryContext.CacheContext()
}
} else {
// Get the query context at the given height.
var err error
ctx, err = p.qfn()(int64Number, false)
if err != nil {
return nil, err
}
ms, err := p.rms.CacheMultiStoreWithVersion(int64(number))
if err != nil {
ms = p.rms.CacheMultiStore()
}

ctx = ctx.WithMultiStore(NullCacher{CacheMultiAlias: ms}).WithEventManager(sdk.NewEventManager()).
WithGasMeter(storetypes.NewInfiniteGasMeter()).WithKVGasConfig(storetypes.GasConfig{})

// 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)
}
sp.Reset(ctx)
return sp, nil
}

Expand All @@ -575,3 +563,21 @@ func (p *plugin) Clone() ethstate.Plugin {
func (p *plugin) SetGasConfig(kvGasConfig, transientKVGasConfig storetypes.GasConfig) {
p.ctx = p.ctx.WithKVGasConfig(kvGasConfig).WithTransientKVGasConfig(transientKVGasConfig)
}

type NullCommiter struct {
storetypes.CommitMultiStore
}

func (NullCommiter) Commit() storetypes.CommitID {
return storetypes.CommitID{}
}

type CacheMultiAlias = storetypes.CacheMultiStore

type NullCacher struct {
CacheMultiAlias
}

func (NullCacher) Write() {
// no-opf
}
1 change: 1 addition & 0 deletions e2e/testapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func NewPolarisApp(

// Build the app using the app builder.
app.App = appBuilder.Build(db, traceStore, baseAppOptions...)
app.EVMKeeper.SetCommitStore(app.CommitMultiStore())
app.Polaris = polarruntime.New(
evmconfig.MustReadConfigFromAppOpts(appOpts), app.Logger(), app.EVMKeeper.Host, nil,
)
Expand Down
3 changes: 1 addition & 2 deletions e2e/testapp/docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
events {}

http {
upstream nodes {
sticky;
server polard-node0:8545;
server polard-node1:8545;
server polard-node2:8545;
Expand Down
2 changes: 1 addition & 1 deletion e2e/testapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

replace (
// 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-20231024060913-70d774cdaecb
github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5
// Required at the moment until a bug in the comsos-sdk is fixed.
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
Expand Down
4 changes: 2 additions & 2 deletions e2e/testapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-20231024060913-70d774cdaecb h1:4oWKO5gaauAaOqAuVFz1J0/5+raBtr+SZuFNOU9HQn0=
github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5 h1:qqyoNcIlOSnIuCmofS6HRSrEXcAupPlqgEFtQij35E0=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
Expand Down
2 changes: 1 addition & 1 deletion eth/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module pkg.berachain.dev/polaris/eth
go 1.21

// We replace `go-ethereum` with `polaris-geth` in order include our required changes.
replace github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb
replace github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5

require (
github.com/ethereum/go-ethereum v1.13.1
Expand Down
4 changes: 2 additions & 2 deletions eth/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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-20231024060913-70d774cdaecb h1:4oWKO5gaauAaOqAuVFz1J0/5+raBtr+SZuFNOU9HQn0=
github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5 h1:qqyoNcIlOSnIuCmofS6HRSrEXcAupPlqgEFtQij35E0=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/bits-and-blooms/bitset v1.8.0 h1:FD+XqgOZDUxxZ8hzoBFuV9+cGWY9CslN6d5MS5JVb4c=
github.com/bits-and-blooms/bitset v1.8.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
Expand Down
4 changes: 2 additions & 2 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,11 @@ github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd3
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible h1:Ppm0npCCsmuR9oQaBtRuZcmILVE74aXE+AmrJj8L2ns=
github.com/berachain/polaris-geth 88eca5365ecc96474ca94bd4f0d8d9d99bed2a09 h1:qqyoNcIlOSnIuCmofS6HRSrEXcAupPlqgEFtQij35E0=
github.com/berachain/polaris-geth 88eca5365ecc96474ca94bd4f0d8d9d99bed2a09/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5 h1:qqyoNcIlOSnIuCmofS6HRSrEXcAupPlqgEFtQij35E0=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231024032003-b94ca5da2234/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231024032731-4fdd2b9deba9/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231024043959-88eca5365ecc/go.mod h1:I0U5VewuuTzvBtVzKo7b3hJzDhXOUtn9mJW7SsIPB0Q=
github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb h1:4oWKO5gaauAaOqAuVFz1J0/5+raBtr+SZuFNOU9HQn0=
github.com/berachain/polaris-geth v0.0.0-20231024060913-70d774cdaecb/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/bits-and-blooms/bitset v1.7.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
Expand Down

0 comments on commit 562929a

Please sign in to comment.