Unverified Commit 6d082da0 authored by Dev Ojha's avatar Dev Ojha Committed by GitHub
Browse files

Switch to SDK branch that lowers epoch time (#451)

* Switch to SDK branch that eliminates epoch time

* Improve benchmark accuracy

* Sync more things
parent 1a1c5913
No related merge requests found
Showing with 87 additions and 14 deletions
+87 -14
......@@ -197,4 +197,5 @@ $RECYCLE.BIN/
/.idea/
/artifacts/
/.vscode/
/scripts/local/
\ No newline at end of file
/scripts/local/
/x/incentives/keeper/osmosis_testing/
\ No newline at end of file
......@@ -34,15 +34,21 @@ Ref: https://keepachangelog.com/en/1.0.0/
# Changelog
## [v2.0.0](https://github.com/osmosis/osmosis-labs/releases/tag/v2.0.0) - 2021-06-28
## [Upcoming]
* Update the cosmos-sdk version we modify to v0.42.6
* Fix a bug in the min commission rate code that allows validators to be created with commission rates less than the minimum.
* Automatically upgrade any validator with less than the minimum comission rate to the minimum at upgrade time.
* Significantly speedup epoch times
* Fix bug in the lockup module code that caused it to take a linear amount of gas.
* Make unbonding tokens from the lockup module get automatically claimed when unbonding is done.
* Add events for all tx types in the gamm module.
* Make queries to bank total chain balance account for developer vesting correctly.
* Add ability for nodes to query
## [v3.2.0](https://github.com/osmosis/osmosis-labs/releases/tag/v2.0.0) - 2021-06-28
* Update the cosmos-sdk version we modify to v0.42.9
* Fix a bug in the min commission rate code that allows validators to be created with commission rates less than the minimum.
* Automatically upgrade any validator with less than the minimum comission rate to the minimum at upgrade time.
* Unbrick on-chain governance, by fixing the deposit parameter to use `uosmo` instead of `osmo`.
## [v1.0.2](https://github.com/osmosis/osmosis-labs/releases/tag/v1.0.2) - 2021-06-18
......
......@@ -2,8 +2,10 @@ package app
import (
"encoding/json"
"os"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
......@@ -31,3 +33,39 @@ func Setup(isCheckTx bool) *OsmosisApp {
return app
}
// SetupTestingAppWithLevelDb initializes a new OsmosisApp intended for testing,
// with LevelDB as a db
func SetupTestingAppWithLevelDb(isCheckTx bool) (app *OsmosisApp, cleanupFn func()) {
dir := "osmosis_testing"
db, err := sdk.NewLevelDB("osmosis_leveldb_testing", dir)
if err != nil {
panic(err)
}
app = NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, MakeEncodingConfig(), simapp.EmptyAppOptions{})
if !isCheckTx {
genesisState := NewDefaultGenesisState()
stateBytes, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
panic(err)
}
app.InitChain(
abci.RequestInitChain{
Validators: []abci.ValidatorUpdate{},
ConsensusParams: simapp.DefaultConsensusParams,
AppStateBytes: stateBytes,
},
)
}
cleanupFn = func() {
db.Close()
err = os.RemoveAll(dir)
if err != nil {
panic(err)
}
}
return
}
......@@ -31,4 +31,4 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.2-alpha.regen.4
replace github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.42.10-0.20210819201800-7d5063b74305
replace github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.42.10-0.20210829064313-2c87644925da
......@@ -66,7 +66,8 @@ func benchmarkDistributionLogic(numAccts, numDenoms, numGauges, numLockups, numD
b.StopTimer()
blockStartTime := time.Now().UTC()
app := app.Setup(false)
app, cleanupFn := app.SetupTestingAppWithLevelDb(false)
defer cleanupFn()
ctx := app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "osmosis-1", Time: blockStartTime})
r := rand.New(rand.NewSource(time.Now().UnixNano()))
......@@ -86,6 +87,7 @@ func benchmarkDistributionLogic(numAccts, numDenoms, numGauges, numLockups, numD
distrEpoch := app.EpochsKeeper.GetEpochInfo(ctx, app.IncentivesKeeper.GetParams(ctx).DistrEpochIdentifier)
durationOptions := app.IncentivesKeeper.GetLockableDurations(ctx)
fmt.Println(durationOptions)
// setup gauges
gaugeIds := []uint64{}
for i := 0; i < numGauges; i++ {
......@@ -118,17 +120,23 @@ func benchmarkDistributionLogic(numAccts, numDenoms, numGauges, numLockups, numD
futureSecs := r.Intn(1 * 60 * 60 * 24 * 7)
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(time.Duration(futureSecs) * time.Second))
lockSecs := r.Intn(1 * 60 * 60 * 8)
// setup lockups
for i := 0; i < numLockups; i++ {
addr := addrs[r.Int()%numAccts]
addr := addrs[i%numAccts]
simCoins := app.BankKeeper.SpendableCoins(ctx, addr)
duration := time.Second
if i%10 == 0 {
lockSecs = r.Intn(1 * 60 * 60 * 8)
}
duration := time.Duration(lockSecs) * time.Second
_, err := app.LockupKeeper.LockTokens(ctx, addr, simCoins, duration)
if err != nil {
fmt.Printf("Lock tokens, %v\n", err)
b.FailNow()
}
}
fmt.Println("created all lockups")
// begin distribution for all gauges
for _, gaugeId := range gaugeIds {
......@@ -173,7 +181,13 @@ func BenchmarkDistributionLogicMedium(b *testing.B) {
}
func BenchmarkDistributionLogicLarge(b *testing.B) {
benchmarkDistributionLogic(100, 10, 100, 100, 5000, b)
numAccts := 50000
numDenoms := 10
numGauges := 60
numLockups := 100000
numDistrs := 1
benchmarkDistributionLogic(numAccts, numDenoms, numGauges, numLockups, numDistrs, b)
}
func BenchmarkDistributionLogicHuge(b *testing.B) {
......
......@@ -290,7 +290,7 @@ func (k Keeper) Distribute(ctx sdk.Context, gauge types.Gauge) (sdk.Coins, error
distrCoins := sdk.Coins{}
for _, coin := range remainCoins {
// distribution amount = gauge_size * denom_lock_amount / (total_denom_lock_amount * remain_epochs)
denomLockAmt := lock.Coins.AmountOf(gauge.DistributeTo.Denom)
denomLockAmt := lock.Coins.AmountOfNoDenomValidation(gauge.DistributeTo.Denom)
amt := coin.Amount.Mul(denomLockAmt).Quo(lockSum.Mul(sdk.NewInt(int64(remainEpochs))))
if amt.IsPositive() {
distrCoins = distrCoins.Add(sdk.NewCoin(coin.Denom, amt))
......
......@@ -16,6 +16,7 @@ type KeeperTestSuite struct {
ctx sdk.Context
querier sdk.Querier
app *app.OsmosisApp
cleanup func()
}
func (suite *KeeperTestSuite) SetupTest() {
......@@ -23,6 +24,15 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "osmosis-1", Time: time.Now().UTC()})
}
func (suite *KeeperTestSuite) SetupTestWithLevelDb() {
suite.app, suite.cleanup = app.SetupTestingAppWithLevelDb(false)
suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "osmosis-1", Time: time.Now().UTC()})
}
func (suite *KeeperTestSuite) Cleanup() {
suite.cleanup()
}
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
......@@ -242,10 +242,12 @@ func (suite *KeeperTestSuite) TestLocksLongerThanDurationDenom() {
}
func (suite *KeeperTestSuite) TestLockTokensAlot() {
suite.SetupTest()
addr1 := sdk.AccAddress([]byte("addr1---------------"))
coins := sdk.Coins{sdk.NewInt64Coin("stake", 10)}
startAveragingAt := 1000
totalNumLocks := 2000
totalNumLocks := 5000
for i := 1; i < startAveragingAt; i++ {
suite.LockTokens(addr1, coins, time.Second)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment