From 9ee3cf6f74ccad56890976227b8dd746a116713c Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Mon, 3 Oct 2022 14:44:03 -0700 Subject: [PATCH 1/2] [app] Add behavior to process blocks with gov txs sync --- app/app.go | 21 +++++++++++++++++---- app/graph.go | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index afe16a3781..6ddabdeecb 100644 --- a/app/app.go +++ b/app/app.go @@ -876,6 +876,15 @@ func (app *App) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProcess }, nil } +func isGovMessage(msg sdk.Msg) bool { + switch msg.(type) { + case *govtypes.MsgVoteWeighted, *govtypes.MsgVote, *govtypes.MsgSubmitProposal, *govtypes.MsgDeposit: + return true + default: + return false + } +} + func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) { // contains the latest msg index for a specific Access Operation dependencyDag := NewDag() @@ -886,6 +895,9 @@ func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) } msgs := tx.GetMsgs() for messageIndex, msg := range msgs { + if isGovMessage(msg) { + return nil, ErrGovMsgInBlock + } msgDependencies := app.AccessControlKeeper.GetResourceDependencyMapping(ctx, acltypes.GenerateMessageKey(msg)) for _, accessOp := range msgDependencies.GetAccessOps() { // make a new node in the dependency dag @@ -1091,11 +1103,12 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ txResults := []*abci.ExecTxResult{} // TODO:: add metrics for async vs sync - if err != nil { + if err == ErrGovMsgInBlock { + ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err)) + txResults = app.ProcessBlockSynchronous(ctx, txs) + } else if err != nil { ctx.Logger().Error(fmt.Sprintf("Error while building DAG, processing synchronously: %s", err)) - if err == ErrCycleInDAG { - txResults = app.ProcessBlockSynchronous(ctx, txs) - } + txResults = app.ProcessBlockSynchronous(ctx, txs) } else { completionSignalingMap, blockingSignalsMap := dependencyDag.BuildCompletionSignalMaps() txResults = app.ProcessBlockConcurrent(ctx, txs, completionSignalingMap, blockingSignalsMap) diff --git a/app/graph.go b/app/graph.go index b97e2c3710..3166d05b34 100644 --- a/app/graph.go +++ b/app/graph.go @@ -327,3 +327,4 @@ func (dag *Dag) BuildCompletionSignalMaps() ( } var ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") +var ErrGovMsgInBlock = fmt.Errorf("gov msg in block") From b121ec89e8e20be509523f098e084aa0533a72ff Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 4 Oct 2022 10:42:59 -0700 Subject: [PATCH 2/2] lint --- app/app.go | 9 +++++---- app/graph.go | 6 ++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index 6ddabdeecb..0ab29d22d0 100644 --- a/app/app.go +++ b/app/app.go @@ -1100,16 +1100,17 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ // app.batchVerifier.VerifyTxs(ctx, typedTxs) dependencyDag, err := app.BuildDependencyDag(ctx, txs) - txResults := []*abci.ExecTxResult{} + var txResults []*abci.ExecTxResult // TODO:: add metrics for async vs sync - if err == ErrGovMsgInBlock { + switch err { + case ErrGovMsgInBlock: ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) - } else if err != nil { + case nil: ctx.Logger().Error(fmt.Sprintf("Error while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) - } else { + default: completionSignalingMap, blockingSignalsMap := dependencyDag.BuildCompletionSignalMaps() txResults = app.ProcessBlockConcurrent(ctx, txs, completionSignalingMap, blockingSignalsMap) } diff --git a/app/graph.go b/app/graph.go index 3166d05b34..d999d5b573 100644 --- a/app/graph.go +++ b/app/graph.go @@ -326,5 +326,7 @@ func (dag *Dag) BuildCompletionSignalMaps() ( return completionSignalingMap, blockingSignalsMap } -var ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") -var ErrGovMsgInBlock = fmt.Errorf("gov msg in block") +var ( + ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") + ErrGovMsgInBlock = fmt.Errorf("gov msg in block") +)