From 347bf0113086f88a133ba19325dff901513538fd Mon Sep 17 00:00:00 2001 From: Tony Stark Date: Wed, 20 Nov 2024 21:21:44 +0530 Subject: [PATCH] feat: added block interval in the oracle params --- proto/sentinel/oracle/v1/params.proto | 7 ++- x/oracle/keeper/abci.go | 5 ++ x/oracle/keeper/params.go | 5 ++ x/oracle/types/v1/params.pb.go | 86 ++++++++++++++++++--------- 4 files changed, 72 insertions(+), 31 deletions(-) diff --git a/proto/sentinel/oracle/v1/params.proto b/proto/sentinel/oracle/v1/params.proto index 1842528a..94fa72c1 100644 --- a/proto/sentinel/oracle/v1/params.proto +++ b/proto/sentinel/oracle/v1/params.proto @@ -9,9 +9,10 @@ option (gogoproto.equal_all) = false; option (gogoproto.goproto_getters_all) = false; message Params { - string channel_id = 1 [(gogoproto.customname) = "ChannelID"]; - string port_id = 2 [(gogoproto.customname) = "PortID"]; - google.protobuf.Duration timeout = 3 [ + int64 block_interval = 1; + string channel_id = 2 [(gogoproto.customname) = "ChannelID"]; + string port_id = 3 [(gogoproto.customname) = "PortID"]; + google.protobuf.Duration timeout = 4 [ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ]; diff --git a/x/oracle/keeper/abci.go b/x/oracle/keeper/abci.go index 75bb5147..e2c412ca 100644 --- a/x/oracle/keeper/abci.go +++ b/x/oracle/keeper/abci.go @@ -11,6 +11,11 @@ import ( // BeginBlock is called at the beginning of each block to trigger IBC query packets for relevant assets. func (k *Keeper) BeginBlock(ctx sdk.Context) { + interval := k.GetBlockInterval(ctx) + if ctx.BlockHeight()%interval != 0 { + return + } + portID := k.GetPortID(ctx) if portID == "" { ctx.Logger().Info("PortID is empty, skipping BeginBlock execution") diff --git a/x/oracle/keeper/params.go b/x/oracle/keeper/params.go index 30e5e181..6309d3a6 100644 --- a/x/oracle/keeper/params.go +++ b/x/oracle/keeper/params.go @@ -28,6 +28,11 @@ func (k *Keeper) GetParams(ctx sdk.Context) (v v1.Params) { return v } +// GetBlockInterval retrieves the BlockInterval parameter from the module's parameters. +func (k *Keeper) GetBlockInterval(ctx sdk.Context) int64 { + return k.GetParams(ctx).BlockInterval +} + // GetChannelID retrieves the ChannelID parameter from the module's parameters. func (k *Keeper) GetChannelID(ctx sdk.Context) string { return k.GetParams(ctx).ChannelID diff --git a/x/oracle/types/v1/params.pb.go b/x/oracle/types/v1/params.pb.go index 1fead299..e78a0276 100644 --- a/x/oracle/types/v1/params.pb.go +++ b/x/oracle/types/v1/params.pb.go @@ -28,9 +28,10 @@ var _ = time.Kitchen const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Params struct { - ChannelID string `protobuf:"bytes,1,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` - PortID string `protobuf:"bytes,2,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` - Timeout time.Duration `protobuf:"bytes,3,opt,name=timeout,proto3,stdduration" json:"timeout"` + BlockInterval int64 `protobuf:"varint,1,opt,name=block_interval,json=blockInterval,proto3" json:"block_interval,omitempty"` + ChannelID string `protobuf:"bytes,2,opt,name=channel_id,json=channelId,proto3" json:"channel_id,omitempty"` + PortID string `protobuf:"bytes,3,opt,name=port_id,json=portId,proto3" json:"port_id,omitempty"` + Timeout time.Duration `protobuf:"bytes,4,opt,name=timeout,proto3,stdduration" json:"timeout"` } func (m *Params) Reset() { *m = Params{} } @@ -73,26 +74,28 @@ func init() { func init() { proto.RegisterFile("sentinel/oracle/v1/params.proto", fileDescriptor_86cf63c01067cd84) } var fileDescriptor_86cf63c01067cd84 = []byte{ - // 303 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x90, 0xb1, 0x4e, 0xfb, 0x30, - 0x10, 0xc6, 0xed, 0xff, 0x5f, 0x4a, 0xa9, 0x11, 0x4b, 0xc4, 0x50, 0x3a, 0x38, 0x15, 0x2c, 0x1d, - 0xc0, 0x56, 0x8a, 0xc4, 0xc6, 0x52, 0xba, 0x64, 0xab, 0x3a, 0x21, 0x16, 0xe4, 0x24, 0x6e, 0x6a, - 0x29, 0xcd, 0x45, 0xae, 0x13, 0xc1, 0x5b, 0x30, 0x22, 0x9e, 0x80, 0x47, 0xe9, 0xd8, 0x91, 0x29, - 0x80, 0xf3, 0x22, 0x28, 0x49, 0xb3, 0xdd, 0xdd, 0xf7, 0xbb, 0xbb, 0x4f, 0x1f, 0xf1, 0x76, 0x32, - 0x33, 0x2a, 0x93, 0x29, 0x07, 0x2d, 0xa2, 0x54, 0xf2, 0xd2, 0xe7, 0xb9, 0xd0, 0x62, 0xbb, 0x63, - 0xb9, 0x06, 0x03, 0xae, 0xdb, 0x03, 0xac, 0x03, 0x58, 0xe9, 0x8f, 0xcf, 0x13, 0x48, 0xa0, 0x95, - 0x79, 0x53, 0x75, 0xe4, 0x98, 0x26, 0x00, 0x49, 0x2a, 0x79, 0xdb, 0x85, 0xc5, 0x9a, 0xc7, 0x85, - 0x16, 0x46, 0x41, 0xd6, 0xe9, 0x97, 0x1f, 0x98, 0x38, 0xcb, 0xf6, 0xb4, 0x7b, 0x4d, 0x48, 0xb4, - 0x11, 0x59, 0x26, 0xd3, 0x67, 0x15, 0x8f, 0xf0, 0x04, 0x4f, 0x87, 0xf3, 0x33, 0x5b, 0x79, 0xc3, - 0x87, 0x6e, 0x1a, 0x2c, 0x56, 0xc3, 0x23, 0x10, 0xc4, 0xee, 0x15, 0x19, 0xe4, 0xa0, 0x4d, 0x83, - 0xfe, 0x6b, 0x51, 0x62, 0x2b, 0xcf, 0x59, 0x82, 0x36, 0xc1, 0x62, 0xe5, 0x34, 0x52, 0x10, 0xbb, - 0xf7, 0x64, 0x60, 0xd4, 0x56, 0x42, 0x61, 0x46, 0xff, 0x27, 0x78, 0x7a, 0x3a, 0xbb, 0x60, 0x9d, - 0x1f, 0xd6, 0xfb, 0x61, 0x8b, 0xa3, 0x9f, 0xf9, 0xc9, 0xbe, 0xf2, 0xd0, 0xfb, 0xb7, 0x87, 0x57, - 0xfd, 0xce, 0xfc, 0x71, 0xff, 0x4b, 0xd1, 0xa7, 0xa5, 0x68, 0x6f, 0x29, 0x3e, 0x58, 0x8a, 0x7f, - 0x2c, 0xc5, 0x6f, 0x35, 0x45, 0x87, 0x9a, 0xa2, 0xaf, 0x9a, 0xa2, 0xa7, 0xbb, 0x44, 0x99, 0x4d, - 0x11, 0xb2, 0x08, 0xb6, 0xbc, 0xcf, 0xe4, 0x06, 0xd6, 0x6b, 0x15, 0x29, 0x91, 0xf2, 0x4d, 0x11, - 0xf2, 0xd2, 0x9f, 0xf1, 0x97, 0x3e, 0x47, 0xf3, 0x9a, 0xcb, 0x1d, 0x2f, 0xfd, 0xd0, 0x69, 0xff, - 0xdf, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0xca, 0x51, 0xef, 0xe3, 0x6a, 0x01, 0x00, 0x00, + // 328 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x34, 0x90, 0xb1, 0x4e, 0xc3, 0x30, + 0x14, 0x45, 0x63, 0x8a, 0x52, 0x6a, 0x54, 0x86, 0x88, 0xa1, 0x74, 0x70, 0x2a, 0x10, 0x52, 0x07, + 0xb0, 0x95, 0x22, 0xb1, 0xb1, 0x94, 0x2e, 0xd9, 0xaa, 0x4c, 0x88, 0xa5, 0x72, 0x12, 0x37, 0xb5, + 0x70, 0xf3, 0x22, 0xd7, 0x89, 0xe0, 0x2f, 0x18, 0xf9, 0x04, 0x7e, 0x83, 0xad, 0x63, 0x47, 0xa6, + 0x02, 0xe9, 0x8f, 0xa0, 0x26, 0xcd, 0x66, 0xdf, 0x7b, 0xde, 0x7b, 0x57, 0x17, 0xbb, 0x2b, 0x91, + 0x1a, 0x99, 0x0a, 0xc5, 0x40, 0xf3, 0x48, 0x09, 0x56, 0x78, 0x2c, 0xe3, 0x9a, 0x2f, 0x57, 0x34, + 0xd3, 0x60, 0xc0, 0x71, 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 0x04, 0x4b, 0xd6, 0x54, 0x77, + 0x0b, 0xf3, 0xb9, 0x8c, 0x24, 0x57, 0x6c, 0x91, 0x87, 0xac, 0xf0, 0x46, 0xec, 0xb5, 0xa9, 0xdb, + 0xbc, 0x65, 0x62, 0xc5, 0x0a, 0x2f, 0xb4, 0xab, 0xfb, 0x77, 0xff, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x0a, 0x04, 0x43, 0x0f, 0x91, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -122,20 +125,25 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= n1 i = encodeVarintParams(dAtA, i, uint64(n1)) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 if len(m.PortID) > 0 { i -= len(m.PortID) copy(dAtA[i:], m.PortID) i = encodeVarintParams(dAtA, i, uint64(len(m.PortID))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } if len(m.ChannelID) > 0 { i -= len(m.ChannelID) copy(dAtA[i:], m.ChannelID) i = encodeVarintParams(dAtA, i, uint64(len(m.ChannelID))) i-- - dAtA[i] = 0xa + dAtA[i] = 0x12 + } + if m.BlockInterval != 0 { + i = encodeVarintParams(dAtA, i, uint64(m.BlockInterval)) + i-- + dAtA[i] = 0x8 } return len(dAtA) - i, nil } @@ -157,6 +165,9 @@ func (m *Params) Size() (n int) { } var l int _ = l + if m.BlockInterval != 0 { + n += 1 + sovParams(uint64(m.BlockInterval)) + } l = len(m.ChannelID) if l > 0 { n += 1 + l + sovParams(uint64(l)) @@ -206,6 +217,25 @@ func (m *Params) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlockInterval", wireType) + } + m.BlockInterval = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlockInterval |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ChannelID", wireType) } @@ -237,7 +267,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.ChannelID = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PortID", wireType) } @@ -269,7 +299,7 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.PortID = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Timeout", wireType) }