Skip to content

Commit

Permalink
Merge branch 'rafilx/refactory' of github.com:babylonlabs-io/babylon …
Browse files Browse the repository at this point in the history
…into rafilx/improve-performance-btc-dist
  • Loading branch information
RafilxTenfen committed Dec 16, 2024
2 parents 1e97f58 + 1d53ecb commit 8192785
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 64 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ virtual block periods for each finality provider that has delegations and reward
- [#316](https://github.com/babylonlabs-io/babylon/pull/316) Add testnet upgrade data
- [#326](https://github.com/babylonlabs-io/babylon/pull/326) docs: btcstaking:
Update btcstaking module docs to include EOI
- [#348](https://github.com/babylonlabs-io/babylon/pull/348) refactory `PrivateSigner`
and module account vars in appparams

### Bug fixes

Expand Down
3 changes: 1 addition & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ import (
ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
"github.com/spf13/cast"

"github.com/babylonlabs-io/babylon/testutil/addr"
"github.com/babylonlabs-io/babylon/x/mint"
minttypes "github.com/babylonlabs-io/babylon/x/mint/types"

Expand Down Expand Up @@ -802,7 +801,7 @@ func BlockedAddresses() map[string]bool {
}

// allow the following addresses to receive funds
delete(modAccAddrs, addr.AccGov.String())
delete(modAccAddrs, appparams.AccGov.String())

return modAccAddrs
}
43 changes: 21 additions & 22 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/babylonlabs-io/babylon/testutil/addr"
mintkeeper "github.com/babylonlabs-io/babylon/x/mint/keeper"
minttypes "github.com/babylonlabs-io/babylon/x/mint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -219,15 +218,15 @@ func (ak *AppKeepers) InitKeepers(
maccPerms,
authcodec.NewBech32Codec(appparams.Bech32PrefixAccAddr),
appparams.Bech32PrefixAccAddr,
addr.AccGov.String(),
appparams.AccGov.String(),
)

bankKeeper := bankkeeper.NewBaseKeeper(
appCodec,
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
accountKeeper,
blockedAddress,
addr.AccGov.String(),
appparams.AccGov.String(),
logger,
)

Expand All @@ -236,7 +235,7 @@ func (ak *AppKeepers) InitKeepers(
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
accountKeeper,
bankKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
authcodec.NewBech32Codec(appparams.Bech32PrefixValAddr),
authcodec.NewBech32Codec(appparams.Bech32PrefixConsAddr),
)
Expand All @@ -247,7 +246,7 @@ func (ak *AppKeepers) InitKeepers(
runtime.NewKVStoreService(keys[epochingtypes.StoreKey]),
bankKeeper,
stakingKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
)

checkpointingKeeper := checkpointingkeeper.NewKeeper(
Expand All @@ -272,7 +271,7 @@ func (ak *AppKeepers) InitKeepers(
ak.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]),
addr.AccGov.String(),
appparams.AccGov.String(),
runtime.EventService{},
)
bApp.SetParamStore(ak.ConsensusParamsKeeper.ParamsStore)
Expand Down Expand Up @@ -302,7 +301,7 @@ func (ak *AppKeepers) InitKeepers(
ak.CircuitKeeper = circuitkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[circuittypes.StoreKey]),
addr.AccGov.String(),
appparams.AccGov.String(),
ak.AccountKeeper.AddressCodec(),
)
bApp.SetCircuitBreaker(&ak.CircuitKeeper)
Expand All @@ -314,7 +313,7 @@ func (ak *AppKeepers) InitKeepers(
ak.AccountKeeper,
ak.BankKeeper,
authtypes.FeeCollectorName,
addr.AccGov.String(),
appparams.AccGov.String(),
)

