Skip to content

Commit

Permalink
Merge pull request #225 from binance-chain/refactor-cross
Browse files Browse the repository at this point in the history
[R4R]Refactor cross chain mechanism and governance of bsc
  • Loading branch information
unclezoro authored Jul 8, 2020
2 parents cf6c9b1 + 799fd5c commit f430a26
Show file tree
Hide file tree
Showing 158 changed files with 4,981 additions and 1,042 deletions.
19 changes: 11 additions & 8 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func handleQueryCustom(app *BaseApp, path []string, req abci.RequestQuery) (res
}
querier := app.queryRouter.Route(path[1])
if querier == nil {
return sdk.ErrUnknownRequest("no custom querier found for route "+ path[1]).QueryResult()
return sdk.ErrUnknownRequest("no custom querier found for route " + path[1]).QueryResult()
}

ctx := sdk.NewContext(app.cms.CacheMultiStore(), app.CheckState.Ctx.BlockHeader(), sdk.RunTxModeCheck, app.Logger)
Expand Down Expand Up @@ -589,7 +589,7 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckTx)
Code: uint32(result.Code),
Data: result.Data,
Log: result.Log,
Events: result.Tags.ToEvents(),
Events: result.GetEvents(),
}
}

Expand Down Expand Up @@ -617,7 +617,7 @@ func (app *BaseApp) PreCheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckT
Code: uint32(result.Code),
Data: result.Data,
Log: result.Log,
Events: result.Tags.ToEvents(),
Events: result.GetEvents(),
}
}

Expand All @@ -644,7 +644,7 @@ func (app *BaseApp) ReCheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckTx
Code: uint32(result.Code),
Data: result.Data,
Log: result.Log,
Events: result.Tags.ToEvents(),
Events: result.GetEvents(),
}
}

Expand Down Expand Up @@ -679,7 +679,7 @@ func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliv
Code: uint32(result.Code),
Data: result.Data,
Log: result.Log,
Events: result.Tags.ToEvents(),
Events: result.GetEvents(),
}
}

Expand All @@ -691,7 +691,7 @@ func (app *BaseApp) PreDeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDe
Code: uint32(result.Code),
Data: result.Data,
Log: result.Log,
Events: result.Tags.ToEvents(),
Events: result.GetEvents(),
}
}

Expand Down Expand Up @@ -747,6 +747,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode sdk.RunTxMode)
logs := make([]string, 0, len(msgs))
var data []byte // NOTE: we just append them all (?!)
var tags sdk.Tags // also just append them all
var events sdk.Events
var code sdk.ABCICodeType
for msgIdx, msg := range msgs {
// Match route.
Expand All @@ -762,6 +763,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode sdk.RunTxMode)
// Append Data and Tags
data = append(data, msgResult.Data...)
tags = append(tags, msgResult.Tags...)
events = append(events, msgResult.Events...)

// Stop execution and return on first failed message.
if !msgResult.IsOK() {
Expand All @@ -771,7 +773,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode sdk.RunTxMode)
}

// Construct usable logs in multi-message transactions.
logs = append(logs, "Msg " + strconv.Itoa(msgIdx) + ": " + msgResult.Log)
logs = append(logs, "Msg "+strconv.Itoa(msgIdx)+": "+msgResult.Log)
}
// A tx must only contain one msg. If the msg execution is success, record it
if code == sdk.ABCICodeOK {
Expand All @@ -783,7 +785,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode sdk.RunTxMode)
Data: data,
Log: strings.Join(logs, "\n"),
// TODO: FeeAmount/FeeDenom
Tags: tags,
Tags: tags,
Events: events,
}

return result
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion x/slashing/bsc/header.go → bsc/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"io"
"math/big"

"github.com/cosmos/cosmos-sdk/x/slashing/bsc/rlp"
"github.com/tendermint/tendermint/crypto/secp256k1"
"golang.org/x/crypto/sha3"

"github.com/cosmos/cosmos-sdk/bsc/rlp"
)

