Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EVM] Add transient receipts with eventual flush to store #1742

Merged
merged 27 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
90d53e6
add transient receipts
stevenlanders Jun 21, 2024
1c6dfc9
add state store to keeper
stevenlanders Jun 25, 2024
289434b
avoid using ctx evm store
stevenlanders Jun 25, 2024
7bde4f7
goimports
stevenlanders Jun 25, 2024
7bf55e9
Merge conflicts
yzang2019 Jun 25, 2024
3ba4688
Update cosmos
yzang2019 Jun 25, 2024
98385e5
Add backend
yzang2019 Jun 25, 2024
e514541
add close function
stevenlanders Jun 25, 2024
8c7e16c
add debug lines
stevenlanders Jun 25, 2024
f1b7bf3
include prefix on write
stevenlanders Jun 25, 2024
c05acee
Fix initialization logic
yzang2019 Jun 26, 2024
7443743
rename close to handle close
stevenlanders Jun 26, 2024
c847aff
remove transient deletion
stevenlanders Jun 26, 2024
ab1b6e0
Update seidb version
yzang2019 Jun 26, 2024
df7363c
update sei-cosmos
stevenlanders Jun 26, 2024
4127b51
add in-memory state store for tests
stevenlanders Jun 26, 2024
5409b38
Set KeepLastVersion to false
yzang2019 Jun 26, 2024
0c685ea
fix mocking of receipts
stevenlanders Jun 26, 2024
a13a453
flush after receipts exist
stevenlanders Jun 26, 2024
dd2415e
add transient->pebble->legacy fallback
stevenlanders Jun 26, 2024
86d36f8
make error name consistent
stevenlanders Jun 26, 2024
b8f98a3
avoid reading from transient store
stevenlanders Jun 26, 2024
c72564e
use latest version
stevenlanders Jun 26, 2024
2e2a3f6
fix goimports
stevenlanders Jun 26, 2024
f4780e8
add test coverage for test state store
stevenlanders Jun 26, 2024
868fde9
Merge branch 'main' into add-transient-receipts
stevenlanders Jun 26, 2024
7876601
tick sei-cosmos
stevenlanders Jun 27, 2024
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
92 changes: 68 additions & 24 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"sync"
"time"

"github.com/cosmos/cosmos-sdk/server"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/sei-protocol/sei-db/ss"

"github.com/ethereum/go-ethereum/ethclient"
ethrpc "github.com/ethereum/go-ethereum/rpc"
Expand All @@ -26,14 +28,6 @@ import (

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

"github.com/sei-protocol/sei-chain/aclmapping"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
appparams "github.com/sei-protocol/sei-chain/app/params"
"github.com/sei-protocol/sei-chain/app/upgrades"
v0upgrade "github.com/sei-protocol/sei-chain/app/upgrades/v0"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/wasmbinding"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand All @@ -47,27 +41,26 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol"
aclclient "github.com/cosmos/cosmos-sdk/x/accesscontrol/client"
aclconstants "github.com/cosmos/cosmos-sdk/x/accesscontrol/constants"
aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper"
acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -118,18 +111,25 @@ import (
ibcporttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
"github.com/sei-protocol/sei-chain/x/mint"
mintclient "github.com/sei-protocol/sei-chain/x/mint/client/cli"
mintkeeper "github.com/sei-protocol/sei-chain/x/mint/keeper"
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"

"github.com/sei-protocol/sei-chain/aclmapping"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
appparams "github.com/sei-protocol/sei-chain/app/params"
"github.com/sei-protocol/sei-chain/app/upgrades"
v0upgrade "github.com/sei-protocol/sei-chain/app/upgrades/v0"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/wasmbinding"
"github.com/sei-protocol/sei-chain/x/evm"
evmante "github.com/sei-protocol/sei-chain/x/evm/ante"
"github.com/sei-protocol/sei-chain/x/evm/blocktest"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
"github.com/sei-protocol/sei-chain/x/evm/querier"
"github.com/sei-protocol/sei-chain/x/evm/replay"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/sei-protocol/sei-chain/x/mint"
mintclient "github.com/sei-protocol/sei-chain/x/mint/client/cli"
mintkeeper "github.com/sei-protocol/sei-chain/x/mint/keeper"
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
seidb "github.com/sei-protocol/sei-db/ss/types"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmcfg "github.com/tendermint/tendermint/config"
Expand Down Expand Up @@ -166,6 +166,8 @@ import (

// unnamed import of statik for openapi/swagger UI support
_ "github.com/sei-protocol/sei-chain/docs/swagger"

ssconfig "github.com/sei-protocol/sei-db/config"
)

// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
Expand Down Expand Up @@ -264,7 +266,8 @@ var (
// EmptyAclmOpts defines a type alias for a list of wasm options.
EmptyACLOpts []aclkeeper.Option
// EnableOCC allows tests to override default OCC enablement behavior
EnableOCC = true
EnableOCC = true
EmptyAppOptions []AppOption
)

var (
Expand Down Expand Up @@ -382,8 +385,12 @@ type App struct {
encodingConfig appparams.EncodingConfig
evmRPCConfig evmrpc.Config
lightInvarianceConfig LightInvarianceConfig

receiptStore seidb.StateStore
}

type AppOption func(*App)

// New returns a reference to an initialized blockchain app
func New(
logger log.Logger,
Expand All @@ -400,13 +407,15 @@ func New(
appOpts servertypes.AppOptions,
wasmOpts []wasm.Option,
aclOpts []aclkeeper.Option,
appOptions []AppOption,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
appCodec := encodingConfig.Marshaler
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bAppOptions := SetupSeiDB(logger, homePath, appOpts, baseAppOptions)

bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), tmConfig, appOpts, bAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
Expand All @@ -423,7 +432,7 @@ func New(
tokenfactorytypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey, dexmoduletypes.MemStoreKey, banktypes.DeferredCacheStoreKey, evmtypes.MemStoreKey, oracletypes.MemStoreKey)

app := &App{
Expand All @@ -440,6 +449,11 @@ func New(
metricCounter: &map[string]float32{},
encodingConfig: encodingConfig,
}

for _, option := range appOptions {
option(app)
}

app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])

// set the BaseApp's parameter store
Expand Down Expand Up @@ -596,9 +610,26 @@ func New(
wasmOpts...,
)

receiptStorePath := filepath.Join(homePath, "data", "receipt.db")
ssConfig := ssconfig.DefaultStateStoreConfig()
ssConfig.DedicatedChangelog = true
ssConfig.KeepRecent = cast.ToInt(appOpts.Get(server.FlagMinRetainBlocks))
ssConfig.DBDirectory = receiptStorePath
if app.receiptStore == nil {
app.receiptStore, err = ss.NewStateStore(logger, receiptStorePath, ssConfig)
if err != nil {
panic(fmt.Sprintf("error while creating receipt store: %s", err))
}
}

app.EvmKeeper = *evmkeeper.NewKeeper(keys[evmtypes.StoreKey], memKeys[evmtypes.MemStoreKey],
app.GetSubspace(evmtypes.ModuleName), app.BankKeeper, &app.AccountKeeper, &app.StakingKeeper,
app.TransferKeeper, wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper), &app.WasmKeeper)
tkeys[evmtypes.TransientStoreKey], app.GetSubspace(evmtypes.ModuleName), app.receiptStore, app.BankKeeper,
&app.AccountKeeper, &app.StakingKeeper, app.TransferKeeper,
wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper), &app.WasmKeeper)

