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 all 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
73 changes: 48 additions & 25 deletions chain/emitter/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,43 @@ var (
StatusInactive = 6
)

func (app *App) emitSetDeposit(txHash []byte, id uint64, depositor sdk.AccAddress) {
deposit, _ := app.GovKeeper.GetDeposit(app.DeliverContext, id, depositor)
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, deposit.Amount)
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, amount sdk.Coins) {
app.Write("SET_DEPOSIT", JsDict{
"proposal_id": id,
"depositor": depositor,
"amount": deposit.Amount.String(),
"amount": amount.String(),
"tx_hash": txHash,
})
}
Expand All @@ -33,47 +64,39 @@ 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.emitSetDeposit(txHash, proposalId, msg.Proposer)
app.emitNewProposal(proposal, msg.Proposer)
app.emitSetDeposit(txHash, proposalId, msg.Proposer, msg.InitialDeposit)
}

// handleMsgDeposit implements emitter handler for MsgDeposit.
func (app *App) handleMsgDeposit(
txHash []byte, msg gov.MsgDeposit, evMap EvMap, extra JsDict,
) {
app.emitSetDeposit(txHash, msg.ProposalID, msg.Depositor)
app.emitSetDeposit(txHash, msg.ProposalID, msg.Depositor, msg.Amount)
app.emitUpdateProposalAfterDeposit(msg.ProposalID)
}

// handleMsgVote implements emitter handler for MsgVote.
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
6 changes: 3 additions & 3 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def Column(*args, **kwargs):
"proposals",
metadata,
Column("id", sa.Integer, primary_key=True),
Column("proposer_id", sa.Integer, sa.ForeignKey("accounts.id")),
Column("proposer_id", sa.Integer, sa.ForeignKey("accounts.id"), nullable=True),
Benzbeeb marked this conversation as resolved.
Show resolved Hide resolved
Column("type", sa.String),
Column("title", sa.String),
Column("description", sa.String),
Expand All @@ -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