Skip to content

Commit

Permalink
fix: bnb wording change (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
randyahx authored Jul 7, 2023
1 parent ca00a6f commit b5c1003
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 128 deletions.
4 changes: 2 additions & 2 deletions app/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func BenchmarkGetAccount(b *testing.B) {
memDB := db.NewMemDB()
logger := log.NewTMLogger(io.Discard)
testApp := NewBinanceChain(logger, memDB, io.Discard)
testApp := NewBNBBeaconChain(logger, memDB, io.Discard)

pk := ed25519.GenPrivKey().PubKey()
addr := sdk.AccAddress(pk.Address())
Expand Down Expand Up @@ -49,7 +49,7 @@ func BenchmarkGetAccount(b *testing.B) {
func BenchmarkSetAccount(b *testing.B) {
memDB := db.NewMemDB()
logger := log.NewTMLogger(io.Discard)
testApp := NewBinanceChain(logger, memDB, io.Discard)
testApp := NewBNBBeaconChain(logger, memDB, io.Discard)

pk := ed25519.GenPrivKey().PubKey()
addr := sdk.AccAddress(pk.Address())
Expand Down
80 changes: 40 additions & 40 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ var (
Bech32PrefixAccAddr string
)

// BinanceChain implements ChainApp
var _ types.ChainApp = (*BinanceChain)(nil)
// BNBBeaconChain implements ChainApp
var _ types.ChainApp = (*BNBBeaconChain)(nil)

var (
Codec = MakeCodec()
ServerContext = config.NewDefaultContext()
)

// BinanceChain is the BNBChain ABCI application
type BinanceChain struct {
// BNBBeaconChain is the BNBChain ABCI application
type BNBBeaconChain struct {
*baseapp.BaseApp
Codec *wire.Codec

Expand Down Expand Up @@ -132,15 +132,15 @@ type BinanceChain struct {
takeSnapshotHeight int64 // whether to take snapshot of current height, set at endblock(), reset at commit()
}

// NewBinanceChain creates a new instance of the BinanceChain.
func NewBinanceChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*baseapp.BaseApp)) *BinanceChain {
// NewBNBBeaconChain creates a new instance of the BNBBeaconChain.
func NewBNBBeaconChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*baseapp.BaseApp)) *BNBBeaconChain {
// create app-level codec for txs and accounts
var cdc = Codec
// create composed tx decoder
decoders := wire.ComposeTxDecoders(cdc, defaultTxDecoder)

// create the applicationsimulate object
var app = &BinanceChain{
var app = &BNBBeaconChain{
BaseApp: baseapp.NewBaseApp(appName /*, cdc*/, logger, db, decoders, sdk.CollectConfig{CollectAccountBalance: ServerContext.PublishAccountBalance, CollectTxs: ServerContext.PublishTransfer || ServerContext.PublishBlock}, baseAppOptions...),
Codec: cdc,
queryHandlers: make(map[string]types.AbciQueryHandler),
Expand Down Expand Up @@ -292,15 +292,15 @@ func NewBinanceChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseApp
return app
}

func (app *BinanceChain) startPubSub(logger log.Logger) {
func (app *BNBBeaconChain) startPubSub(logger log.Logger) {
pubLogger := logger.With("module", "bnc_pubsub")
app.psServer = pubsub.NewServer(pubLogger)
if err := app.psServer.Start(); err != nil {
panic(err)
}
}

func (app *BinanceChain) subscribeEvent(logger log.Logger) {
func (app *BNBBeaconChain) subscribeEvent(logger log.Logger) {
subLogger := logger.With("module", "bnc_sub")
sub, err := app.psServer.NewSubscriber(pubsub.ClientID("bnc_app"), subLogger)
if err != nil {
Expand Down Expand Up @@ -408,14 +408,14 @@ func getABCIQueryBlackList(queryConfig *config.QueryConfig) map[string]bool {
return cfg
}

func (app *BinanceChain) initRunningMode() {
func (app *BNBBeaconChain) initRunningMode() {
err := runtime.RecoverFromFile(ServerContext.Config.RootDir, runtime.Mode(ServerContext.StartMode))
if err != nil {
cmn.Exit(err.Error())
}
}

func (app *BinanceChain) initDex() {
func (app *BNBBeaconChain) initDex() {
pairMapper := dex.NewTradingPairMapper(app.Codec, common.PairStoreKey)
app.DexKeeper = dex.NewDexKeeper(common.DexStoreKey, app.AccountKeeper, pairMapper,
app.RegisterCodespace(dex.DefaultCodespace), app.baseConfig.OrderKeeperConcurrency, app.Codec,
Expand Down Expand Up @@ -445,7 +445,7 @@ func (app *BinanceChain) initDex() {

}

func (app *BinanceChain) initPlugins() {
func (app *BNBBeaconChain) initPlugins() {
app.initSideChain()
app.initIbc()
app.initDex()
Expand Down Expand Up @@ -484,7 +484,7 @@ func (app *BinanceChain) initPlugins() {

}

func (app *BinanceChain) initSideChain() {
func (app *BNBBeaconChain) initSideChain() {
app.scKeeper.SetGovKeeper(&app.govKeeper)
app.scKeeper.SetIbcKeeper(&app.ibcKeeper)
upgrade.Mgr.RegisterBeginBlocker(sdk.LaunchBscUpgrade, func(ctx sdk.Context) {
Expand All @@ -511,7 +511,7 @@ func (app *BinanceChain) initSideChain() {
})
}

func (app *BinanceChain) initOracle() {
func (app *BNBBeaconChain) initOracle() {
app.oracleKeeper.SetPbsbServer(app.psServer)
if ServerContext.Config.Instrumentation.Prometheus {
app.oracleKeeper.EnablePrometheusMetrics()
Expand All @@ -520,7 +520,7 @@ func (app *BinanceChain) initOracle() {
oracle.RegisterUpgradeBeginBlocker(app.oracleKeeper)
}

func (app *BinanceChain) initBridge() {
func (app *BNBBeaconChain) initBridge() {
app.bridgeKeeper.SetPbsbServer(app.psServer)
upgrade.Mgr.RegisterBeginBlocker(sdk.LaunchBscUpgrade, func(ctx sdk.Context) {
app.scKeeper.SetChannelSendPermission(ctx, sdk.ChainID(ServerContext.BscIbcChainId), bTypes.BindChannelID, sdk.ChannelAllow)
Expand All @@ -529,7 +529,7 @@ func (app *BinanceChain) initBridge() {
})
}

func (app *BinanceChain) initParamHub() {
func (app *BNBBeaconChain) initParamHub() {
app.ParamHub.SetGovKeeper(&app.govKeeper)
app.ParamHub.SetupForSideChain(&app.scKeeper, &app.ibcKeeper)

Expand All @@ -547,7 +547,7 @@ func (app *BinanceChain) initParamHub() {
})
}

func (app *BinanceChain) initStaking() {
func (app *BNBBeaconChain) initStaking() {
app.stakeKeeper.SetupForSideChain(&app.scKeeper, &app.ibcKeeper)
app.stakeKeeper.SetPbsbServer(app.psServer)
upgrade.Mgr.RegisterBeginBlocker(sdk.LaunchBscUpgrade, func(ctx sdk.Context) {
Expand Down Expand Up @@ -611,7 +611,7 @@ func (app *BinanceChain) initStaking() {
}
}

func (app *BinanceChain) initGov() {
func (app *BNBBeaconChain) initGov() {
app.govKeeper.SetupForSideChain(&app.scKeeper)
upgrade.Mgr.RegisterBeginBlocker(sdk.LaunchBscUpgrade, func(ctx sdk.Context) {
storePrefix := app.scKeeper.GetSideChainStorePrefix(ctx, ServerContext.BscChainId)
Expand All @@ -632,7 +632,7 @@ func (app *BinanceChain) initGov() {
})
}

func (app *BinanceChain) initSlashing() {
func (app *BNBBeaconChain) initSlashing() {
app.slashKeeper.SetPbsbServer(app.psServer)
app.slashKeeper.SetSideChain(&app.scKeeper)
app.slashKeeper.SubscribeParamChange(app.ParamHub)
Expand Down Expand Up @@ -666,7 +666,7 @@ func (app *BinanceChain) initSlashing() {
})
}

func (app *BinanceChain) initIbc() {
func (app *BNBBeaconChain) initIbc() {
// set up IBC chainID for BBC
app.scKeeper.SetSrcChainID(sdk.ChainID(ServerContext.IbcChainId))
// set up IBC chainID for BSC
Expand All @@ -684,7 +684,7 @@ func (app *BinanceChain) initIbc() {
})
}

func (app *BinanceChain) initGovHooks() {
func (app *BNBBeaconChain) initGovHooks() {
listHooks := list.NewListHooks(app.DexKeeper, app.TokenMapper)
feeChangeHooks := paramHub.NewFeeChangeHooks(app.Codec)
cscParamChangeHooks := paramHub.NewCSCParamsChangeHook(app.Codec)
Expand All @@ -701,14 +701,14 @@ func (app *BinanceChain) initGovHooks() {
app.govKeeper.AddHooks(gov.ProposalTypeParameterChange, bcParamChangeHooks)
}

func (app *BinanceChain) initParams() {
func (app *BNBBeaconChain) initParams() {
if app.CheckState != nil && app.CheckState.Ctx.BlockHeight() != 0 {
app.ParamHub.Load(app.CheckState.Ctx)
}
}

// initChainerFn performs custom logic for chain initialization.
func (app *BinanceChain) initChainerFn() sdk.InitChainer {
func (app *BNBBeaconChain) initChainerFn() sdk.InitChainer {
return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
stateJSON := req.AppStateBytes

Expand Down Expand Up @@ -778,7 +778,7 @@ func (app *BinanceChain) initChainerFn() sdk.InitChainer {
}
}

func (app *BinanceChain) CheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckTx) {
func (app *BNBBeaconChain) CheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckTx) {
var result sdk.Result
var tx sdk.Tx
txBytes := req.Tx
Expand Down Expand Up @@ -822,7 +822,7 @@ func (app *BinanceChain) CheckTx(req abci.RequestCheckTx) (res abci.ResponseChec
}

// Implements ABCI
func (app *BinanceChain) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
func (app *BNBBeaconChain) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
res = app.BaseApp.DeliverTx(req)
txHash := cmn.HexBytes(tmhash.Sum(req.Tx)).String()
if res.IsOK() {
Expand All @@ -847,7 +847,7 @@ func (app *BinanceChain) DeliverTx(req abci.RequestDeliverTx) (res abci.Response

// PreDeliverTx implements extended ABCI for concurrency
// PreCheckTx would perform decoding, signture and other basic verification
func (app *BinanceChain) PreDeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
func (app *BNBBeaconChain) PreDeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
res = app.BaseApp.PreDeliverTx(req)
if res.IsErr() {
txHash := cmn.HexBytes(tmhash.Sum(req.Tx)).String()
Expand All @@ -856,7 +856,7 @@ func (app *BinanceChain) PreDeliverTx(req abci.RequestDeliverTx) (res abci.Respo
return res
}

func (app *BinanceChain) isBreatheBlock(height int64, lastBlockTime time.Time, blockTime time.Time) bool {
func (app *BNBBeaconChain) isBreatheBlock(height int64, lastBlockTime time.Time, blockTime time.Time) bool {
// lastBlockTime is zero if this blockTime is for the first block (first block doesn't mean height = 1, because after
// state sync from breathe block, the height is breathe block + 1)
if app.baseConfig.BreatheBlockInterval > 0 {
Expand All @@ -866,12 +866,12 @@ func (app *BinanceChain) isBreatheBlock(height int64, lastBlockTime time.Time, b
}
}

func (app *BinanceChain) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
func (app *BNBBeaconChain) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
upgrade.Mgr.BeginBlocker(ctx)
return
}

func (app *BinanceChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
func (app *BNBBeaconChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
// lastBlockTime would be 0 if this is the first block.
lastBlockTime := app.CheckState.Ctx.BlockHeader().Time
blockTime := ctx.BlockHeader().Time
Expand Down Expand Up @@ -959,7 +959,7 @@ func (app *BinanceChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) a
}
}

func (app *BinanceChain) Commit() (res abci.ResponseCommit) {
func (app *BNBBeaconChain) Commit() (res abci.ResponseCommit) {
res = app.BaseApp.Commit()
if ServerContext.Config.StateSyncReactor && app.takeSnapshotHeight > 0 {
app.StateSyncHelper.SnapshotHeights <- app.takeSnapshotHeight
Expand All @@ -968,7 +968,7 @@ func (app *BinanceChain) Commit() (res abci.ResponseCommit) {
return
}

func (app *BinanceChain) WriteRecoveryChunk(hash abci.SHA256Sum, chunk *abci.AppStateChunk, isComplete bool) (err error) {
func (app *BNBBeaconChain) WriteRecoveryChunk(hash abci.SHA256Sum, chunk *abci.AppStateChunk, isComplete bool) (err error) {
err = app.BaseApp.WriteRecoveryChunk(hash, chunk, isComplete)
if err != nil {
return err
Expand All @@ -980,7 +980,7 @@ func (app *BinanceChain) WriteRecoveryChunk(hash abci.SHA256Sum, chunk *abci.App
}

// ExportAppStateAndValidators exports blockchain world state to json.
func (app *BinanceChain) ExportAppStateAndValidators() (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
func (app *BNBBeaconChain) ExportAppStateAndValidators() (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
ctx := app.NewContext(sdk.RunTxModeCheck, abci.Header{})

// iterate to get the accounts
Expand All @@ -1005,7 +1005,7 @@ func (app *BinanceChain) ExportAppStateAndValidators() (appState json.RawMessage
}

// Query performs an abci query.
func (app *BinanceChain) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
func (app *BNBBeaconChain) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
defer func() {
if r := recover(); r != nil {
app.Logger.Error("internal error caused by query", "req", req, "stack", debug.Stack())
Expand Down Expand Up @@ -1033,7 +1033,7 @@ func (app *BinanceChain) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
return app.BaseApp.Query(req)
}

func (app *BinanceChain) AccountHandler(chainApp types.ChainApp, req abci.RequestQuery, path []string) *abci.ResponseQuery {
func (app *BNBBeaconChain) AccountHandler(chainApp types.ChainApp, req abci.RequestQuery, path []string) *abci.ResponseQuery {
var res abci.ResponseQuery
if len(path) == 2 {
addr := path[1]
Expand Down Expand Up @@ -1066,7 +1066,7 @@ func (app *BinanceChain) AccountHandler(chainApp types.ChainApp, req abci.Reques
}

// RegisterQueryHandler registers an abci query handler, implements ChainApp.RegisterQueryHandler.
func (app *BinanceChain) RegisterQueryHandler(prefix string, handler types.AbciQueryHandler) {
func (app *BNBBeaconChain) RegisterQueryHandler(prefix string, handler types.AbciQueryHandler) {
if _, ok := app.queryHandlers[prefix]; ok {
panic(fmt.Errorf("registerQueryHandler: prefix `%s` is already registered", prefix))
} else {
Expand All @@ -1075,17 +1075,17 @@ func (app *BinanceChain) RegisterQueryHandler(prefix string, handler types.AbciQ
}

// GetCodec returns the app's Codec.
func (app *BinanceChain) GetCodec() *wire.Codec {
func (app *BNBBeaconChain) GetCodec() *wire.Codec {
return app.Codec
}

// GetRouter returns the app's Router.
func (app *BinanceChain) GetRouter() baseapp.Router {
func (app *BNBBeaconChain) GetRouter() baseapp.Router {
return app.Router()
}

// GetContextForCheckState gets the context for the check state.
func (app *BinanceChain) GetContextForCheckState() sdk.Context {
func (app *BNBBeaconChain) GetContextForCheckState() sdk.Context {
return app.CheckState.Ctx
}

Expand Down Expand Up @@ -1130,14 +1130,14 @@ func MakeCodec() *wire.Codec {
return cdc
}

func (app *BinanceChain) publishEvent() {
func (app *BNBBeaconChain) publishEvent() {
if appsub.ToPublish() != nil && appsub.ToPublish().EventData != nil {
pub.ToPublishEventCh <- appsub.ToPublish()
}

}

func (app *BinanceChain) publish(tradesToPublish []*pub.Trade, proposalsToPublish *pub.Proposals, sideProposalsToPublish *pub.SideProposals, stakeUpdates *pub.StakeUpdates, blockFee pub.BlockFee, ctx sdk.Context, height, blockTime int64) {
func (app *BNBBeaconChain) publish(tradesToPublish []*pub.Trade, proposalsToPublish *pub.Proposals, sideProposalsToPublish *pub.SideProposals, stakeUpdates *pub.StakeUpdates, blockFee pub.BlockFee, ctx sdk.Context, height, blockTime int64) {
pub.Logger.Info("start to collect publish information", "height", height)

var accountsToPublish map[string]pub.Account
Expand Down
7 changes: 3 additions & 4 deletions app/app_paramhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/stretchr/testify/assert"
"github.com/tendermint/go-amino"
abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/types"
abci "github.com/tendermint/tendermint/abci/types"
Expand All @@ -51,12 +50,12 @@ var (
sdk.Coins{sdk.NewCoin("BNB", 500000e8), sdk.NewCoin("BTC-000", 200e8)})
testScParams = `[{"type": "params/StakeParamSet","value": {"unbonding_time": "604800000000000","max_validators": 11,"bond_denom": "BNB","min_self_delegation": "5000000000000","min_delegation_change": "100000000","reward_distribution_batch_size":"1000"}},{"type": "params/SlashParamSet","value": {"max_evidence_age": "259200000000000","signed_blocks_window": "0","min_signed_per_window": "0","double_sign_unbond_duration": "9223372036854775807","downtime_unbond_duration": "172800000000000","too_low_del_unbond_duration": "86400000000000","slash_fraction_double_sign": "0","slash_fraction_downtime": "0","double_sign_slash_amount": "1000000000000","downtime_slash_amount": "5000000000","submitter_reward": "100000000000","downtime_slash_fee": "1000000000"}},{"type": "params/OracleParamSet","value": {"ConsensusNeeded": "70000000"}},{"type": "params/IbcParamSet","value": {"relayer_fee": "1000000"}}]`
testClient *TestClient
testApp *BinanceChain
testApp *BNBBeaconChain
)

func init() {
ServerContext.UpgradeConfig.LaunchBscUpgradeHeight = 1
testApp = NewBinanceChain(logger, memDB, os.Stdout)
testApp = NewBNBBeaconChain(logger, memDB, os.Stdout)
testClient = NewTestClient(testApp)
}

Expand Down Expand Up @@ -368,7 +367,7 @@ func TestSCParamUpdatesFail(t *testing.T) {

// =========== setup for test cases ====

func NewTestClient(a *BinanceChain) *TestClient {
func NewTestClient(a *BNBBeaconChain) *TestClient {
a.SetDeliverState(types.Header{})
a.SetAnteHandler(newMockAnteHandler(a.Codec)) // clear AnteHandler to skip the signature verification step
return &TestClient{abcicli.NewLocalClient(nil, a), MakeCodec()}
Expand Down
6 changes: 3 additions & 3 deletions app/app_pub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func prepareGenTx(cdc *codec.Codec, chainId string,
return txBytes
}

func setupAppTest(t *testing.T) (*assert.Assertions, *require.Assertions, *BinanceChain, sdk.Account, sdk.Account) {
func setupAppTest(t *testing.T) (*assert.Assertions, *require.Assertions, *BNBBeaconChain, sdk.Account, sdk.Account) {
logger := log.NewNopLogger()
db := dbm.NewMemDB()

app := NewBinanceChain(logger, db, os.Stdout)
app := NewBNBBeaconChain(logger, db, os.Stdout)
app.SetAnteHandler(nil)
app.SetDeliverState(abci.Header{})
am := app.AccountKeeper
Expand All @@ -74,7 +74,7 @@ func setupAppTest(t *testing.T) (*assert.Assertions, *require.Assertions, *Binan
// set ante handler to nil to skip the sig verification. the side effect is that we also skip the tx fee collection.
chainId := "chain-pub"
genTx := prepareGenTx(app.Codec, chainId, sdk.ValAddress(proposerAcc.GetAddress()), proposerPubKey)
appState, _ := BinanceAppGenState(app.Codec, []json.RawMessage{genTx})
appState, _ := BNBAppGenState(app.Codec, []json.RawMessage{genTx})
appGenState, _ := wire.MarshalJSONIndent(app.Codec, appState)
app.InitChain(abci.RequestInitChain{AppStateBytes: appGenState})
app.BeginBlock(abci.RequestBeginBlock{Header: abci.Header{Height: 42, Time: time.Unix(0, 100), ProposerAddress: proposerValAddr}})
Expand Down
Loading

0 comments on commit b5c1003

Please sign in to comment.