diff --git a/docs/core/proto-docs.md b/docs/core/proto-docs.md index 2ed7c9cc1d..209143f2b6 100644 --- a/docs/core/proto-docs.md +++ b/docs/core/proto-docs.md @@ -760,6 +760,7 @@ - [ProvisionData](#lbm.fbridge.v1.ProvisionData) - [ProvisionStatus](#lbm.fbridge.v1.ProvisionStatus) - [RoleMetadata](#lbm.fbridge.v1.RoleMetadata) + - [RolePair](#lbm.fbridge.v1.RolePair) - [RoleProposal](#lbm.fbridge.v1.RoleProposal) - [Vote](#lbm.fbridge.v1.Vote) @@ -11482,6 +11483,22 @@ RoleMetadata defines the metadata of the role. + + +### RolePair + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `address` | [string](#string) | | | +| `role` | [Role](#lbm.fbridge.v1.Role) | | | + + + + + + ### RoleProposal @@ -11743,6 +11760,7 @@ GenesisState defines the fbridge module's genesis state. | `role_proposals` | [RoleProposal](#lbm.fbridge.v1.RoleProposal) | repeated | role_proposals defines all the role proposals present at genesis. | | `votes` | [Vote](#lbm.fbridge.v1.Vote) | repeated | votes defines all the votes present for role proposals at genesis. | | `role_metadata` | [RoleMetadata](#lbm.fbridge.v1.RoleMetadata) | | role_metadata defines all the role metadata present at genesis. | +| `roles` | [RolePair](#lbm.fbridge.v1.RolePair) | repeated | roles defines all addresses assigned roles at genesis. | diff --git a/proto/lbm/fbridge/v1/fbridge.proto b/proto/lbm/fbridge/v1/fbridge.proto index 65d411b053..c54d9a632e 100644 --- a/proto/lbm/fbridge/v1/fbridge.proto +++ b/proto/lbm/fbridge/v1/fbridge.proto @@ -60,6 +60,11 @@ enum Role { JUDGE = 3 [(gogoproto.enumvalue_customname) = "RoleJudge"]; } +message RolePair { + string address = 1; + Role role = 2; +} + message RoleProposal { uint64 id = 1; // the proposer address @@ -106,4 +111,4 @@ message RoleMetadata { uint32 operator = 2; // the number of the judges uint32 judge = 3; -} \ No newline at end of file +} diff --git a/proto/lbm/fbridge/v1/genesis.proto b/proto/lbm/fbridge/v1/genesis.proto index a2fadc6e4c..cda0f10e39 100644 --- a/proto/lbm/fbridge/v1/genesis.proto +++ b/proto/lbm/fbridge/v1/genesis.proto @@ -22,6 +22,8 @@ message GenesisState { repeated Vote votes = 6 [(gogoproto.nullable) = false]; // role_metadata defines all the role metadata present at genesis. RoleMetadata role_metadata = 7 [(gogoproto.nullable) = false]; + // roles defines all addresses assigned roles at genesis. + repeated RolePair roles = 8 [(gogoproto.nullable) = false]; } message SendingState { diff --git a/x/fbridge/keeper/auth.go b/x/fbridge/keeper/auth.go index 9477084df0..bd10693c2b 100644 --- a/x/fbridge/keeper/auth.go +++ b/x/fbridge/keeper/auth.go @@ -157,7 +157,21 @@ func (k Keeper) GetVote(ctx sdk.Context, proposalID uint64, voter sdk.AccAddress return types.VoteOption(binary.BigEndian.Uint32(bz)), nil } -func (k Keeper) setRole(ctx sdk.Context, role types.Role, addr sdk.AccAddress) { +func (k Keeper) GetVotes(ctx sdk.Context, proposalID uint64) []types.VoteOption { + store := ctx.KVStore(k.storeKey) + + votes := make([]types.VoteOption, 0) + iterator := sdk.KVStorePrefixIterator(store, types.VotesKey(proposalID)) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + v := types.VoteOption(binary.BigEndian.Uint32(iterator.Value())) + votes = append(votes, v) + } + + return votes +} + +func (k Keeper) SetRole(ctx sdk.Context, role types.Role, addr sdk.AccAddress) { store := ctx.KVStore(k.storeKey) bz := make([]byte, 4) binary.BigEndian.PutUint32(bz, uint32(role)) @@ -174,7 +188,26 @@ func (k Keeper) GetRole(ctx sdk.Context, addr sdk.AccAddress) types.Role { return types.Role(binary.BigEndian.Uint32(bz)) } -func (k Keeper) setRoleMetadata(ctx sdk.Context, data types.RoleMetadata) { +func (k Keeper) GetRolePairs(ctx sdk.Context) []types.RolePair { + store := ctx.KVStore(k.storeKey) + + pairs := make([]types.RolePair, 0) + iterator := sdk.KVStorePrefixIterator(store, types.KeyRolePrefix) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + assignee := types.SplitRoleKey(iterator.Key()) + pairs = append(pairs, types.RolePair{Address: assignee.String(), Role: types.Role(binary.BigEndian.Uint32(iterator.Value()))}) + } + + return pairs +} + +func (k Keeper) DeleteRole(ctx sdk.Context, addr sdk.AccAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.RoleKey(addr)) +} + +func (k Keeper) SetRoleMetadata(ctx sdk.Context, data types.RoleMetadata) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&data) store.Set(types.KeyRoleMetadata, bz) diff --git a/x/fbridge/keeper/genesis.go b/x/fbridge/keeper/genesis.go index 1a30f28c20..5f31056776 100644 --- a/x/fbridge/keeper/genesis.go +++ b/x/fbridge/keeper/genesis.go @@ -9,12 +9,21 @@ import ( func (k Keeper) InitGenesis(ctx sdk.Context, gs *types.GenesisState) error { k.SetParams(ctx, gs.Params) k.setNextSequence(ctx, gs.SendingState.NextSeq) - k.setNextProposalID(ctx, gs.NextRoleProposalId) - k.setRoleMetadata(ctx, gs.RoleMetadata) + k.setNextProposalID(ctx, gs.NextRoleProposalId) for _, proposal := range gs.RoleProposals { k.setRoleProposal(ctx, proposal) } + + for _, vote := range gs.Votes { + k.setVote(ctx, vote.ProposalId, sdk.MustAccAddressFromBech32(vote.Voter), vote.Option) + } + + k.SetRoleMetadata(ctx, gs.RoleMetadata) + for _, pair := range gs.Roles { + k.SetRole(ctx, pair.Role, sdk.MustAccAddressFromBech32(pair.Address)) + } + // TODO: we initialize the appropriate genesis parameters whenever the feature is added return nil @@ -27,9 +36,10 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { NextSeq: k.GetNextSequence(ctx), }, NextRoleProposalId: k.GetNextProposalID(ctx), - RoleMetadata: k.GetRoleMetadata(ctx), RoleProposals: k.GetProposals(ctx), Votes: k.GetAllVotes(ctx), + RoleMetadata: k.GetRoleMetadata(ctx), + Roles: k.GetRolePairs(ctx), } } @@ -43,7 +53,6 @@ func (k Keeper) IterateVotes(ctx sdk.Context, cb func(proposal types.Vote) (stop id, voter := types.SplitVoterVoteKey(iterator.Key()) opt := types.VoteOption(binary.BigEndian.Uint32(iterator.Value())) v := types.Vote{ProposalId: id, Voter: voter.String(), Option: opt} - k.cdc.MustUnmarshal(iterator.Value(), &v) if cb(v) { break } diff --git a/x/fbridge/module/abci.go b/x/fbridge/module/abci.go new file mode 100644 index 0000000000..acb8d7874e --- /dev/null +++ b/x/fbridge/module/abci.go @@ -0,0 +1,70 @@ +package module + +import ( + "fmt" + sdk "github.com/Finschia/finschia-sdk/types" + "github.com/Finschia/finschia-sdk/x/fbridge/keeper" + "github.com/Finschia/finschia-sdk/x/fbridge/types" +) + +func EndBlocker(ctx sdk.Context, k keeper.Keeper) { + guardianTrustLevel := k.GetParams(ctx).GuardianTrustLevel + proposals := k.GetProposals(ctx) + for _, proposal := range proposals { + if ctx.BlockTime().After(proposal.ExpiredAt) { + k.DeleteRoleProposal(ctx, proposal.Id) + continue + } + + votes := k.GetVotes(ctx, proposal.Id) + + voteYes := 0 + for _, vote := range votes { + if vote == types.OptionYes { + voteYes++ + } + } + + var total uint32 = 0 + roleMeta := k.GetRoleMetadata(ctx) + previousRole := k.GetRole(ctx, sdk.MustAccAddressFromBech32(proposal.Target)) + switch proposal.Role { + case types.RoleGuardian: + total = roleMeta.Guardian + case types.RoleOperator: + total = roleMeta.Operator + case types.RoleJudge: + total = roleMeta.Judge + default: + panic(fmt.Sprintf("invalid role: %s\n", proposal.Role)) + } + + if types.CheckTrustLevelThreshold(uint64(total), uint64(voteYes), guardianTrustLevel) { + if proposal.Role == types.RoleEmpty { + k.DeleteRole(ctx, sdk.MustAccAddressFromBech32(proposal.Target)) + } else { + k.SetRole(ctx, proposal.Role, sdk.MustAccAddressFromBech32(proposal.Target)) + } + + switch proposal.Role { + case types.RoleGuardian: + roleMeta.Guardian++ + case types.RoleOperator: + roleMeta.Operator++ + case types.RoleJudge: + roleMeta.Judge++ + } + switch previousRole { + case types.RoleGuardian: + roleMeta.Guardian-- + case types.RoleOperator: + roleMeta.Operator-- + case types.RoleJudge: + roleMeta.Judge-- + } + k.SetRoleMetadata(ctx, roleMeta) + + k.DeleteRoleProposal(ctx, proposal.Id) + } + } +} diff --git a/x/fbridge/module/module.go b/x/fbridge/module/module.go index e7f7cfc28c..9c654c7ed5 100644 --- a/x/fbridge/module/module.go +++ b/x/fbridge/module/module.go @@ -24,9 +24,10 @@ const ( ) var ( - _ module.AppModuleBasic = AppModuleBasic{} - _ module.AppModuleGenesis = AppModule{} - _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleGenesis = AppModule{} + _ module.AppModule = AppModule{} + _ module.EndBlockAppModule = AppModule{} ) // AppModuleBasic defines the basic application module used by the fbridge module. @@ -121,6 +122,13 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // ConsensusVersion implements AppModule/ConsensusVersion. func (AppModule) ConsensusVersion() uint64 { return consensusVersion } +// EndBlock returns the end blocker for the fbridge module. +// It returns no validator updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + EndBlocker(ctx, am.keeper) + return []abci.ValidatorUpdate{} +} + // RegisterInvariants does nothing, there are no invariants to enforce func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { _ = ir diff --git a/x/fbridge/types/fbridge.pb.go b/x/fbridge/types/fbridge.pb.go index 719aeaeee3..8d9cb5aeec 100644 --- a/x/fbridge/types/fbridge.pb.go +++ b/x/fbridge/types/fbridge.pb.go @@ -358,6 +358,58 @@ func (m *Fraction) GetDenominator() uint64 { return 0 } +type RolePair struct { + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + Role Role `protobuf:"varint,2,opt,name=role,proto3,enum=lbm.fbridge.v1.Role" json:"role,omitempty"` +} + +func (m *RolePair) Reset() { *m = RolePair{} } +func (m *RolePair) String() string { return proto.CompactTextString(m) } +func (*RolePair) ProtoMessage() {} +func (*RolePair) Descriptor() ([]byte, []int) { + return fileDescriptor_62374d75fc6aa1ba, []int{4} +} +func (m *RolePair) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RolePair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RolePair.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RolePair) XXX_Merge(src proto.Message) { + xxx_messageInfo_RolePair.Merge(m, src) +} +func (m *RolePair) XXX_Size() int { + return m.Size() +} +func (m *RolePair) XXX_DiscardUnknown() { + xxx_messageInfo_RolePair.DiscardUnknown(m) +} + +var xxx_messageInfo_RolePair proto.InternalMessageInfo + +func (m *RolePair) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *RolePair) GetRole() Role { + if m != nil { + return m.Role + } + return RoleEmpty +} + type RoleProposal struct { Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` // the proposer address @@ -378,7 +430,7 @@ func (m *RoleProposal) Reset() { *m = RoleProposal{} } func (m *RoleProposal) String() string { return proto.CompactTextString(m) } func (*RoleProposal) ProtoMessage() {} func (*RoleProposal) Descriptor() ([]byte, []int) { - return fileDescriptor_62374d75fc6aa1ba, []int{4} + return fileDescriptor_62374d75fc6aa1ba, []int{5} } func (m *RoleProposal) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -453,7 +505,7 @@ func (m *Vote) Reset() { *m = Vote{} } func (m *Vote) String() string { return proto.CompactTextString(m) } func (*Vote) ProtoMessage() {} func (*Vote) Descriptor() ([]byte, []int) { - return fileDescriptor_62374d75fc6aa1ba, []int{5} + return fileDescriptor_62374d75fc6aa1ba, []int{6} } func (m *Vote) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -517,7 +569,7 @@ func (m *RoleMetadata) Reset() { *m = RoleMetadata{} } func (m *RoleMetadata) String() string { return proto.CompactTextString(m) } func (*RoleMetadata) ProtoMessage() {} func (*RoleMetadata) Descriptor() ([]byte, []int) { - return fileDescriptor_62374d75fc6aa1ba, []int{6} + return fileDescriptor_62374d75fc6aa1ba, []int{7} } func (m *RoleMetadata) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -574,6 +626,7 @@ func init() { proto.RegisterType((*ProvisionData)(nil), "lbm.fbridge.v1.ProvisionData") proto.RegisterType((*ProvisionStatus)(nil), "lbm.fbridge.v1.ProvisionStatus") proto.RegisterType((*Fraction)(nil), "lbm.fbridge.v1.Fraction") + proto.RegisterType((*RolePair)(nil), "lbm.fbridge.v1.RolePair") proto.RegisterType((*RoleProposal)(nil), "lbm.fbridge.v1.RoleProposal") proto.RegisterType((*Vote)(nil), "lbm.fbridge.v1.Vote") proto.RegisterType((*RoleMetadata)(nil), "lbm.fbridge.v1.RoleMetadata") @@ -582,61 +635,63 @@ func init() { func init() { proto.RegisterFile("lbm/fbridge/v1/fbridge.proto", fileDescriptor_62374d75fc6aa1ba) } var fileDescriptor_62374d75fc6aa1ba = []byte{ - // 860 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0xcd, 0x6e, 0x23, 0x45, - 0x10, 0xf6, 0x38, 0x93, 0xc8, 0x2e, 0xc7, 0x3f, 0xb4, 0x22, 0x88, 0x46, 0xcb, 0xd8, 0x58, 0x42, - 0x44, 0x2b, 0x18, 0xb3, 0xe6, 0xc6, 0x2d, 0x3f, 0x4e, 0x64, 0x0b, 0x6c, 0xab, 0xe3, 0xac, 0xb4, - 0x08, 0xc9, 0x1a, 0x7b, 0x3a, 0xb3, 0xcd, 0xce, 0x4c, 0x0f, 0x3d, 0x6d, 0xb3, 0xcb, 0x03, 0x20, - 0x94, 0xd3, 0xbe, 0x40, 0x24, 0x10, 0x4f, 0xc2, 0x6d, 0xc5, 0x69, 0x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0xc8, 0xd1, 0xe8, 0xd5, 0x8d, 0x6b, 0xbd, 0xbe, 0x71, 0xad, 0x7f, 0x6e, - 0x5c, 0xeb, 0xe5, 0xad, 0x5b, 0x7a, 0x7d, 0xeb, 0x96, 0xfe, 0xbc, 0x75, 0x4b, 0xdf, 0x7c, 0xfe, - 0xbf, 0x6b, 0xff, 0xbc, 0xf8, 0x0f, 0x50, 0x3f, 0x00, 0x8b, 0x1d, 0x35, 0x5d, 0x5f, 0xfc, 0x17, - 0x00, 0x00, 0xff, 0xff, 0x0c, 0x54, 0xda, 0x5d, 0x1f, 0x06, 0x00, 0x00, + // 886 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x55, 0x4f, 0x8f, 0x1b, 0x35, + 0x14, 0xcf, 0xa4, 0xb3, 0x21, 0x79, 0xd9, 0xfc, 0xc1, 0x5a, 0x41, 0x34, 0x2a, 0x93, 0x10, 0x09, + 0xb1, 0xaa, 0x20, 0xa1, 0xe1, 0xc6, 0x6d, 0xff, 0x64, 0x57, 0x89, 0x20, 0x89, 0xbc, 0xd9, 0x4a, + 0x45, 0x48, 0x91, 0x93, 0xf1, 0xa6, 0xa6, 0x33, 0xe3, 0xc1, 0xe3, 0x84, 0x96, 0x0f, 0x80, 0xd0, + 0x9e, 0xfa, 0x05, 0x56, 0x02, 0xf1, 0x49, 0xb8, 0x55, 0x9c, 0x7a, 0x44, 0x1c, 0x0a, 0xda, 0xbd, + 0xf0, 0x31, 0x90, 0xed, 0x78, 0x36, 0xdb, 0x4b, 0x7b, 0xf3, 0xfb, 0xf9, 0xf7, 0x7e, 0xef, 0xe7, + 0xe7, 0xe7, 0x19, 0xb8, 0x1f, 0xce, 0xa3, 0xee, 0xc5, 0x5c, 0xb0, 0x60, 0x49, 0xbb, 0xeb, 0x87, + 0x76, 0xd9, 0x49, 0x04, 0x97, 0x1c, 0x55, 0xc3, 0x79, 0xd4,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+ 0x8b, 0xd5, 0x12, 0x0d, 0xa1, 0x40, 0x22, 0xbe, 0x8a, 0xa5, 0xee, 0x42, 0xe9, 0xb0, 0xa7, 0xcc, + 0xfd, 0xfd, 0xba, 0xf9, 0x60, 0xc9, 0xe4, 0x93, 0xd5, 0xbc, 0xb3, 0xe0, 0x51, 0xf7, 0x84, 0xc5, + 0xe9, 0xe2, 0x09, 0x23, 0xdd, 0x8b, 0xcd, 0xe2, 0xf3, 0x34, 0x78, 0xda, 0x95, 0xcf, 0x13, 0x9a, + 0x76, 0x06, 0xb1, 0xc4, 0x1b, 0x05, 0xf4, 0x01, 0x14, 0x52, 0x1a, 0x07, 0x54, 0xe8, 0x16, 0x94, + 0xf0, 0x26, 0x42, 0x1e, 0x14, 0x05, 0x5d, 0x50, 0xb6, 0xa6, 0x42, 0x1f, 0xa9, 0x84, 0xb3, 0xb8, + 0xfd, 0x13, 0xd4, 0x32, 0x8b, 0x67, 0x92, 0xc8, 0x55, 0x8a, 0x3e, 0x86, 0xdd, 0xac, 0x11, 0x34, + 0x0e, 0x36, 0x6e, 0xcb, 0x16, 0xeb, 0xc7, 0x01, 0xfa, 0x04, 0xaa, 0x0b, 0x1e, 0x5f, 0x30, 0x11, + 0xcd, 0x16, 0xaa, 0x74, 0xaa, 0xdd, 0xef, 0xe0, 0xca, 0x06, 0x3d, 0xd2, 0x20, 0xfa, 0x08, 0x80, + 0xa5, 0xb3, 0x45, 0x48, 0x58, 0x44, 0x03, 0x6d, 0xaa, 0x88, 0x4b, 0x2c, 0x3d, 0x32, 0x40, 0x7b, + 0x08, 0x45, 0x7b, 0x29, 0xe8, 0x3e, 0x94, 0xe2, 0x55, 0x64, 0x46, 0x66, 0x53, 0xf1, 0x16, 0x40, + 0x2d, 0x28, 0x07, 0x34, 0xe6, 0x11, 0x8b, 0xf5, 0x7e, 0xde, 0x38, 0xda, 0x82, 0xda, 0x23, 0x28, + 0x62, 0x1e, 0xd2, 0x09, 0x61, 0x02, 0x35, 0xe0,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0xf8, 0xb9, 0xbf, 0x6e, 0xfc, 0xdc, 0xb7, 0x5f, 0xbc, 0xf5, 0x33, 0xf2, 0x2c, 0xfb, 0xa7, + 0xe8, 0x0f, 0xca, 0xbc, 0xa0, 0xa7, 0xeb, 0xcb, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0xf0, 0xe7, + 0x51, 0xc1, 0x6f, 0x06, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -830,6 +885,41 @@ func (m *Fraction) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *RolePair) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RolePair) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RolePair) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Role != 0 { + i = encodeVarintFbridge(dAtA, i, uint64(m.Role)) + i-- + dAtA[i] = 0x10 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintFbridge(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *RoleProposal) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -1050,6 +1140,22 @@ func (m *Fraction) Size() (n int) { return n } +func (m *RolePair) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovFbridge(uint64(l)) + } + if m.Role != 0 { + n += 1 + sovFbridge(uint64(m.Role)) + } + return n +} + func (m *RoleProposal) Size() (n int) { if m == nil { return 0 @@ -1668,6 +1774,107 @@ func (m *Fraction) Unmarshal(dAtA []byte) error { } return nil } +func (m *RolePair) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFbridge + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RolePair: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RolePair: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFbridge + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthFbridge + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthFbridge + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Role", wireType) + } + m.Role = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowFbridge + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Role |= Role(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipFbridge(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthFbridge + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *RoleProposal) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/fbridge/types/genesis.pb.go b/x/fbridge/types/genesis.pb.go index 4df591827b..de4f09477f 100644 --- a/x/fbridge/types/genesis.pb.go +++ b/x/fbridge/types/genesis.pb.go @@ -39,6 +39,8 @@ type GenesisState struct { Votes []Vote `protobuf:"bytes,6,rep,name=votes,proto3" json:"votes"` // role_metadata defines all the role metadata present at genesis. RoleMetadata RoleMetadata `protobuf:"bytes,7,opt,name=role_metadata,json=roleMetadata,proto3" json:"role_metadata"` + // roles defines all addresses assigned roles at genesis. + Roles []RolePair `protobuf:"bytes,8,rep,name=roles,proto3" json:"roles"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -123,6 +125,13 @@ func (m *GenesisState) GetRoleMetadata() RoleMetadata { return RoleMetadata{} } +func (m *GenesisState) GetRoles() []RolePair { + if m != nil { + return m.Roles + } + return nil +} + type SendingState struct { // the next sequence number of the bridge request (greatest sequence number + 1) NextSeq uint64 `protobuf:"varint,1,opt,name=next_seq,json=nextSeq,proto3" json:"next_seq,omitempty"` @@ -511,55 +520,56 @@ func init() { func init() { proto.RegisterFile("lbm/fbridge/v1/genesis.proto", fileDescriptor_0fc3cc4535a29f6d) } var fileDescriptor_0fc3cc4535a29f6d = []byte{ - // 755 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x95, 0xcd, 0x4e, 0xdb, 0x40, - 0x10, 0xc7, 0xe3, 0xc4, 0x04, 0x18, 0x42, 0x40, 0x2b, 0x40, 0x26, 0xa5, 0x4e, 0x64, 0xf5, 0x90, - 0x43, 0x9b, 0x90, 0xb6, 0x52, 0x3f, 0x84, 0x54, 0x29, 0x20, 0x10, 0x95, 0x50, 0x91, 0x5d, 0x55, - 0x15, 0x17, 0xcb, 0x71, 0x36, 0xc1, 0x22, 0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6, 0x93, 0x25, 0x34, 0xce, - 0x00, 0xa6, 0xd0, 0xff, 0x8b, 0x45, 0x3a, 0x40, 0xaa, 0xa9, 0x82, 0xd0, 0xa7, 0x2c, 0xc6, 0x37, - 0x05, 0x96, 0x93, 0x56, 0x32, 0x6a, 0x25, 0xab, 0x46, 0x2d, 0x50, 0xc5, 0x39, 0x9f, 0xdc, 0x97, - 0x8f, 0x1f, 0x1c, 0xf4, 0x81, 0xc3, 0x1c, 0x53, 0x48, 0xd1, 0x2b, 0x28, 0xf2, 0x8b, 0x71, 0x44, - 0xe5, 0xcd, 0x58, 0x7d, 0x30, 0xc8, 0x12, 0x32, 0x53, 0xca, 0x8d, 0x43, 0x40, 0xf7, 0x87, 0x3d, - 0xe7, 0x88, 0xce, 0xd6, 0x9c, 0xcf, 0xd6, 0xdc, 0x7e, 0x7f, 0x7d, 0xab, 0x2b, 0x37, 0xb7, 0xba, - 0xf2, 0xe7, 0x56, 0x57, 0xbe, 0xde, 0xe9, 0xb9, 0x9b, 0x3b, 0x3d, 0xf7, 0xeb, 0x4e, 0xcf, 0x9d, - 0xed, 0xf6, 0x3d, 0x76, 0x3e, 0xea, 0x34, 0x5c, 0xe2, 0x37, 0x0f, 0xbd, 0x80, 0xba, 0xe7, 0x9e, - 0xd3, 0xec, 0xc9, 0x87, 0x67, 0xb4, 0x7b, 0xd1, 0xbc, 0x4c, 0x7e, 0x45, 0xec, 0x2a, 0xc4, 0xb4, - 0x53, 0x14, 0xbf, 0xa1, 0x17, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xaa, 0xe4, 0xeb, 0xcd, 0xea, - 0x06, 0x00, 0x00, + // 772 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0x4f, 0x4f, 0xdb, 0x4e, + 0x10, 0x8d, 0x13, 0x13, 0x60, 0x08, 0x01, 0xad, 0x00, 0x99, 0xfc, 0xf8,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0x61, 0x17, 0x7b, 0xe3, 0x29, 0x55, 0x41, 0x50, 0xe9, 0x59, 0x2a, 0x33, 0x86, + 0xa5, 0xc9, 0xca, 0xd1, 0x4c, 0x14, 0xb5, 0x60, 0x33, 0xc0, 0x57, 0xcc, 0x8e, 0xc8, 0x00, 0xdb, + 0x61, 0x44, 0x42, 0x42, 0x9d, 0x81, 0xed, 0x75, 0x35, 0xb5, 0xa6, 0xd4, 0x55, 0x13, 0xf1, 0xa4, + 0x49, 0x06, 0xf8, 0x4c, 0xa6, 0x4e, 0xba, 0xe8, 0x04, 0xca, 0x33, 0x68, 0xaa, 0x2d, 0xd4, 0x0a, + 0xf3, 0xce, 0x92, 0xae, 0x93, 0xf2, 0xab, 0x51, 0x2a, 0x46, 0xd1, 0x2e, 0x2c, 0x8c, 0x09, 0xc3, + 0x54, 0x2b, 0x0a, 0x86, 0x8d, 0x2c, 0xc3, 0x47, 0x92, 0x34, 0x3e, 0x01, 0xf2, 0x39, 0x0a, 0x71, + 0x1f, 0x33, 0xa7, 0xeb, 0x30, 0x47, 0x5b, 0x9c, 0x3f, 0x47, 0xae, 0x7d, 0x2a, 0x31, 0xf1, 0x1c, + 0xa3, 0x54, 0x0c, 0xed, 0xc1, 0x02, 0xdf, 0x53, 0x6d, 0x49, 0x48, 0x6b, 0x73, 0x9b, 0x77, 0xbc, + 0x28, 0x96, 0x17, 0x60, 0x63, 0x04, 0xa5, 0xf4, 0x17, 0x42, 0xdb, 0xb0, 0x24, 0xc6, 0x47, 0xf1, + 0x50, 0xd8, 0x41, 0x35, 0x17, 0xf9, 0xde, 0xc2, 0x43, 0x74, 0x08, 0x6b, 0x14, 0x0f, 0x6d, 0x46, + 0xec, 0xce, 0x80, 0xb8, 0x97, 0xc1, 0xc8, 0xd7, 0xf2, 0xf3, 0xe7, 0xd4, 0xe6, 0x79, 0x0b, 0x0f, + 0x4f, 0x82, 0x1e, 0x31, 0x57, 0x29, 0x1e, 0x7e, 0x20, 0x6d, 0x59, 0x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0x09, 0x00, 0x00, 0xff, 0xff, 0x83, 0x3c, 0x4b, 0x92, + 0x20, 0x07, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -582,6 +592,20 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Roles) > 0 { + for iNdEx := len(m.Roles) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Roles[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x42 + } + } { size, err := m.RoleMetadata.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -1055,6 +1079,12 @@ func (m *GenesisState) Size() (n int) { } l = m.RoleMetadata.Size() n += 1 + l + sovGenesis(uint64(l)) + if len(m.Roles) > 0 { + for _, e := range m.Roles { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -1467,6 +1497,40 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Roles", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Roles = append(m.Roles, RolePair{}) + if err := m.Roles[len(m.Roles)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/fbridge/types/keys.go b/x/fbridge/types/keys.go index 4d43b76208..110d6a8136 100644 --- a/x/fbridge/types/keys.go +++ b/x/fbridge/types/keys.go @@ -68,3 +68,9 @@ func SplitVoterVoteKey(key []byte) (uint64, sdk.AccAddress) { func RoleKey(target sdk.AccAddress) []byte { return append(KeyRolePrefix, address.MustLengthPrefix(target.Bytes())...) } + +// SplitRoleKey split the role key and returns the address +func SplitRoleKey(key []byte) sdk.AccAddress { + kv.AssertKeyAtLeastLength(key, 3) + return key[2:] +} diff --git a/x/fbridge/types/params.go b/x/fbridge/types/params.go index c4d8f2a5fc..45fdbdc7d2 100644 --- a/x/fbridge/types/params.go +++ b/x/fbridge/types/params.go @@ -1,12 +1,39 @@ package types -import "time" +import ( + sdkerrors "github.com/Finschia/finschia-sdk/types/errors" + "time" +) func DefaultParams() Params { return Params{ GuardianTrustLevel: Fraction{Numerator: 2, Denominator: 3}, OperatorTrustLevel: Fraction{Numerator: 2, Denominator: 3}, - JudgeTrustLevel: Fraction{Numerator: 2, Denominator: 3}, + JudgeTrustLevel: Fraction{Numerator: 1, Denominator: 1}, ProposalPeriod: uint64(time.Minute * 60), } } + +func CheckTrustLevelThreshold(total, current uint64, trustLevel Fraction) bool { + if err := ValidateTrustLevel(trustLevel); err != nil { + panic(err) + } + + if total*trustLevel.Numerator <= current*trustLevel.Denominator && + total != 0 && current != 0 && + current <= total { + return true + } + + return false +} + +func ValidateTrustLevel(trustLevel Fraction) error { + if trustLevel.Denominator < 1 || trustLevel.Numerator < 1 { + return sdkerrors.ErrInvalidRequest.Wrap("trust level must be positive") + } else if trustLevel.Denominator < trustLevel.Numerator { + return sdkerrors.ErrInvalidRequest.Wrap("trust level denominator must be greater than or equal to the numerator") + } + + return nil +}