Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0f9bd91
Cherry pick 0b7909952d98023bbb56ea3fc316177dfd3571d8
codchen Aug 23, 2022
1a32c79
Rebase
philipsu522 Oct 17, 2022
1211560
update local scripts
codchen Aug 24, 2022
6cba0e3
Fix validator mode
philipsu522 Oct 17, 2022
c362a63
Fix rebase conflicts
codchen Sep 6, 2022
6f55bc7
Use SR25519 as signing algo (#238)
codchen Sep 9, 2022
7248ade
Register accesscontrol module (#257)
BrandonWeng Sep 23, 2022
b369033
Ante decorator for tx priorities
Kbhat1 Sep 26, 2022
b9451d3
Revert "Ante decorator for tx priorities"
Kbhat1 Sep 26, 2022
b84b9e1
Prioritize ante decorator (#262)
Kbhat1 Sep 26, 2022
2c6503a
Use tx digest dissemination binaries (#265)
philipsu522 Sep 29, 2022
6282e08
Update tm and cosmos releases (#267)
philipsu522 Sep 29, 2022
bb70ccb
fix populate genesis script
philipsu522 Oct 18, 2022
1fb0423
upgrade tm version
philipsu522 Oct 18, 2022
fd850da
Uncomment script
philipsu522 Oct 18, 2022
260ebd0
Merge branch 'master' into 200beta-rebase
philipsu522 Oct 18, 2022
3fa040d
fix go mod
philipsu522 Oct 18, 2022
06d1a09
Fix script
philipsu522 Oct 18, 2022
14cfd63
Revert "Register accesscontrol module (#257)"
philipsu522 Oct 18, 2022
72dd49e
rm priority
philipsu522 Oct 19, 2022
ab1ae9d
rm test
philipsu522 Oct 19, 2022
206bbf7
more fixes
philipsu522 Oct 19, 2022
e60060c
Add back cancel test
philipsu522 Oct 20, 2022
4022147
Fix dex module test (#321)
codchen Oct 20, 2022
9a8838c
fix cancel tests
philipsu522 Oct 20, 2022
841f2cb
Constant load test (#326)
McFly222 Oct 22, 2022
cb8cd2b
Add failure load client (#323)
kwhuo68 Oct 24, 2022
f7471de
Fix tokens
philipsu522 Oct 24, 2022
246358b
Fix keeper memstate
philipsu522 Oct 24, 2022
580857f
more fixes for memstate
philipsu522 Oct 24, 2022
f9c59ca
Fix limit order test
philipsu522 Oct 24, 2022
1cf366c
Merge branch 'master' into 200beta-rebase
philipsu522 Oct 24, 2022
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ c.out
# loadtest contracts build artifact
loadtest/contracts/**/artifacts/
loadtest/contracts/**/target/
loadtest/contracts/**.json
loadtest/contracts/**.json

loadtest_results.txt
35 changes: 18 additions & 17 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,49 @@ package app
import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
"go.opentelemetry.io/otel/attribute"
)

func (app *App) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
ctx, topSpan := (*app.tracingInfo.Tracer).Start(context.Background(), "Block")
func (app *App) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) (res abci.ResponseBeginBlock) {
tracectx, topSpan := (*app.tracingInfo.Tracer).Start(context.Background(), "Block")
topSpan.SetAttributes(attribute.Int64("height", req.Header.Height))
app.tracingInfo.BlockSpan = &topSpan
app.tracingInfo.TracerContext = ctx
app.tracingInfo.TracerContext = tracectx
_, beginBlockSpan := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "BeginBlock")
defer beginBlockSpan.End()
return app.BaseApp.BeginBlock(req)
return app.BaseApp.BeginBlock(ctx, req)
}

func (app *App) EndBlock(req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
func (app *App) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) (res abci.ResponseEndBlock) {
_, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "EndBlock")
defer span.End()
return app.BaseApp.EndBlock(req)
return app.BaseApp.EndBlock(ctx, req)
}

func (app *App) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
_, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "CheckTx")
defer span.End()
return app.BaseApp.CheckTx(req)
return app.BaseApp.CheckTx(ctx, req)
}

func (app *App) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx {
ctx, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "DeliverTx")
oldCtx := app.tracingInfo.TracerContext
app.tracingInfo.TracerContext = ctx
defer span.End()
defer func() { app.tracingInfo.TracerContext = oldCtx }()
return app.BaseApp.DeliverTx(req)
func (app *App) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx) abci.ResponseDeliverTx {
// tracectx, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "DeliverTx")
// oldCtx := app.tracingInfo.TracerContext
// app.tracingInfo.TracerContext = tracectx
// defer span.End()
// defer func() { app.tracingInfo.TracerContext = oldCtx }()
return app.BaseApp.DeliverTx(ctx, req)
}

func (app *App) Commit() (res abci.ResponseCommit) {
func (app *App) Commit(ctx context.Context) (res *abci.ResponseCommit, err error) {
if app.tracingInfo.BlockSpan != nil {
defer (*app.tracingInfo.BlockSpan).End()
}
_, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "Commit")
defer span.End()
app.tracingInfo.TracerContext = context.Background()
app.tracingInfo.BlockSpan = nil
return app.BaseApp.Commit()
return app.BaseApp.Commit(ctx)
}
17 changes: 10 additions & 7 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
"github.com/sei-protocol/sei-chain/app/antedecorators"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/utils/tracing"
"github.com/sei-protocol/sei-chain/x/dex"
dexkeeper "github.com/sei-protocol/sei-chain/x/dex/keeper"
Expand Down Expand Up @@ -64,6 +63,14 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}

// var sigVerifyDecorator sdk.AnteDecorator
sequentialVerifyDecorator := ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler)
// if options.BatchVerifier == nil {
// sigVerifyDecorator = sequentialVerifyDecorator
// } else {
// sigVerifyDecorator = ante.NewBatchSigVerificationDecorator(options.BatchVerifier, sequentialVerifyDecorator)
// }

memPoolDecorator := ante.NewMempoolFeeDecorator()
anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
Expand All @@ -82,15 +89,11 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
sequentialVerifyDecorator,
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
dex.NewTickSizeMultipleDecorator(*options.DexKeeper),
}

tracedDecorators := utils.Map(anteDecorators, func(d sdk.AnteDecorator) sdk.AnteDecorator {
return antedecorators.NewTracedAnteDecorator(d, options.TracingInfo)
})

return sdk.ChainAnteDecorators(tracedDecorators...), nil
return sdk.ChainAnteDecorators(anteDecorators...), nil
}
188 changes: 184 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package app

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"time"

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

appparams "github.com/sei-protocol/sei-chain/app/params"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/wasmbinding"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand Down Expand Up @@ -91,7 +95,6 @@ import (
minttypes "github.com/sei-protocol/sei-chain/x/mint/types"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
Expand All @@ -100,8 +103,10 @@ import (
"github.com/sei-protocol/sei-chain/utils/tracing"

dexmodule "github.com/sei-protocol/sei-chain/x/dex"
dexcache "github.com/sei-protocol/sei-chain/x/dex/cache"
dexmodulekeeper "github.com/sei-protocol/sei-chain/x/dex/keeper"
dexmoduletypes "github.com/sei-protocol/sei-chain/x/dex/types"
dexutils "github.com/sei-protocol/sei-chain/x/dex/utils"

oraclemodule "github.com/sei-protocol/sei-chain/x/oracle"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
Expand Down Expand Up @@ -312,6 +317,11 @@ type App struct {

tracingInfo *tracing.Info
configurator module.Configurator

optimisticProcessingInfo *OptimisticProcessingInfo

// batchVerifier *ante.SR25519BatchVerifier
// txDecoder sdk.TxDecoder
}

// New returns a reference to an initialized blockchain app
Expand All @@ -333,7 +343,7 @@ func New(
cdc := encodingConfig.Amino
interfaceRegistry := encodingConfig.InterfaceRegistry

bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
bApp := baseapp.NewBaseApp(AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), appOpts, baseAppOptions...)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
bApp.SetInterfaceRegistry(interfaceRegistry)
Expand Down Expand Up @@ -371,6 +381,7 @@ func New(
Tracer: &tr,
TracerContext: context.Background(),
},
// txDecoder: encodingConfig.TxConfig.TxDecoder(),
}

app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
Expand Down Expand Up @@ -712,14 +723,18 @@ func New(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

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

anteHandler, err := NewAnteHandler(
HandlerOptions{
HandlerOptions: ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SignModeHandler: signModeHandler,
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
// BatchVerifier: app.batchVerifier,
},
IBCKeeper: app.IBCKeeper,
TXCounterStoreKey: keys[wasm.StoreKey],
Expand All @@ -736,6 +751,9 @@ func New(

app.SetAnteHandler(anteHandler)
app.SetEndBlocker(app.EndBlocker)
app.SetPrepareProposalHandler(app.PrepareProposalHandler)
app.SetProcessProposalHandler(app.ProcessProposalHandler)
app.SetFinalizeBlocker(app.FinalizeBlocker)

// Register snapshot extensions to enable state-sync for wasm.
if manager := app.SnapshotManager(); manager != nil {
Expand Down Expand Up @@ -829,13 +847,171 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
// InitChainer application update at chain initialization
func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}

func (app *App) PrepareProposalHandler(ctx sdk.Context, req *abci.RequestPrepareProposal) (*abci.ResponsePrepareProposal, error) {
return &abci.ResponsePrepareProposal{
TxRecords: utils.Map(req.Txs, func(tx []byte) *abci.TxRecord {
return &abci.TxRecord{Action: abci.TxRecord_UNMODIFIED, Tx: tx}
}),
}, nil
}

func (app *App) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) {
if app.optimisticProcessingInfo == nil {
completionSignal := make(chan struct{}, 1)
optimisticProcessingInfo := &OptimisticProcessingInfo{
Height: req.Height,
Hash: req.Hash,
Completion: completionSignal,
}
app.optimisticProcessingInfo = optimisticProcessingInfo
go func() {
events, txResults, endBlockResp, _ := app.ProcessBlock(ctx, req.Txs, req, req.ProposedLastCommit)
optimisticProcessingInfo.Events = events
optimisticProcessingInfo.TxRes = txResults
optimisticProcessingInfo.EndBlockResp = endBlockResp
optimisticProcessingInfo.Completion <- struct{}{}
}()
} else if !bytes.Equal(app.optimisticProcessingInfo.Hash, req.Hash) {
app.optimisticProcessingInfo.Aborted = true
}
return &abci.ResponseProcessProposal{
Status: abci.ResponseProcessProposal_ACCEPT,
}, nil
}

func (app *App) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) {
startTime := time.Now()
defer func() {
app.optimisticProcessingInfo = nil
duration := time.Since(startTime)
ctx.Logger().Info(fmt.Sprintf("FinalizeBlock took %dms", duration/time.Millisecond))
}()

if app.optimisticProcessingInfo != nil && !app.optimisticProcessingInfo.Aborted && bytes.Equal(app.optimisticProcessingInfo.Hash, req.Hash) {
select {
case <-app.optimisticProcessingInfo.Completion:
app.SetProcessProposalStateToCommit()
appHash := app.WriteStateToCommitAndGetWorkingHash()
resp := app.getFinalizeBlockResponse(appHash, app.optimisticProcessingInfo.Events, app.optimisticProcessingInfo.TxRes, app.optimisticProcessingInfo.EndBlockResp)
return &resp, nil
case <-time.After(OptimisticProcessingTimeoutInSeconds * time.Second):
ctx.Logger().Info("optimistic processing timed out")
break
}
}
ctx.Logger().Info("optimistic processing ineligible")
events, txResults, endBlockResp, _ := app.ProcessBlock(ctx, req.Txs, req, req.DecidedLastCommit)

app.SetDeliverStateToCommit()
appHash := app.WriteStateToCommitAndGetWorkingHash()
resp := app.getFinalizeBlockResponse(appHash, events, txResults, endBlockResp)
return &resp, nil
}

func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequest, lastCommit abci.CommitInfo) ([]abci.Event, []*abci.ExecTxResult, abci.ResponseEndBlock, error) {
goCtx := app.decorateContextWithDexMemState(ctx.Context())
ctx = ctx.WithContext(goCtx)

events := []abci.Event{}
beginBlockReq := abci.RequestBeginBlock{
Hash: req.GetHash(),
ByzantineValidators: utils.Map(req.GetByzantineValidators(), func(mis abci.Misbehavior) abci.Evidence {
return abci.Evidence(mis)
}),
LastCommitInfo: abci.LastCommitInfo{
Round: lastCommit.Round,
Votes: utils.Map(lastCommit.Votes, func(vote abci.VoteInfo) abci.VoteInfo {
return abci.VoteInfo{
Validator: vote.Validator,
SignedLastBlock: vote.SignedLastBlock,
}
}),
},
Header: tmproto.Header{
ChainID: app.ChainID,
Height: req.GetHeight(),
Time: req.GetTime(),
ProposerAddress: ctx.BlockHeader().ProposerAddress,
},
}

beginBlockResp := app.BeginBlock(ctx, beginBlockReq)
events = append(events, beginBlockResp.Events...)

// typedTxs := []sdk.Tx{}
// for _, tx := range req.GetTxs() {
// typedTx, err := app.txDecoder(tx)
// if err != nil {
// typedTxs = append(typedTxs, nil)
// } else {
// typedTxs = append(typedTxs, typedTx)
// }
// }
// app.batchVerifier.VerifyTxs(ctx, typedTxs)

txResults := []*abci.ExecTxResult{}
for _, tx := range txs {
// ctx = ctx.WithContext(context.WithValue(ctx.Context(), ante.ContextKeyTxIndexKey, i))
deliverTxResp := app.DeliverTx(ctx, abci.RequestDeliverTx{
Tx: tx,
})
txResults = append(txResults, &abci.ExecTxResult{
Code: deliverTxResp.Code,
Data: deliverTxResp.Data,
Log: deliverTxResp.Log,
Info: deliverTxResp.Info,
GasWanted: deliverTxResp.GasWanted,
GasUsed: deliverTxResp.GasUsed,
Events: deliverTxResp.Events,
Codespace: deliverTxResp.Codespace,
})
}
endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{
Height: req.GetHeight(),
})
events = append(events, endBlockResp.Events...)

return events, txResults, endBlockResp, nil
}

func (app *App) getFinalizeBlockResponse(appHash []byte, events []abci.Event, txResults []*abci.ExecTxResult, endBlockResp abci.ResponseEndBlock) abci.ResponseFinalizeBlock {
return abci.ResponseFinalizeBlock{
Events: events,
TxResults: txResults,
ValidatorUpdates: utils.Map(endBlockResp.ValidatorUpdates, func(v abci.ValidatorUpdate) abci.ValidatorUpdate {
return abci.ValidatorUpdate{
PubKey: v.PubKey,
Power: v.Power,
}
}),
ConsensusParamUpdates: &tmproto.ConsensusParams{
Block: &tmproto.BlockParams{
MaxBytes: endBlockResp.ConsensusParamUpdates.Block.MaxBytes,
MaxGas: endBlockResp.ConsensusParamUpdates.Block.MaxGas,
},
Evidence: &tmproto.EvidenceParams{
MaxAgeNumBlocks: endBlockResp.ConsensusParamUpdates.Evidence.MaxAgeNumBlocks,
MaxAgeDuration: endBlockResp.ConsensusParamUpdates.Evidence.MaxAgeDuration,
MaxBytes: endBlockResp.ConsensusParamUpdates.Block.MaxBytes,
},
Validator: &tmproto.ValidatorParams{
PubKeyTypes: endBlockResp.ConsensusParamUpdates.Validator.PubKeyTypes,
},
Version: &tmproto.VersionParams{
AppVersion: endBlockResp.ConsensusParamUpdates.Version.AppVersion,
},
},
AppHash: appHash,
}
}

// LoadHeight loads a particular height
func (app *App) LoadHeight(height int64) error {
return app.LoadVersion(height)
Expand Down Expand Up @@ -976,6 +1152,10 @@ func (app *App) BlacklistedAccAddrs() map[string]bool {
return blacklistedAddrs
}

func (app *App) decorateContextWithDexMemState(base context.Context) context.Context {
return context.WithValue(base, dexutils.DexMemStateContextKey, dexcache.NewMemState())
}

func init() {
// override max wasm size to 1MB
wasmtypes.MaxWasmSize = 1024 * 1024
Expand Down
Loading