From 6d98dcf2263cda2fcd0408234fa2f0034c5afb77 Mon Sep 17 00:00:00 2001 From: ap0calypse644 <91111707+ap0calypse644@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:00:32 +0530 Subject: [PATCH] parameterizing average block time (#233) --- api/fairyring/keyshare/params.pulsar.go | 93 +++++++++++++++----- proto/fairyring/keyshare/params.proto | 2 +- scripts/tests/start.sh | 3 + x/keyshare/keeper/params.go | 5 ++ x/keyshare/keeper/process_queues.go | 6 +- x/keyshare/keeper/request_decryption_key.go | 3 +- x/keyshare/migrations/v2/store.go | 4 +- x/keyshare/types/keys.go | 2 - x/keyshare/types/params.go | 19 +++++ x/keyshare/types/params.pb.go | 95 ++++++++++++++------- 10 files changed, 176 insertions(+), 56 deletions(-) diff --git a/api/fairyring/keyshare/params.pulsar.go b/api/fairyring/keyshare/params.pulsar.go index 0dff213f..d5692b42 100644 --- a/api/fairyring/keyshare/params.pulsar.go +++ b/api/fairyring/keyshare/params.pulsar.go @@ -3,6 +3,7 @@ package keyshare import ( _ "cosmossdk.io/api/amino" + binary "encoding/binary" fmt "fmt" runtime "github.com/cosmos/cosmos-proto/runtime" _ "github.com/cosmos/gogoproto/gogoproto" @@ -10,6 +11,7 @@ import ( protoiface "google.golang.org/protobuf/runtime/protoiface" protoimpl "google.golang.org/protobuf/runtime/protoimpl" io "io" + math "math" reflect "reflect" sync "sync" ) @@ -68,6 +70,7 @@ var ( fd_Params_trusted_addresses protoreflect.FieldDescriptor fd_Params_slash_fraction_no_keyshare protoreflect.FieldDescriptor fd_Params_slash_fraction_wrong_keyshare protoreflect.FieldDescriptor + fd_Params_avg_block_time protoreflect.FieldDescriptor ) func init() { @@ -79,6 +82,7 @@ func init() { fd_Params_trusted_addresses = md_Params.Fields().ByName("trusted_addresses") fd_Params_slash_fraction_no_keyshare = md_Params.Fields().ByName("slash_fraction_no_keyshare") fd_Params_slash_fraction_wrong_keyshare = md_Params.Fields().ByName("slash_fraction_wrong_keyshare") + fd_Params_avg_block_time = md_Params.Fields().ByName("avg_block_time") } var _ protoreflect.Message = (*fastReflection_Params)(nil) @@ -182,6 +186,12 @@ func (x *fastReflection_Params) Range(f func(protoreflect.FieldDescriptor, proto return } } + if x.AvgBlockTime != float32(0) || math.Signbit(float64(x.AvgBlockTime)) { + value := protoreflect.ValueOfFloat32(x.AvgBlockTime) + if !f(fd_Params_avg_block_time, value) { + return + } + } } // Has reports whether a field is populated. @@ -209,6 +219,8 @@ func (x *fastReflection_Params) Has(fd protoreflect.FieldDescriptor) bool { return len(x.SlashFractionNoKeyshare) != 0 case "fairyring.keyshare.Params.slash_fraction_wrong_keyshare": return len(x.SlashFractionWrongKeyshare) != 0 + case "fairyring.keyshare.Params.avg_block_time": + return x.AvgBlockTime != float32(0) || math.Signbit(float64(x.AvgBlockTime)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: fairyring.keyshare.Params")) @@ -237,6 +249,8 @@ func (x *fastReflection_Params) Clear(fd protoreflect.FieldDescriptor) { x.SlashFractionNoKeyshare = nil case "fairyring.keyshare.Params.slash_fraction_wrong_keyshare": x.SlashFractionWrongKeyshare = nil + case "fairyring.keyshare.Params.avg_block_time": + x.AvgBlockTime = float32(0) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: fairyring.keyshare.Params")) @@ -274,6 +288,9 @@ func (x *fastReflection_Params) Get(descriptor protoreflect.FieldDescriptor) pro case "fairyring.keyshare.Params.slash_fraction_wrong_keyshare": value := x.SlashFractionWrongKeyshare return protoreflect.ValueOfBytes(value) + case "fairyring.keyshare.Params.avg_block_time": + value := x.AvgBlockTime + return protoreflect.ValueOfFloat32(value) default: if descriptor.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: fairyring.keyshare.Params")) @@ -308,6 +325,8 @@ func (x *fastReflection_Params) Set(fd protoreflect.FieldDescriptor, value proto x.SlashFractionNoKeyshare = value.Bytes() case "fairyring.keyshare.Params.slash_fraction_wrong_keyshare": x.SlashFractionWrongKeyshare = value.Bytes() + case "fairyring.keyshare.Params.avg_block_time": + x.AvgBlockTime = float32(value.Float()) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: fairyring.keyshare.Params")) @@ -344,6 +363,8 @@ func (x *fastReflection_Params) Mutable(fd protoreflect.FieldDescriptor) protore panic(fmt.Errorf("field slash_fraction_no_keyshare of message fairyring.keyshare.Params is not mutable")) case "fairyring.keyshare.Params.slash_fraction_wrong_keyshare": panic(fmt.Errorf("field slash_fraction_wrong_keyshare of message fairyring.keyshare.Params is not mutable")) + case "fairyring.keyshare.Params.avg_block_time": + panic(fmt.Errorf("field avg_block_time of message fairyring.keyshare.Params is not mutable")) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: fairyring.keyshare.Params")) @@ -370,6 +391,8 @@ func (x *fastReflection_Params) NewField(fd protoreflect.FieldDescriptor) protor return protoreflect.ValueOfBytes(nil) case "fairyring.keyshare.Params.slash_fraction_wrong_keyshare": return protoreflect.ValueOfBytes(nil) + case "fairyring.keyshare.Params.avg_block_time": + return protoreflect.ValueOfFloat32(float32(0)) default: if fd.IsExtension() { panic(fmt.Errorf("proto3 declared messages do not support extensions: fairyring.keyshare.Params")) @@ -462,6 +485,9 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { if l > 0 { n += 1 + l + runtime.Sov(uint64(l)) } + if x.AvgBlockTime != 0 || math.Signbit(float64(x.AvgBlockTime)) { + n += 5 + } if x.unknownFields != nil { n += len(x.unknownFields) } @@ -491,6 +517,12 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { i -= len(x.unknownFields) copy(dAtA[i:], x.unknownFields) } + if x.AvgBlockTime != 0 || math.Signbit(float64(x.AvgBlockTime)) { + i -= 4 + binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(x.AvgBlockTime)))) + i-- + dAtA[i] = 0x3d + } if len(x.SlashFractionWrongKeyshare) > 0 { i -= len(x.SlashFractionWrongKeyshare) copy(dAtA[i:], x.SlashFractionWrongKeyshare) @@ -735,6 +767,17 @@ func (x *fastReflection_Params) ProtoMethods() *protoiface.Methods { x.SlashFractionWrongKeyshare = []byte{} } iNdEx = postIndex + case 7: + if wireType != 5 { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, fmt.Errorf("proto: wrong wireType = %d for field AvgBlockTime", wireType) + } + var v uint32 + if (iNdEx + 4) > l { + return protoiface.UnmarshalOutput{NoUnkeyedLiterals: input.NoUnkeyedLiterals, Flags: input.Flags}, io.ErrUnexpectedEOF + } + v = uint32(binary.LittleEndian.Uint32(dAtA[iNdEx:])) + iNdEx += 4 + x.AvgBlockTime = float32(math.Float32frombits(v)) default: iNdEx = preIndex skippy, err := runtime.Skip(dAtA[iNdEx:]) @@ -795,6 +838,7 @@ type Params struct { TrustedAddresses []string `protobuf:"bytes,4,rep,name=trusted_addresses,json=trustedAddresses,proto3" json:"trusted_addresses,omitempty"` SlashFractionNoKeyshare []byte `protobuf:"bytes,5,opt,name=slash_fraction_no_keyshare,json=slashFractionNoKeyshare,proto3" json:"slash_fraction_no_keyshare,omitempty"` SlashFractionWrongKeyshare []byte `protobuf:"bytes,6,opt,name=slash_fraction_wrong_keyshare,json=slashFractionWrongKeyshare,proto3" json:"slash_fraction_wrong_keyshare,omitempty"` + AvgBlockTime float32 `protobuf:"fixed32,7,opt,name=avg_block_time,json=avgBlockTime,proto3" json:"avg_block_time,omitempty"` } func (x *Params) Reset() { @@ -859,6 +903,13 @@ func (x *Params) GetSlashFractionWrongKeyshare() []byte { return nil } +func (x *Params) GetAvgBlockTime() float32 { + if x != nil { + return x.AvgBlockTime + } + return 0 +} + var File_fairyring_keyshare_params_proto protoreflect.FileDescriptor var file_fairyring_keyshare_params_proto_rawDesc = []byte{ @@ -867,8 +918,8 @@ var file_fairyring_keyshare_params_proto_rawDesc = []byte{ 0x6f, 0x12, 0x12, 0x66, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x1a, 0x11, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2f, 0x61, 0x6d, 0x69, 0x6e, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x67, 0x6f, 0x67, 0x6f, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe3, - 0x04, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x34, 0x0a, 0x0a, 0x6b, 0x65, 0x79, + 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x67, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa4, + 0x05, 0x0a, 0x06, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x34, 0x0a, 0x0a, 0x6b, 0x65, 0x79, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x42, 0x15, 0xf2, 0xde, 0x1f, 0x11, 0x79, 0x61, 0x6d, 0x6c, 0x3a, 0x22, 0x6b, 0x65, 0x79, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x79, 0x22, 0x52, 0x09, 0x6b, 0x65, 0x79, 0x45, 0x78, 0x70, 0x69, 0x72, 0x79, 0x12, @@ -902,23 +953,27 @@ var file_fairyring_keyshare_params_proto_rawDesc = []byte{ 0x6c, 0x61, 0x73, 0x68, 0x5f, 0x66, 0x72, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x77, 0x72, 0x6f, 0x6e, 0x67, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x22, 0x52, 0x1a, 0x73, 0x6c, 0x61, 0x73, 0x68, 0x46, 0x72, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x57, 0x72, 0x6f, 0x6e, - 0x67, 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x3a, 0x39, 0xe8, 0xa0, 0x1f, 0x01, 0x8a, - 0xe7, 0xb0, 0x2a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x46, - 0x61, 0x69, 0x72, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x66, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, - 0x6e, 0x67, 0x2f, 0x78, 0x2f, 0x6b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x50, 0x61, - 0x72, 0x61, 0x6d, 0x73, 0x42, 0xb3, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x66, 0x61, 0x69, - 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x42, - 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x23, - 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, 0x69, - 0x2f, 0x66, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x6b, 0x65, 0x79, 0x73, 0x68, - 0x61, 0x72, 0x65, 0xa2, 0x02, 0x03, 0x46, 0x4b, 0x58, 0xaa, 0x02, 0x12, 0x46, 0x61, 0x69, 0x72, - 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0xca, 0x02, - 0x12, 0x46, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x4b, 0x65, 0x79, 0x73, 0x68, - 0x61, 0x72, 0x65, 0xe2, 0x02, 0x1e, 0x46, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, - 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, - 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x46, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, - 0x3a, 0x3a, 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x67, 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x12, 0x3f, 0x0a, 0x0e, 0x61, 0x76, 0x67, + 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x02, 0x42, 0x19, 0xf2, 0xde, 0x1f, 0x15, 0x79, 0x61, 0x6d, 0x6c, 0x3a, 0x22, 0x61, 0x76, 0x67, + 0x5f, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x22, 0x52, 0x0c, 0x61, 0x76, + 0x67, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x54, 0x69, 0x6d, 0x65, 0x3a, 0x39, 0xe8, 0xa0, 0x1f, 0x01, + 0x8a, 0xe7, 0xb0, 0x2a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x46, 0x61, 0x69, 0x72, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x66, 0x61, 0x69, 0x72, 0x79, 0x72, + 0x69, 0x6e, 0x67, 0x2f, 0x78, 0x2f, 0x6b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x2f, 0x50, + 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0xb3, 0x01, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x66, 0x61, + 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x6b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, + 0x42, 0x0b, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, + 0x23, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x73, 0x64, 0x6b, 0x2e, 0x69, 0x6f, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x66, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x6b, 0x65, 0x79, 0x73, + 0x68, 0x61, 0x72, 0x65, 0xa2, 0x02, 0x03, 0x46, 0x4b, 0x58, 0xaa, 0x02, 0x12, 0x46, 0x61, 0x69, + 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0xca, + 0x02, 0x12, 0x46, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, 0x5c, 0x4b, 0x65, 0x79, 0x73, + 0x68, 0x61, 0x72, 0x65, 0xe2, 0x02, 0x1e, 0x46, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, 0x67, + 0x5c, 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, + 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x13, 0x46, 0x61, 0x69, 0x72, 0x79, 0x72, 0x69, 0x6e, + 0x67, 0x3a, 0x3a, 0x4b, 0x65, 0x79, 0x73, 0x68, 0x61, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/proto/fairyring/keyshare/params.proto b/proto/fairyring/keyshare/params.proto index f5a059a7..731da14f 100644 --- a/proto/fairyring/keyshare/params.proto +++ b/proto/fairyring/keyshare/params.proto @@ -17,5 +17,5 @@ message Params { repeated string trusted_addresses = 4 [(gogoproto.moretags) = "yaml:\"trusted_addresses\""]; bytes slash_fraction_no_keyshare = 5 [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"slash_fraction_no_keyshare\""]; bytes slash_fraction_wrong_keyshare = 6 [(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"slash_fraction_wrong_keyshare\""]; - + float avg_block_time = 7 [(gogoproto.moretags) = "yaml:\"avg_block_time\""]; } \ No newline at end of file diff --git a/scripts/tests/start.sh b/scripts/tests/start.sh index b9d7412c..7e60d616 100755 --- a/scripts/tests/start.sh +++ b/scripts/tests/start.sh @@ -150,6 +150,9 @@ sed -i -e 's/"trusted_counter_parties": \[\]/"trusted_counter_parties": \['"$TRU sed -i -e 's/"key_expiry": "100"/"key_expiry": "10000"/g' $CHAIN_DIR/$CHAINID_1/config/genesis.json sed -i -e 's/"key_expiry": "100"/"key_expiry": "10000"/g' $CHAIN_DIR/$CHAINID_2/config/genesis.json +sed -i -e 's/"avg_block_time": 5.6/"avg_block_time": 1.12/g' $CHAIN_DIR/$CHAINID_1/config/genesis.json +sed -i -e 's/"avg_block_time": 5.6/"avg_block_time": 1.12/g' $CHAIN_DIR/$CHAINID_2/config/genesis.json + sed -i -e 's/"is_source_chain": false/"is_source_chain": true/g' $CHAIN_DIR/$CHAINID_1/config/genesis.json jsonData2=$(cat "$CHAIN_DIR/$CHAINID_2/config/genesis.json") diff --git a/x/keyshare/keeper/params.go b/x/keyshare/keeper/params.go index 0a82bda6..1a6cda69 100644 --- a/x/keyshare/keeper/params.go +++ b/x/keyshare/keeper/params.go @@ -64,3 +64,8 @@ func (k Keeper) SlashFractionWrongKeyshare(ctx sdk.Context) (res math.LegacyDec) func (k Keeper) MaxIdledBlock(ctx sdk.Context) (res uint64) { return k.GetParams(ctx).MaxIdledBlock } + +// AvgBlockTime returns the MaxIdledBlock param +func (k Keeper) AvgBlockTime(ctx sdk.Context) (res float32) { + return k.GetParams(ctx).AvgBlockTime +} diff --git a/x/keyshare/keeper/process_queues.go b/x/keyshare/keeper/process_queues.go index be385f63..c40a0ebf 100644 --- a/x/keyshare/keeper/process_queues.go +++ b/x/keyshare/keeper/process_queues.go @@ -27,7 +27,8 @@ func (k Keeper) ProcessPepRequestQueue(ctx sdk.Context) error { continue } delay := req.EstimatedDelay - blockDelay := uint64(math.Ceil(delay.Seconds() / types.AvgBlockTime)) + avgBlockTime := k.AvgBlockTime(ctx) + blockDelay := uint64(math.Ceil(delay.Seconds() / float64(avgBlockTime))) currentHeight := uint64(ctx.BlockHeight()) executionHeight := currentHeight + blockDelay if executionHeight > activePubkey.Expiry { @@ -189,7 +190,8 @@ func (k Keeper) ProcessGovRequestQueue(ctx sdk.Context) error { reqs := k.govKeeper.GetAllReqQueueEntry(ctx) for _, req := range reqs { delay := req.EstimatedDelay - blockDelay := uint64(math.Ceil(delay.Seconds() / types.AvgBlockTime)) + avgBlockTime := k.AvgBlockTime(ctx) + blockDelay := uint64(math.Ceil(delay.Seconds() / float64(avgBlockTime))) currentHeight := uint64(ctx.BlockHeight()) executionHeight := currentHeight + blockDelay diff --git a/x/keyshare/keeper/request_decryption_key.go b/x/keyshare/keeper/request_decryption_key.go index 5449557d..6dbd3d59 100644 --- a/x/keyshare/keeper/request_decryption_key.go +++ b/x/keyshare/keeper/request_decryption_key.go @@ -51,7 +51,8 @@ func (k Keeper) OnRecvRequestDecryptionKeyPacket( } delay := data.EstimatedDelay - blockDelay := uint64(math.Ceil(delay.Seconds() / types.AvgBlockTime)) + avgBlockTime := k.AvgBlockTime(ctx) + blockDelay := uint64(math.Ceil(delay.Seconds() / float64(avgBlockTime))) currentHeight := uint64(ctx.BlockHeight()) executionHeight := currentHeight + blockDelay if executionHeight > activePubkey.Expiry { diff --git a/x/keyshare/migrations/v2/store.go b/x/keyshare/migrations/v2/store.go index b3c62db5..9034b6c0 100644 --- a/x/keyshare/migrations/v2/store.go +++ b/x/keyshare/migrations/v2/store.go @@ -15,7 +15,9 @@ func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, cdc codec. types.DefaultMinimumBonded, types.DefaultSlashFractionNoKeyshare, types.DefaultSlashFractionWrongKeyshare, - types.DefaultMaxIdledBlock) + types.DefaultMaxIdledBlock, + types.DefaultAvgBlockTime, + ) bz, err := cdc.Marshal(&currParams) if err != nil { diff --git a/x/keyshare/types/keys.go b/x/keyshare/types/keys.go index 6af46022..bd14d776 100644 --- a/x/keyshare/types/keys.go +++ b/x/keyshare/types/keys.go @@ -117,5 +117,3 @@ const ( func KeyPrefix(p string) []byte { return []byte(p) } - -const AvgBlockTime = 5.6 diff --git a/x/keyshare/types/params.go b/x/keyshare/types/params.go index a0369249..54f1f1bd 100644 --- a/x/keyshare/types/params.go +++ b/x/keyshare/types/params.go @@ -41,6 +41,11 @@ var ( DefaultMaxIdledBlock uint64 = 10 ) +var ( + KeyAvgBlockTime = []byte("KeyAvgBlockTime") + DefaultAvgBlockTime float32 = 5.6 +) + // ParamKeyTable the param key table for launch module func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) @@ -54,6 +59,7 @@ func NewParams( noKeyshareFraction math.LegacyDec, wrongKeyshareFraction math.LegacyDec, maxIdledBlock uint64, + avgBlockTime float32, ) Params { return Params{ KeyExpiry: keyExp, @@ -62,6 +68,7 @@ func NewParams( SlashFractionWrongKeyshare: wrongKeyshareFraction, MaxIdledBlock: maxIdledBlock, MinimumBonded: minimumBonded, + AvgBlockTime: avgBlockTime, } } @@ -74,6 +81,7 @@ func DefaultParams() Params { DefaultSlashFractionNoKeyshare, DefaultSlashFractionWrongKeyshare, DefaultMaxIdledBlock, + DefaultAvgBlockTime, ) } @@ -86,6 +94,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { paramtypes.NewParamSetPair(KeySlashFractionNoKeyshare, &p.SlashFractionNoKeyshare, validateSlashFractionNoKeyshare), paramtypes.NewParamSetPair(KeySlashFractionWrongKeyshare, &p.SlashFractionWrongKeyshare, validateSlashFractionWrongKeyshare), paramtypes.NewParamSetPair(KeyMaxIdledBlock, &p.MaxIdledBlock, validateMaxIdledBlock), + paramtypes.NewParamSetPair(KeyAvgBlockTime, &p.AvgBlockTime, validateAvgBlockTime), } } @@ -177,3 +186,13 @@ func validateMaxIdledBlock(v interface{}) error { return nil } + +// validateAvgBlockTime validates the AvgBlockTime param +func validateAvgBlockTime(v interface{}) error { + _, ok := v.(float32) + if !ok { + return fmt.Errorf("invalid parameter type: %T", v) + } + + return nil +} diff --git a/x/keyshare/types/params.pb.go b/x/keyshare/types/params.pb.go index 3b2f9f3e..45c83a2f 100644 --- a/x/keyshare/types/params.pb.go +++ b/x/keyshare/types/params.pb.go @@ -5,6 +5,7 @@ package types import ( cosmossdk_io_math "cosmossdk.io/math" + encoding_binary "encoding/binary" fmt "fmt" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" @@ -33,6 +34,7 @@ type Params struct { TrustedAddresses []string `protobuf:"bytes,4,rep,name=trusted_addresses,json=trustedAddresses,proto3" json:"trusted_addresses,omitempty" yaml:"trusted_addresses"` SlashFractionNoKeyshare cosmossdk_io_math.LegacyDec `protobuf:"bytes,5,opt,name=slash_fraction_no_keyshare,json=slashFractionNoKeyshare,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"slash_fraction_no_keyshare" yaml:"slash_fraction_no_keyshare"` SlashFractionWrongKeyshare cosmossdk_io_math.LegacyDec `protobuf:"bytes,6,opt,name=slash_fraction_wrong_keyshare,json=slashFractionWrongKeyshare,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"slash_fraction_wrong_keyshare" yaml:"slash_fraction_wrong_keyshare"` + AvgBlockTime float32 `protobuf:"fixed32,7,opt,name=avg_block_time,json=avgBlockTime,proto3" json:"avg_block_time,omitempty" yaml:"avg_block_time"` } func (m *Params) Reset() { *m = Params{} } @@ -96,6 +98,13 @@ func (m *Params) GetTrustedAddresses() []string { return nil } +func (m *Params) GetAvgBlockTime() float32 { + if m != nil { + return m.AvgBlockTime + } + return 0 +} + func init() { proto.RegisterType((*Params)(nil), "fairyring.keyshare.Params") } @@ -103,36 +112,39 @@ func init() { func init() { proto.RegisterFile("fairyring/keyshare/params.proto", fileDescriptor_09ef7bd565425b36) } var fileDescriptor_09ef7bd565425b36 = []byte{ - // 463 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0x4f, 0x8b, 0xd3, 0x40, - 0x1c, 0xed, 0xb8, 0xb5, 0xb0, 0x83, 0xff, 0x1a, 0x5c, 0x8d, 0x51, 0x33, 0x35, 0x78, 0x28, 0x1e, - 0x12, 0x41, 0x2f, 0xee, 0x49, 0x83, 0x2e, 0x96, 0x15, 0x91, 0x5c, 0x04, 0x2f, 0x61, 0x9a, 0x99, - 0x4d, 0x87, 0x74, 0x32, 0x65, 0x26, 0xc5, 0xce, 0x07, 0xf0, 0xe2, 0x41, 0xfc, 0x08, 0x7e, 0x04, - 0x3f, 0xc6, 0x1e, 0xf7, 0x28, 0x1e, 0x82, 0xb4, 0x07, 0x3d, 0xe7, 0x13, 0x48, 0x26, 0xa9, 0xa5, - 0xea, 0x42, 0x2f, 0xe1, 0xf7, 0x7b, 0xef, 0xfd, 0x5e, 0x1e, 0xc9, 0x83, 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d, 0x30, 0x72, 0x12, 0x17, 0x03, 0x00, 0x00, + // 497 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x52, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0xcd, 0xf4, 0x11, 0xd4, 0x51, 0x29, 0xc4, 0xa2, 0x60, 0x02, 0x78, 0x82, 0xc5, 0x22, 0x62, + 0x61, 0x23, 0xc1, 0x86, 0x6e, 0x00, 0x0b, 0x2a, 0xa2, 0x22, 0x84, 0x2c, 0x24, 0x24, 0x36, 0xa3, + 0x89, 0x3d, 0x75, 0x46, 0xce, 0x78, 0xa2, 0x19, 0xa7, 0xc4, 0x1f, 0xc0, 0x86, 0x05, 0xe2, 0x13, + 0x58, 0xf0, 0x01, 0x7c, 0x46, 0x97, 0x5d, 0x22, 0x16, 0x16, 0x4a, 0x16, 0xb0, 0xf6, 0x17, 0x20, + 0x8f, 0x9d, 0x06, 0x03, 0x95, 0xba, 0xb1, 0xee, 0x3d, 0xe7, 0xdc, 0xe3, 0xa3, 0xb9, 0x17, 0xa2, + 0x43, 0xc2, 0x64, 0x26, 0x59, 0x12, 0xb9, 0x31, 0xcd, 0xd4, 0x88, 0x48, 0xea, 0x4e, 0x88, 0x24, + 0x5c, 0x39, 0x13, 0x29, 0x52, 0x61, 0x18, 0xa7, 0x02, 0x67, 0x29, 0xe8, 0x76, 0x08, 0x67, 0x89, + 0x70, 0xf5, 0xb7, 0x92, 0x75, 0xaf, 0x44, 0x22, 0x12, 0xba, 0x74, 0xcb, 0xaa, 0x42, 0xed, 0x2f, + 0x9b, 0xb0, 0xfd, 0x4a, 0xbb, 0x19, 0x0f, 0x20, 0x8c, 0x69, 0x86, 0xe9, 0x6c, 0xc2, 0x64, 0x66, + 0x82, 0x1e, 0xe8, 0x6f, 0x78, 0xbb, 0x45, 0x8e, 0x3a, 0x19, 0xe1, 0xe3, 0x3d, 0x7b, 0xc5, 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, 0xe0, 0x3b, 0x29, 0x92, 0x68, 0x15, 0xa5, 0xad, 0xa3, 0x1c, + 0x9c, 0x2f, 0xca, 0x9d, 0xff, 0x46, 0x69, 0x3a, 0xda, 0x7e, 0xb7, 0x91, 0xe6, 0x4d, 0xc9, 0x9e, + 0x06, 0x7a, 0x04, 0x77, 0xc8, 0x51, 0x54, 0x2d, 0x00, 0xa7, 0x8c, 0x53, 0xf3, 0x42, 0x0f, 0xf4, + 0xd7, 0xfe, 0xdc, 0x74, 0x93, 0xb7, 0xfd, 0x6d, 0x72, 0x14, 0xe9, 0x05, 0xbd, 0x66, 0x9c, 0xee, + 0x3d, 0xfc, 0xf5, 0x19, 0x81, 0x0f, 0x3f, 0xbf, 0xde, 0xbd, 0x17, 0xb1, 0x74, 0x34, 0x1d, 0x3a, + 0x81, 0xe0, 0xee, 0x3e, 0x61, 0x52, 0x8f, 0xb8, 0xab, 0x3b, 0x9f, 0xad, 0x2e, 0xbd, 0xba, 0x4d, + 0x6f, 0x70, 0x3c, 0xb7, 0xc0, 0xc9, 0xdc, 0x02, 0x3f, 0xe6, 0x16, 0xf8, 0xb4, 0xb0, 0x5a, 0x27, + 0x0b, 0xab, 0xf5, 0x6d, 0x61, 0xb5, 0xde, 0xba, 0xe7, 0xf7, 0x4a, 0xb3, 0x09, 0x55, 0xc3, 0xb6, + 0x3e, 0xfc, 0xfb, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0xb3, 0xa7, 0x9b, 0xa0, 0x58, 0x03, 0x00, + 0x00, } func (this *Params) Equal(that interface{}) bool { @@ -177,6 +189,9 @@ func (this *Params) Equal(that interface{}) bool { if !this.SlashFractionWrongKeyshare.Equal(that1.SlashFractionWrongKeyshare) { return false } + if this.AvgBlockTime != that1.AvgBlockTime { + return false + } return true } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -199,6 +214,12 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.AvgBlockTime != 0 { + i -= 4 + encoding_binary.LittleEndian.PutUint32(dAtA[i:], uint32(math.Float32bits(float32(m.AvgBlockTime)))) + i-- + dAtA[i] = 0x3d + } { size := m.SlashFractionWrongKeyshare.Size() i -= size @@ -282,6 +303,9 @@ func (m *Params) Size() (n int) { n += 1 + l + sovParams(uint64(l)) l = m.SlashFractionWrongKeyshare.Size() n += 1 + l + sovParams(uint64(l)) + if m.AvgBlockTime != 0 { + n += 5 + } return n } @@ -475,6 +499,17 @@ func (m *Params) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 7: + if wireType != 5 { + return fmt.Errorf("proto: wrong wireType = %d for field AvgBlockTime", wireType) + } + var v uint32 + if (iNdEx + 4) > l { + return io.ErrUnexpectedEOF + } + v = uint32(encoding_binary.LittleEndian.Uint32(dAtA[iNdEx:])) + iNdEx += 4 + m.AvgBlockTime = float32(math.Float32frombits(v)) default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])