Skip to content

Commit

Permalink
Merge pull request #629 from binance-chain/release/v0.6.1
Browse files Browse the repository at this point in the history
[R4R] Release v0.6.1
  • Loading branch information
unclezoro authored Jul 19, 2019
2 parents eee40f6 + 7a613cb commit a17eb00
Show file tree
Hide file tree
Showing 48 changed files with 15,033 additions and 223 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.6.1
FEATURES
* [\#605](https://github.com/binance-chain/node/pull/605) [Account] accounts can set flags to turn on memo validation

## 0.6.0
FEATURES
* [\#598](https://github.com/binance-chain/node/pull/598) [CLI] don't broadcast time lock related txs to blockchain by default
Expand Down
36 changes: 18 additions & 18 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
[[override]]
name = "github.com/tendermint/tendermint"
source = "github.com/binance-chain/bnc-tendermint"
version = "=v0.31.5-binance.0"
version = "=v0.31.5-binance.1"

[[constraint]]
name = "github.com/cosmos/cosmos-sdk"
source = "github.com/binance-chain/bnc-cosmos-sdk"
version = "=v0.25.0-binance.18"
version = "=v0.25.0-binance.19"
[[prune.project]]
name = "github.com/zondax/hid"
unused-packages = false
Expand Down
15 changes: 12 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/binance-chain/node/common/types"
"github.com/binance-chain/node/common/upgrade"
"github.com/binance-chain/node/common/utils"
"github.com/binance-chain/node/plugins/account"
"github.com/binance-chain/node/plugins/dex"
"github.com/binance-chain/node/plugins/dex/list"
"github.com/binance-chain/node/plugins/dex/order"
Expand Down Expand Up @@ -247,6 +248,7 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP6, upgradeConfig.BEP6Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP9, upgradeConfig.BEP9Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP10, upgradeConfig.BEP10Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP12, upgradeConfig.BEP12Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP19, upgradeConfig.BEP19Height)

// register store keys of upgrade
Expand All @@ -258,6 +260,9 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
timelock.TimeRelockMsg{}.Type(),
timelock.TimeUnlockMsg{}.Type(),
)

// register msg types of upgrade
upgrade.Mgr.RegisterMsgTypes(upgrade.BEP12, account.SetAccountFlagsMsg{}.Type())
}

func (app *BinanceChain) initRunningMode() {
Expand Down Expand Up @@ -298,6 +303,7 @@ func (app *BinanceChain) initPlugins() {
tokens.InitPlugin(app, app.TokenMapper, app.AccountKeeper, app.CoinKeeper, app.timeLockKeeper)
dex.InitPlugin(app, app.DexKeeper, app.TokenMapper, app.AccountKeeper, app.govKeeper)
param.InitPlugin(app, app.ParamHub)
account.InitPlugin(app, app.AccountKeeper)
}

func (app *BinanceChain) initGovHooks() {
Expand Down Expand Up @@ -396,7 +402,7 @@ func (app *BinanceChain) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
if admin.IsTxAllowed(tx) {
txHash := cmn.HexBytes(tmhash.Sum(txBytes)).String()
app.Logger.Debug("Handle CheckTx", "Tx", txHash)
result = app.RunTx(sdk.RunTxModeCheckAfterPre, txBytes, tx, txHash)
result = app.RunTx(sdk.RunTxModeCheckAfterPre, tx, txHash)
if !result.IsOK() {
app.RemoveTxFromCache(txBytes)
}
Expand All @@ -411,7 +417,7 @@ func (app *BinanceChain) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
if admin.IsTxAllowed(tx) {
txHash := cmn.HexBytes(tmhash.Sum(txBytes)).String()
app.Logger.Debug("Handle CheckTx", "Tx", txHash)
result = app.RunTx(sdk.RunTxModeCheck, txBytes, tx, txHash)
result = app.RunTx(sdk.RunTxModeCheck, tx, txHash)
if result.IsOK() {
app.AddTxToCache(txBytes, tx)
}
Expand Down Expand Up @@ -520,7 +526,9 @@ func (app *BinanceChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) a
if isBreatheBlock || ctx.RouterCallRecord()["stake"] {
// some endblockers without fees will execute after publish to make publication run as early as possible.
validatorUpdates, completedUbd = stake.EndBlocker(ctx, app.stakeKeeper)
app.ValAddrCache.ClearCache()
if len(validatorUpdates) != 0 {
app.ValAddrCache.ClearCache()
}
}

if app.publicationConfig.ShouldPublishAny() &&
Expand Down Expand Up @@ -699,6 +707,7 @@ func MakeCodec() *wire.Codec {
sdk.RegisterCodec(cdc) // Register Msgs
dex.RegisterWire(cdc)
tokens.RegisterWire(cdc)
account.RegisterWire(cdc)
types.RegisterWire(cdc)
tx.RegisterWire(cdc)
stake.RegisterCodec(cdc)
Expand Down
165 changes: 0 additions & 165 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,187 +8,22 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/mock"
"github.com/stretchr/testify/require"
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"
"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"
"github.com/tendermint/tendermint/libs/db"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"

"github.com/binance-chain/node/common/fees"
"github.com/binance-chain/node/common/testutils"
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"
)

type TestClient struct {
cl abcicli.Client
cdc *wire.Codec
}

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)

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)
}

return newCtx, sdk.Result{}, false
}
}

func (tc *TestClient) DeliverTxAsync(msg sdk.Msg, cdc *wire.Codec) *abcicli.ReqRes {
stdtx := auth.NewStdTx([]sdk.Msg{msg}, nil, "test", 0, nil)
tx, _ := tc.cdc.MarshalBinaryLengthPrefixed(stdtx)
return tc.cl.DeliverTxAsync(tx)
}

