From 9d15e399d8152a86ecd4e09a53045877877d3527 Mon Sep 17 00:00:00 2001 From: MiniFrenchBread <103425574+MiniFrenchBread@users.noreply.github.com> Date: Thu, 16 May 2024 23:25:43 +0800 Subject: [PATCH] fix: quorum --- precompiles/dasigners/dasigners.go | 15 ++++++++------- x/dasigners/v1/keeper/abci.go | 6 +++++- x/dasigners/v1/keeper/grpc_query.go | 9 +++++---- x/dasigners/v1/types/errors.go | 2 +- x/dasigners/v1/types/genesis.go | 6 ++++-- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/precompiles/dasigners/dasigners.go b/precompiles/dasigners/dasigners.go index 87816ae6..5a23598e 100644 --- a/precompiles/dasigners/dasigners.go +++ b/precompiles/dasigners/dasigners.go @@ -29,13 +29,14 @@ const ( ) var RequiredGasBasic = map[string]uint64{ - "epochNumber": 1000, - "getSigner": 10000, - "getSigners": 1000000, - "updateSocket": 50000, - "registerNextEpoch": 100000, - "registerSigner": 100000, - "getAggPkG1": 1000000, + DASignersFunctionEpochNumber: 1000, + DASignersFunctionQuorumCount: 1000, + DASignersFunctionGetSigner: 100000, + DASignersFunctionGetQuorum: 100000, + DASignersFunctionRegisterSigner: 100000, + DASignersFunctionUpdateSocket: 50000, + DASignersFunctionRegisterNextEpoch: 100000, + DASignersFunctionGetAggPkG1: 1000000, } var KVGasConfig storetypes.GasConfig = storetypes.GasConfig{ diff --git a/x/dasigners/v1/keeper/abci.go b/x/dasigners/v1/keeper/abci.go index cc509269..b3291c60 100644 --- a/x/dasigners/v1/keeper/abci.go +++ b/x/dasigners/v1/keeper/abci.go @@ -86,7 +86,7 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { } quorums.Quorums = append(quorums.Quorums, &quorum) } - } else { + } else if len(ballots) > 0 { quorum := types.Quorum{ Signers: make([]string, params.EncodedSlices), } @@ -95,6 +95,10 @@ func (k Keeper) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { quorum.Signers[i] = ballots[i%n].account } quorums.Quorums = append(quorums.Quorums, &quorum) + } else { + quorums.Quorums = append(quorums.Quorums, &types.Quorum{ + Signers: make([]string, 0), + }) } // save to store diff --git a/x/dasigners/v1/keeper/grpc_query.go b/x/dasigners/v1/keeper/grpc_query.go index 484d970c..cd0fedfe 100644 --- a/x/dasigners/v1/keeper/grpc_query.go +++ b/x/dasigners/v1/keeper/grpc_query.go @@ -84,13 +84,15 @@ func (k Keeper) AggregatePubkeyG1(c context.Context, request *types.QueryAggrega hit := 0 added := make(map[string]struct{}) for i, signer := range quorum.Signers { + if _, ok := added[signer]; ok { + hit += 1 + continue + } b := request.QuorumBitmap[i/8] & (1 << (i % 8)) if b == 0 { continue } - if _, ok := added[signer]; ok { - continue - } + hit += 1 added[signer] = struct{}{} signer, found, err := k.GetSigner(ctx, signer) if err != nil { @@ -99,7 +101,6 @@ func (k Keeper) AggregatePubkeyG1(c context.Context, request *types.QueryAggrega if !found { return nil, types.ErrSignerNotFound } - hit += 1 aggPubkeyG1.Add(aggPubkeyG1, bn254util.DeserializeG1(signer.PubkeyG1)) } return &types.QueryAggregatePubkeyG1Response{ diff --git a/x/dasigners/v1/types/errors.go b/x/dasigners/v1/types/errors.go index 35d89ad6..e5c916e8 100644 --- a/x/dasigners/v1/types/errors.go +++ b/x/dasigners/v1/types/errors.go @@ -9,5 +9,5 @@ var ( ErrInvalidSignature = errorsmod.Register(ModuleName, 4, "invalid signature") ErrQuorumNotFound = errorsmod.Register(ModuleName, 5, "quorum for epoch not found") ErrQuorumIdOutOfBound = errorsmod.Register(ModuleName, 6, "quorum id out of bound") - ErrQuorumBitmapLengthMismatch = errorsmod.Register(ModuleName, 6, "quorum bitmap length mismatch") + ErrQuorumBitmapLengthMismatch = errorsmod.Register(ModuleName, 7, "quorum bitmap length mismatch") ) diff --git a/x/dasigners/v1/types/genesis.go b/x/dasigners/v1/types/genesis.go index d13aa4c4..1f87bcc2 100644 --- a/x/dasigners/v1/types/genesis.go +++ b/x/dasigners/v1/types/genesis.go @@ -19,7 +19,9 @@ func DefaultGenesisState() *GenesisState { MaxVotes: 100, EpochBlocks: 1000, EncodedSlices: 3072, - }, 0, make([]*Signer, 0), make([]*Quorums, 0)) + }, 0, make([]*Signer, 0), []*Quorums{{ + Quorums: make([]*Quorum, 0), + }}) } // Validate performs basic validation of genesis data. @@ -31,7 +33,7 @@ func (gs GenesisState) Validate() error { } registered[signer.Account] = struct{}{} } - if len(gs.QuorumsByEpoch) != int(gs.EpochNumber) { + if len(gs.QuorumsByEpoch) != int(gs.EpochNumber)+1 { return fmt.Errorf("epoch history missing") } for _, quorums := range gs.QuorumsByEpoch {