type Header struct {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions bsc/rate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package bsc

import (
"math/big"

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

const (
BNBDecimalOnBC = 8
BNBDecimalOnBSC = 18
)

func ConvertBCAmountToBSCAmount(bcAmount int64) *big.Int {
decimals := sdk.NewIntWithDecimal(1, int(BNBDecimalOnBSC-BNBDecimalOnBC))
bscAmount := sdk.NewInt(bcAmount).Mul(decimals)
return bscAmount.BigInt()
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 7 additions & 4 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"sort"

"github.com/cosmos/cosmos-sdk/x/ibc"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
Expand All @@ -21,8 +20,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/sidechain"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
)
Expand Down Expand Up @@ -60,6 +61,7 @@ type GaiaApp struct {
keyParams *sdk.KVStoreKey
tkeyParams *sdk.TransientStoreKey
keyIbc *sdk.KVStoreKey
keySide *sdk.KVStoreKey

// Manage getting and setting accounts
accountKeeper auth.AccountKeeper
Expand Down Expand Up @@ -116,7 +118,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
app.cdc,
app.keyParams, app.tkeyParams,
)
app.ibcKeeper = ibc.NewKeeper(app.keyIbc, ibc.DefaultCodespace)
app.ibcKeeper = ibc.NewKeeper(app.keyIbc, app.paramsKeeper.Subspace(ibc.DefaultParamspace), ibc.DefaultCodespace,
sidechain.NewKeeper(app.keySide, app.paramsKeeper.Subspace(sidechain.DefaultParamspace), app.cdc))
app.stakeKeeper = stake.NewKeeper(
app.cdc,
app.keyStake, app.tkeyStake,
Expand Down Expand Up @@ -223,7 +226,7 @@ func (app *GaiaApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) ab
// nolint: unparam
func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
ctx = ctx.WithEventManager(sdk.NewEventManager())
tags, _, _ := gov.EndBlocker(ctx, app.govKeeper)
gov.EndBlocker(ctx, app.govKeeper)
validatorUpdates, _ := stake.EndBlocker(ctx, app.stakeKeeper)
ibc.EndBlocker(ctx, app.ibcKeeper)

Expand All @@ -232,7 +235,7 @@ func (app *GaiaApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.R

return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Events: append(tags.ToEvents(), ctx.EventManager().ABCIEvents()...),
Events: ctx.EventManager().ABCIEvents(),
}
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/gaia/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/sidechain"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -53,6 +54,7 @@ func NewMockGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppO
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
keyIbc: sdk.NewKVStoreKey("ibc"),
keySide: sdk.NewKVStoreKey("side"),
}

var app = &MockGaiaApp{gApp}
Expand All @@ -70,7 +72,9 @@ func NewMockGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppO
app.cdc,
app.keyParams, app.tkeyParams,
)
app.ibcKeeper = ibc.NewKeeper(app.keyIbc, ibc.DefaultCodespace)
app.ibcKeeper = ibc.NewKeeper(app.keyIbc, app.paramsKeeper.Subspace(ibc.DefaultParamspace), ibc.DefaultCodespace,
sidechain.NewKeeper(app.keySide, app.paramsKeeper.Subspace(sidechain.DefaultParamspace), app.cdc))

app.stakeKeeper = stake.NewKeeper(
app.cdc,
app.keyStake, app.tkeyStake,
Expand Down
6 changes: 5 additions & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/sidechain"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"

Expand Down Expand Up @@ -138,6 +139,7 @@ type GaiaApp struct {
keyParams *sdk.KVStoreKey
tkeyParams *sdk.TransientStoreKey
keyIbc *sdk.KVStoreKey
keySide *sdk.KVStoreKey

// Manage getting and setting accounts
accountKeeper auth.AccountKeeper
Expand Down Expand Up @@ -166,6 +168,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
keyIbc: sdk.NewKVStoreKey("ibc"),
keySide: sdk.NewKVStoreKey("ibc"),
}

// define the accountKeeper
Expand All @@ -178,7 +181,8 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
// add handlers
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.ibcKeeper = ibc.NewKeeper(app.keyIbc, app.RegisterCodespace(ibc.DefaultCodespace))
app.ibcKeeper = ibc.NewKeeper(app.keyIbc, app.paramsKeeper.Subspace(ibc.DefaultParamspace), ibc.DefaultCodespace, sidechain.NewKeeper(app.keySide, app.paramsKeeper.Subspace(sidechain.DefaultParamspace), app.cdc))

app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, nil, app.paramsKeeper.Subspace(stake.DefaultParamspace), app.RegisterCodespace(stake.DefaultCodespace))
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace), app.RegisterCodespace(slashing.DefaultCodespace), app.bankKeeper)

Expand Down
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ require (
github.com/binance-chain/tss-lib v1.0.0
github.com/btcsuite/btcd v0.20.0-beta
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d
github.com/go-kit/kit v0.9.0
github.com/golang/protobuf v1.3.2
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2
github.com/gorilla/mux v1.7.3
github.com/hashicorp/golang-lru v0.5.3
github.com/ipfs/go-log v0.0.1
github.com/magiconair/properties v1.8.1
github.com/mattn/go-isatty v0.0.10
github.com/mitchellh/go-homedir v1.1.0
github.com/pelletier/go-toml v1.4.0
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.1.0
github.com/rakyll/statik v0.1.5
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
Expand All @@ -35,7 +37,7 @@ require (
replace (
github.com/tendermint/go-amino => github.com/binance-chain/bnc-go-amino v0.14.1-binance.2
github.com/tendermint/iavl => github.com/binance-chain/bnc-tendermint-iavl v0.12.0-binance.4
github.com/tendermint/tendermint => github.com/binance-chain/bnc-tendermint v0.32.3-binance.1
github.com/tendermint/tendermint => github.com/binance-chain/bnc-tendermint v0.32.3-binance.1.0.20200430083314-39f228dd6425
github.com/zondax/ledger-cosmos-go => github.com/binance-chain/ledger-cosmos-go v0.9.9-binance.3
golang.org/x/crypto => github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae
)
Loading

0 comments on commit f430a26

Please sign in to comment.