feat: max quorum num

This commit is contained in:
MiniFrenchBread 2024-05-16 23:39:07 +08:00 committed by 0g-wh
parent 9d15e399d8
commit b3e526871e
4 changed files with 51 additions and 44 deletions

View File

@ -11,7 +11,7 @@ option go_package = "github.com/0glabs/0g-chain/x/dasigners/v1/types";
message Params { message Params {
string tokens_per_vote = 1; string tokens_per_vote = 1;
uint64 max_votes = 2; uint64 max_quorums = 2;
uint64 epoch_blocks = 3; uint64 epoch_blocks = 3;
uint64 encoded_slices = 4; uint64 encoded_slices = 4;
} }

View File

@ -2,7 +2,6 @@ package keeper
import ( import (
"bytes" "bytes"
"math/big"
"sort" "sort"
"github.com/0glabs/0g-chain/x/dasigners/v1/types" "github.com/0glabs/0g-chain/x/dasigners/v1/types"
@ -56,9 +55,6 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
continue continue
} }
num := validator.Tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000)).Quo(tokensPerVote).Abs().BigInt() num := validator.Tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000)).Quo(tokensPerVote).Abs().BigInt()
if num.Cmp(big.NewInt(int64(params.MaxVotes))) > 0 {
num = big.NewInt(int64(params.MaxVotes))
}
content := registration.content content := registration.content
ballotNum := num.Int64() ballotNum := num.Int64()
for j := 0; j < int(ballotNum); j += 1 { for j := 0; j < int(ballotNum); j += 1 {
@ -78,6 +74,9 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
} }
if len(ballots) >= int(params.EncodedSlices) { if len(ballots) >= int(params.EncodedSlices) {
for i := 0; i+int(params.EncodedSlices) < len(ballots); i += 1 { for i := 0; i+int(params.EncodedSlices) < len(ballots); i += 1 {
if int(params.MaxQuorums) < len(quorums.Quorums) {
break
}
quorum := types.Quorum{ quorum := types.Quorum{
Signers: make([]string, params.EncodedSlices), Signers: make([]string, params.EncodedSlices),
} }
@ -86,6 +85,15 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {
} }
quorums.Quorums = append(quorums.Quorums, &quorum) quorums.Quorums = append(quorums.Quorums, &quorum)
} }
if len(ballots)%int(params.EncodedSlices) != 0 && int(params.MaxQuorums) < len(quorums.Quorums) {
quorum := types.Quorum{
Signers: make([]string, 0),
}
for j := len(ballots) - int(params.EncodedSlices); j < len(ballots); j += 1 {
quorum.Signers = append(quorum.Signers, ballots[j].account)
}
quorums.Quorums = append(quorums.Quorums, &quorum)
}
} else if len(ballots) > 0 { } else if len(ballots) > 0 {
quorum := types.Quorum{ quorum := types.Quorum{
Signers: make([]string, params.EncodedSlices), Signers: make([]string, params.EncodedSlices),

View File

@ -16,7 +16,7 @@ func NewGenesisState(params Params, epoch uint64, signers []*Signer, quorumsByEp
func DefaultGenesisState() *GenesisState { func DefaultGenesisState() *GenesisState {
return NewGenesisState(Params{ return NewGenesisState(Params{
TokensPerVote: "100", TokensPerVote: "100",
MaxVotes: 100, MaxQuorums: 100,
EpochBlocks: 1000, EpochBlocks: 1000,
EncodedSlices: 3072, EncodedSlices: 3072,
}, 0, make([]*Signer, 0), []*Quorums{{ }, 0, make([]*Signer, 0), []*Quorums{{

View File

@ -28,7 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type Params struct { type Params struct {
TokensPerVote string `protobuf:"bytes,1,opt,name=tokens_per_vote,json=tokensPerVote,proto3" json:"tokens_per_vote,omitempty"` TokensPerVote string `protobuf:"bytes,1,opt,name=tokens_per_vote,json=tokensPerVote,proto3" json:"tokens_per_vote,omitempty"`
MaxVotes uint64 `protobuf:"varint,2,opt,name=max_votes,json=maxVotes,proto3" json:"max_votes,omitempty"` MaxQuorums uint64 `protobuf:"varint,2,opt,name=max_quorums,json=maxQuorums,proto3" json:"max_quorums,omitempty"`
EpochBlocks uint64 `protobuf:"varint,3,opt,name=epoch_blocks,json=epochBlocks,proto3" json:"epoch_blocks,omitempty"` EpochBlocks uint64 `protobuf:"varint,3,opt,name=epoch_blocks,json=epochBlocks,proto3" json:"epoch_blocks,omitempty"`
EncodedSlices uint64 `protobuf:"varint,4,opt,name=encoded_slices,json=encodedSlices,proto3" json:"encoded_slices,omitempty"` EncodedSlices uint64 `protobuf:"varint,4,opt,name=encoded_slices,json=encodedSlices,proto3" json:"encoded_slices,omitempty"`
} }
@ -73,9 +73,9 @@ func (m *Params) GetTokensPerVote() string {
return "" return ""
} }
func (m *Params) GetMaxVotes() uint64 { func (m *Params) GetMaxQuorums() uint64 {
if m != nil { if m != nil {
return m.MaxVotes return m.MaxQuorums
} }
return 0 return 0
} }
@ -175,34 +175,33 @@ func init() {
func init() { proto.RegisterFile("zgc/dasigners/v1/genesis.proto", fileDescriptor_896efa766aaca3be) } func init() { proto.RegisterFile("zgc/dasigners/v1/genesis.proto", fileDescriptor_896efa766aaca3be) }
var fileDescriptor_896efa766aaca3be = []byte{ var fileDescriptor_896efa766aaca3be = []byte{
// 417 bytes of a gzipped FileDescriptorProto // 416 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xcf, 0x6e, 0xd3, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x6e, 0x13, 0x31,
0x10, 0xc6, 0x63, 0x12, 0x05, 0xba, 0xfd, 0x43, 0x65, 0x71, 0x70, 0x8a, 0xe4, 0x86, 0x4a, 0xa0, 0x10, 0x86, 0xb3, 0x24, 0x0a, 0xc2, 0x69, 0x4b, 0xb5, 0xe2, 0xb0, 0xe9, 0x61, 0x13, 0x2a, 0x81,
0x5e, 0xf0, 0xb6, 0x45, 0xe2, 0x01, 0x82, 0x10, 0xe2, 0x82, 0x8a, 0x23, 0x71, 0xe0, 0x62, 0xad, 0x7a, 0x61, 0xdd, 0x16, 0x89, 0x07, 0x08, 0x42, 0x88, 0x0b, 0x2a, 0x1b, 0x89, 0x03, 0x17, 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x02, 0x00, 0x00,
0x00,
} }
func (m *Params) Marshal() (dAtA []byte, err error) { func (m *Params) Marshal() (dAtA []byte, err error) {
@ -235,8 +234,8 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i-- i--
dAtA[i] = 0x18 dAtA[i] = 0x18
} }
if m.MaxVotes != 0 { if m.MaxQuorums != 0 {
i = encodeVarintGenesis(dAtA, i, uint64(m.MaxVotes)) i = encodeVarintGenesis(dAtA, i, uint64(m.MaxQuorums))
i-- i--
dAtA[i] = 0x10 dAtA[i] = 0x10
} }
@ -337,8 +336,8 @@ func (m *Params) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovGenesis(uint64(l)) n += 1 + l + sovGenesis(uint64(l))
} }
if m.MaxVotes != 0 { if m.MaxQuorums != 0 {
n += 1 + sovGenesis(uint64(m.MaxVotes)) n += 1 + sovGenesis(uint64(m.MaxQuorums))
} }
if m.EpochBlocks != 0 { if m.EpochBlocks != 0 {
n += 1 + sovGenesis(uint64(m.EpochBlocks)) n += 1 + sovGenesis(uint64(m.EpochBlocks))
@ -444,9 +443,9 @@ func (m *Params) Unmarshal(dAtA []byte) error {
iNdEx = postIndex iNdEx = postIndex
case 2: case 2:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field MaxVotes", wireType) return fmt.Errorf("proto: wrong wireType = %d for field MaxQuorums", wireType)
} }
m.MaxVotes = 0 m.MaxQuorums = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowGenesis return ErrIntOverflowGenesis
@ -456,7 +455,7 @@ func (m *Params) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
m.MaxVotes |= uint64(b&0x7F) << shift m.MaxQuorums |= uint64(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }