Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.25.0-binance.12 #89

Merged
merged 7 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The reason is that we need to keep the import path.
```bash
> cd $GOPATH/src/github.com
> rm -rf cosmos/cosmos-sdk
> git clone https://github.com/BiJie/bnc-cosmos-sdk.git cosmos/cosmos-sdk
> git clone https://github.com/binance-chain/bnc-cosmos-sdk.git cosmos/cosmos-sdk
> cd cosmos-sdk
> git checkout develop
> make get_vendor_deps
Expand Down Expand Up @@ -63,4 +63,4 @@ See the [Cosmos Docs](https://cosmos.network/docs/)

## Disambiguation

This Cosmos-SDK project is not related to the [React-Cosmos](https://github.com/react-cosmos/react-cosmos) project (yet). Many thanks to Evan Coury and Ovidiu (@skidding) for this Github organization name. As per our agreement, this disambiguation notice will stay here.
This Cosmos-SDK project is not related to the [React-Cosmos](https://github.com/react-cosmos/react-cosmos) project (yet). Many thanks to Evan Coury and Ovidiu (@skidding) for this Github organization name. As per our agreement, this disambiguation notice will stay here.
8 changes: 6 additions & 2 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"runtime/debug"
"strings"

"github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru"
"github.com/pkg/errors"
"github.com/spf13/viper"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -109,6 +109,8 @@ func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecod
Pool: new(sdk.Pool),
}

sdk.UpgradeMgr = sdk.NewUpgradeManager(sdk.MainNetConfig) // TODO: make this configurable

// Register the undefined & root codespaces, which should not be used by
// any modules.
app.codespacer.RegisterOrPanic(sdk.CodespaceRoot)
Expand Down Expand Up @@ -506,6 +508,8 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
))
}

sdk.UpgradeMgr.SetHeight(req.Header.Height)

// Initialize the DeliverTx state. If this is the first block, it should
// already be initialized in InitChain. Otherwise app.DeliverState will be
// nil, since it is reset on Commit.
Expand Down Expand Up @@ -736,7 +740,7 @@ func validateMsgSend(height int64, msg bank.MsgSend) sdk.Error {
}

func validateOutput(height int64, out bank.Output) sdk.Error {
if height >= 545000 {
if sdk.IsLimitAddressLengthUpgrade() {
if len(out.Address) != sdk.AddrLen {
return sdk.ErrInvalidAddress(out.Address.String())
}
Expand Down
2 changes: 1 addition & 1 deletion client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func createVerifier() tmlite.Verifier {
node := rpcclient.NewHTTP(nodeURI, "/websocket")
cacheSize := 10 // TODO: determine appropriate cache size
verifier, err := tmliteProxy.NewVerifier(
chainID, filepath.Join(home, ".gaialite"),
chainID, filepath.Join(home, ".bnblite"),
node, log.NewNopLogger(), cacheSize,
)

Expand Down
6 changes: 3 additions & 3 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func startStandAlone(ctx *Context, appCreator AppCreator) error {
// nolint: unparam
func startInProcess(ctx *Context, appCreator AppCreator) (*node.Node, error) {
cfg := ctx.Config
home := cfg.RootDir
traceWriterFile := viper.GetString(flagTraceStore)
isSequentialABCI := viper.GetBool(flagSequentialABCI)

db, err := openDB(home)
dbProvider := node.DefaultDBProvider
db, err := dbProvider(&node.DBContext{"application", cfg})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func startInProcess(ctx *Context, appCreator AppCreator) (*node.Node, error) {
nodeKey,
cliCreator,
node.DefaultGenesisDocProviderFunc(cfg),
node.DefaultDBProvider,
dbProvider,
node.DefaultMetricsProvider(cfg.Instrumentation),
ctx.Logger.With("module", "node"),
)
Expand Down
71 changes: 71 additions & 0 deletions types/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package types

var UpgradeMgr = &UpgradeManager{}

const UpgradeLimitAddressLength = "UpgradeLimitAddressLength" // limit address length to 20 bytes

var MainNetConfig = UpgradeConfig{
map[string]int64{
UpgradeLimitAddressLength: 554000,
},
}

type UpgradeConfig struct {
HeightMap map[string]int64
}

type UpgradeManager struct {
Config UpgradeConfig
Height int64
}

func NewUpgradeManager(config UpgradeConfig) *UpgradeManager {
return &UpgradeManager{
Config: config,
}
}

func (mgr *UpgradeManager) SetHeight(height int64) {
mgr.Height = height
}

func (mgr *UpgradeManager) GetHeight() int64 {
return mgr.Height
}

func (mgr *UpgradeManager) AddUpgradeHeight(name string, height int64) {
if mgr.Config.HeightMap == nil {
mgr.Config.HeightMap = map[string]int64{}
}

mgr.Config.HeightMap[name] = height
}

func (mgr *UpgradeManager) GetUpgradeHeight(name string) int64 {
if mgr.Config.HeightMap == nil {
return 0
}
return mgr.Config.HeightMap[name]
}

func IsUpgradeHeight(name string) bool {
upgradeHeight := UpgradeMgr.GetUpgradeHeight(name)
if upgradeHeight == 0 {
return false
}

return upgradeHeight == UpgradeMgr.GetHeight()
}

func IsUpgrade(name string) bool {
upgradeHeight := UpgradeMgr.GetUpgradeHeight(name)
if upgradeHeight == 0 {
return false
}

return UpgradeMgr.GetHeight() >= upgradeHeight
}

func IsLimitAddressLengthUpgrade() bool {
return IsUpgrade(UpgradeLimitAddressLength)
}
69 changes: 69 additions & 0 deletions types/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package types

import (
"testing"

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

func TestIsLimitAddressLengthFork(t *testing.T) {
config := UpgradeConfig{
map[string]int64{
UpgradeLimitAddressLength: 545000,
},
}
UpgradeMgr = NewUpgradeManager(config)

type testCase struct {
config UpgradeConfig
height int64
upgradeResult bool
heightResult bool
}

testCases := []testCase{
{
config: UpgradeConfig{
map[string]int64{},
},
height: 10000,
upgradeResult: false,
heightResult: false,
},
{
config: UpgradeConfig{
map[string]int64{
UpgradeLimitAddressLength: 545000,
},
},
height: 10000,
upgradeResult: false,
heightResult: false,
}, {
config: UpgradeConfig{
map[string]int64{
UpgradeLimitAddressLength: 545000,
},
},
height: 545000,
upgradeResult: true,
heightResult: true,
}, {
config: UpgradeConfig{
map[string]int64{
UpgradeLimitAddressLength: 545000,
},
},
height: 545001,
upgradeResult: true,
heightResult: false,
},
}

for _, tc := range testCases {
UpgradeMgr.SetHeight(tc.height)
require.Equal(t, tc.upgradeResult, IsLimitAddressLengthUpgrade())
require.Equal(t, tc.upgradeResult, IsUpgrade(UpgradeLimitAddressLength))
require.Equal(t, tc.heightResult, IsUpgradeHeight(UpgradeLimitAddressLength))
}
}