1
1
package app
2
2
3
3
import (
4
- "crypto/sha256"
5
- "encoding/hex"
6
4
stderrors "errors"
7
5
"fmt"
8
6
"io"
@@ -11,10 +9,10 @@ import (
11
9
"net/http"
12
10
"os"
13
11
"path/filepath"
14
- "sort"
15
12
16
13
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
17
14
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
15
+ "filippo.io/age"
18
16
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
19
17
"golang.org/x/exp/slices"
20
18
@@ -23,6 +21,7 @@ import (
23
21
tmjson "github.com/cometbft/cometbft/libs/json"
24
22
"github.com/cometbft/cometbft/libs/log"
25
23
tmos "github.com/cometbft/cometbft/libs/os"
24
+ tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
26
25
"github.com/cosmos/cosmos-sdk/client"
27
26
"github.com/cosmos/cosmos-sdk/codec/types"
28
27
"github.com/gorilla/mux"
@@ -123,6 +122,7 @@ import (
123
122
icaauthkeeper "github.com/crypto-org-chain/cronos/v2/x/icaauth/keeper"
124
123
icaauthtypes "github.com/crypto-org-chain/cronos/v2/x/icaauth/types"
125
124
125
+ clientflags "github.com/cosmos/cosmos-sdk/client/flags"
126
126
evmante "github.com/evmos/ethermint/app/ante"
127
127
srvflags "github.com/evmos/ethermint/server/flags"
128
128
ethermint "github.com/evmos/ethermint/types"
@@ -159,6 +159,11 @@ import (
159
159
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
160
160
ethparams "github.com/ethereum/go-ethereum/params"
161
161
162
+ e2ee "github.com/crypto-org-chain/cronos/v2/x/e2ee"
163
+ e2eekeeper "github.com/crypto-org-chain/cronos/v2/x/e2ee/keeper"
164
+ e2eekeyring "github.com/crypto-org-chain/cronos/v2/x/e2ee/keyring"
165
+ e2eetypes "github.com/crypto-org-chain/cronos/v2/x/e2ee/types"
166
+
162
167
// force register the extension json-rpc.
163
168
_ "github.com/crypto-org-chain/cronos/v2/x/cronos/rpc"
164
169
)
@@ -170,8 +175,6 @@ const (
170
175
//
171
176
// NOTE: In the SDK, the default value is 255.
172
177
AddrLen = 20
173
-
174
- FlagBlockedAddresses = "blocked-addresses"
175
178
)
176
179
177
180
var Forks = []Fork {}
@@ -260,6 +263,7 @@ func GenModuleBasics() module.BasicManager {
260
263
ibcfee.AppModuleBasic {},
261
264
evm.AppModuleBasic {},
262
265
feemarket.AppModuleBasic {},
266
+ e2ee.AppModuleBasic {},
263
267
// this line is used by starport scaffolding # stargate/app/moduleBasic
264
268
gravity.AppModuleBasic {},
265
269
cronos.AppModuleBasic {},
@@ -286,6 +290,8 @@ func StoreKeys(skipGravity bool) (
286
290
icaauthtypes .StoreKey ,
287
291
// ethermint keys
288
292
evmtypes .StoreKey , feemarkettypes .StoreKey ,
293
+ // e2ee keys
294
+ e2eetypes .StoreKey ,
289
295
// this line is used by starport scaffolding # stargate/app/storeKey
290
296
cronostypes .StoreKey ,
291
297
}
@@ -357,6 +363,9 @@ type App struct {
357
363
// Gravity module
358
364
GravityKeeper gravitykeeper.Keeper
359
365
366
+ // e2ee keeper
367
+ E2EEKeeper e2eekeeper.Keeper
368
+
360
369
// this line is used by starport scaffolding # stargate/app/keeperDeclaration
361
370
362
371
CronosKeeper cronoskeeper.Keeper
@@ -371,6 +380,8 @@ type App struct {
371
380
configurator module.Configurator
372
381
373
382
qms storetypes.MultiStore
383
+
384
+ blockProposalHandler * ProposalHandler
374
385
}
375
386
376
387
// New returns a reference to an initialized chain.
@@ -385,15 +396,37 @@ func New(
385
396
cdc := encodingConfig .Amino
386
397
interfaceRegistry := encodingConfig .InterfaceRegistry
387
398
399
+ var identity age.Identity
400
+ {
401
+ if cast .ToString (appOpts .Get ("mode" )) == "validator" {
402
+ krBackend := cast .ToString (appOpts .Get (clientflags .FlagKeyringBackend ))
403
+ kr , err := e2eekeyring .New ("cronosd" , krBackend , homePath , os .Stdin )
404
+ if err != nil {
405
+ panic (err )
406
+ }
407
+ bz , err := kr .Get (e2eetypes .DefaultKeyringName )
408
+ if err != nil {
409
+ logger .Error ("e2ee identity for validator not found" , "error" , err )
410
+ } else {
411
+ identity , err = age .ParseX25519Identity (string (bz ))
412
+ if err != nil {
413
+ panic (err )
414
+ }
415
+ }
416
+ }
417
+ }
418
+
388
419
baseAppOptions = memiavlstore .SetupMemIAVL (logger , homePath , appOpts , false , false , baseAppOptions )
420
+
421
+ blockProposalHandler := NewProposalHandler (encodingConfig .TxConfig .TxDecoder (), identity )
422
+
389
423
// NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx
390
424
// Setup Mempool and Proposal Handlers
391
425
baseAppOptions = append (baseAppOptions , func (app * baseapp.BaseApp ) {
392
426
mempool := mempool.NoOpMempool {}
393
427
app .SetMempool (mempool )
394
- handler := baseapp .NewDefaultProposalHandler (mempool , app )
395
- app .SetPrepareProposal (handler .PrepareProposalHandler ())
396
- app .SetProcessProposal (handler .ProcessProposalHandler ())
428
+ app .SetPrepareProposal (blockProposalHandler .PrepareProposalHandler ())
429
+ app .SetProcessProposal (blockProposalHandler .ProcessProposalHandler ())
397
430
})
398
431
bApp := baseapp .NewBaseApp (Name , logger , db , encodingConfig .TxConfig .TxDecoder (), baseAppOptions ... )
399
432
@@ -404,14 +437,15 @@ func New(
404
437
keys , memKeys , tkeys := StoreKeys (skipGravity )
405
438
406
439
app := & App {
407
- BaseApp : bApp ,
408
- cdc : cdc ,
409
- appCodec : appCodec ,
410
- interfaceRegistry : interfaceRegistry ,
411
- invCheckPeriod : invCheckPeriod ,
412
- keys : keys ,
413
- tkeys : tkeys ,
414
- memKeys : memKeys ,
440
+ BaseApp : bApp ,
441
+ cdc : cdc ,
442
+ appCodec : appCodec ,
443
+ interfaceRegistry : interfaceRegistry ,
444
+ invCheckPeriod : invCheckPeriod ,
445
+ keys : keys ,
446
+ tkeys : tkeys ,
447
+ memKeys : memKeys ,
448
+ blockProposalHandler : blockProposalHandler ,
415
449
}
416
450
417
451
// init params keeper and subspaces
@@ -666,6 +700,8 @@ func New(
666
700
// this line is used by starport scaffolding # ibc/app/router
667
701
app .IBCKeeper .SetRouter (ibcRouter )
668
702
703
+ app .E2EEKeeper = e2eekeeper .NewKeeper (keys [e2eetypes .StoreKey ])
704
+
669
705
/**** Module Options ****/
670
706
671
707
// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
@@ -709,6 +745,9 @@ func New(
709
745
feeModule ,
710
746
feemarket .NewAppModule (app .FeeMarketKeeper , feeMarketS ),
711
747
evm .NewAppModule (app .EvmKeeper , app .AccountKeeper , evmS ),
748
+ e2ee .NewAppModule (app .E2EEKeeper ),
749
+
750
+ // Cronos app modules
712
751
cronosModule ,
713
752
}
714
753
@@ -737,6 +776,7 @@ func New(
737
776
vestingtypes .ModuleName ,
738
777
cronostypes .ModuleName ,
739
778
consensusparamtypes .ModuleName ,
779
+ e2eetypes .ModuleName ,
740
780
}
741
781
endBlockersOrder := []string {
742
782
crisistypes .ModuleName , govtypes .ModuleName , stakingtypes .ModuleName ,
@@ -760,6 +800,7 @@ func New(
760
800
vestingtypes .ModuleName ,
761
801
cronostypes .ModuleName ,
762
802
consensusparamtypes .ModuleName ,
803
+ e2eetypes .ModuleName ,
763
804
}
764
805
// NOTE: The genutils module must occur after staking so that pools are
765
806
// properly initialized with tokens from genesis accounts.
@@ -795,6 +836,7 @@ func New(
795
836
consensusparamtypes .ModuleName ,
796
837
// NOTE: crisis module must go at the end to check for invariants on each module
797
838
crisistypes .ModuleName ,
839
+ e2eetypes .ModuleName ,
798
840
}
799
841
800
842
if ! skipGravity {
@@ -876,7 +918,6 @@ func New(
876
918
app .SetEndBlocker (app .EndBlocker )
877
919
if err := app .setAnteHandler (encodingConfig .TxConfig ,
878
920
cast .ToUint64 (appOpts .Get (srvflags .EVMMaxTxGasWanted )),
879
- cast .ToStringSlice (appOpts .Get (FlagBlockedAddresses )),
880
921
); err != nil {
881
922
panic (err )
882
923
}
@@ -908,6 +949,10 @@ func New(
908
949
tmos .Exit (fmt .Sprintf ("versiondb version %d lag behind iavl version %d" , v1 , v2 ))
909
950
}
910
951
}
952
+
953
+ if err := app .RefreshBlockList (app .NewUncachedContext (false , tmproto.Header {})); err != nil {
954
+ panic (err )
955
+ }
911
956
}
912
957
913
958
app .ScopedIBCKeeper = scopedIBCKeeper
@@ -920,34 +965,7 @@ func New(
920
965
}
921
966
922
967
// use Ethermint's custom AnteHandler
923
- func (app * App ) setAnteHandler (txConfig client.TxConfig , maxGasWanted uint64 , blacklist []string ) error {
924
- if len (blacklist ) > 0 {
925
- sort .Strings (blacklist )
926
- // hash blacklist concatenated
927
- h := sha256 .New ()
928
- for _ , addr := range blacklist {
929
- _ , err := h .Write ([]byte (addr ))
930
- if err != nil {
931
- panic (err )
932
- }
933
- }
934
- app .Logger ().Error ("Setting ante handler with blacklist" , "size" , len (blacklist ), "hash" , hex .EncodeToString (h .Sum (nil )))
935
- for _ , addr := range blacklist {
936
- app .Logger ().Error ("Blacklisted address" , "address" , addr )
937
- }
938
- } else {
939
- app .Logger ().Error ("Setting ante handler without blacklist" )
940
- }
941
- blockedMap := make (map [string ]struct {}, len (blacklist ))
942
- for _ , str := range blacklist {
943
- addr , err := sdk .AccAddressFromBech32 (str )
944
- if err != nil {
945
- return fmt .Errorf ("invalid bech32 address: %s, err: %w" , str , err )
946
- }
947
-
948
- blockedMap [string (addr )] = struct {}{}
949
- }
950
- blockAddressDecorator := NewBlockAddressesDecorator (blockedMap )
968
+ func (app * App ) setAnteHandler (txConfig client.TxConfig , maxGasWanted uint64 ) error {
951
969
options := evmante.HandlerOptions {
952
970
AccountKeeper : app .AccountKeeper ,
953
971
BankKeeper : app .BankKeeper ,
@@ -964,7 +982,6 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64, bl
964
982
sdk .MsgTypeURL (& evmtypes.MsgEthereumTx {}),
965
983
sdk .MsgTypeURL (& vestingtypes.MsgCreateVestingAccount {}),
966
984
},
967
- ExtraDecorators : []sdk.AnteDecorator {blockAddressDecorator },
968
985
}
969
986
970
987
anteHandler , err := evmante .NewAnteHandler (options )
@@ -1002,7 +1019,22 @@ func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.R
1002
1019
1003
1020
// EndBlocker application updates every end block
1004
1021
func (app * App ) EndBlocker (ctx sdk.Context , req abci.RequestEndBlock ) abci.ResponseEndBlock {
1005
- return app .mm .EndBlock (ctx , req )
1022
+ rsp := app .mm .EndBlock (ctx , req )
1023
+
1024
+ if err := app .RefreshBlockList (ctx ); err != nil {
1025
+ app .Logger ().Error ("failed to update blocklist" , "error" , err )
1026
+ }
1027
+
1028
+ return rsp
1029
+ }
1030
+
1031
+ func (app * App ) RefreshBlockList (ctx sdk.Context ) error {
1032
+ if app .blockProposalHandler == nil || app .blockProposalHandler .Identity == nil {
1033
+ return nil
1034
+ }
1035
+
1036
+ // refresh blocklist
1037
+ return app .blockProposalHandler .SetBlockList (app .CronosKeeper .GetBlockList (ctx ))
1006
1038
}
1007
1039
1008
1040
// InitChainer application update at chain initialization
0 commit comments