func (tc *TestClient) CheckTxAsync(msg sdk.Msg, cdc *wire.Codec) *abcicli.ReqRes {
stdtx := auth.NewStdTx([]sdk.Msg{msg}, nil, "test", 0, nil)
tx, _ := tc.cdc.MarshalBinaryLengthPrefixed(stdtx)
return tc.cl.CheckTxAsync(tx)
}

func (tc *TestClient) DeliverTxSync(msg sdk.Msg, cdc *wire.Codec) (*types.ResponseDeliverTx, error) {
stdtx := auth.NewStdTx([]sdk.Msg{msg}, nil, "test", 0, nil)
tx, _ := tc.cdc.MarshalBinaryLengthPrefixed(stdtx)
return tc.cl.DeliverTxSync(tx)
}

func (tc *TestClient) CheckTxSync(msg sdk.Msg, cdc *wire.Codec) (*types.ResponseCheckTx, error) {
stdtx := auth.NewStdTx([]sdk.Msg{msg}, nil, "test", 0, nil)
tx, _ := tc.cdc.MarshalBinaryLengthPrefixed(stdtx)
return tc.cl.CheckTxSync(tx)
}

// util objects
var (
memDB = db.NewMemDB()
logger = log.NewTMLogger(os.Stdout)
testApp = NewBinanceChain(logger, memDB, os.Stdout)
genAccs, addrs, pubKeys, privKeys = mock.CreateGenAccounts(4,
sdk.Coins{sdk.NewCoin("BNB", 500e8), sdk.NewCoin("BTC-000", 200e8)})
testClient = NewTestClient(testApp)
)

func TearDown() {
// remove block db
os.RemoveAll(cfg.DefaultConfig().DBDir())
}

func InitAccounts(ctx sdk.Context, app *BinanceChain) *[]sdk.Account {
for _, acc := range genAccs {
aacc := &common.AppAccount{
BaseAccount: auth.BaseAccount{
Address: acc.GetAddress(),
Coins: acc.GetCoins(),
}}
if app.AccountKeeper.GetAccount(ctx, acc.GetAddress()) == nil {
aacc.BaseAccount.AccountNumber = app.AccountKeeper.GetNextAccountNumber(ctx)
}
app.AccountKeeper.SetAccount(ctx, aacc)
}
return &genAccs
}

func ResetAccounts(ctx sdk.Context, app *BinanceChain, ccy1 int64, ccy2 int64, ccy3 int64) {
for _, acc := range genAccs {
a := app.AccountKeeper.GetAccount(ctx, acc.GetAddress())
a.SetCoins(sdk.Coins{sdk.NewCoin("BNB", ccy1), sdk.NewCoin("BTC-000", ccy2), sdk.NewCoin("ETH-000", ccy3)})
app.AccountKeeper.SetAccount(ctx, a)
}
}

func Account(i int) sdk.Account {
return genAccs[i]
}

func Address(i int) sdk.AccAddress {
return addrs[i]
}

func NewTestClient(a *BinanceChain) *TestClient {
a.SetCheckState(types.Header{})
a.SetAnteHandler(NewMockAnteHandler(a.Codec)) // clear AnteHandler to skip the signature verification step
return &TestClient{abcicli.NewLocalClient(nil, a), MakeCodec()}
}

func GetAvail(ctx sdk.Context, add sdk.AccAddress, ccy string) int64 {
return testApp.CoinKeeper.GetCoins(ctx, add).AmountOf(ccy)
}

func GetLocked(ctx sdk.Context, add sdk.AccAddress, ccy string) int64 {
return testApp.AccountKeeper.GetAccount(ctx, add).(common.NamedAccount).GetLockedCoins().AmountOf(ccy)
}

func setGenesis(bapp *BinanceChain, tokens []tokens.GenesisToken, accs ...*common.AppAccount) error {
genaccs := make([]GenesisAccount, len(accs))
for i, acc := range accs {
pk := ed25519.GenPrivKey().PubKey()
valAddr := pk.Address()
genaccs[i] = NewGenesisAccount(acc, valAddr)
}

genesisState := GenesisState{
Tokens: tokens,
Accounts: genaccs,
DexGenesis: dex.DefaultGenesis,
ParamGenesis: param.DefaultGenesisState,
}

stateBytes, err := wire.MarshalJSONIndent(bapp.Codec, genesisState)
if err != nil {
return err
}

// Initialize the chain
vals := []abci.ValidatorUpdate{}
bapp.InitChain(abci.RequestInitChain{Validators: vals, AppStateBytes: stateBytes})
bapp.Commit()

return nil
}

func TestGenesis(t *testing.T) {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
db := dbm.NewMemDB()
bapp := NewBinanceChain(logger, db, os.Stdout)

// Construct some genesis bytes to reflect democoin/types/AppAccount
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
baseAcc := auth.BaseAccount{
Address: addr,
}
tokens := []tokens.GenesisToken{{"BNB", "BNB", 100000, addr, false}}
acc := &common.AppAccount{baseAcc, "blah", sdk.Coins(nil), sdk.Coins(nil)}

err := setGenesis(bapp, tokens, acc)
require.Nil(t, err)
// A checkTx context
ctx := bapp.BaseApp.NewContext(sdk.RunTxModeCheck, abci.Header{})
if err := acc.SetCoins(sdk.Coins{sdk.Coin{"BNB", 100000}}); err != nil {
t.Fatalf("SetCoins error: " + err.Error())
}
res1 := bapp.AccountKeeper.GetAccount(ctx, baseAcc.Address).(common.NamedAccount)
require.Equal(t, acc, res1)
}

func defaultLogger() log.Logger {
return log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
}
Expand Down
Loading

0 comments on commit a17eb00

Please sign in to comment.