diff --git a/cli/commands/genesis/collect.go b/cli/commands/genesis/collect.go index 22440d8a97..9b810745f3 100644 --- a/cli/commands/genesis/collect.go +++ b/cli/commands/genesis/collect.go @@ -29,6 +29,7 @@ import ( "github.com/berachain/beacon-kit/consensus-types/types" "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/primitives/encoding/json" + cmtcfg "github.com/cometbft/cometbft/config" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/spf13/afero" @@ -43,64 +44,67 @@ func CollectGenesisDepositsCmd() *cobra.Command { Short: "adds a validator to the genesis file", RunE: func(cmd *cobra.Command, _ []string) error { config := context.GetConfigFromCmd(cmd) - - appGenesis, err := genutiltypes.AppGenesisFromFile( - config.GenesisFile(), - ) - if err != nil { - return errors.Wrap(err, "failed to read genesis doc from file") - } - - // create the app state - appGenesisState, err := genutiltypes.GenesisStateFromAppGenesis( - appGenesis, - ) - if err != nil { - return err - } - - var deposits []*types.Deposit - if deposits, err = CollectValidatorJSONFiles( - filepath.Join(config.RootDir, "config", "premined-deposits"), - appGenesis, - ); err != nil { - return errors.Wrap( - err, - "failed to collect validator json files", - ) - } - - genesisInfo := &types.Genesis{} - - if err = json.Unmarshal( - appGenesisState["beacon"], genesisInfo, - ); err != nil { - return errors.Wrap(err, "failed to unmarshal beacon genesis") - } - - for i, deposit := range deposits { - deposit.Index = uint64(i) // #nosec G115 -- won't realistically overflow. - genesisInfo.Deposits = append(genesisInfo.Deposits, deposit) - } - - appGenesisState["beacon"], err = json.Marshal(genesisInfo) - if err != nil { - return errors.Wrap(err, "failed to marshal beacon genesis") - } - - if appGenesis.AppState, err = json.MarshalIndent( - appGenesisState, "", " ", - ); err != nil { - return err - } - - return genutil.ExportGenesisFile(appGenesis, config.GenesisFile()) + return CollectGenesisValidators(config) }, } return cmd } +func CollectGenesisValidators(config *cmtcfg.Config) error { + appGenesis, err := genutiltypes.AppGenesisFromFile( + config.GenesisFile(), + ) + if err != nil { + return errors.Wrap(err, "failed to read genesis doc from file") + } + + // create the app state + appGenesisState, err := genutiltypes.GenesisStateFromAppGenesis( + appGenesis, + ) + if err != nil { + return err + } + + var deposits []*types.Deposit + if deposits, err = CollectValidatorJSONFiles( + filepath.Join(config.RootDir, "config", "premined-deposits"), + appGenesis, + ); err != nil { + return errors.Wrap( + err, + "failed to collect validator json files", + ) + } + + genesisInfo := &types.Genesis{} + + if err = json.Unmarshal( + appGenesisState["beacon"], genesisInfo, + ); err != nil { + return errors.Wrap(err, "failed to unmarshal beacon genesis") + } + + for i, deposit := range deposits { + deposit.Index = uint64(i) // #nosec G115 -- won't realistically overflow. + genesisInfo.Deposits = append(genesisInfo.Deposits, deposit) + } + + appGenesisState["beacon"], err = json.Marshal(genesisInfo) + if err != nil { + return errors.Wrap(err, "failed to marshal beacon genesis") + } + + if appGenesis.AppState, err = json.MarshalIndent( + appGenesisState, "", " ", + ); err != nil { + return err + } + + return genutil.ExportGenesisFile(appGenesis, config.GenesisFile()) +} + // CollectValidatorJSONFiles collects JSON files from the specified directory // and unmarshals them into a list of Deposit objects. func CollectValidatorJSONFiles( diff --git a/config/config.go b/config/config.go index 9cff5de006..af619f548b 100644 --- a/config/config.go +++ b/config/config.go @@ -76,6 +76,16 @@ func (c Config) GetEngine() *engineclient.Config { return &c.Engine } +// GetPayloadBuilder returns the block store configuration. +func (c Config) GetPayloadBuilder() *builder.Config { + return &c.PayloadBuilder +} + +// GetBlockStoreService returns the block store configuration. +func (c Config) GetBlockStoreService() *blockstore.Config { + return &c.BlockStoreService +} + // GetLogger returns the logger configuration. func (c Config) GetLogger() *log.Config { return &c.Logger diff --git a/consensus/cometbft/service/init_chain.go b/consensus/cometbft/service/init_chain.go index fe9d924104..e0839cb882 100644 --- a/consensus/cometbft/service/init_chain.go +++ b/consensus/cometbft/service/init_chain.go @@ -85,7 +85,6 @@ func (s *Service) initChain( s.finalizeBlockState = s.resetState(ctx) - //nolint:contextcheck // ctx already passed via resetState resValidators, err := s.initChainer( s.finalizeBlockState.Context(), req.AppStateBytes, diff --git a/testing/injected-consensus/eth-genesis.json b/testing/injected-consensus/eth-genesis.json new file mode 100644 index 0000000000..8071960a7f --- /dev/null +++ b/testing/injected-consensus/eth-genesis.json @@ -0,0 +1,362 @@ +{ + "alloc": { + "0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02": { + "balance": "0x0", + "code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500", + "nonce": "0x1" + }, + "0x0474f52d25529c4db5f4E72F43303dA71B3541C6": { + "balance": "0x12345000000000000000000" + }, + "0x0e10cDAd84D788843aF48673C5b260A02ef78742": { + "balance": "0x12345000000000000000000" + }, + "0x0fb648Cb08e21602AF61AF53fE104E29d46433F7": { + "balance": "0x12345000000000000000000" + }, + "0x10FdFa4EFc83d6CC42F5ef14c13da8b98E458214": { + "balance": "0x12345000000000000000000" + }, + "0x12De044207a90709Ef2602D3D9D945d64dAe6147": { + "balance": "0x12345000000000000000000" + }, + "0x14DA5251a1EB236238969575ccE943e2Fb0f4AA1": { + "balance": "0x12345000000000000000000" + }, + "0x185F4Eebd01614aE3d12a5E49b184B054C46d37B": { + "balance": "0x12345000000000000000000" + }, + "0x187bE38A1f448b0F42423151A683dCAea949008B": { + "balance": "0x12345000000000000000000" + }, + "0x1CF7e940A657eE706718CF180eb21864DE9672C3": { + "balance": "0x12345000000000000000000" + }, + "0x1a0A57e5e6a66aD732295ddAF0aed286a4e64310": { + "balance": "0x12345000000000000000000" + }, + "0x1a0c826048DF0E4661E3c53bBd447d497E3f701F": { + "balance": "0x12345000000000000000000" + }, + "0x1e2e53c2451d0f9ED4B7952991BE0c95165D5c01": { + "balance": "0x12345000000000000000000" + }, + "0x1f1D0FCa7e19b799c315d4fDf31bA50e6A2AB153": { + "balance": "0x12345000000000000000000" + }, + "0x20f33ce90a13a4b5e7697e3544c3083b8f8a51d4": { + "balance": "0x123450000000000000000" + }, + "0x25fc16D8E2314B305dF05C032E617638284801D6": { + "balance": "0x12345000000000000000000" + }, + "0x28879749Dda99387bdB43295B28bdF251d999F3b": { + "balance": "0x12345000000000000000000" + }, + "0x2B9935698dc5c19Ab7414AE22f27Da5F4478008a": { + "balance": "0x12345000000000000000000" + }, + "0x2E5f031578e8FF82199aaF16f42c44D43Fe61819": { + "balance": "0x12345000000000000000000" + }, + "0x2F4fD8a82A1400E654eeEC59b0e588445ffE0F96": { + "balance": "0x12345000000000000000000" + }, + "0x2d88ECD4d8F4b0A954886eE8C0802aE14684cd07": { + "balance": "0x12345000000000000000000" + }, + "0x2f6eB3D9a41157322dE01A6E707F6F118Cb00A7b": { + "balance": "0x12345000000000000000000" + }, + "0x3124d9885b11B52c56A2aee610AfCf5740d484F0": { + "balance": "0x12345000000000000000000" + }, + "0x3649839562C8dA64E6215EB0f5371629Ead9729D": { + "balance": "0x12345000000000000000000" + }, + "0x3DFb4173ec41EB976260fd689E5AB9772C66beaf": { + "balance": "0x12345000000000000000000" + }, + "0x3bd0E8f1B1E8Ec99a4E1762F4058F9884C93af31": { + "balance": "0x12345000000000000000000" + }, + "0x3f51B3BB6A18141282Ba002F7709c7E2f337F961": { + "balance": "0x12345000000000000000000" + }, + "0x4242424242424242424242424242424242424242": { + "code": "0x608060405260043610610093575f3560e01c8063577212fe11610066578063c53925d91161004c578063c53925d914610231578063e12cf4cb14610250578063fea7ab7714610263575f80fd5b8063577212fe146101cc5780639eaffa96146101ed575f80fd5b806301ffc9a7146100975780632dfdf0b5146100cb5780633523f9bd14610103578063560036ec14610126575b5f80fd5b3480156100a2575f80fd5b506100b66100b1366004610c22565b610282565b60405190151581526020015b60405180910390f35b3480156100d6575f80fd5b505f546100ea9067ffffffffffffffff1681565b60405167ffffffffffffffff90911681526020016100c2565b34801561010e575f80fd5b5061011860015481565b6040519081526020016100c2565b348015610131575f80fd5b50610193610140366004610c95565b80516020818301810180516003825292820191909301209152546bffffffffffffffffffffffff8116906c01000000000000000000000000900473ffffffffffffffffffffffffffffffffffffffff1682565b604080516bffffffffffffffffffffffff909316835273ffffffffffffffffffffffffffffffffffffffff9091166020830152016100c2565b3480156101d7575f80fd5b506101eb6101e6366004610dca565b61031a565b005b3480156101f8575f80fd5b5061020c610207366004610dca565b6103f0565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100c2565b34801561023c575f80fd5b506101eb61024b366004610dca565b610431565b6101eb61025e366004610e2c565b610658565b34801561026e575f80fd5b506101eb61027d366004610edb565b6109ab565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a700000000000000000000000000000000000000000000000000000000148061031457507fffffffff0000000000000000000000000000000000000000000000000000000082167f136f920d00000000000000000000000000000000000000000000000000000000145b92915050565b6002828260405161032c929190610f2b565b908152604051908190036020019020543373ffffffffffffffffffffffffffffffffffffffff9091161461038c576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6003828260405161039e929190610f2b565b9081526040519081900360200181205f90556103bd9083908390610f2b565b604051908190038120907f1c0a7e1bd09da292425c039309671a03de56b89a0858598aab6df6ce84b006db905f90a25050565b5f60028383604051610403929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16905092915050565b5f60038383604051610444929190610f2b565b908152604051908190036020019020805490915073ffffffffffffffffffffffffffffffffffffffff6c01000000000000000000000000820416906bffffffffffffffffffffffff163382146104c6576040517f819a0d0b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6bffffffffffffffffffffffff42166104e26201518083610f67565b6bffffffffffffffffffffffff161115610528576040517fe8966d7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6002868660405161053b929190610f2b565b9081526040519081900360200181205473ffffffffffffffffffffffffffffffffffffffff16915083906002906105759089908990610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff0000000000000000000000000000000000000000909316929092179091556003906105da9088908890610f2b565b9081526040519081900360200181205f90556105f99087908790610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff808716845284166020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a2505050505050565b60308614610692576040517f9f10647200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602084146106cc576040517fb39bca1600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608214610706576040517f4be6321b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff166002888860405161072f929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff16036108765773ffffffffffffffffffffffffffffffffffffffff81166107a7576040517f51969a7a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80600288886040516107ba929190610f2b565b908152604051908190036020018120805473ffffffffffffffffffffffffffffffffffffffff939093167fffffffffffffffffffffffff00000000000000000000000000000000000000009093169290921790915561081c9088908890610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff841683525f6020840152917f0adffd98d3072c48341843974dffd7a910bb849ba6ca04163d43bb26feb17403910160405180910390a26108c4565b73ffffffffffffffffffffffffffffffffffffffff8116156108c4576040517fc4142b4100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6108cd610b5d565b9050633b9aca0067ffffffffffffffff82161015610917576040517f0e1eddda00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f80547f68af751683498a9f9be59fe8b0d52a64dd155255d85cdb29fea30b1e3f891d46918a918a918a918a9187918b918b9167ffffffffffffffff16908061095f83610f8b565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff160217905550604051610999989796959493929190610ffe565b60405180910390a15050505050505050565b5f600284846040516109be929190610f2b565b9081526040519081900360200190205473ffffffffffffffffffffffffffffffffffffffff169050338114610a1f576040517f7c214f0400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216610a6c576040517fd92e233d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f60038585604051610a7f929190610f2b565b908152604051908190036020018120426bffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff86166c01000000000000000000000000027fffffffffffffffffffffffffffffffffffffffff000000000000000000000000161781559150610af79086908690610f2b565b6040805191829003822073ffffffffffffffffffffffffffffffffffffffff8681168452851660208401524283830152905190917f7640ec3c8c4695deadda414dd20400acf275297a7c38715f9237657e97ddba5f919081900360600190a25050505050565b5f610b6c633b9aca0034611096565b15610ba3576040517f40567b3800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610bb2633b9aca00346110a9565b905067ffffffffffffffff811115610bf6576040517f2aa6673400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c005f34610c05565b919050565b5f385f3884865af1610c1e5763b12d13eb5f526004601cfd5b5050565b5f60208284031215610c32575f80fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114610c61575f80fd5b9392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60208284031215610ca5575f80fd5b813567ffffffffffffffff811115610cbb575f80fd5b8201601f81018413610ccb575f80fd5b803567ffffffffffffffff811115610ce557610ce5610c68565b6040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0603f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8501160116810181811067ffffffffffffffff82111715610d5157610d51610c68565b604052818152828201602001861015610d68575f80fd5b816020840160208301375f91810160200191909152949350505050565b5f8083601f840112610d95575f80fd5b50813567ffffffffffffffff811115610dac575f80fd5b602083019150836020828501011115610dc3575f80fd5b9250929050565b5f8060208385031215610ddb575f80fd5b823567ffffffffffffffff811115610df1575f80fd5b610dfd85828601610d85565b90969095509350505050565b803573ffffffffffffffffffffffffffffffffffffffff81168114610c00575f80fd5b5f805f805f805f6080888a031215610e42575f80fd5b873567ffffffffffffffff811115610e58575f80fd5b610e648a828b01610d85565b909850965050602088013567ffffffffffffffff811115610e83575f80fd5b610e8f8a828b01610d85565b909650945050604088013567ffffffffffffffff811115610eae575f80fd5b610eba8a828b01610d85565b9094509250610ecd905060608901610e09565b905092959891949750929550565b5f805f60408486031215610eed575f80fd5b833567ffffffffffffffff811115610f03575f80fd5b610f0f86828701610d85565b9094509250610f22905060208501610e09565b90509250925092565b818382375f9101908152919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b6bffffffffffffffffffffffff818116838216019081111561031457610314610f3a565b5f67ffffffffffffffff821667ffffffffffffffff8103610fae57610fae610f3a565b60010192915050565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60a081525f61101160a083018a8c610fb7565b828103602084015261102481898b610fb7565b905067ffffffffffffffff871660408401528281036060840152611049818688610fb7565b91505067ffffffffffffffff831660808301529998505050505050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b5f826110a4576110a4611069565b500690565b5f826110b7576110b7611069565b50049056fea264697066735822122069227307258cbe8f29985bb4f3e283b1b03d5c0cbab8add81bf3c22e3d13729664736f6c634300081a0033", + "storage": { + "0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000001", + "0x0000000000000000000000000000000000000000000000000000000000000001": "0x7b941e6d4bdec0e30738edb7b1d2c9ca373abc85a6c4f97854ababd2909b2aa7" + }, + "balance": "0x0", + "nonce": "0x1" + }, + "0x4245537d9e3fb36fBBf054247FfFB28b0d931503": { + "balance": "0x12345000000000000000000" + }, + "0x440C37b22e8D7469128Ea7De6ac2f31419B4A8b1": { + "balance": "0x12345000000000000000000" + }, + "0x44a5FBfa7d6f3Fd92cca01f6764509f8Fc33dfa5": { + "balance": "0x12345000000000000000000" + }, + "0x47575DAE85403cD408d4639068D1187C427B9897": { + "balance": "0x12345000000000000000000" + }, + "0x49cE37B2019bb2d0B8b6a094ef87a6Dd625454A0": { + "balance": "0x12345000000000000000000" + }, + "0x4Afe0DFDAcc91F0fA2AEe39F9eAd66b64d03EbD6": { + "balance": "0x12345000000000000000000" + }, + "0x4bD04ABA9fc709835b1EE4789195d10E9e8E53F5": { + "balance": "0x12345000000000000000000" + }, + "0x4dC3aC871b22F8a98197B0aae976a8dE08e5Bebe": { + "balance": "0x12345000000000000000000" + }, + "0x4e59b44847b379578588920cA78FbF26c0B4956C": { + "balance": "0x0", + "code": "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3", + "nonce": "0x1" + }, + "0x5145b1B855bca67A119CB02A42aF4Bdbc66B725C": { + "balance": "0x12345000000000000000000" + }, + "0x51e15e71c865FE702C9347610667f83658A20e00": { + "balance": "0x12345000000000000000000" + }, + "0x5227aaebCA3E5e893547A667666E2e4e12Ca20e0": { + "balance": "0x12345000000000000000000" + }, + "0x54e1F990Dc0B7367F1E8eD96dA63BC4bca0E8061": { + "balance": "0x12345000000000000000000" + }, + "0x56898d1aFb10cad584961eb96AcD476C6826e41E": { + "balance": "0x12345000000000000000000" + }, + "0x5DD7bc3BEE395831ce499315ecAFE81DE0556F99": { + "balance": "0x12345000000000000000000" + }, + "0x611a42A2EF62c2461D123e3F0B64b93938bc4781": { + "balance": "0x12345000000000000000000" + }, + "0x62cB9bF32EA104f6D5eBf6879e876439f9492E4B": { + "balance": "0x12345000000000000000000" + }, + "0x67c942Ef50Fc690eA779067a6A0d444a8234baB5": { + "balance": "0x12345000000000000000000" + }, + "0x6CBcF4198fDA91D00fD469340E6DF6df086159e3": { + "balance": "0x12345000000000000000000" + }, + "0x6F69542fC88fF84C480FFf510aB7108120447247": { + "balance": "0x12345000000000000000000" + }, + "0x6a354C708fd248FD778F6adF75E41AA554700F68": { + "balance": "0x12345000000000000000000" + }, + "0x719Be866A77CeEc1BaC4FD37910c0975eFd52f55": { + "balance": "0x12345000000000000000000" + }, + "0x7469CeEf99FB67e4990c5F1c085a1B39b2902331": { + "balance": "0x12345000000000000000000" + }, + "0x7689BE67b205EB5d32811d95D60587Eae4F3036F": { + "balance": "0x12345000000000000000000" + }, + "0x795B761Db5969B7ba53472d5D37c230C859a472F": { + "balance": "0x12345000000000000000000" + }, + "0x7c4d7dB81c544B768E1f4782011077202B74B5C0": { + "balance": "0x12345000000000000000000" + }, + "0x7d7f187C2A05cDDCF700dCF2E02c96E7eF03f9B0": { + "balance": "0x12345000000000000000000" + }, + "0x7f0E54bc3C1a72405646F5dFbBE0D4565c649fe2": { + "balance": "0x12345000000000000000000" + }, + "0x800830F031ab1dd5895a5ec5B561427AD18f9ea8": { + "balance": "0x12345000000000000000000" + }, + "0x868a33C94F91398B6245e1f0E4CF128B2F28714B": { + "balance": "0x12345000000000000000000" + }, + "0x8724C57fb8f38A1FccA7177543dd1D8FcD49E5aa": { + "balance": "0x12345000000000000000000" + }, + "0x8a88215ae882dfA519730c40109556c1C235729f": { + "balance": "0x12345000000000000000000" + }, + "0x8b1e58f651CacaAa40291d2a6E0a6404d7Ed99e6": { + "balance": "0x12345000000000000000000" + }, + "0x92B3feac5b7816Dcef96a303c1D5112271A70D2c": { + "balance": "0x12345000000000000000000" + }, + "0x9C75eD1A37ae420b4FC0a1F4c26B673227Fd3AFa": { + "balance": "0x12345000000000000000000" + }, + "0x9beFa0FB7a1A9E6cC7596204DbB8962E87091D64": { + "balance": "0x12345000000000000000000" + }, + "0xA1d283f1a11A36D20FF38F29e12CA8F7Cf8709c1": { + "balance": "0x12345000000000000000000" + }, + "0xA6177defF3b768b1D678EdF7583b8cf210C777c0": { + "balance": "0x12345000000000000000000" + }, + "0xAC3c80F41C3049A89Aba8072FFbFc38a90fb6D8c": { + "balance": "0x12345000000000000000000" + }, + "0xAf325Ccc92ae883DEF1634D499d8B093192D7a0c": { + "balance": "0x12345000000000000000000" + }, + "0xB8865B4B8C56861534CC07ebBD2EA569a9a16323": { + "balance": "0x12345000000000000000000" + }, + "0xBC3c03b4185A6F10618CC4E7B9f4AdD59AB5FbbA": { + "balance": "0x12345000000000000000000" + }, + "0xBC9BC89b295a14F3976234Cc37C73e3D286f3a49": { + "balance": "0x12345000000000000000000" + }, + "0xC4DD08191B4d5173e3698491A11e05b63F9Ee097": { + "balance": "0x12345000000000000000000" + }, + "0xC4eD09A472B82516daa3A4d8D1E38AE94CF4855C": { + "balance": "0x12345000000000000000000" + }, + "0xC59D8935c0570E75BA0E55E3C661f535C86e368B": { + "balance": "0x12345000000000000000000" + }, + "0xD073a84e2ccDF91a9025179330438485E886D206": { + "balance": "0x12345000000000000000000" + }, + "0xD2a3b89AE8D2c3bD39E2F24612ecFCD8600360C9": { + "balance": "0x12345000000000000000000" + }, + "0xD3c5dAC705289cD005C402C79C8445a47502d8be": { + "balance": "0x12345000000000000000000" + }, + "0xD6D4Fb22B91FAa54700852a05698B37d45514166": { + "balance": "0x12345000000000000000000" + }, + "0xDE8E0E641E2Fb52c22460e6a1533c6BD13A00B37": { + "balance": "0x12345000000000000000000" + }, + "0xDc6De65f6070b409125217a12Cf576A208Cc1998": { + "balance": "0x12345000000000000000000" + }, + "0xDe5C7198e2416baB7e7a1EA758858Cd7301740bF": { + "balance": "0x12345000000000000000000" + }, + "0xE3d2b9191EaBD3636A5dd057D522335cfae8c7CF": { + "balance": "0x12345000000000000000000" + }, + "0xE5981AA0807eb05611cDb666e32e53b2001bd61d": { + "balance": "0x12345000000000000000000" + }, + "0xE69ac59e1DF47291AaB8DEc540C796f81De7c892": { + "balance": "0x12345000000000000000000" + }, + "0xE7F444b5f772281384117674002d540131e533Ca": { + "balance": "0x12345000000000000000000" + }, + "0xF60fD8632Fc77E19b3A0637d115d0fdd06F36968": { + "balance": "0x12345000000000000000000" + }, + "0xF99139D2FCc5E25F57B0B91fd382a21B3AFF9cbA": { + "balance": "0x12345000000000000000000" + }, + "0xF9f58a87C3f0B3A4a0592938c80C41a7c659f855": { + "balance": "0x12345000000000000000000" + }, + "0xFeb1eafa0154D291e28e393FAF10Bc89e5cCbB22": { + "balance": "0x12345000000000000000000" + }, + "0xaEf63D7F7e2637c99FeA1B63366b244B4da12D70": { + "balance": "0x12345000000000000000000" + }, + "0xb86d37333072eFb48cEaa46C67271A27CA5Bda82": { + "balance": "0x12345000000000000000000" + }, + "0xb87fb371Bd3C2093b608cd0E7a8dDD60Bb05C995": { + "balance": "0x12345000000000000000000" + }, + "0xbE651bc261b9Da5499a24Bf4214fD494c6e1F5Ac": { + "balance": "0x12345000000000000000000" + }, + "0xbcC90AD39D377cA0b7b4F36eC463103E2728C33F": { + "balance": "0x12345000000000000000000" + }, + "0xcB6632daA65e6c921c2963C37320f63f54fC8fE3": { + "balance": "0x12345000000000000000000" + }, + "0xd0F043dED28773953562f824334C4cbb84210AE7": { + "balance": "0x12345000000000000000000" + }, + "0xdBfb742BD2e0e6E353cb61E75B9e11257aC8fB1A": { + "balance": "0x12345000000000000000000" + }, + "0xdb96E9cDD1e457b602f97d33e51736D7a5216496": { + "balance": "0x12345000000000000000000" + }, + "0xdb9cB94B166DfdC9F337EA63b32B448d993d7008": { + "balance": "0x12345000000000000000000" + }, + "0xe3024d098953661638d59E06f7FcD0B61c424854": { + "balance": "0x12345000000000000000000" + }, + "0xea94749deFcc40dC5992687974b1C84B1bB9D6df": { + "balance": "0x12345000000000000000000" + }, + "0xf11D16e2EE6BefED82Fbca0b005906E09303aB95": { + "balance": "0x12345000000000000000000" + }, + "0xf22FbA9cBeB75ED353931418E9eca71EF1Ab9921": { + "balance": "0x12345000000000000000000" + }, + "0xf4b2eb959A4C4b0E148340676999FC0446D446D4": { + "balance": "0x12345000000000000000000" + }, + "0xf6B6A52aA9BD788837c6682f47ACE009BD84b6fc": { + "balance": "0x12345000000000000000000" + }, + "0xf97a36c417D33D1fC60a9163A8715e1aecb29102": { + "balance": "0x12345000000000000000000" + } + }, + "coinbase": "0x0000000000000000000000000000000000000000", + "config": { + "arrowGlacierBlock": 0, + "berlinBlock": 0, + "byzantiumBlock": 0, + "cancunTime": 0, + "chainId": 80087, + "constantinopleBlock": 0, + "daoForkBlock": 0, + "daoForkSupport": true, + "eip150Block": 0, + "eip155Block": 0, + "eip158Block": 0, + "ethash": {}, + "grayGlacierBlock": 0, + "homesteadBlock": 0, + "istanbulBlock": 0, + "londonBlock": 0, + "mergeNetsplitBlock": 0, + "muirGlacierBlock": 0, + "petersburgBlock": 0, + "shanghaiTime": 0, + "terminalTotalDifficulty": 0, + "terminalTotalDifficultyPassed": true + }, + "difficulty": "0x0", + "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000658bdf435d810c91414ec09147daa6db624063790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "gasLimit": "0x1c9c380", + "nonce": "0x0000000000000000", + "timestamp": "0x0" +} \ No newline at end of file diff --git a/testing/injected-consensus/injected-consensus.go b/testing/injected-consensus/injected-consensus.go new file mode 100644 index 0000000000..7d966ce09b --- /dev/null +++ b/testing/injected-consensus/injected-consensus.go @@ -0,0 +1,240 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2025, Berachain Foundation. All rights reserved. +// Use of this software is governed by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package injectedconsensus + +import ( + "context" + "os" + "testing" + + "github.com/berachain/beacon-kit/beacon/blockchain" + "github.com/berachain/beacon-kit/cli/commands/genesis" + servertypes "github.com/berachain/beacon-kit/cli/commands/server/types" + "github.com/berachain/beacon-kit/cli/flags" + beaconkitconfig "github.com/berachain/beacon-kit/config" + "github.com/berachain/beacon-kit/config/spec" + cometbft "github.com/berachain/beacon-kit/consensus/cometbft/service" + "github.com/berachain/beacon-kit/da/kzg" + "github.com/berachain/beacon-kit/log/phuslu" + nodebuilder "github.com/berachain/beacon-kit/node-core/builder" + "github.com/berachain/beacon-kit/node-core/components" + "github.com/berachain/beacon-kit/node-core/components/signer" + nodetypes "github.com/berachain/beacon-kit/node-core/types" + "github.com/berachain/beacon-kit/primitives/common" + "github.com/berachain/beacon-kit/primitives/math" + "github.com/berachain/beacon-kit/storage/db" + cmtcfg "github.com/cometbft/cometbft/config" + "github.com/cometbft/cometbft/crypto/bls12381" + "github.com/cometbft/cometbft/types" + dbm "github.com/cosmos/cosmos-db" + "github.com/spf13/viper" + "github.com/stretchr/testify/require" +) + +// DefaultComponents requires testing.T to avoid accidental misuse. +func DefaultComponents(_ *testing.T) []any { + c := []any{ + components.ProvideAttributesFactory, + components.ProvideAvailabilityStore, + components.ProvideDepositContract, + components.ProvideBlockStore, + components.ProvideBlsSigner, + components.ProvideBlobProcessor, + components.ProvideBlobProofVerifier, + components.ProvideChainService, + components.ProvideNode, + components.ProvideChainSpec, + components.ProvideConfig, + components.ProvideServerConfig, + components.ProvideDepositStore, + components.ProvideEngineClient, + components.ProvideExecutionEngine, + components.ProvideJWTSecret, + components.ProvideLocalBuilder, + components.ProvideReportingService, + components.ProvideCometBFTService, + components.ProvideServiceRegistry, + components.ProvideSidecarFactory, + components.ProvideStateProcessor, + components.ProvideKVStore, + components.ProvideStorageBackend, + components.ProvideTelemetrySink, + components.ProvideTelemetryService, + components.ProvideTrustedSetup, + components.ProvideValidatorService, + components.ProvideShutDownService, + } + c = append(c, + components.ProvideNodeAPIServer, + components.ProvideNodeAPIEngine, + components.ProvideNodeAPIBackend, + ) + // + c = append(c, components.ProvideNodeAPIHandlers, + components.ProvideNodeAPIBeaconHandler, + components.ProvideNodeAPIBuilderHandler, + components.ProvideNodeAPIConfigHandler, + components.ProvideNodeAPIDebugHandler, + components.ProvideNodeAPIEventsHandler, + components.ProvideNodeAPINodeHandler, + components.ProvideNodeAPIProofHandler, + ) + + return c +} + +type TestNode struct { + Node nodetypes.Node + CometService *cometbft.Service + BlockchainService *blockchain.Service + CometConfig *cmtcfg.Config + Homedir string + Context context.Context + CancelFunc context.CancelFunc +} + +// createConfiguration creates the BeaconKit configuration and the CometBFT configuration. +func createConfiguration(t *testing.T, tempHomeDir string) ( + *beaconkitconfig.Config, + *cmtcfg.Config, +) { + t.Helper() + cmtCfg := cometbft.DefaultConfig() + cmtCfg.RootDir = tempHomeDir + // Forces Comet to Create it + cmtCfg.NodeKey = "node_key.json" + beaconCfg := beaconkitconfig.DefaultConfig() + return beaconCfg, cmtCfg +} + +// getAppOptions returns the Application Options we need to set for the Node Builder. +// Ideally we can avoid having to set the flags like this and just directly modify a config type. +func getAppOptions(t *testing.T, beaconKitConfig *beaconkitconfig.Config, tempHomeDir string) servertypes.AppOptions { + t.Helper() + appOpts := viper.New() + // Execution Client Config + appOpts.Set(flags.JWTSecretPath, "../files/jwt.hex") + appOpts.Set(flags.RPCJWTRefreshInterval, beaconKitConfig.GetEngine().RPCJWTRefreshInterval) + appOpts.Set(flags.RPCStartupCheckInterval, beaconKitConfig.GetEngine().RPCStartupCheckInterval) + appOpts.Set(flags.RPCDialURL, beaconKitConfig.GetEngine().RPCDialURL) + appOpts.Set(flags.RPCTimeout, beaconKitConfig.GetEngine().RPCTimeout) + + // BLS Config + appOpts.Set(flags.PrivValidatorKeyFile, "./config/priv_validator_key.json") + appOpts.Set(flags.PrivValidatorStateFile, "./data/priv_validator_state.json") + + // Beacon Config + appOpts.Set(flags.BlockStoreServiceAvailabilityWindow, beaconKitConfig.GetBlockStoreService().AvailabilityWindow) + appOpts.Set(flags.BlockStoreServiceEnabled, beaconKitConfig.GetBlockStoreService().Enabled) + appOpts.Set(flags.KZGTrustedSetupPath, "../files/kzg-trusted-setup.json") + appOpts.Set(flags.KZGImplementation, kzg.DefaultConfig().Implementation) + + // Payload Builder Config + beaconKitConfig.GetPayloadBuilder().SuggestedFeeRecipient = common.NewExecutionAddressFromHex("0x981114102592310C347E61368342DDA67017bf84") + appOpts.Set(flags.BuilderEnabled, beaconKitConfig.GetPayloadBuilder().Enabled) + appOpts.Set(flags.BuildPayloadTimeout, beaconKitConfig.GetPayloadBuilder().PayloadTimeout) + appOpts.Set(flags.SuggestedFeeRecipient, beaconKitConfig.GetPayloadBuilder().SuggestedFeeRecipient) + + // TODO: Cleanup this Set + appOpts.Set("pruning", "default") + appOpts.Set("home", tempHomeDir) + return appOpts +} + +// NewTestNode Uses the mainnet chainspec. +func NewTestNode(t *testing.T) *TestNode { + t.Helper() + + ctx, cancelFunc := context.WithCancel(context.Background()) + logger := phuslu.NewLogger(os.Stdout, nil) + + tempHomeDir := t.TempDir() + beaconKitConfig, cometConfig := createConfiguration(t, tempHomeDir) + + chainSpec, err := spec.MainnetChainSpec() + require.NoError(t, err) + + appOpts := getAppOptions(t, beaconKitConfig, tempHomeDir) + + // Chain Spec + t.Setenv(components.ChainSpecTypeEnvVar, components.MainnetChainSpecType) + + // Create the genesis deposit + blsSigner := signer.BLSSigner{PrivValidator: types.NewMockPVWithKeyType(bls12381.KeyType)} + + // Make the deposit amount the Max effective balance - set arbitrarily higher than 250K BERA required for mainnet + depositAmount := math.Gwei(chainSpec.MaxEffectiveBalance()) + withdrawalAddress := common.NewExecutionAddressFromHex("0x6Eb9C23e4c187452504Ef8c5fD8fA1a4b15BE162") + err = genesis.AddGenesisDeposit(chainSpec, cometConfig, blsSigner, depositAmount, withdrawalAddress, "") + require.NoError(t, err) + + // Collect the genesis deposit + err = genesis.CollectGenesisValidators(cometConfig) + require.NoError(t, err) + + // Update the EL Deposit Storage + err = genesis.SetDepositStorage(chainSpec, cometConfig, "TBD", false) + require.NoError(t, err) + + // 1. Build a node builder with your default or custom test components. + nb := nodebuilder.New( + nodebuilder.WithComponents[nodetypes.Node](DefaultComponents(t)), + ) + + database, err := db.OpenDB(tempHomeDir, dbm.PebbleDBBackend) + require.NoError(t, err) + + node := nb.Build( + logger, + database, + os.Stdout, // or some other writer + cometConfig, + appOpts, + ) + + // Fetch services we will want to query and interact with so they are easily accessible in testing + var cometService *cometbft.Service + err = node.FetchService(&cometService) + require.NoError(t, err) + require.NotNil(t, cometService) + + var blockchainService *blockchain.Service + err = node.FetchService(&blockchainService) + require.NoError(t, err) + require.NotNil(t, blockchainService) + + return &TestNode{ + Node: node, + CometService: cometService, + BlockchainService: blockchainService, + CometConfig: cometConfig, + Homedir: tempHomeDir, + Context: ctx, + CancelFunc: cancelFunc, + } +} + +// func genesisFromFile(t *testing.T, file string) *cosmosutil.AppGenesis { +// t.Helper() +// appGenesis, err := cosmosutil.AppGenesisFromFile(file) +// require.NoError(t, err) +// return appGenesis +//} diff --git a/testing/injected-consensus/invalid_block_test.go b/testing/injected-consensus/invalid_block_test.go new file mode 100644 index 0000000000..0df14c55a5 --- /dev/null +++ b/testing/injected-consensus/invalid_block_test.go @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: BUSL-1.1 +// +// Copyright (C) 2025, Berachain Foundation. All rights reserved. +// Use of this software is governed by the Business Source License included +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. +// +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER +// VERSIONS OF THE LICENSED WORK. +// +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). +// +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND +// TITLE. + +package injectedconsensus_test + +import ( + "testing" + "time" + + injectedconsensus "github.com/berachain/beacon-kit/testing/injected-consensus" + comettypes "github.com/cometbft/cometbft/abci/types" + "github.com/stretchr/testify/suite" +) + +type InjectedConsensus struct { + suite.Suite + testNode *injectedconsensus.TestNode +} + +func (s *InjectedConsensus) SetupTest() { + s.testNode = injectedconsensus.NewTestNode(s.T()) +} + +func (s *InjectedConsensus) TearDownTest() { + // Ensure teardown runs no matter what + s.testNode.CancelFunc() + // err := os.RemoveAll(s.testNode.Homedir) + // s.Require().NoError(err) +} + +func (s *InjectedConsensus) TestInitChainRequestsInvalidChainID() { + request := &comettypes.InitChainRequest{ + ChainId: "80090", + } + _, err := s.testNode.CometService.InitChain(s.testNode.Context, request) + s.Require().Error(err, "invalid chain-id on InitChain; expected: beacond-2061, got: 80090") +} + +// TestProcessProposalRequestInvalidBlock tests the scenario where a peer sends us a block with an invalid timestamp. +func (s *InjectedConsensus) TestProcessProposalRequestInvalidBlock() { + go func() { + if err := s.testNode.Node.Start(s.testNode.Context); err != nil { + s.T().Error(err) + } + }() + + <-time.After(30 * time.Second) + + // genesis := genesisFromFile(t, testNode.cometConfig.Genesis) + + // genesisFile := testNode.cometConfig.GenesisFile() + + // request := &comettypes.InitChainRequest{ + // ChainId: "beacond-2061", + // AppStateBytes: genesis.AppState, + //} + // fmt.Println(genesis) + // fmt.Println(genesisFile) + // response, err := testNode.cometService.InitChain(ctx, request) + // require.NoError(t, err) + minimumBlockHeight := int64(2) + s.Greater(s.testNode.CometService.LastBlockHeight(), minimumBlockHeight) + // We expect one deposit given the genesis file in 'config/genesis.json' + // require.Len(t, response.GetValidators(), 1) +} + +func TestInjectedConsensus(t *testing.T) { + t.Parallel() + suite.Run(t, new(InjectedConsensus)) +}