Skip to content

Commit

Permalink
Merge pull request #796 from binance-chain/bsc_base_master
Browse files Browse the repository at this point in the history
Release v0.8.0
  • Loading branch information
fletcher142 authored Aug 22, 2020
2 parents 82e2af8 + 7451c03 commit 422f0a9
Show file tree
Hide file tree
Showing 94 changed files with 5,936 additions and 1,828 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Changelog
## 0.8.0
FEATURES
[Stake] import stake module for side chain
[Slashing] import slashing module for side chain
[Token] support cross chain transfer

IMPROVEMENTS
[Pub] import pubsub server for publishing message


## 0.7.2-hf.1
BUG FIXES
* [\#766](https://github.com/binance-chain/node/pull/766)[Dex] remove orderInfo from orderInfoForPub when publish anything
Expand Down
375 changes: 319 additions & 56 deletions app/app.go

Large diffs are not rendered by default.

502 changes: 502 additions & 0 deletions app/app_paramhub_test.go

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions app/app_pub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/fees"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
Expand All @@ -22,7 +25,7 @@ import (

"github.com/binance-chain/node/app/config"
"github.com/binance-chain/node/app/pub"
"github.com/binance-chain/node/common/fees"
appsub "github.com/binance-chain/node/app/pub/sub"
"github.com/binance-chain/node/common/testutils"
orderPkg "github.com/binance-chain/node/plugins/dex/order"
dextypes "github.com/binance-chain/node/plugins/dex/types"
Expand Down Expand Up @@ -93,9 +96,13 @@ func setupAppTest(t *testing.T) (*assert.Assertions, *require.Assertions, *Binan
pub.Logger = logger.With("module", "pub")
pub.Cfg = app.publicationConfig
pub.ToPublishCh = make(chan pub.BlockInfoToPublish, app.publicationConfig.PublicationChannelSize)
pub.ToPublishEventCh = make(chan *appsub.ToPublishEvent, app.publicationConfig.PublicationChannelSize)
app.publisher = pub.NewMockMarketDataPublisher()
go pub.Publish(app.publisher, app.metrics, logger, app.publicationConfig, pub.ToPublishCh)
pub.IsLive = true
go pub.PublishEvent(app.publisher, logger, app.publicationConfig, pub.ToPublishEventCh)
app.startPubSub(logger)
app.subscribeEvent(logger)

keeper := app.DexKeeper
keeper.EnablePublish()
Expand Down
18 changes: 10 additions & 8 deletions app/apptest/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import (
"os"
"testing"

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkfees "github.com/cosmos/cosmos-sdk/types/fees"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/mock"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/x/paramHub"

abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/types"
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/ed25519"
. "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"
Expand All @@ -21,10 +25,8 @@ import (
"github.com/tendermint/tendermint/libs/log"

"github.com/binance-chain/node/app"
"github.com/binance-chain/node/common/fees"
common "github.com/binance-chain/node/common/types"
"github.com/binance-chain/node/plugins/dex"
"github.com/binance-chain/node/plugins/param"
"github.com/binance-chain/node/plugins/tokens"
"github.com/binance-chain/node/wire"
)
Expand All @@ -37,13 +39,13 @@ type TestClient struct {
func NewMockAnteHandler(cdc *wire.Codec) sdk.AnteHandler {
return func(ctx sdk.Context, tx sdk.Tx, runTxMode sdk.RunTxMode) (newCtx sdk.Context, result sdk.Result, abort bool) {
msg := tx.GetMsgs()[0]
fee := fees.GetCalculator(msg.Type())(msg)
fee := sdkfees.GetCalculator(msg.Type())(msg)

if ctx.IsDeliverTx() {
// add fee to pool, even it's free
stdTx := tx.(auth.StdTx)
txHash := cmn.HexBytes(tmhash.Sum(cdc.MustMarshalBinaryLengthPrefixed(stdTx))).String()
fees.Pool.AddFee(txHash, fee)
sdkfees.Pool.AddFee(txHash, fee)
}

return newCtx, sdk.Result{}, false
Expand Down Expand Up @@ -137,7 +139,7 @@ func GetLocked(ctx sdk.Context, add sdk.AccAddress, ccy string) int64 {
func setGenesis(bapp *app.BinanceChain, tokens []tokens.GenesisToken, accs ...*common.AppAccount) error {
genaccs := make([]app.GenesisAccount, len(accs))
for i, acc := range accs {
pk := ed25519.GenPrivKey().PubKey()
pk := GenPrivKey().PubKey()
valAddr := pk.Address()
genaccs[i] = app.NewGenesisAccount(acc, valAddr)
}
Expand All @@ -146,7 +148,7 @@ func setGenesis(bapp *app.BinanceChain, tokens []tokens.GenesisToken, accs ...*c
Tokens: tokens,
Accounts: genaccs,
DexGenesis: dex.DefaultGenesis,
ParamGenesis: param.DefaultGenesisState,
ParamGenesis: paramHub.DefaultGenesisState,
}

stateBytes, err := wire.MarshalJSONIndent(bapp.Codec, genesisState)
Expand Down
3 changes: 2 additions & 1 deletion app/apptest/match_allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
param "github.com/cosmos/cosmos-sdk/x/paramHub"

"github.com/stretchr/testify/assert"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
Expand All @@ -21,7 +23,6 @@ import (
"github.com/binance-chain/node/plugins/dex"
"github.com/binance-chain/node/plugins/dex/order"
"github.com/binance-chain/node/plugins/dex/types"
"github.com/binance-chain/node/plugins/param"
"github.com/binance-chain/node/plugins/tokens"
"github.com/binance-chain/node/wire"
)
Expand Down
2 changes: 1 addition & 1 deletion app/apptest/ordertx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
abci "github.com/tendermint/tendermint/abci/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/fees"
"github.com/cosmos/cosmos-sdk/x/auth"

"github.com/binance-chain/node/common/fees"
"github.com/binance-chain/node/common/utils"
o "github.com/binance-chain/node/plugins/dex/order"
"github.com/binance-chain/node/plugins/dex/types"
Expand Down
139 changes: 125 additions & 14 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import (
"path/filepath"
"text/template"

"github.com/cosmos/cosmos-sdk/server"
"github.com/spf13/viper"

"github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/common"

"github.com/cosmos/cosmos-sdk/server"
)

var configTemplate *template.Template
Expand Down Expand Up @@ -67,6 +65,8 @@ LotSizeUpgradeHeight = {{ .UpgradeConfig.LotSizeUpgradeHeight }}
ListingRuleUpgradeHeight = {{ .UpgradeConfig.ListingRuleUpgradeHeight }}
# Block height of FixZeroBalanceHeight upgrade
FixZeroBalanceHeight = {{ .UpgradeConfig.FixZeroBalanceHeight }}
# Block height of smart chain upgrade
LaunchBscUpgradeHeight = {{ .UpgradeConfig.LaunchBscUpgradeHeight }}
# Block height of BEP8 upgrade
BEP8Height = {{ .UpgradeConfig.BEP8Height }}
# Block height of BEP67 upgrade
Expand Down Expand Up @@ -125,6 +125,36 @@ publishBlock = {{ .PublicationConfig.PublishBlock }}
blockTopic = "{{ .PublicationConfig.BlockTopic }}"
blockKafka = "{{ .PublicationConfig.BlockKafka }}"
# Whether we want publish distribution
publishDistributeReward = {{ .PublicationConfig.PublishDistributeReward }}
distributeRewardTopic = "{{ .PublicationConfig.DistributeRewardTopic }}"
distributeRewardKafka = "{{ .PublicationConfig.DistributeRewardKafka }}"
# Whether we want publish staking
publishStaking = {{ .PublicationConfig.PublishStaking }}
stakingTopic = "{{ .PublicationConfig.StakingTopic }}"
stakingKafka = "{{ .PublicationConfig.StakingKafka }}"
# Whether we want publish slashing
publishSlashing = {{ .PublicationConfig.PublishSlashing }}
slashingTopic = "{{ .PublicationConfig.SlashingTopic }}"
slashingKafka = "{{ .PublicationConfig.SlashingKafka }}"
# Whether we want publish cross transfer
publishCrossTransfer = {{ .PublicationConfig.PublishCrossTransfer }}
crossTransferTopic = "{{ .PublicationConfig.CrossTransferTopic }}"
crossTransferKafka = "{{ .PublicationConfig.CrossTransferKafka }}"
# Whether we want publish side proposals
publishSideProposal = {{ .PublicationConfig.PublishSideProposal }}
sideProposalTopic = "{{ .PublicationConfig.SideProposalTopic }}"
sideProposalKafka = "{{ .PublicationConfig.SideProposalKafka }}"
# Whether we want publish breatheBlock
publishBreatheBlock = {{ .PublicationConfig.PublishBreatheBlock }}
breatheBlockTopic = "{{ .PublicationConfig.BreatheBlockTopic }}"
breatheBlockKafka = "{{ .PublicationConfig.BreatheBlockKafka }}"
# Global setting
publicationChannelSize = {{ .PublicationConfig.PublicationChannelSize }}
publishKafka = {{ .PublicationConfig.PublishKafka }}
Expand Down Expand Up @@ -159,6 +189,14 @@ logFilePath = "{{ .LogConfig.LogFilePath }}"
# Number of logs keep in memory before writing to file
logBuffSize = {{ .LogConfig.LogBuffSize }}
[cross_chain]
# IBC chain-id for current chain
ibcChainId = {{ .CrossChainConfig.IbcChainId }}
# chain-id for bsc chain
bscChainId = "{{ .CrossChainConfig.BscChainId }}"
# IBC chain-id for bsc chain
bscIbcChainId = {{ .CrossChainConfig.BscIbcChainId }}
[dex]
# The suffixed symbol of BUSD
BUSDSymbol = "{{ .DexConfig.BUSDSymbol }}"
Expand Down Expand Up @@ -188,6 +226,7 @@ type BinanceChainConfig struct {
*BaseConfig `mapstructure:"base"`
*UpgradeConfig `mapstructure:"upgrade"`
*QueryConfig `mapstructure:"query"`
*CrossChainConfig `mapstructure:"cross_chain"`
*DexConfig `mapstructure:"dex"`
}

Expand All @@ -199,6 +238,7 @@ func DefaultBinanceChainConfig() *BinanceChainConfig {
BaseConfig: defaultBaseConfig(),
UpgradeConfig: defaultUpgradeConfig(),
QueryConfig: defaultQueryConfig(),
CrossChainConfig: defaultCrossChainConfig(),
DexConfig: defaultGovConfig(),
}
}
Expand Down Expand Up @@ -248,6 +288,30 @@ type PublicationConfig struct {
BlockTopic string `mapstructure:"blockTopic"`
BlockKafka string `mapstructure:"blockKafka"`

PublishDistributeReward bool `mapstructure:"publishDistributeReward"`
DistributeRewardTopic string `mapstructure:"distributeRewardTopic"`
DistributeRewardKafka string `mapstructure:"distributeRewardKafka"`

PublishStaking bool `mapstructure:"publishStaking"`
StakingTopic string `mapstructure:"stakingTopic"`
StakingKafka string `mapstructure:"stakingKafka"`

PublishSlashing bool `mapstructure:"publishSlashing"`
SlashingTopic string `mapstructure:"slashingTopic"`
SlashingKafka string `mapstructure:"slashingKafka"`

PublishCrossTransfer bool `mapstructure:"publishCrossTransfer"`
CrossTransferTopic string `mapstructure:"crossTransferTopic"`
CrossTransferKafka string `mapstructure:"crossTransferKafka"`

PublishSideProposal bool `mapstructure:"publishSideProposal"`
SideProposalTopic string `mapstructure:"sideProposalTopic"`
SideProposalKafka string `mapstructure:"sideProposalKafka"`

PublishBreatheBlock bool `mapstructure:"publichBreatheBlock"`
BreatheBlockTopic string `mapstructure:"breatheBlockTopic"`
BreatheBlockKafka string `mapstructure:"breatheBlockKafka"`

PublicationChannelSize int `mapstructure:"publicationChannelSize"`

// DO NOT put this option in config file
Expand Down Expand Up @@ -299,6 +363,30 @@ func defaultPublicationConfig() *PublicationConfig {
BlockTopic: "block",
BlockKafka: "127.0.0.1:9092",

PublishDistributeReward: false,
DistributeRewardTopic: "distribution",
DistributeRewardKafka: "127.0.0.1:9092",

PublishStaking: false,
StakingTopic: "staking",
StakingKafka: "127.0.0.1:9092",

PublishSlashing: false,
SlashingTopic: "slashing",
SlashingKafka: "127.0.0.1:9092",

PublishCrossTransfer: false,
CrossTransferTopic: "crossTransfer",
CrossTransferKafka: "127.0.0.1:9092",

PublishSideProposal: false,
SideProposalTopic: "sideProposal",
SideProposalKafka: "127.0.0.1:9092",

PublishBreatheBlock: false,
BreatheBlockTopic: "breatheBlock",
BreatheBlockKafka: "127.0.0.1:9092",

PublicationChannelSize: 10000,
FromHeightInclusive: 1,
PublishKafka: false,
Expand All @@ -322,7 +410,29 @@ func (pubCfg PublicationConfig) ShouldPublishAny() bool {
pubCfg.PublishOrderBook ||
pubCfg.PublishBlockFee ||
pubCfg.PublishTransfer ||
pubCfg.PublishBlock
pubCfg.PublishBlock ||
pubCfg.PublishDistributeReward ||
pubCfg.PublishStaking ||
pubCfg.PublishSlashing ||
pubCfg.PublishCrossTransfer ||
pubCfg.PublishSideProposal ||
pubCfg.PublishBreatheBlock
}

type CrossChainConfig struct {
IbcChainId uint16 `mapstructure:"ibcChainId"`

BscChainId string `mapstructure:"bscChainId"`
BscIbcChainId uint16 `mapstructure:"bscIBCChainId"`
}

func defaultCrossChainConfig() *CrossChainConfig {
return &CrossChainConfig{
IbcChainId: 1,

BscChainId: "bsc",
BscIbcChainId: 2,
}
}

type LogConfig struct {
Expand Down Expand Up @@ -362,7 +472,6 @@ func defaultBaseConfig() *BaseConfig {
}

type UpgradeConfig struct {

// Galileo Upgrade
BEP6Height int64 `mapstructure:"BEP6Height"`
BEP9Height int64 `mapstructure:"BEP9Height"`
Expand All @@ -372,12 +481,13 @@ type UpgradeConfig struct {
BEP12Height int64 `mapstructure:"BEP12Height"`
// Archimedes Upgrade
BEP3Height int64 `mapstructure:"BEP3Height"`

// TODO: add upgrade name
// Heisenberg Upgrade
FixSignBytesOverflowHeight int64 `mapstructure:"FixSignBytesOverflowHeight"`
LotSizeUpgradeHeight int64 `mapstructure:"LotSizeUpgradeHeight"`
ListingRuleUpgradeHeight int64 `mapstructure:"ListingRuleUpgradeHeight"`
FixZeroBalanceHeight int64 `mapstructure:"FixZeroBalanceHeight"`
// TODO: add upgrade name
LaunchBscUpgradeHeight int64 `mapstructure:"LaunchBscUpgradeHeight"`

// TODO: add upgrade name
BEP8Height int64 `mapstructure:"BEP8Height"`
Expand All @@ -394,13 +504,14 @@ func defaultUpgradeConfig() *UpgradeConfig {
BEP19Height: 1,
BEP12Height: 1,
BEP3Height: 1,
FixSignBytesOverflowHeight: math.MaxInt64,
LotSizeUpgradeHeight: math.MaxInt64,
ListingRuleUpgradeHeight: math.MaxInt64,
FixZeroBalanceHeight: math.MaxInt64,
BEP8Height: math.MaxInt64,
BEP67Height: math.MaxInt64,
BEP70Height: math.MaxInt64,
FixSignBytesOverflowHeight: 1,
LotSizeUpgradeHeight: 1,
ListingRuleUpgradeHeight: 1,
FixZeroBalanceHeight: 1,
BEP8Height: 1,
BEP67Height: 1,
BEP70Height: 1,
LaunchBscUpgradeHeight: math.MaxInt64,
}
}

Expand Down
Loading

0 comments on commit 422f0a9

Please sign in to comment.