Skip to content

Commit

Permalink
Merge branch 'main' into default-min-gas
Browse files Browse the repository at this point in the history
  • Loading branch information
philipsu522 authored Jul 11, 2023
2 parents 93b5952 + ef9c6ac commit c33aa7a
Show file tree
Hide file tree
Showing 33 changed files with 499 additions and 85 deletions.
58 changes: 27 additions & 31 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@ jobs:
integration-tests:
name: Integration Test (${{ matrix.test.name }})
runs-on: ubuntu-latest
timeout-minutes: 20
timeout-minutes: 30
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
strategy:
# other jobs should run even if one integration test fails
fail-fast: false
fail-fast: true
matrix:
test: [
{
name: "Dex Module",
name: "Dex & Wasm Module",
scripts: [
"docker exec sei-node-0 integration_test/contracts/deploy_dex_contract.sh mars",
"python3 integration_test/scripts/runner.py integration_test/dex_module/place_order_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/dex_module/cancel_order_test.yaml"
]
},
{
name: "Wasm Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/dex_module/cancel_order_test.yaml",
"docker exec sei-node-0 integration_test/contracts/deploy_timelocked_token_contract.sh",
"python3 integration_test/scripts/runner.py integration_test/wasm_module/timelocked_token_delegation_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/wasm_module/timelocked_token_admin_test.yaml",
Expand All @@ -46,51 +41,49 @@ jobs:
]
},
{
name: "Mint Module",
name: "Mint & Staking & Bank Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/staking_module/staking_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/bank_module/send_funds_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/mint_module/mint_test.yaml"
]
},
{
name: "Staking Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/staking_module/staking_test.yaml"
]
},
{
name: "Gov Module",
name: "Gov & Oracle & Authz Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/gov_module/gov_proposal_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/gov_module/staking_proposal_test.yaml"
]
},
{
name: "Oracle Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/gov_module/staking_proposal_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/oracle_module/verify_penalty_counts.yaml",
"python3 integration_test/scripts/runner.py integration_test/oracle_module/set_feeder_test.yaml"
]
},
{
name: "Authz Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/oracle_module/set_feeder_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/authz_module/send_authorization_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/authz_module/staking_authorization_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/authz_module/generic_authorization_test.yaml"
]
},
{
name: "Bank Module",
name: "Chain Operation Test",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/bank_module/send_funds_test.yaml",
"until [ $(cat build/generated/rpc-launch.complete |wc -l) = 1 ]; do sleep 10; done",
"until [[ $(docker exec sei-rpc-node build/seid status |jq -M -r .SyncInfo.latest_block_height) -gt 10 ]]; do sleep 10; done",
"echo rpc node started",
"python3 integration_test/scripts/runner.py integration_test/chain_operation/snapshot_operation.yaml",
"python3 integration_test/scripts/runner.py integration_test/chain_operation/statesync_operation.yaml"
]

},
{
name: "Accesscontrol Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/acl_module/accesscontrol_register_test.yaml",
]
},
{
name: "Distribution Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/distribution_module/community_pool.yaml",
"python3 integration_test/scripts/runner.py integration_test/distribution_module/rewards.yaml",
]
},
]
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -121,6 +114,9 @@ jobs:
done
sleep 10
- name: Start rpc node
run: make run-rpc-node-skipbuild &

- name: Verify Sei Chain is running
run: python3 integration_test/scripts/runner.py integration_test/startup/startup_test.yaml

Expand Down
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ run-local-node: kill-sei-node build-docker-node
.PHONY: run-local-node

# Run a single rpc state sync node docker container
run-rpc-node: kill-rpc-node build-rpc-node
run-rpc-node: build-rpc-node
docker run --rm \
--name sei-rpc-node \
--network docker_localnet \
Expand All @@ -153,6 +153,20 @@ run-rpc-node: kill-rpc-node build-rpc-node
sei-chain/rpcnode
.PHONY: run-rpc-node

run-rpc-node-skipbuild: build-rpc-node
docker run --rm \
--name sei-rpc-node \
--network docker_localnet \
-v $(PROJECT_HOME):/sei-protocol/sei-chain:Z \
-v $(PROJECT_HOME)/../sei-tendermint:/sei-protocol/sei-tendermint:Z \
-v $(PROJECT_HOME)/../sei-cosmos:/sei-protocol/sei-cosmos:Z \
-v $(GO_PKG_PATH)/mod:/root/go/pkg/mod:Z \
-p 26668-26670:26656-26658 \
--platform linux/x86_64 \
--env SKIP_BUILD=true \
sei-chain/rpcnode
.PHONY: run-rpc-node

kill-sei-node:
docker ps --filter name=sei-node --filter status=running -aq | xargs docker kill

Expand Down
4 changes: 1 addition & 3 deletions app/antedecorators/gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ func (gd GaslessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
// Otherwise (i.e. in the case of checkTx), we only want to perform fee checks and fee deduction if the tx is not considered
// gasless, or if it specifies a non-zero gas limit even if it is considered gasless, so that the wrapped deduct fee
// handler will assign an appropriate priority to it.
if !isGasless {
ctx = ctx.WithGasMeter(originalGasMeter)
}
ctx = ctx.WithGasMeter(originalGasMeter)
return gd.handleWrapped(ctx, tx, simulate, next)
}

