@@ -14,8 +14,10 @@ import (
14
14
"sync"
15
15
"time"
16
16
17
+ "github.com/cosmos/cosmos-sdk/server"
17
18
"github.com/gorilla/mux"
18
19
"github.com/rakyll/statik/fs"
20
+ "github.com/sei-protocol/sei-db/ss"
19
21
20
22
"github.com/ethereum/go-ethereum/ethclient"
21
23
ethrpc "github.com/ethereum/go-ethereum/rpc"
@@ -26,14 +28,6 @@ import (
26
28
27
29
storetypes "github.com/cosmos/cosmos-sdk/store/types"
28
30
29
- "github.com/sei-protocol/sei-chain/aclmapping"
30
- aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
31
- appparams "github.com/sei-protocol/sei-chain/app/params"
32
- "github.com/sei-protocol/sei-chain/app/upgrades"
33
- v0upgrade "github.com/sei-protocol/sei-chain/app/upgrades/v0"
34
- "github.com/sei-protocol/sei-chain/utils"
35
- "github.com/sei-protocol/sei-chain/wasmbinding"
36
-
37
31
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
38
32
"github.com/cosmos/cosmos-sdk/baseapp"
39
33
"github.com/cosmos/cosmos-sdk/client"
@@ -47,27 +41,26 @@ import (
47
41
"github.com/cosmos/cosmos-sdk/simapp"
48
42
sdk "github.com/cosmos/cosmos-sdk/types"
49
43
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
44
+ sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
50
45
"github.com/cosmos/cosmos-sdk/types/module"
51
46
"github.com/cosmos/cosmos-sdk/version"
52
- "github.com/cosmos/cosmos-sdk/x/auth"
53
- "github.com/cosmos/cosmos-sdk/x/auth/ante"
54
- "github.com/cosmos/cosmos-sdk/x/authz"
55
- authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
56
- authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
57
-
58
- sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
59
47
aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol"
60
48
aclclient "github.com/cosmos/cosmos-sdk/x/accesscontrol/client"
61
49
aclconstants "github.com/cosmos/cosmos-sdk/x/accesscontrol/constants"
62
50
aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper"
63
51
acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types"
52
+ "github.com/cosmos/cosmos-sdk/x/auth"
53
+ "github.com/cosmos/cosmos-sdk/x/auth/ante"
64
54
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
65
55
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
66
56
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
67
57
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
68
58
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
69
59
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
70
60
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
61
+ "github.com/cosmos/cosmos-sdk/x/authz"
62
+ authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
63
+ authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
71
64
"github.com/cosmos/cosmos-sdk/x/bank"
72
65
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
73
66
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
@@ -118,18 +111,25 @@ import (
118
111
ibcporttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
119
112
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
120
113
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
121
- "github.com/sei-protocol/sei-chain/x/mint"
122
- mintclient "github.com/sei-protocol/sei-chain/x/mint/client/cli"
123
- mintkeeper "github.com/sei-protocol/sei-chain/x/mint/keeper"
124
- minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
125
-
114
+ "github.com/sei-protocol/sei-chain/aclmapping"
115
+ aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
116
+ appparams "github.com/sei-protocol/sei-chain/app/params"
117
+ "github.com/sei-protocol/sei-chain/app/upgrades"
118
+ v0upgrade "github.com/sei-protocol/sei-chain/app/upgrades/v0"
119
+ "github.com/sei-protocol/sei-chain/utils"
120
+ "github.com/sei-protocol/sei-chain/wasmbinding"
126
121
"github.com/sei-protocol/sei-chain/x/evm"
127
122
evmante "github.com/sei-protocol/sei-chain/x/evm/ante"
128
123
"github.com/sei-protocol/sei-chain/x/evm/blocktest"
129
124
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
130
125
"github.com/sei-protocol/sei-chain/x/evm/querier"
131
126
"github.com/sei-protocol/sei-chain/x/evm/replay"
132
127
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
128
+ "github.com/sei-protocol/sei-chain/x/mint"
129
+ mintclient "github.com/sei-protocol/sei-chain/x/mint/client/cli"
130
+ mintkeeper "github.com/sei-protocol/sei-chain/x/mint/keeper"
131
+ minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
132
+ seidb "github.com/sei-protocol/sei-db/ss/types"
133
133
"github.com/spf13/cast"
134
134
abci "github.com/tendermint/tendermint/abci/types"
135
135
tmcfg "github.com/tendermint/tendermint/config"
@@ -166,6 +166,8 @@ import (
166
166
167
167
// unnamed import of statik for openapi/swagger UI support
168
168
_ "github.com/sei-protocol/sei-chain/docs/swagger"
169
+
170
+ ssconfig "github.com/sei-protocol/sei-db/config"
169
171
)
170
172
171
173
// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
@@ -264,7 +266,8 @@ var (
264
266
// EmptyAclmOpts defines a type alias for a list of wasm options.
265
267
EmptyACLOpts []aclkeeper.Option
266
268
// EnableOCC allows tests to override default OCC enablement behavior
267
- EnableOCC = true
269
+ EnableOCC = true
270
+ EmptyAppOptions []AppOption
268
271
)
269
272
270
273
var (
@@ -382,8 +385,12 @@ type App struct {
382
385
encodingConfig appparams.EncodingConfig
383
386
evmRPCConfig evmrpc.Config
384
387
lightInvarianceConfig LightInvarianceConfig
388
+
389
+ receiptStore seidb.StateStore
385
390
}
386
391
392
+ type AppOption func (* App )
393
+
387
394
// New returns a reference to an initialized blockchain app
388
395
func New (
389
396
logger log.Logger ,
@@ -400,13 +407,15 @@ func New(
400
407
appOpts servertypes.AppOptions ,
401
408
wasmOpts []wasm.Option ,
402
409
aclOpts []aclkeeper.Option ,
410
+ appOptions []AppOption ,
403
411
baseAppOptions ... func (* baseapp.BaseApp ),
404
412
) * App {
405
413
appCodec := encodingConfig .Marshaler
406
414
cdc := encodingConfig .Amino
407
415
interfaceRegistry := encodingConfig .InterfaceRegistry
408
416
409
417
bAppOptions := SetupSeiDB (logger , homePath , appOpts , baseAppOptions )
418
+
410
419
bApp := baseapp .NewBaseApp (AppName , logger , db , encodingConfig .TxConfig .TxDecoder (), tmConfig , appOpts , bAppOptions ... )
411
420
bApp .SetCommitMultiStoreTracer (traceStore )
412
421
bApp .SetVersion (version .Version )
@@ -423,7 +432,7 @@ func New(
423
432
tokenfactorytypes .StoreKey ,
424
433
// this line is used by starport scaffolding # stargate/app/storeKey
425
434
)
426
- tkeys := sdk .NewTransientStoreKeys (paramstypes .TStoreKey )
435
+ tkeys := sdk .NewTransientStoreKeys (paramstypes .TStoreKey , evmtypes . TransientStoreKey )
427
436
memKeys := sdk .NewMemoryStoreKeys (capabilitytypes .MemStoreKey , dexmoduletypes .MemStoreKey , banktypes .DeferredCacheStoreKey , evmtypes .MemStoreKey , oracletypes .MemStoreKey )
428
437
429
438
app := & App {
@@ -440,6 +449,11 @@ func New(
440
449
metricCounter : & map [string ]float32 {},
441
450
encodingConfig : encodingConfig ,
442
451
}
452
+
453
+ for _ , option := range appOptions {
454
+ option (app )
455
+ }
456
+
443
457
app .ParamsKeeper = initParamsKeeper (appCodec , cdc , keys [paramstypes .StoreKey ], tkeys [paramstypes .TStoreKey ])
444
458
445
459
// set the BaseApp's parameter store
@@ -596,9 +610,26 @@ func New(
596
610
wasmOpts ... ,
597
611
)
598
612
613
+ receiptStorePath := filepath .Join (homePath , "data" , "receipt.db" )
614
+ ssConfig := ssconfig .DefaultStateStoreConfig ()
615
+ ssConfig .DedicatedChangelog = true
616
+ ssConfig .KeepRecent = cast .ToInt (appOpts .Get (server .FlagMinRetainBlocks ))
617
+ ssConfig .DBDirectory = receiptStorePath
618
+ ssConfig .KeepLastVersion = false
619
+ if app .receiptStore == nil {
620
+ app .receiptStore , err = ss .NewStateStore (logger , receiptStorePath , ssConfig )
621
+ if err != nil {
622
+ panic (fmt .Sprintf ("error while creating receipt store: %s" , err ))
623
+ }
624
+ }
599
625
app .EvmKeeper = * evmkeeper .NewKeeper (keys [evmtypes .StoreKey ], memKeys [evmtypes .MemStoreKey ],
600
- app .GetSubspace (evmtypes .ModuleName ), app .BankKeeper , & app .AccountKeeper , & app .StakingKeeper ,
601
- app .TransferKeeper , wasmkeeper .NewDefaultPermissionKeeper (app .WasmKeeper ), & app .WasmKeeper )
626
+ tkeys [evmtypes .TransientStoreKey ], app .GetSubspace (evmtypes .ModuleName ), app .receiptStore , app .BankKeeper ,
627
+ & app .AccountKeeper , & app .StakingKeeper , app .TransferKeeper ,
628
+ wasmkeeper .NewDefaultPermissionKeeper (app .WasmKeeper ), & app .WasmKeeper )
629
+
630
+ bApp .SetPreCommitHandler (app .HandlePreCommit )
631
+ bApp .SetCloseHandler (app .HandleClose )
632
+
602
633
app .evmRPCConfig , err = evmrpc .ReadConfig (appOpts )
603
634
if err != nil {
604
635
panic (fmt .Sprintf ("error reading EVM config due to %s" , err ))
@@ -970,6 +1001,19 @@ func New(
970
1001
return app
971
1002
}
972
1003
1004
+ // HandlePreCommit happens right before the block is committed
1005
+ func (app * App ) HandlePreCommit (ctx sdk.Context ) error {
1006
+ return app .EvmKeeper .FlushTransientReceipts (ctx )
1007
+ }
1008
+
1009
+ // Close closes all items that needs closing (called by baseapp)
1010
+ func (app * App ) HandleClose () error {
1011
+ if app .receiptStore != nil {
1012
+ return app .receiptStore .Close ()
1013
+ }
1014
+ return nil
1015
+ }
1016
+
973
1017
// Add (or remove) keepers when they are introduced / removed in different versions
974
1018
func (app * App ) SetStoreUpgradeHandlers () {
975
1019
upgradeInfo , err := app .UpgradeKeeper .ReadUpgradeInfoFromDisk ()
0 commit comments