bApp.SetPreCommitHandler(app.HandlePreCommit)
bApp.SetCloseHandler(app.HandleClose)

app.evmRPCConfig, err = evmrpc.ReadConfig(appOpts)
if err != nil {
panic(fmt.Sprintf("error reading EVM config due to %s", err))
Expand Down Expand Up @@ -970,6 +1001,19 @@ func New(
return app
}

// HandlePreCommit happens right before the block is committed
func (app *App) HandlePreCommit(ctx sdk.Context) error {
return app.EvmKeeper.FlushTransientReceipts(ctx)
}

// Close closes all items that needs closing (called by baseapp)
func (app *App) HandleClose() error {
if app.receiptStore != nil {
return app.receiptStore.Close()
}
return nil
}

// Add (or remove) keepers when they are introduced / removed in different versions
func (app *App) SetStoreUpgradeHandlers() {
upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
Expand Down
10 changes: 10 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ func Setup(isCheckTx bool, enableEVMCustomPrecompiles bool, baseAppOptions ...fu
db := dbm.NewMemDB()
encodingConfig := MakeEncodingConfig()
cdc := encodingConfig.Marshaler

options := []AppOption{
func(app *App) {
app.receiptStore = NewInMemoryStateStore()
},
}

res = New(
log.NewNopLogger(),
db,
Expand All @@ -192,6 +199,7 @@ func Setup(isCheckTx bool, enableEVMCustomPrecompiles bool, baseAppOptions ...fu
TestAppOpts{},
EmptyWasmOpts,
EmptyACLOpts,
options,
baseAppOptions...,
)
if !isCheckTx {
Expand Down Expand Up @@ -235,6 +243,7 @@ func SetupWithSc(isCheckTx bool, enableEVMCustomPrecompiles bool, baseAppOptions
TestAppOpts{true},
EmptyWasmOpts,
EmptyACLOpts,
EmptyAppOptions,
baseAppOptions...,
)
if !isCheckTx {
Expand Down Expand Up @@ -285,6 +294,7 @@ func SetupTestingAppWithLevelDb(isCheckTx bool, enableEVMCustomPrecompiles bool)
TestAppOpts{},
EmptyWasmOpts,
EmptyACLOpts,
nil,
)
if !isCheckTx {
genesisState := NewDefaultGenesisState(cdc)
Expand Down
Loading
Loading