Skip to content

Commit

Permalink
fix gov tally
Browse files Browse the repository at this point in the history
  • Loading branch information
zheng-bin committed May 15, 2024
1 parent 8952b64 commit 8224c95
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 39 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/shentufoundation/shentu/v2
go 1.19

require (
cosmossdk.io/math v1.0.0-rc.0
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.13
github.com/cosmos/go-bip39 v1.0.0
Expand Down Expand Up @@ -44,7 +45,6 @@ require (
cloud.google.com/go/iam v0.12.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.0-rc.0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/keyring v1.2.1 // indirect
github.com/Abirdcfly/dupword v0.0.7 // indirect
Expand Down Expand Up @@ -351,10 +351,10 @@ require (
//replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

replace (
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 // indirect

// Use cosmos keyring
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.2 // indirect
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/ledger-cosmos-go => github.com/cosmos/ledger-cosmos-go v0.11.2-0.20220719170349-e736b9afa7d1

Expand Down
111 changes: 74 additions & 37 deletions x/gov/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,46 @@ func processActiveProposal(ctx sdk.Context, k keeper.Keeper, proposal govtypesv1
}

if pass {
//handler := k.Router().GetRoute(proposal.ProposalRoute())
//cacheCtx, writeCache := ctx.CacheContext()
//// The proposal handler may execute state mutating logic depending on the
//// proposal content. If the handler fails, no state mutation is written and
//// the error message is logged.
//err := handler(cacheCtx, proposal.GetContent())
//if err == nil {
// proposal.Status = govtypesv1.StatusPassed
// tagValue = govtypes.AttributeValueProposalPassed
// logMsg = "passed"
//
// // write state to the underlying multi-store
// writeCache()
//} else {
// proposal.Status = govtypesv1.StatusFailed
// tagValue = govtypes.AttributeValueProposalFailed
// logMsg = fmt.Sprintf("passed, but failed on execution: %s", err)
//}
var (
idx int
events sdk.Events
msg sdk.Msg
)

// attempt to execute all messages within the passed proposal
// Messages may mutate state thus we use a cached context. If one of
// the handlers fails, no state mutation is written and the error
// message is logged.
cacheCtx, writeCache := ctx.CacheContext()
messages, err := proposal.GetMsgs()
if err == nil {
for idx, msg = range messages {
handler := k.Router().Handler(msg)

var res *sdk.Result
res, err = handler(cacheCtx, msg)
if err != nil {
break
}

events = append(events, res.GetEvents()...)
}
}

// `err == nil` when all handlers passed.
// Or else, `idx` and `err` are populated with the msg index and error.
if err == nil {
proposal.Status = govtypesv1.StatusPassed
tagValue = govtypes.AttributeValueProposalPassed
logMsg = "passed"

// write state to the underlying multi-store
writeCache()
} else {
proposal.Status = govtypesv1.StatusFailed
tagValue = govtypes.AttributeValueProposalFailed
logMsg = fmt.Sprintf("passed, but msg %d (%s) failed on execution: %s", idx, sdk.MsgTypeURL(msg), err)
}
} else {
proposal.Status = govtypesv1.StatusRejected
tagValue = govtypes.AttributeValueProposalRejected
Expand Down Expand Up @@ -172,25 +194,40 @@ func processSecurityVote(ctx sdk.Context, k keeper.Keeper, proposal govtypesv1.P
// Else: the proposal passed the certifier voting period.

if endVoting {
//handler := k.Router().GetRoute(proposal.ProposalRoute())
//cacheCtx, writeCache := ctx.CacheContext()
//
//// The proposal handler may execute state mutating logic depending on the
//// proposal content. If the handler fails, no state mutation is written and
//// the error message is logged.
//err := handler(cacheCtx, proposal.GetContent())
//if err == nil {
// proposal.Status = govtypesv1.StatusPassed
// tagValue = govtypes.AttributeValueProposalPassed
// logMsg = "passed"
//
// // write state to the underlying multi-store
// writeCache()
//} else {
//proposal.Status = govtypesv1.StatusFailed
//tagValue = govtypes.AttributeValueProposalFailed
//logMsg = fmt.Sprintf("passed, but failed on execution: %s", err)
//}
var (
idx int
events sdk.Events
msg sdk.Msg
)

cacheCtx, writeCache := ctx.CacheContext()
messages, err := proposal.GetMsgs()
if err == nil {
for idx, msg = range messages {
handler := k.Router().Handler(msg)

var res *sdk.Result
res, err = handler(cacheCtx, msg)
if err != nil {
break
}

events = append(events, res.GetEvents()...)
}
}

if err == nil {
proposal.Status = govtypesv1.StatusPassed
tagValue = govtypes.AttributeValueProposalPassed
logMsg = "passed"

// write state to the underlying multi-store
writeCache()
} else {
proposal.Status = govtypesv1.StatusFailed
tagValue = govtypes.AttributeValueProposalFailed
logMsg = fmt.Sprintf("passed, but msg %d (%s) failed on execution: %s", idx, sdk.MsgTypeURL(msg), err)
}

proposal.FinalTallyResult = &tallyResults

Expand Down

0 comments on commit 8224c95

Please sign in to comment.