@@ -2,15 +2,21 @@ package app
22
33import (
44 "encoding/json"
5- "fmt"
65 "io"
76 "os"
87 "path/filepath"
98
9+ "fairyring/blockbuster/abci"
10+ "fairyring/blockbuster/lanes/base"
11+
12+ blockbuster "fairyring/blockbuster"
13+
14+ keyshare "fairyring/blockbuster/lanes/keyshare"
15+
1016 autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
1117 reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
1218 dbm "github.com/cometbft/cometbft-db"
13- abci "github.com/cometbft/cometbft/abci/types"
19+ cometabci "github.com/cometbft/cometbft/abci/types"
1420 "github.com/cometbft/cometbft/libs/log"
1521 tmos "github.com/cometbft/cometbft/libs/os"
1622 "github.com/cosmos/cosmos-sdk/baseapp"
@@ -124,6 +130,7 @@ import (
124130const (
125131 AccountAddressPrefix = "fairy"
126132 Name = "fairyring"
133+ ChainID = "fairytest-1"
127134)
128135
129136// this line is used by starport scaffolding # stargate/wasm/app/enabledProposals
@@ -215,6 +222,7 @@ type App struct {
215222 cdc * codec.LegacyAmino
216223 appCodec codec.Codec
217224 interfaceRegistry types.InterfaceRegistry
225+ txConfig client.TxConfig
218226
219227 invCheckPeriod uint
220228
@@ -260,6 +268,9 @@ type App struct {
260268 // sm is the simulation manager
261269 sm * module.SimulationManager
262270 configurator module.Configurator
271+
272+ // Custom checkTx handler
273+ checkTxHandler abci.CheckTx
263274}
264275
265276// New returns a reference to an initialized blockchain app
@@ -308,6 +319,7 @@ func New(
308319 cdc : cdc ,
309320 appCodec : appCodec ,
310321 interfaceRegistry : interfaceRegistry ,
322+ txConfig : encodingConfig .TxConfig ,
311323 invCheckPeriod : invCheckPeriod ,
312324 keys : keys ,
313325 tkeys : tkeys ,
@@ -369,6 +381,98 @@ func New(
369381 authtypes .NewModuleAddress (govtypes .ModuleName ).String (),
370382 )
371383
384+ // ---------------------------------------------------------------------------- //
385+ // ------------------------- Begin Custom Code -------------------------------- //
386+ // ---------------------------------------------------------------------------- //
387+
388+ // Set fairyring's mempool into the app.
389+ config := blockbuster.BaseLaneConfig {
390+ Logger : app .Logger (),
391+ TxEncoder : app .txConfig .TxEncoder (),
392+ TxDecoder : app .txConfig .TxDecoder (),
393+ MaxBlockSpace : sdk .ZeroDec (),
394+ }
395+
396+ // Create the lanes.
397+ //
398+ // NOTE: The lanes are ordered by priority. The first lane is the highest priority
399+ // lane and the last lane is the lowest priority lane.
400+
401+ // Keyshare lane allows for CreateAggrgatedKeyShare transactions to be processed before others.
402+ keyshareLane := keyshare .NewKeyShareLane (
403+ config ,
404+ 0 ,
405+ keyshare .NewDefaultKeyshareFactory (app .txConfig .TxDecoder ()),
406+ )
407+
408+ // Default lane accepts all other transactions.
409+ defaultConfig := blockbuster.BaseLaneConfig {
410+ Logger : app .Logger (),
411+ TxEncoder : app .txConfig .TxEncoder (),
412+ TxDecoder : app .txConfig .TxDecoder (),
413+ MaxBlockSpace : sdk .ZeroDec (),
414+ IgnoreList : []blockbuster.Lane {
415+ keyshareLane ,
416+ },
417+ }
418+ defaultLane := base .NewDefaultLane (defaultConfig )
419+
420+ lanes := []blockbuster.Lane {
421+ keyshareLane ,
422+ defaultLane ,
423+ }
424+
425+ mempool := blockbuster .NewMempool (lanes ... )
426+ app .BaseApp .SetMempool (mempool )
427+
428+ // Create a global ante handler that will be called on each transaction when
429+ // proposals are being built and verified.
430+ handlerOptions := ante.HandlerOptions {
431+ AccountKeeper : app .AccountKeeper ,
432+ BankKeeper : app .BankKeeper ,
433+ FeegrantKeeper : app .FeeGrantKeeper ,
434+ SigGasConsumer : ante .DefaultSigVerificationGasConsumer ,
435+ SignModeHandler : app .txConfig .SignModeHandler (),
436+ }
437+ options := FairyringHandlerOptions {
438+ BaseOptions : handlerOptions ,
439+ PepKeeper : app .PepKeeper ,
440+ TxDecoder : app .txConfig .TxDecoder (),
441+ TxEncoder : app .txConfig .TxEncoder (),
442+ KeyShareLane : keyshareLane ,
443+ Mempool : mempool ,
444+ }
445+ anteHandler := NewFairyringAnteHandler (options )
446+
447+ // Set the lane config on the lanes.
448+ for _ , lane := range lanes {
449+ lane .SetAnteHandler (anteHandler )
450+ }
451+
452+ // Set the proposal handlers on the BaseApp along with the custom antehandler.
453+ proposalHandlers := abci .NewProposalHandler (
454+ app .Logger (),
455+ app .txConfig .TxDecoder (),
456+ mempool ,
457+ )
458+ app .BaseApp .SetPrepareProposal (proposalHandlers .PrepareProposalHandler ())
459+ app .BaseApp .SetProcessProposal (proposalHandlers .ProcessProposalHandler ())
460+ app .BaseApp .SetAnteHandler (anteHandler )
461+
462+ // Set the custom CheckTx handler on BaseApp.
463+ checkTxHandler := abci .NewCheckTxHandler (
464+ app .BaseApp ,
465+ app .txConfig .TxDecoder (),
466+ keyshareLane ,
467+ anteHandler ,
468+ ChainID ,
469+ )
470+ app .SetCheckTx (checkTxHandler .CheckTx ())
471+
472+ // ---------------------------------------------------------------------------- //
473+ // ------------------------- End Custom Code ---------------------------------- //
474+ // ---------------------------------------------------------------------------- //
475+
372476 app .StakingKeeper = stakingkeeper .NewKeeper (
373477 appCodec ,
374478 keys [stakingtypes .StoreKey ],
@@ -740,21 +844,6 @@ func New(
740844 app .MountTransientStores (tkeys )
741845 app .MountMemoryStores (memKeys )
742846
743- // initialize BaseApp
744- anteHandler , err := ante .NewAnteHandler (
745- ante.HandlerOptions {
746- AccountKeeper : app .AccountKeeper ,
747- BankKeeper : app .BankKeeper ,
748- SignModeHandler : encodingConfig .TxConfig .SignModeHandler (),
749- FeegrantKeeper : app .FeeGrantKeeper ,
750- SigGasConsumer : ante .DefaultSigVerificationGasConsumer ,
751- },
752- )
753- if err != nil {
754- panic (fmt .Errorf ("failed to create AnteHandler: %w" , err ))
755- }
756-
757- app .SetAnteHandler (anteHandler )
758847 app .SetInitChainer (app .InitChainer )
759848 app .SetBeginBlocker (app .BeginBlocker )
760849 app .SetEndBlocker (app .EndBlocker )
@@ -777,17 +866,17 @@ func New(
777866func (app * App ) Name () string { return app .BaseApp .Name () }
778867
779868// BeginBlocker application updates every begin block
780- func (app * App ) BeginBlocker (ctx sdk.Context , req abci .RequestBeginBlock ) abci .ResponseBeginBlock {
869+ func (app * App ) BeginBlocker (ctx sdk.Context , req cometabci .RequestBeginBlock ) cometabci .ResponseBeginBlock {
781870 return app .mm .BeginBlock (ctx , req )
782871}
783872
784873// EndBlocker application updates every end block
785- func (app * App ) EndBlocker (ctx sdk.Context , req abci .RequestEndBlock ) abci .ResponseEndBlock {
874+ func (app * App ) EndBlocker (ctx sdk.Context , req cometabci .RequestEndBlock ) cometabci .ResponseEndBlock {
786875 return app .mm .EndBlock (ctx , req )
787876}
788877
789878// InitChainer application update at chain initialization
790- func (app * App ) InitChainer (ctx sdk.Context , req abci .RequestInitChain ) abci .ResponseInitChain {
879+ func (app * App ) InitChainer (ctx sdk.Context , req cometabci .RequestInitChain ) cometabci .ResponseInitChain {
791880 var genesisState GenesisState
792881 if err := json .Unmarshal (req .AppStateBytes , & genesisState ); err != nil {
793882 panic (err )
@@ -954,3 +1043,8 @@ func (app *App) SimulationManager() *module.SimulationManager {
9541043func (app * App ) ModuleManager () * module.Manager {
9551044 return app .mm
9561045}
1046+
1047+ // SetCheckTx sets the checkTxHandler for the app.
1048+ func (app * App ) SetCheckTx (handler abci.CheckTx ) {
1049+ app .checkTxHandler = handler
1050+ }
0 commit comments