ak.DistrKeeper = distrkeeper.NewKeeper(
Expand All @@ -324,7 +323,7 @@ func (ak *AppKeepers) InitKeepers(
ak.BankKeeper,
ak.StakingKeeper,
authtypes.FeeCollectorName,
addr.AccGov.String(),
appparams.AccGov.String(),
)

// set up incentive keeper
Expand All @@ -334,7 +333,7 @@ func (ak *AppKeepers) InitKeepers(
ak.BankKeeper,
ak.AccountKeeper,
&epochingKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
authtypes.FeeCollectorName,
)

Expand All @@ -343,7 +342,7 @@ func (ak *AppKeepers) InitKeepers(
encodingConfig.Amino,
runtime.NewKVStoreService(keys[slashingtypes.StoreKey]),
ak.StakingKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
)

ak.CrisisKeeper = crisiskeeper.NewKeeper(
Expand All @@ -352,7 +351,7 @@ func (ak *AppKeepers) InitKeepers(
invCheckPeriod,
ak.BankKeeper,
authtypes.FeeCollectorName,
addr.AccGov.String(),
appparams.AccGov.String(),
ak.AccountKeeper.AddressCodec(),
)

Expand All @@ -374,7 +373,7 @@ func (ak *AppKeepers) InitKeepers(
appCodec,
homePath,
bApp,
addr.AccGov.String(),
appparams.AccGov.String(),
)

ak.AuthzKeeper = authzkeeper.NewKeeper(
Expand All @@ -395,7 +394,7 @@ func (ak *AppKeepers) InitKeepers(
// `MsgIBCSoftwareUpgrade` and `MsgRecoverClient`
// https://github.com/cosmos/ibc-go/releases/tag/v8.0.0
// Gov is the proper authority for those types of messages
addr.AccGov.String(),
appparams.AccGov.String(),
)

// register the proposal types
Expand All @@ -422,7 +421,7 @@ func (ak *AppKeepers) InitKeepers(
ak.DistrKeeper,
bApp.MsgServiceRouter(),
govConfig,
addr.AccGov.String())
appparams.AccGov.String())

ak.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
Expand All @@ -435,7 +434,7 @@ func (ak *AppKeepers) InitKeepers(
runtime.NewKVStoreService(keys[btclightclienttypes.StoreKey]),
*btcConfig,
&ak.IncentiveKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
)

btcCheckpointKeeper := btccheckpointkeeper.NewKeeper(
Expand All @@ -446,7 +445,7 @@ func (ak *AppKeepers) InitKeepers(
&checkpointingKeeper,
&ak.IncentiveKeeper,
&powLimit,
addr.AccGov.String(),
appparams.AccGov.String(),
)

ak.IBCFeeKeeper = ibcfeekeeper.NewKeeper(
Expand All @@ -467,7 +466,7 @@ func (ak *AppKeepers) InitKeepers(
ak.AccountKeeper,
ak.BankKeeper,
scopedTransferKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
)

ak.MonitorKeeper = monitorkeeper.NewKeeper(
Expand Down Expand Up @@ -500,7 +499,7 @@ func (ak *AppKeepers) InitKeepers(
&btcCheckpointKeeper,
&ak.IncentiveKeeper,
btcNetParams,
addr.AccGov.String(),
appparams.AccGov.String(),
)

// set up finality keeper
Expand All @@ -510,7 +509,7 @@ func (ak *AppKeepers) InitKeepers(
ak.BTCStakingKeeper,
ak.IncentiveKeeper,
ak.CheckpointingKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
)

// create evidence keeper with router
Expand Down Expand Up @@ -544,7 +543,7 @@ func (ak *AppKeepers) InitKeepers(
homePath,
wasmConfig,
WasmCapabilities(),
addr.AccGov.String(),
appparams.AccGov.String(),
wasmOpts...,
)

Expand All @@ -559,7 +558,7 @@ func (ak *AppKeepers) InitKeepers(
appCodec,
runtime.NewKVStoreService(keys[ibcwasmtypes.StoreKey]),
ak.IBCKeeper.ClientKeeper,
addr.AccGov.String(),
appparams.AccGov.String(),
ibcWasmConfig,
bApp.GRPCQueryRouter(),
)
Expand Down
2 changes: 1 addition & 1 deletion testutil/addr/const.go → app/params/addr.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package addr
package params

import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand Down
14 changes: 7 additions & 7 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"cosmossdk.io/log"
"cosmossdk.io/math"
pruningtypes "cosmossdk.io/store/pruning/types"
testsigner "github.com/babylonlabs-io/babylon/testutil/signer"
"github.com/babylonlabs-io/babylon/testutil/signer"
minttypes "github.com/babylonlabs-io/babylon/x/mint/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/ed25519"
Expand All @@ -32,7 +32,7 @@ import (
"github.com/stretchr/testify/require"

appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/app/signer"
appsigner "github.com/babylonlabs-io/babylon/app/signer"
"github.com/babylonlabs-io/babylon/crypto/bls12381"
"github.com/babylonlabs-io/babylon/privval"
bbn "github.com/babylonlabs-io/babylon/types"
Expand All @@ -49,7 +49,7 @@ type SetupOptions struct {
AppOpts types.AppOptions
}

func setup(t *testing.T, ps *signer.PrivSigner, withGenesis bool, invCheckPeriod uint, btcConf bbn.SupportedBtcNetwork) (*BabylonApp, GenesisState) {
func setup(t *testing.T, ps *appsigner.PrivSigner, withGenesis bool, invCheckPeriod uint, btcConf bbn.SupportedBtcNetwork) (*BabylonApp, GenesisState) {
db := dbm.NewMemDB()
nodeHome := t.TempDir()

Expand Down Expand Up @@ -83,7 +83,7 @@ func setup(t *testing.T, ps *signer.PrivSigner, withGenesis bool, invCheckPeriod
// Created Babylon application will have one validator with hardcoed amount of tokens.
// This is necessary as from cosmos-sdk 0.46 it is required that there is at least
// one validator in validator set during InitGenesis abci call - https://github.com/cosmos/cosmos-sdk/pull/9697
func NewBabylonAppWithCustomOptions(t *testing.T, isCheckTx bool, privSigner *signer.PrivSigner, options SetupOptions) *BabylonApp {
func NewBabylonAppWithCustomOptions(t *testing.T, isCheckTx bool, privSigner *appsigner.PrivSigner, options SetupOptions) *BabylonApp {
t.Helper()
// create validator set with single validator
valKeys, err := privval.NewValidatorKeys(ed25519.GenPrivKey(), bls12381.GenPrivKey())
Expand Down Expand Up @@ -237,7 +237,7 @@ func Setup(t *testing.T, isCheckTx bool) *BabylonApp {
func SetupWithBitcoinConf(t *testing.T, isCheckTx bool, btcConf bbn.SupportedBtcNetwork) *BabylonApp {
t.Helper()

ps, err := testsigner.SetupTestPrivSigner()
ps, err := signer.SetupTestPrivSigner()
require.NoError(t, err)
valPubKey := ps.WrappedPV.Key.PubKey
// generate genesis account
Expand All @@ -248,7 +248,7 @@ func SetupWithBitcoinConf(t *testing.T, isCheckTx bool, btcConf bbn.SupportedBtc
}
ps.WrappedPV.Key.DelegatorAddress = acc.GetAddress().String()
// create validator set with single validator
genesisKey, err := testsigner.GenesisKeyFromPrivSigner(ps)
genesisKey, err := signer.GenesisKeyFromPrivSigner(ps)
require.NoError(t, err)
genesisValSet := []*checkpointingtypes.GenesisKey{genesisKey}

Expand All @@ -262,7 +262,7 @@ func SetupWithBitcoinConf(t *testing.T, isCheckTx bool, btcConf bbn.SupportedBtc
// of one consensus engine unit (10^6) in the default token of the babylon app from first genesis
// account. A Nop logger is set in BabylonApp.
// Note that the privSigner should be the 0th item of valSet
func SetupWithGenesisValSet(t *testing.T, btcConf bbn.SupportedBtcNetwork, valSet []*checkpointingtypes.GenesisKey, privSigner *signer.PrivSigner, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *BabylonApp {
func SetupWithGenesisValSet(t *testing.T, btcConf bbn.SupportedBtcNetwork, valSet []*checkpointingtypes.GenesisKey, privSigner *appsigner.PrivSigner, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *BabylonApp {
t.Helper()
app, genesisState := setup(t, privSigner, true, 5, btcConf)
genesisState = genesisStateWithValSet(t, app, genesisState, valSet, genAccs, balances...)
Expand Down
3 changes: 1 addition & 2 deletions app/upgrades/v1/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/app/upgrades"
"github.com/babylonlabs-io/babylon/test/e2e/util"
"github.com/babylonlabs-io/babylon/testutil/addr"
"github.com/babylonlabs-io/babylon/testutil/datagen"
"github.com/babylonlabs-io/babylon/testutil/sample"
bbn "github.com/babylonlabs-io/babylon/types"
Expand Down Expand Up @@ -117,7 +116,7 @@ func (s *UpgradeTestSuite) TestUpgrade() {

// onlu gov account can store new contracts
respFromGov, err := wasmMsgServer.StoreCode(s.ctx, &wasmtypes.MsgStoreCode{
Sender: addr.AccGov.String(),
Sender: appparams.AccGov.String(),
WASMByteCode: wasmContract,
})
s.NoError(err)
Expand Down
8 changes: 4 additions & 4 deletions test/replay/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"cosmossdk.io/math"
"github.com/babylonlabs-io/babylon/app"
babylonApp "github.com/babylonlabs-io/babylon/app"
"github.com/babylonlabs-io/babylon/app/signer"
appsigner "github.com/babylonlabs-io/babylon/app/signer"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"
"github.com/babylonlabs-io/babylon/testutil/datagen"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
Expand Down Expand Up @@ -137,7 +137,7 @@ type FinalizedBlock struct {

type BabylonAppDriver struct {
App *app.BabylonApp
PrivSigner *signer.PrivSigner
PrivSigner *appsigner.PrivSigner
DriverAccountPrivKey cryptotypes.PrivKey
DriverAccountSeqNr uint64
DriverAccountAccNr uint64
Expand Down Expand Up @@ -193,7 +193,7 @@ func NewBabylonAppDriver(
panic(err)
}

signer, err := signer.InitPrivSigner(chain.Nodes[0].ConfigDir)
signer, err := appsigner.InitPrivSigner(chain.Nodes[0].ConfigDir)
require.NoError(t, err)
require.NotNil(t, signer)
signerValAddress := signer.WrappedPV.GetAddress()
Expand Down Expand Up @@ -732,7 +732,7 @@ func NewBlockReplayer(t *testing.T, nodeDir string) *BlockReplayer {
panic(err)
}

signer, err := signer.InitPrivSigner(nodeDir)
signer, err := appsigner.InitPrivSigner(nodeDir)
require.NoError(t, err)
require.NotNil(t, signer)
signerValAddress := signer.WrappedPV.GetAddress()
Expand Down
10 changes: 5 additions & 5 deletions testutil/datagen/genesiskey.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package datagen

import (
"github.com/babylonlabs-io/babylon/app/signer"
appsigner "github.com/babylonlabs-io/babylon/app/signer"
"github.com/babylonlabs-io/babylon/crypto/bls12381"
"github.com/babylonlabs-io/babylon/privval"
testsigner "github.com/babylonlabs-io/babylon/testutil/signer"
"github.com/babylonlabs-io/babylon/testutil/signer"
checkpointingtypes "github.com/babylonlabs-io/babylon/x/checkpointing/types"
cmtcrypto "github.com/cometbft/cometbft/crypto"
cmted25519 "github.com/cometbft/cometbft/crypto/ed25519"
Expand Down Expand Up @@ -88,12 +88,12 @@ func GenesisValidatorSet(numVals int) (*GenesisValidators, error) {

// GenesisValidatorSetWithPrivSigner generates a set with `numVals` genesis validators
// along with the privSigner, which will be in the 0th position of the return validator set
func GenesisValidatorSetWithPrivSigner(numVals int) (*GenesisValidators, *signer.PrivSigner, error) {
ps, err := testsigner.SetupTestPrivSigner()
func GenesisValidatorSetWithPrivSigner(numVals int) (*GenesisValidators, *appsigner.PrivSigner, error) {
ps, err := signer.SetupTestPrivSigner()
if err != nil {
return nil, nil, err
}
signerGenesisKey, err := testsigner.GenesisKeyFromPrivSigner(ps)
signerGenesisKey, err := signer.GenesisKeyFromPrivSigner(ps)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions testutil/keeper/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"

"github.com/babylonlabs-io/babylon/testutil/addr"
appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/x/incentive/types"
)

Expand All @@ -37,7 +37,7 @@ func BankKeeper(
runtime.NewKVStoreService(storeKey),
accountKeeper,
map[string]bool{},
addr.AccGov.String(),
appparams.AccGov.String(),
log.NewNopLogger(),
)

Expand Down
Loading

0 comments on commit 8192785

Please sign in to comment.