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

refactor: end block ordering - staking after gov and module sorting #2937

Merged
merged 5 commits into from
Oct 3, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* [#2803](https://github.com/osmosis-labs/osmosis/pull/2803) Fix total pool liquidity CLI query.
* [#2914](https://github.com/osmosis-labs/osmosis/pull/2914) Remove out of gas panics from node logs
* [#2937](https://github.com/osmosis-labs/osmosis/pull/2937) End block ordering - staking after gov and module sorting.

### Misc Improvements

Expand Down
5 changes: 5 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func orderBeginBlockers(allModuleNames []string) []string {
// OrderEndBlockers returns EndBlockers (crisis, govtypes, staking) with no relative order.
func OrderEndBlockers(allModuleNames []string) []string {
ord := partialord.NewPartialOrdering(allModuleNames)

// Staking must be after gov.
ord.FirstElements(govtypes.ModuleName)
ord.LastElements(stakingtypes.ModuleName)

// only Osmosis modules with endblock code are: twap, crisis, govtypes, staking
// we don't care about the relative ordering between them.
return ord.TotalOrdering()
Expand Down
22 changes: 22 additions & 0 deletions app/modules_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package app

import (
"reflect"
"testing"

"github.com/cosmos/cosmos-sdk/simapp"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"
)

func TestOrderEndBlockers_Determinism(t *testing.T) {
db := dbm.NewMemDB()
app := NewOsmosisApp(log.NewNopLogger(), db, nil, true, map[int64]bool{}, DefaultNodeHome, 5, simapp.EmptyAppOptions{}, GetWasmEnabledProposals(), EmptyWasmOpts)

for i := 0; i < 1000; i++ {
a := OrderEndBlockers(app.mm.ModuleNames())
b := OrderEndBlockers(app.mm.ModuleNames())
require.True(t, reflect.DeepEqual(a, b))
}
}
2 changes: 1 addition & 1 deletion osmoutils/partialord/partialord.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewPartialOrdering(elements []string) PartialOrdering {
copy(elementsCopy, elements)
sort.Strings(elementsCopy)
return PartialOrdering{
dag: dag.NewDAG(elements),
dag: dag.NewDAG(elementsCopy),
firstSealed: false,
lastSealed: false,
}
Expand Down
2 changes: 1 addition & 1 deletion osmoutils/partialord/partialord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAPI(t *testing.T) {
totalOrd := beginBlockOrd.TotalOrdering()
expTotalOrd := []string{
"upgrades", "epochs", "capabilities",
"bank", "staking", "mint", "ibc", "distribution", "ibctransfers",
"bank", "ibc", "mint", "staking", "ibctransfers", "distribution",
"auth", "authz", "wasm",
}
require.Equal(t, expTotalOrd, totalOrd)
Expand Down