Expand Down
6 changes: 4 additions & 2 deletions app/antedecorators/gasless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestGaslessDecorator(t *testing.T) {
// gasless tx (checkTx w/ gas limit) -> wrapped should still be run
output = ""
outputDeps = ""
_, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
resCtx, err := chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
FakeMsgs: []sdk.Msg{&types.MsgPlaceOrders{}},
Gas: 100,
}, false)
Expand All @@ -158,18 +158,20 @@ func TestGaslessDecorator(t *testing.T) {
_, err = depGen([]accesscontrol.AccessOperation{}, FakeTx{}, 1)
require.NoError(t, err)
require.Equal(t, "onetwothree", outputDeps)
require.NotEqual(t, resCtx.GasMeter().Limit(), 0) // make sure gas meter is limited

// gasless tx (checkTx w/o gas limit) -> wrapped should not be run
output = ""
outputDeps = ""
_, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
resCtx, err = chainedHandler(ctx.WithIsCheckTx(true), FakeTx{
FakeMsgs: []sdk.Msg{&types.MsgPlaceOrders{}},
}, false)
require.NoError(t, err)
require.Equal(t, "onethree", output)
_, err = depGen([]accesscontrol.AccessOperation{}, FakeTx{}, 1)
require.NoError(t, err)
require.Equal(t, "onetwothree", outputDeps)
require.NotEqual(t, resCtx.GasMeter().Limit(), 0) // make sure gas meter is limited
}

func TestOracleVoteGasless(t *testing.T) {
Expand Down
15 changes: 13 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ type App struct {
CheckTxMemState *dexcache.MemState
ProcessProposalMemState *dexcache.MemState
MemState *dexcache.MemState

HardForkManager *HardForkManager
}

// New returns a reference to an initialized blockchain app
Expand Down Expand Up @@ -779,6 +781,11 @@ func New(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

// register hard fork handlers with the hard fork manager
app.HardForkManager = NewHardForkManager(app.ChainID)
// register and hard fork handlers below
// example: app.HardForkManager.RegisterHandler(myHandler)

signModeHandler := encodingConfig.TxConfig.SignModeHandler()
// app.batchVerifier = ante.NewSR25519BatchVerifier(app.AccountKeeper, signModeHandler)

Expand Down Expand Up @@ -893,8 +900,8 @@ func (app *App) SetStoreUpgradeHandlers() {
// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
// TODO: add upgrade name for authz module
if false && upgradeInfo.Name == "TODO" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {

if upgradeInfo.Name == "3.0.6" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{authzkeeper.StoreKey},
}
Expand All @@ -913,6 +920,10 @@ func (app App) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }
// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
metrics.GaugeSeidVersionAndCommit(app.versionInfo.Version, app.versionInfo.GitCommit)
// check if we've reached a target height, if so, execute any applicable handlers
if app.HardForkManager.TargetHeightReached(ctx) {
app.HardForkManager.ExecuteForTargetHeight(ctx)
}
return app.mm.BeginBlock(ctx, req)
}

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

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/goutils"
)

type HardForkHandler interface {
// a unique identifying name to ensure no duplicate handlers are registered
GetName() string
// The target chain ID for which to run this handler (which chain to run on)
GetTargetChainID() string
// The target height at which the handler should be executed
GetTargetHeight() int64
// An execution function used to process a hard fork handler
ExecuteHandler(ctx sdk.Context) error
}

type HardForkManager struct {
chainID string
handlerMap map[int64][]HardForkHandler
uniqueNameMap map[string]struct{}
}

// Create a new hard fork manager for a given chain ID.
// This will filter out any handlers for other chain IDs,
// and create a map that maps between target height and handlers to run for the given heights.
func NewHardForkManager(chainID string) *HardForkManager {
return &HardForkManager{
chainID: chainID,
handlerMap: make(map[int64][]HardForkHandler),
uniqueNameMap: make(map[string]struct{}),
}
}

// This tries to register a handler with the hard fork manager.
// If the handler's target chain ID doesn't match the chain ID of the manager,
// this is a no-op and the handler is ignored.
func (hfm *HardForkManager) RegisterHandler(handler HardForkHandler) {
if handler.GetTargetChainID() != hfm.chainID {
return
}
handlerName := handler.GetName()
if _, ok := hfm.uniqueNameMap[handlerName]; ok {
// we already have a migration with this name - panic
panic(fmt.Errorf("hard fork handler with name %s already registered", handlerName))
}
// register name for uniqueness assertion
hfm.uniqueNameMap[handlerName] = struct{}{}
targetHeight := handler.GetTargetHeight()
if handlers, ok := hfm.handlerMap[targetHeight]; ok {
goutils.InPlaceAppend[[]HardForkHandler](&handlers, handler)
hfm.handlerMap[targetHeight] = handlers
} else {
hfm.handlerMap[targetHeight] = []HardForkHandler{handler}
}
}

// This returns a boolean indicating whether or not the current height is a
// target height for which there are hard fork handlers to run.
func (hfm *HardForkManager) TargetHeightReached(ctx sdk.Context) bool {
_, ok := hfm.handlerMap[ctx.BlockHeight()]
return ok
}

// This executes the hard fork handlers for the current height. This will function will panic upon receiving an error during hard fork handler execution
func (hfm *HardForkManager) ExecuteForTargetHeight(ctx sdk.Context) {
handlers, ok := hfm.handlerMap[ctx.BlockHeight()]
if !ok {
return
}
for _, handler := range handlers {
handlerName := handler.GetName()
ctx.Logger().Info(fmt.Sprintf(
"Executing hard fork handler %s for chain ID %s at height %d",
handlerName,
handler.GetTargetChainID(),
handler.GetTargetHeight(),
))
err := handler.ExecuteHandler(ctx)
if err != nil {
panic(err)
}
ctx.Logger().Info(fmt.Sprintf(
"Completed execution for hard fork handler %s",
handlerName,
))
}
// TODO: do we want to emit any events to the context event manager (for use in beginBlockResponse)
}
Loading

0 comments on commit c33aa7a

Please sign in to comment.