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

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Nov 2, 2023
2 parents e10c202 + a097397 commit b606312
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 21 deletions.
1 change: 1 addition & 0 deletions cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4M
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 h1:T+Np/xtzIjYM/P5NAw0e2Rf1FGvzDau1h54MKvx8G7w=
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7HpxfjgkzCGz6s=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
Expand Down
18 changes: 13 additions & 5 deletions cosmos/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

"github.com/cosmos/gogoproto/proto"

storetypes "cosmossdk.io/store/types"

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

"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -100,11 +102,6 @@ func (m *Miner) PrepareProposal(
ethGasUsed uint64
)

// We have to prime the state plugin.
if err = m.keeper.SetLatestQueryContext(ctx); err != nil {
return nil, err
}

// 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, nil); err != nil {
Expand All @@ -113,6 +110,17 @@ func (m *Miner) PrepareProposal(
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
}

// Trigger the geth miner to build a block.
if payloadEnvelopeBz, ethGasUsed, err = m.buildBlock(ctx); err != nil {
return nil, err
Expand Down
14 changes: 5 additions & 9 deletions cosmos/x/evm/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ import (
)

// Precommit runs on the Cosmo-SDK lifecycle Precommit().
func (k *Keeper) Precommit(ctx context.Context) error {
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.chain.GetBlockByNumber(blockNum)
if block == nil {
panic(
fmt.Sprintf(
"EVM BLOCK %d FAILED TO PROCESS", blockNum,
),
return fmt.Errorf(
"evm block %d failed to process", blockNum,
)
} else if block.NumberU64() != blockNum {
panic(
fmt.Sprintf(
"EVM BLOCK [%d] DOES NOT MATCH COMET BLOCK [%d]", block.NumberU64(), blockNum,
),
return fmt.Errorf(
"evm block [%d] does not match comet block [%d]", block.NumberU64(), blockNum,
)
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions cosmos/x/evm/keeper/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"context"
"fmt"

storetypes "cosmossdk.io/store/types"

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

"github.com/ethereum/go-ethereum/beacon/engine"
Expand Down Expand Up @@ -61,6 +63,8 @@ func (k *Keeper) ProcessPayloadEnvelope(
}

// Prepare should be moved to the blockchain? THIS IS VERY HOOD YES NEEDS TO BE MOVED.
ctx = sCtx.WithKVGasConfig(storetypes.GasConfig{}).
WithTransientKVGasConfig(storetypes.GasConfig{})
k.chain.PreparePlugins(ctx)
if err = k.chain.InsertBlockAndSetHead(block); err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions cosmos/x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const ConsensusVersion = 1
var (
_ appmodule.HasServices = AppModule{}
_ appmodule.HasPrepareCheckState = AppModule{}
_ appmodule.HasPrecommit = AppModule{}
_ appmodule.HasEndBlocker = AppModule{}
_ module.AppModule = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
)
Expand Down Expand Up @@ -132,6 +132,6 @@ func (am AppModule) PrepareCheckState(ctx context.Context) error {
}

// Precommit performs precommit operations.
func (am AppModule) Precommit(ctx context.Context) error {
return am.keeper.Precommit(ctx)
func (am AppModule) EndBlock(ctx context.Context) error {
return am.keeper.EndBlock(ctx)
}
4 changes: 1 addition & 3 deletions e2e/testapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,12 @@ func MakeAppConfig(bech32Prefix string) depinject.Config {
genutiltypes.ModuleName,
},
EndBlockers: []string{
evmtypes.ModuleName,
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
genutiltypes.ModuleName,
},
Precommiters: []string{
evmtypes.ModuleName,
},
OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{
{
ModuleName: authtypes.ModuleName,
Expand Down
1 change: 1 addition & 0 deletions e2e/testapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ github.com/cockroachdb/errors v1.11.1/go.mod h1:8MUxA3Gi6b25tYlFEBGLf+D8aISL+M4M
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 h1:T+Np/xtzIjYM/P5NAw0e2Rf1FGvzDau1h54MKvx8G7w=
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06/go.mod h1:bynZ3gvVyhlvjLI7PT6dmZ7g76xzJ7HpxfjgkzCGz6s=
github.com/cockroachdb/redact v1.1.5 h1:u1PMllDkdFfPWaNGMyLD1+so+aq3uUItthCFqzwPJ30=
github.com/cockroachdb/redact v1.1.5/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
Expand Down
Loading

0 comments on commit b606312

Please sign in to comment.