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: draft release for v0.10.15 #966

Merged
merged 6 commits into from
Jul 7, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/go/bin/golangci-lint
key: golangci-lint-1.45.2
key: golangci-lint-1.53.3
- uses: actions/cache@v3
with:
path: |
Expand All @@ -32,6 +32,6 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.45.2
version: v1.53.3
skip-pkg-cache: true
args: --timeout=99m
6 changes: 3 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- uses: actions/cache@v3
with:
path: ~/go/bin
Expand All @@ -27,15 +27,15 @@ jobs:
# used to debug workflow
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
- run: make bep159_integration_test integration_test
- run: make bep159_integration_test recon_integration_test integration_test
coverage-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- uses: actions/cache@v3
with:
path: ~/go/bin
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/multi-nodes-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.19
- run: make docker.build docker.generate docker.start
# fix docker permission issue
- run: chmod 777 -R ~/work/node/node/build/devnet
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Build Release
strategy:
matrix:
go-version: [1.17.x]
go-version: [1.19.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Build Release
strategy:
matrix:
go-version: [1.17.x]
go-version: [1.19.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ app/apptest/data
app_test/data
plugins/param/data
plugins/tokens/data

# e2e temp files
e2e/priv_validator_key.json
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ run:
# If false (default) - golangci-lint acquires file lock on start.
# allow-parallel-runners: false
# Define the Go version limit.
# Mainly related to generics support in go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.17
# go: '1.16'
# Mainly related to generics support in go1.19.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.19
# go: '1.19'
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog

## v0.10.15
FEATURES
* [\#956](https://github.com/bnb-chain/node/pull/956) [BEP] feat: implement bep255
* [\#964](https://github.com/bnb-chain/node/pull/964) [fix] fix: clear side vote addresses

## v0.10.14
FEATURES
* [\#953](https://github.com/bnb-chain/node/pull/953) [cli] feat:support setting acc prefix when collecting gentxs
* [\#953](https://github.com/bnb-chain/node/pull/953) [cli] feat: support setting acc prefix when collecting gentxs
* [\#957](https://github.com/bnb-chain/node/pull/957) [deps] deps: bump cosmos-sdk to v0.26.5

## v0.10.13
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM golang:1.17-alpine AS build-env
FROM golang:1.19-alpine AS build-env

# Set up dependencies
ENV PACKAGES make git libc-dev bash gcc linux-headers eudev-dev curl ca-certificates
ENV PACKAGES make cmake git libc-dev bash gcc linux-headers eudev-dev curl ca-certificates build-base libc-dev

# Set working directory for the build
WORKDIR /go/src/github.com/bnb-chain/node
Expand All @@ -18,7 +18,7 @@ RUN apk add --no-cache $PACKAGES && \
FROM alpine:3.16.0

# Install dependencies
RUN apk add --update ca-certificates tini bash
RUN apk add --update ca-certificates tini bash gcc

ARG USER=bnbchain
ARG USER_UID=1000
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,14 @@ integration_test: build
bep159_integration_test: build
@echo "-->BEP159 Integration Test"
@bash ./scripts/bep159_integration_test.sh

recon_integration_test: build
@echo "-->Recon Integration Test"
@bash ./scripts/recon_integration_test.sh

########################################
### Pre Commit
pre_commit: build test_unit bep159_integration_test integration_test format lint multi-nodes-test
pre_commit: build test_unit recon_integration_test bep159_integration_test integration_test format lint multi-nodes-test

########################################
### Local validator nodes using docker and docker-compose
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Besides, it has many other rich features:
### Environment setup

#### Requirement
Go version above 1.17 is required.
Go version above 1.19 is required.

Please [install it](https://go.dev/doc/install) or use brew on macOS: `brew install go`.

Expand Down
29 changes: 29 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func NewBNBBeaconChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseA
common.BridgeStoreKey,
common.OracleStoreKey,
common.IbcStoreKey,
common.ReconStoreKey,
)
app.SetAnteHandler(tx.NewAnteHandler(app.AccountKeeper))
app.SetPreChecker(tx.NewTxPreChecker())
Expand All @@ -269,6 +270,18 @@ func NewBNBBeaconChain(logger log.Logger, db dbm.DB, traceStore io.Writer, baseA
cmn.Exit(err.Error())
}

// enable diff for reconciliation
accountIavl, ok := app.GetCommitMultiStore().GetCommitStore(common.AccountStoreKey).(*store.IavlStore)
if !ok {
cmn.Exit("cannot convert account store to ival store")
}
accountIavl.EnableDiff()
tokenIavl, ok := app.GetCommitMultiStore().GetCommitStore(common.TokenStoreKey).(*store.IavlStore)
if !ok {
cmn.Exit("cannot convert token store to ival store")
}
tokenIavl.EnableDiff()

// init app cache
accountStore := app.BaseApp.GetCommitMultiStore().GetKVStore(common.AccountStoreKey)
app.SetAccountStoreCache(cdc, accountStore, app.baseConfig.AccountCacheSize)
Expand Down Expand Up @@ -345,13 +358,15 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP173, upgradeConfig.BEP173Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.FixDoubleSignChainId, upgradeConfig.FixDoubleSignChainIdHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP126, upgradeConfig.BEP126Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP255, upgradeConfig.BEP255Height)

// register store keys of upgrade
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, common.TimeLockStoreKey.Name())
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP3, common.AtomicSwapStoreKey.Name())
upgrade.Mgr.RegisterStoreKeys(upgrade.LaunchBscUpgrade, common.IbcStoreKey.Name(), common.SideChainStoreKey.Name(),
common.SlashingStoreKey.Name(), common.BridgeStoreKey.Name(), common.OracleStoreKey.Name())
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP128, common.StakeRewardStoreKey.Name())
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP255, common.ReconStoreKey.Name())

// register msg types of upgrade
upgrade.Mgr.RegisterMsgTypes(upgrade.BEP9,
Expand Down Expand Up @@ -599,6 +614,11 @@ func (app *BNBBeaconChain) initStaking() {
upgrade.Mgr.RegisterBeginBlocker(sdk.BEP159Phase2, func(ctx sdk.Context) {
stake.MigrateWhiteLabelOracleRelayer(ctx, app.stakeKeeper)
})
upgrade.Mgr.RegisterBeginBlocker(sdk.BEP255, func(ctx sdk.Context) {
storePrefix := app.scKeeper.GetSideChainStorePrefix(ctx, ServerContext.BscChainId)
newCtx := ctx.WithSideChainKeyPrefix(storePrefix)
app.stakeKeeper.ClearUpSideVoteAddrs(newCtx)
})
app.stakeKeeper.SubscribeParamChange(app.ParamHub)
app.stakeKeeper.SubscribeBCParamChange(app.ParamHub)
app.stakeKeeper = app.stakeKeeper.WithHooks(app.slashKeeper.Hooks())
Expand Down Expand Up @@ -953,6 +973,15 @@ func (app *BNBBeaconChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock)
pub.Pool.Clean()
// match may end with transaction failure, which is better to save into
// the EndBlock response. However, current cosmos doesn't support this.

accountIavl, _ := app.GetCommitMultiStore().GetCommitStore(common.AccountStoreKey).(*store.IavlStore)
tokenIavl, _ := app.GetCommitMultiStore().GetCommitStore(common.TokenStoreKey).(*store.IavlStore)
if sdk.IsUpgrade(upgrade.BEP255) {
app.reconBalance(ctx, accountIavl, tokenIavl)
}
accountIavl.ResetDiff()
tokenIavl.ResetDiff()

return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Events: ctx.EventManager().ABCIEvents(),
Expand Down
4 changes: 4 additions & 0 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ BEP173Height = {{ .UpgradeConfig.BEP173Height }}
FixDoubleSignChainIdHeight = {{ .UpgradeConfig.FixDoubleSignChainIdHeight }}
# Block height of BEP126 upgrade
BEP126Height = {{ .UpgradeConfig.BEP126Height }}
# Block height of BEP255 upgrade
BEP255Height = {{ .UpgradeConfig.BEP255Height }}

[query]
# ABCI query interface black list, suggested value: ["custom/gov/proposals", "custom/timelock/timelocks", "custom/atomicSwap/swapcreator", "custom/atomicSwap/swaprecipient"]
Expand Down Expand Up @@ -549,6 +551,7 @@ type UpgradeConfig struct {
BEP173Height int64 `mapstructure:"BEP173Height"`
FixDoubleSignChainIdHeight int64 `mapstructure:"FixDoubleSignChainIdHeight"`
BEP126Height int64 `mapstructure:"BEP126Height"`
BEP255Height int64 `mapstructure:"BEP255Height"`
}

func defaultUpgradeConfig() *UpgradeConfig {
Expand Down Expand Up @@ -583,6 +586,7 @@ func defaultUpgradeConfig() *UpgradeConfig {
BEP171Height: math.MaxInt64,
FixFailAckPackageHeight: math.MaxInt64,
EnableAccountScriptsForCrossChainTransferHeight: math.MaxInt64,
BEP255Height: math.MaxInt64,
}
}

Expand Down
143 changes: 143 additions & 0 deletions app/reconciliation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package app

import (
"encoding/binary"
"fmt"
"strings"

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

"github.com/bnb-chain/node/common"
"github.com/bnb-chain/node/common/types"
)

const globalAccountNumber = "globalAccountNumber"

// unbalancedBlockHeightKey for saving unbalanced block height for reconciliation
var unbalancedBlockHeightKey = []byte("0x01")

// reconBalance will do reconciliation for accounts balances.
func (app *BNBBeaconChain) reconBalance(ctx sdk.Context, accountIavl *store.IavlStore, tokenIavl *store.IavlStore) {
height, exists := app.getUnbalancedBlockHeight(ctx)
if exists {
panic(fmt.Sprintf("unbalanced state at block height %d, please use hardfork to bypass it", height))
}

accPre, accCurrent := app.getAccountChanges(ctx, accountIavl)
tokenPre, tokenCurrent := app.getTokenChanges(ctx, tokenIavl)

// accPre and tokenPre are positive, there will be no overflow
accountDiff := accCurrent.Plus(accPre.Negative())
tokenDiff := tokenCurrent.Plus(tokenPre.Negative())

if !accountDiff.IsEqual(tokenDiff) {
ctx.Logger().Error(fmt.Sprintf("unbalanced at block %d, account diff: %s, token diff: %s \n",
ctx.BlockHeight(), accountDiff.String(), tokenDiff.String()))
app.saveUnbalancedBlockHeight(ctx)
}
}

func (app *BNBBeaconChain) getAccountChanges(ctx sdk.Context, accountStore *store.IavlStore) (sdk.Coins, sdk.Coins) {
preCoins := sdk.Coins{}
currentCoins := sdk.Coins{}

diff := accountStore.GetDiff()
version := accountStore.GetTree().Version() - 1
for k := range diff {
if strings.Contains(k, globalAccountNumber) {
continue
}
v := accountStore.Get([]byte(k))
if v != nil {
var acc1 sdk.Account
err := app.Codec.UnmarshalBinaryBare(v, &acc1)
if err != nil {
ctx.Logger().Error("failed to unmarshal current account value", "err", err.Error())
} else {
nacc1 := acc1.(types.NamedAccount)
ctx.Logger().Debug("current account", "address", nacc1.GetAddress(), "coins", nacc1.GetCoins().String())
currentCoins = currentCoins.Plus(nacc1.GetCoins())
currentCoins = currentCoins.Plus(nacc1.GetFrozenCoins())
currentCoins = currentCoins.Plus(nacc1.GetLockedCoins())
}
}

_, v = accountStore.GetTree().GetVersioned([]byte(k), version)
if v != nil { // it is not a new account
var acc2 sdk.Account
err := app.Codec.UnmarshalBinaryBare(v, &acc2)
if err != nil {
ctx.Logger().Error("failed to unmarshal previous account value", "err", err.Error())
} else {
nacc2 := acc2.(types.NamedAccount)
ctx.Logger().Debug("previous account", "address", nacc2.GetAddress(), "coins", nacc2.GetCoins().String())
preCoins = preCoins.Plus(nacc2.GetCoins())
preCoins = preCoins.Plus(nacc2.GetFrozenCoins())
preCoins = preCoins.Plus(nacc2.GetLockedCoins())
}
}
}
ctx.Logger().Debug("account changes", "current", currentCoins.String(), "previous", preCoins.String(),
"version", version, "height", ctx.BlockHeight())

return preCoins, currentCoins
}

func (app *BNBBeaconChain) getTokenChanges(ctx sdk.Context, tokenStore *store.IavlStore) (sdk.Coins, sdk.Coins) {
preCoins := sdk.Coins{}
currentCoins := sdk.Coins{}

diff := tokenStore.GetDiff()
version := tokenStore.GetTree().Version() - 1
for k := range diff {
v := tokenStore.Get([]byte(k))
if v != nil {
var token1 types.IToken
err := app.Codec.UnmarshalBinaryBare(v, &token1)
if err != nil {
ctx.Logger().Error("failed to unmarshal current token value", "err", err.Error())
} else {
ctx.Logger().Debug("current token", "symbol", token1.GetSymbol(), "supply", token1.GetTotalSupply().ToInt64())
currentCoins = currentCoins.Plus(sdk.Coins{
sdk.NewCoin(token1.GetSymbol(), token1.GetTotalSupply().ToInt64()),
})
}
}

_, v = tokenStore.GetTree().GetVersioned([]byte(k), version)
if v != nil { // it is not a new token
var token2 types.IToken
err := app.Codec.UnmarshalBinaryBare(v, &token2)
if err != nil {
ctx.Logger().Error("failed to unmarshal previous token value", "err", err.Error())
} else {
ctx.Logger().Debug("previous token", "symbol", token2.GetSymbol(), "supply", token2.GetTotalSupply().ToInt64())
preCoins = preCoins.Plus(sdk.Coins{
sdk.NewCoin(token2.GetSymbol(), token2.GetTotalSupply().ToInt64()),
})
}
}
}
ctx.Logger().Debug("token changes", "current", currentCoins.String(), "previous", preCoins.String(),
"version", version, "height", ctx.BlockHeight())

return preCoins, currentCoins
}

func (app *BNBBeaconChain) saveUnbalancedBlockHeight(ctx sdk.Context) {
reconStore := app.GetCommitMultiStore().GetCommitStore(common.ReconStoreKey).(*store.IavlStore)
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz[:], uint64(ctx.BlockHeight()))
reconStore.Set(unbalancedBlockHeightKey, bz)
}

func (app *BNBBeaconChain) getUnbalancedBlockHeight(ctx sdk.Context) (uint64, bool) {
reconStore := app.GetCommitMultiStore().GetCommitStore(common.ReconStoreKey).(*store.IavlStore)

bz := reconStore.Get(unbalancedBlockHeightKey)
if bz == nil {
return 0, false
}
return binary.BigEndian.Uint64(bz), true
}
Loading