github.com/Finschia/finschia-sdk@v0.48.1/x/gov/spec/03_messages.md (about)

     1  <!--
     2  order: 3
     3  -->
     4  
     5  # Messages
     6  
     7  ## Proposal Submission
     8  
     9  Proposals can be submitted by any account via a `MsgSubmitProposal`
    10  transaction.
    11  
    12  +++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/gov/v1beta1/tx.proto#L24-L39
    13  
    14  The `Content` of a `MsgSubmitProposal` message must have an appropriate router
    15  set in the governance module.
    16  
    17  **State modifications:**
    18  
    19  - Generate new `proposalID`
    20  - Create new `Proposal`
    21  - Initialise `Proposals` attributes
    22  - Decrease balance of sender by `InitialDeposit`
    23  - If `MinDeposit` is reached:
    24      - Push `proposalID` in `ProposalProcessingQueue`
    25  - Transfer `InitialDeposit` from the `Proposer` to the governance `ModuleAccount`
    26  
    27  A `MsgSubmitProposal` transaction can be handled according to the following
    28  pseudocode.
    29  
    30  ```go
    31  // PSEUDOCODE //
    32  // Check if MsgSubmitProposal is valid. If it is, create proposal //
    33  
    34  upon receiving txGovSubmitProposal from sender do
    35  
    36    if !correctlyFormatted(txGovSubmitProposal)
    37      // check if proposal is correctly formatted. Includes fee payment.
    38      throw
    39  
    40    initialDeposit = txGovSubmitProposal.InitialDeposit
    41    if (initialDeposit.Atoms <= 0) OR (sender.AtomBalance < initialDeposit.Atoms)
    42      // InitialDeposit is negative or null OR sender has insufficient funds
    43      throw
    44  
    45    if (txGovSubmitProposal.Type != ProposalTypePlainText) OR (txGovSubmitProposal.Type != ProposalTypeSoftwareUpgrade)
    46  
    47    sender.AtomBalance -= initialDeposit.Atoms
    48  
    49    depositParam = load(GlobalParams, 'DepositParam')
    50  
    51    proposalID = generate new proposalID
    52    proposal = NewProposal()
    53  
    54    proposal.Title = txGovSubmitProposal.Title
    55    proposal.Description = txGovSubmitProposal.Description
    56    proposal.Type = txGovSubmitProposal.Type
    57    proposal.TotalDeposit = initialDeposit
    58    proposal.SubmitTime = <CurrentTime>
    59    proposal.DepositEndTime = <CurrentTime>.Add(depositParam.MaxDepositPeriod)
    60    proposal.Deposits.append({initialDeposit, sender})
    61    proposal.Submitter = sender
    62    proposal.YesVotes = 0
    63    proposal.NoVotes = 0
    64    proposal.NoWithVetoVotes = 0
    65    proposal.AbstainVotes = 0
    66    proposal.CurrentStatus = ProposalStatusOpen
    67  
    68    store(Proposals, <proposalID|'proposal'>, proposal) // Store proposal in Proposals mapping
    69    return proposalID
    70  ```
    71  
    72  ## Deposit
    73  
    74  Once a proposal is submitted, if
    75  `Proposal.TotalDeposit < ActiveParam.MinDeposit`, Atom holders can send
    76  `MsgDeposit` transactions to increase the proposal's deposit.
    77  
    78  +++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/gov/v1beta1/tx.proto#L61-L72
    79  
    80  **State modifications:**
    81  
    82  - Decrease balance of sender by `deposit`
    83  - Add `deposit` of sender in `proposal.Deposits`
    84  - Increase `proposal.TotalDeposit` by sender's `deposit`
    85  - If `MinDeposit` is reached:
    86      - Push `proposalID` in `ProposalProcessingQueueEnd`
    87  - Transfer `Deposit` from the `proposer` to the governance `ModuleAccount`
    88  
    89  A `MsgDeposit` transaction has to go through a number of checks to be valid.
    90  These checks are outlined in the following pseudocode.
    91  
    92  ```go
    93  // PSEUDOCODE //
    94  // Check if MsgDeposit is valid. If it is, increase deposit and check if MinDeposit is reached
    95  
    96  upon receiving txGovDeposit from sender do
    97    // check if proposal is correctly formatted. Includes fee payment.
    98  
    99    if !correctlyFormatted(txGovDeposit)
   100      throw
   101  
   102    proposal = load(Proposals, <txGovDeposit.ProposalID|'proposal'>) // proposal is a const key, proposalID is variable
   103  
   104    if (proposal == nil)
   105      // There is no proposal for this proposalID
   106      throw
   107  
   108    if (txGovDeposit.Deposit.Atoms <= 0) ORĀ (sender.AtomBalance < txGovDeposit.Deposit.Atoms) OR (proposal.CurrentStatus != ProposalStatusOpen)
   109  
   110      // deposit is negative or null
   111      // OR sender has insufficient funds
   112      // OR proposal is not open for deposit anymore
   113  
   114      throw
   115  
   116    depositParam = load(GlobalParams, 'DepositParam')
   117  
   118    if (CurrentBlock >= proposal.SubmitBlock + depositParam.MaxDepositPeriod)
   119      proposal.CurrentStatus = ProposalStatusClosed
   120  
   121    else
   122      // sender can deposit
   123      sender.AtomBalance -= txGovDeposit.Deposit.Atoms
   124  
   125      proposal.Deposits.append({txGovVote.Deposit, sender})
   126      proposal.TotalDeposit.Plus(txGovDeposit.Deposit)
   127  
   128      if (proposal.TotalDeposit >= depositParam.MinDeposit)
   129        // MinDeposit is reached, vote opens
   130  
   131        proposal.VotingStartBlock = CurrentBlock
   132        proposal.CurrentStatus = ProposalStatusActive
   133        ProposalProcessingQueue.push(txGovDeposit.ProposalID)
   134  
   135    store(Proposals, <txGovVote.ProposalID|'proposal'>, proposal)
   136  ```
   137  
   138  ## Vote
   139  
   140  Once `ActiveParam.MinDeposit` is reached, voting period starts. From there,
   141  bonded Atom holders are able to send `MsgVote` transactions to cast their
   142  vote on the proposal.
   143  
   144  +++ https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/gov/v1beta1/tx.proto#L46-L56
   145  
   146  **State modifications:**
   147  
   148  - Record `Vote` of sender
   149  
   150  _Note: Gas cost for this message has to take into account the future tallying of the vote in EndBlocker_
   151  
   152  Next is a pseudocode outline of the way `MsgVote` transactions are
   153  handled:
   154  
   155  ```go
   156    // PSEUDOCODE //
   157    // Check if MsgVote is valid. If it is, count vote//
   158  
   159    upon receiving txGovVote from sender do
   160      // check if proposal is correctly formatted. Includes fee payment.
   161  
   162      if !correctlyFormatted(txGovDeposit)
   163        throw
   164  
   165      proposal = load(Proposals, <txGovDeposit.ProposalID|'proposal'>)
   166  
   167      if (proposal == nil)
   168        // There is no proposal for this proposalID
   169        throw
   170  
   171  
   172      if  (proposal.CurrentStatus == ProposalStatusActive)
   173  
   174  
   175          // Sender can vote if
   176          // Proposal is active
   177          // Sender has some bonds
   178  
   179          store(Governance, <txGovVote.ProposalID|'addresses'|sender>, txGovVote.Vote)   // Voters can vote multiple times. Re-voting overrides previous vote. This is ok because tallying is done once at the end.
   180  ```