Skip to content

Gov module should use byte prefixes instead of strings for keys #4437

Closed
@fedekunze

Description

Summary of Bug

Currently x/gov uses strings instead of bytes for storing the keys on the store. This makes it harder to parse/split and adds extra bytes to the keys:

func KeyProposal(proposalID uint64) []byte {
	return []byte(fmt.Sprintf("proposals:%d", proposalID))
}

func KeyDeposit(proposalID uint64, depositorAddr sdk.AccAddress) []byte {
	return []byte(fmt.Sprintf("deposits:%d:%d", proposalID, depositorAddr))
}

func KeyVote(proposalID uint64, voterAddr sdk.AccAddress) []byte {
	return []byte(fmt.Sprintf("votes:%d:%d", proposalID, voterAddr))
}

Suggested changes:

var (
    ProposalKeyPrefix        = []byte{0x0}
    DepositsKeyPrefix        = []byte{0x1}
    VotesKeyPrefix             = []byte{0x2}
)

keyProposal: 0x0<proposalID_bytes>
keyDeposit:0x1<proposalID_bytes><depositorAddress_Bytes>
keyVotes: 0x2<proposalID_bytes><voterAddress_Bytes>


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions