Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

fast-sync: Emit all gov module from start state #2564

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### Emitter & Flusher

- (feat) [\#2564](https://github.com/bandprotocol/bandchain/pull/2564) fast-sync: emit all gov module from start state
- (impv) [\#2558](https://github.com/bandprotocol/bandchain/pull/2558) fast-sync: emit all oracle module from start state
- (bugs) [\#2601](https://github.com/bandprotocol/bandchain/pull/2601) Downgrade Kafka go
- (bugs) [\#2600](https://github.com/bandprotocol/bandchain/pull/2600) Fix bug handle new transaction
Expand Down
1 change: 1 addition & 0 deletions chain/emitter/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (app *App) emitNonHistoricalState() {
app.emitAccountModule()
app.emitStakingModule()
app.emitOracleModule()
app.emitGovModule()
app.Write("COMMIT", JsDict{"height": -1})
app.FlushMessages()
app.msgs = []Message{}
Expand Down
64 changes: 44 additions & 20 deletions chain/emitter/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@ var (
StatusInactive = 6
)

func (app *App) emitGovModule() {
app.GovKeeper.IterateProposals(app.DeliverContext, func(proposal types.Proposal) (stop bool) {
app.emitNewProposal(proposal, nil)
return false
})
app.GovKeeper.IterateAllDeposits(app.DeliverContext, func(deposit types.Deposit) (stop bool) {
app.emitSetDeposit(nil, deposit.ProposalID, deposit.Depositor)
return false
})
app.GovKeeper.IterateAllVotes(app.DeliverContext, func(vote types.Vote) (stop bool) {
app.emitSetVote(nil, vote)
return false
})
}

func (app *App) emitNewProposal(proposal gov.Proposal, proposer sdk.AccAddress) {
app.Write("NEW_PROPOSAL", JsDict{
"id": proposal.ProposalID,
"proposer": proposer,
"type": proposal.Content.ProposalType(),
"title": proposal.Content.GetTitle(),
"description": proposal.Content.GetDescription(),
"proposal_route": proposal.Content.ProposalRoute(),
"status": int(proposal.Status),
"submit_time": proposal.SubmitTime.UnixNano(),
"deposit_end_time": proposal.DepositEndTime.UnixNano(),
"total_deposit": proposal.TotalDeposit.String(),
"voting_time": proposal.VotingStartTime.UnixNano(),
"voting_end_time": proposal.VotingEndTime.UnixNano(),
})
}

func (app *App) emitSetDeposit(txHash []byte, id uint64, depositor sdk.AccAddress) {
Benzbeeb marked this conversation as resolved.
Show resolved Hide resolved
deposit, _ := app.GovKeeper.GetDeposit(app.DeliverContext, id, depositor)
app.Write("SET_DEPOSIT", JsDict{
Expand All @@ -33,26 +65,22 @@ func (app *App) emitUpdateProposalAfterDeposit(id uint64) {
})
}

func (app *App) emitSetVote(txHash []byte, vote types.Vote) {
app.Write("SET_VOTE", JsDict{
"proposal_id": vote.ProposalID,
"voter": vote.Voter,
"answer": int(vote.Option),
"tx_hash": txHash,
})
}

// handleMsgSubmitProposal implements emitter handler for MsgSubmitProposal.
func (app *App) handleMsgSubmitProposal(
txHash []byte, msg gov.MsgSubmitProposal, evMap EvMap, extra JsDict,
) {
proposalId := uint64(atoi(evMap[types.EventTypeSubmitProposal+"."+types.AttributeKeyProposalID][0]))
proposal, _ := app.GovKeeper.GetProposal(app.DeliverContext, proposalId)
app.Write("NEW_PROPOSAL", JsDict{
"id": proposalId,
"proposer": msg.Proposer,
"type": msg.Content.ProposalType(),
"title": msg.Content.GetTitle(),
"description": msg.Content.GetDescription(),
"proposal_route": msg.Content.ProposalRoute(),
"status": int(proposal.Status),
"submit_time": proposal.SubmitTime.UnixNano(),
"deposit_end_time": proposal.DepositEndTime.UnixNano(),
"total_deposit": proposal.TotalDeposit.String(),
"voting_time": proposal.VotingStartTime.UnixNano(),
"voting_end_time": proposal.VotingEndTime.UnixNano(),
})
app.emitNewProposal(proposal, msg.Proposer)
app.emitSetDeposit(txHash, proposalId, msg.Proposer)
}

Expand All @@ -68,12 +96,8 @@ func (app *App) handleMsgDeposit(
func (app *App) handleMsgVote(
txHash []byte, msg gov.MsgVote, evMap EvMap, extra JsDict,
) {
app.Write("SET_VOTE", JsDict{
"proposal_id": msg.ProposalID,
"voter": msg.Voter,
"answer": int(msg.Option),
"tx_hash": txHash,
})
vote, _ := app.GovKeeper.GetVote(app.DeliverContext, msg.ProposalID, msg.Voter)
app.emitSetVote(txHash, vote)
}

func (app *App) handleEventInactiveProposal(evMap EvMap) {
Expand Down
4 changes: 2 additions & 2 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def Column(*args, **kwargs):
Column("proposal_id", sa.Integer, sa.ForeignKey("proposals.id"), primary_key=True),
Column("depositor_id", sa.Integer, sa.ForeignKey("accounts.id"), primary_key=True),
Column("amount", sa.String), # uband suffix
Column("tx_id", sa.Integer, sa.ForeignKey("transactions.id")),
Column("tx_id", sa.Integer, sa.ForeignKey("transactions.id"), nullable=True),
)

votes = sa.Table(
Expand All @@ -327,7 +327,7 @@ def Column(*args, **kwargs):
Column("proposal_id", sa.Integer, sa.ForeignKey("proposals.id"), primary_key=True),
Column("voter_id", sa.Integer, sa.ForeignKey("accounts.id"), primary_key=True),
Column("answer", CustomVoteOption),
Column("tx_id", sa.Integer, sa.ForeignKey("transactions.id")),
Column("tx_id", sa.Integer, sa.ForeignKey("transactions.id"), nullable=True),
)

historical_bonded_token_on_validators = sa.Table(
Expand Down