From 562929a5072c258a568fc572f8d6badb22e2cecb Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Fri, 27 Oct 2023 13:45:03 -0400 Subject: [PATCH] ree --- cosmos/go.mod | 2 +- cosmos/go.sum | 4 +- cosmos/x/evm/keeper/keeper.go | 4 ++ cosmos/x/evm/plugins/state/plugin.go | 58 +++++++++++++++------------- e2e/testapp/app.go | 1 + e2e/testapp/docker/nginx.conf | 3 +- e2e/testapp/go.mod | 2 +- e2e/testapp/go.sum | 4 +- eth/go.mod | 2 +- eth/go.sum | 4 +- go.work.sum | 4 +- 11 files changed, 49 insertions(+), 39 deletions(-) diff --git a/cosmos/go.mod b/cosmos/go.mod index a1a613ee9..a3d42f267 100644 --- a/cosmos/go.mod +++ b/cosmos/go.mod @@ -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 ) diff --git a/cosmos/go.sum b/cosmos/go.sum index 1f6df1825..159631882 100644 --- a/cosmos/go.sum +++ b/cosmos/go.sum @@ -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= diff --git a/cosmos/x/evm/keeper/keeper.go b/cosmos/x/evm/keeper/keeper.go index ec6024841..fc42e0243 100644 --- a/cosmos/x/evm/keeper/keeper.go +++ b/cosmos/x/evm/keeper/keeper.go @@ -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() diff --git a/cosmos/x/evm/plugins/state/plugin.go b/cosmos/x/evm/plugins/state/plugin.go index ab4c9b470..7f0ac9c6e 100644 --- a/cosmos/x/evm/plugins/state/plugin.go +++ b/cosmos/x/evm/plugins/state/plugin.go @@ -22,7 +22,6 @@ package state import ( "context" - "errors" "math/big" "sync" @@ -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 @@ -114,6 +114,8 @@ type plugin struct { dbErr error mu sync.Mutex + + rms NullCommiter } // NewPlugin returns a plugin with the given context and keepers. @@ -516,6 +518,10 @@ 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 // ============================================================================= @@ -523,36 +529,18 @@ func (p *plugin) IterateBalances(fn func(common.Address, *big.Int) bool) { // 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 } @@ -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 +} diff --git a/e2e/testapp/app.go b/e2e/testapp/app.go index a3db0b32c..68693a059 100644 --- a/e2e/testapp/app.go +++ b/e2e/testapp/app.go @@ -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, ) diff --git a/e2e/testapp/docker/nginx.conf b/e2e/testapp/docker/nginx.conf index 45a4e4748..b6db7d843 100644 --- a/e2e/testapp/docker/nginx.conf +++ b/e2e/testapp/docker/nginx.conf @@ -1,7 +1,6 @@ -events {} - http { upstream nodes { + sticky; server polard-node0:8545; server polard-node1:8545; server polard-node2:8545; diff --git a/e2e/testapp/go.mod b/e2e/testapp/go.mod index 8b215a9f9..c0f00b39e 100644 --- a/e2e/testapp/go.mod +++ b/e2e/testapp/go.mod @@ -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 ) diff --git a/e2e/testapp/go.sum b/e2e/testapp/go.sum index fe92b27de..07123fe90 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-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= diff --git a/eth/go.mod b/eth/go.mod index 61bf0bf3d..1b80492fd 100644 --- a/eth/go.mod +++ b/eth/go.mod @@ -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 diff --git a/eth/go.sum b/eth/go.sum index f06c23952..e9aaff742 100644 --- a/eth/go.sum +++ b/eth/go.sum @@ -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= diff --git a/go.work.sum b/go.work.sum index 434c59b6e..b985efc4a 100644 --- a/go.work.sum +++ b/go.work.sum @@ -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=