diff --git a/proto/relayer/provers/lcp/config/config.proto b/proto/relayer/provers/lcp/config/config.proto index b407c53..2344fcf 100644 --- a/proto/relayer/provers/lcp/config/config.proto +++ b/proto/relayer/provers/lcp/config/config.proto @@ -11,13 +11,15 @@ message ProverConfig { google.protobuf.Any origin_prover = 1; // hex string string lcp_service_address = 2; + // unit: seconds + uint64 lcp_service_dial_timeout = 3; // hex string - string mrenclave = 3; - repeated string allowed_quote_statuses = 4; - repeated string allowed_advisory_ids = 5; + string mrenclave = 4; + repeated string allowed_quote_statuses = 5; + repeated string allowed_advisory_ids = 6; // unit: seconds - uint64 key_expiration = 6; - string elc_client_id = 7; - bool message_aggregation = 8; - uint64 message_aggregation_batch_size = 9; + uint64 key_expiration = 7; + string elc_client_id = 8; + bool message_aggregation = 9; + uint64 message_aggregation_batch_size = 10; } diff --git a/relay/config.go b/relay/config.go index 777e762..8ef3007 100644 --- a/relay/config.go +++ b/relay/config.go @@ -4,13 +4,17 @@ import ( "encoding/hex" "fmt" "strings" + "time" codectypes "github.com/cosmos/cosmos-sdk/codec/types" lcptypes "github.com/datachainlab/lcp-go/light-clients/lcp/types" "github.com/hyperledger-labs/yui-relayer/core" ) -const DefaultMessageAggregationBatchSize = 8 +const ( + DefaultDialTimeout = 20 // seconds + DefaultMessageAggregationBatchSize = 8 +) var _ core.ProverConfig = (*ProverConfig)(nil) @@ -37,6 +41,14 @@ func (pc ProverConfig) Build(chain core.Chain) (core.Prover, error) { return NewProver(pc, chain, prover) } +func (pc ProverConfig) GetDialTimeout() time.Duration { + if pc.LcpServiceDialTimeout == 0 { + return DefaultDialTimeout * time.Second + } else { + return time.Duration(pc.LcpServiceDialTimeout) * time.Second + } +} + func (pc ProverConfig) GetMrenclave() []byte { mrenclave, err := decodeMrenclaveHex(pc.Mrenclave) if err != nil { diff --git a/relay/config.pb.go b/relay/config.pb.go index 7532a0e..3cf8f7c 100644 --- a/relay/config.pb.go +++ b/relay/config.pb.go @@ -28,15 +28,17 @@ type ProverConfig struct { OriginProver *types.Any `protobuf:"bytes,1,opt,name=origin_prover,json=originProver,proto3" json:"origin_prover,omitempty"` // hex string LcpServiceAddress string `protobuf:"bytes,2,opt,name=lcp_service_address,json=lcpServiceAddress,proto3" json:"lcp_service_address,omitempty"` + // unit: seconds + LcpServiceDialTimeout uint64 `protobuf:"varint,3,opt,name=lcp_service_dial_timeout,json=lcpServiceDialTimeout,proto3" json:"lcp_service_dial_timeout,omitempty"` // hex string - Mrenclave string `protobuf:"bytes,3,opt,name=mrenclave,proto3" json:"mrenclave,omitempty"` - AllowedQuoteStatuses []string `protobuf:"bytes,4,rep,name=allowed_quote_statuses,json=allowedQuoteStatuses,proto3" json:"allowed_quote_statuses,omitempty"` - AllowedAdvisoryIds []string `protobuf:"bytes,5,rep,name=allowed_advisory_ids,json=allowedAdvisoryIds,proto3" json:"allowed_advisory_ids,omitempty"` + Mrenclave string `protobuf:"bytes,4,opt,name=mrenclave,proto3" json:"mrenclave,omitempty"` + AllowedQuoteStatuses []string `protobuf:"bytes,5,rep,name=allowed_quote_statuses,json=allowedQuoteStatuses,proto3" json:"allowed_quote_statuses,omitempty"` + AllowedAdvisoryIds []string `protobuf:"bytes,6,rep,name=allowed_advisory_ids,json=allowedAdvisoryIds,proto3" json:"allowed_advisory_ids,omitempty"` // unit: seconds - KeyExpiration uint64 `protobuf:"varint,6,opt,name=key_expiration,json=keyExpiration,proto3" json:"key_expiration,omitempty"` - ElcClientId string `protobuf:"bytes,7,opt,name=elc_client_id,json=elcClientId,proto3" json:"elc_client_id,omitempty"` - MessageAggregation bool `protobuf:"varint,8,opt,name=message_aggregation,json=messageAggregation,proto3" json:"message_aggregation,omitempty"` - MessageAggregationBatchSize uint64 `protobuf:"varint,9,opt,name=message_aggregation_batch_size,json=messageAggregationBatchSize,proto3" json:"message_aggregation_batch_size,omitempty"` + KeyExpiration uint64 `protobuf:"varint,7,opt,name=key_expiration,json=keyExpiration,proto3" json:"key_expiration,omitempty"` + ElcClientId string `protobuf:"bytes,8,opt,name=elc_client_id,json=elcClientId,proto3" json:"elc_client_id,omitempty"` + MessageAggregation bool `protobuf:"varint,9,opt,name=message_aggregation,json=messageAggregation,proto3" json:"message_aggregation,omitempty"` + MessageAggregationBatchSize uint64 `protobuf:"varint,10,opt,name=message_aggregation_batch_size,json=messageAggregationBatchSize,proto3" json:"message_aggregation_batch_size,omitempty"` } func (m *ProverConfig) Reset() { *m = ProverConfig{} } @@ -81,35 +83,37 @@ func init() { } var fileDescriptor_2e6956e1b8ef896e = []byte{ - // 439 bytes of a gzipped FileDescriptorProto + // 465 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0x31, 0x6f, 0x13, 0x31, - 0x1c, 0xc5, 0x73, 0xa4, 0x94, 0xc6, 0x6d, 0x90, 0x70, 0x23, 0x74, 0x04, 0x74, 0x8a, 0x2a, 0x10, - 0xb7, 0x70, 0x46, 0xc0, 0xc2, 0x98, 0x44, 0x0c, 0xdd, 0xe0, 0xb2, 0xb1, 0x58, 0x3e, 0xfb, 0x5f, - 0xc7, 0xaa, 0x73, 0x3e, 0x6c, 0x27, 0x70, 0xfd, 0x14, 0x7c, 0x24, 0xc6, 0x8e, 0x1d, 0x19, 0x21, - 0xf9, 0x22, 0x28, 0xf6, 0x95, 0x0e, 0x30, 0xd9, 0x7e, 0xbf, 0xf7, 0x9e, 0xfe, 0x92, 0xff, 0xe8, - 0xa5, 0x05, 0xcd, 0x5a, 0xb0, 0xa4, 0xb1, 0x66, 0x03, 0xd6, 0x11, 0xcd, 0x1b, 0xc2, 0x4d, 0x7d, - 0xa1, 0x64, 0x77, 0x14, 0x8d, 0x35, 0xde, 0xe0, 0x71, 0x67, 0x2c, 0x3a, 0x63, 0xa1, 0x79, 0x53, - 0x44, 0xc7, 0x78, 0x24, 0x8d, 0x34, 0xc1, 0x46, 0xf6, 0xb7, 0x98, 0x18, 0x3f, 0x91, 0xc6, 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91, 0x3e, 0x08, 0x03, 0x1f, 0x83, 0xe6, 0xf3, 0xa0, 0x9d, 0x0b, - 0x4c, 0xd0, 0xe9, 0x0a, 0x9c, 0x63, 0x12, 0x28, 0x93, 0xd2, 0x82, 0x8c, 0x7d, 0x47, 0x93, 0x24, - 0x3f, 0x2a, 0x71, 0x87, 0xa6, 0x77, 0x04, 0xcf, 0x51, 0xf6, 0x9f, 0x00, 0xad, 0x98, 0xe7, 0x4b, - 0xea, 0xd4, 0x15, 0xa4, 0x83, 0x30, 0xcb, 0xd3, 0x7f, 0xb3, 0xb3, 0xbd, 0x67, 0xa1, 0xae, 0x60, - 0x36, 0xbb, 0xfe, 0x9d, 0xf5, 0xae, 0xb7, 0x59, 0x72, 0xb3, 0xcd, 0x92, 0x5f, 0xdb, 0x2c, 0xf9, - 0xbe, 0xcb, 0x7a, 0x37, 0xbb, 0xac, 0xf7, 0x73, 0x97, 0xf5, 0x3e, 0x3f, 0x97, 0xca, 0x2f, 0xd7, - 0x55, 0xc1, 0xcd, 0x8a, 0x08, 0xe6, 0x19, 0x5f, 0x32, 0x55, 0x6b, 0x56, 0xed, 0xd7, 0xeb, 0x95, - 0x34, 0x24, 0x2c, 0x53, 0x75, 0x18, 0xbe, 0xf5, 0xed, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc1, - 0xc0, 0x72, 0xde, 0x85, 0x02, 0x00, 0x00, + 0x14, 0xc7, 0x73, 0xa4, 0x94, 0xc6, 0x6d, 0x90, 0x70, 0x03, 0x32, 0x01, 0x9d, 0xa2, 0x0a, 0x44, + 0x16, 0xee, 0x10, 0x20, 0x21, 0xc6, 0x24, 0x30, 0x74, 0x83, 0x84, 0x89, 0xc5, 0x72, 0xec, 0x57, + 0xc7, 0xaa, 0x73, 0x3e, 0x6c, 0x5f, 0xe0, 0xfa, 0x29, 0xf8, 0x58, 0x1d, 0x3b, 0x32, 0x42, 0xf2, + 0x29, 0xd8, 0x50, 0xec, 0x2b, 0x41, 0xa2,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0x85, 0x66, 0xf3, 0xed, 0x5d, 0x3e, 0x97, 0x26, 0x0f, 0x57, 0x38, 0xdf, 0x0f, + 0xf7, 0xf0, 0xea, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xb2, 0x66, 0x9e, 0xbe, 0x02, 0x00, + 0x00, } func (m *ProverConfig) Marshal() (dAtA []byte, err error) { @@ -135,7 +139,7 @@ func (m *ProverConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { if m.MessageAggregationBatchSize != 0 { i = encodeVarintConfig(dAtA, i, uint64(m.MessageAggregationBatchSize)) i-- - dAtA[i] = 0x48 + dAtA[i] = 0x50 } if m.MessageAggregation { i-- @@ -145,19 +149,19 @@ func (m *ProverConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0 } i-- - dAtA[i] = 0x40 + dAtA[i] = 0x48 } if len(m.ElcClientId) > 0 { i -= len(m.ElcClientId) copy(dAtA[i:], m.ElcClientId) i = encodeVarintConfig(dAtA, i, uint64(len(m.ElcClientId))) i-- - dAtA[i] = 0x3a + dAtA[i] = 0x42 } if m.KeyExpiration != 0 { i = encodeVarintConfig(dAtA, i, uint64(m.KeyExpiration)) i-- - dAtA[i] = 0x30 + dAtA[i] = 0x38 } if len(m.AllowedAdvisoryIds) > 0 { for iNdEx := len(m.AllowedAdvisoryIds) - 1; iNdEx >= 0; iNdEx-- { @@ -165,7 +169,7 @@ func (m *ProverConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.AllowedAdvisoryIds[iNdEx]) i = encodeVarintConfig(dAtA, i, uint64(len(m.AllowedAdvisoryIds[iNdEx]))) i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 } } if len(m.AllowedQuoteStatuses) > 0 { @@ -174,7 +178,7 @@ func (m *ProverConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.AllowedQuoteStatuses[iNdEx]) i = encodeVarintConfig(dAtA, i, uint64(len(m.AllowedQuoteStatuses[iNdEx]))) i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } } if len(m.Mrenclave) > 0 { @@ -182,7 +186,12 @@ func (m *ProverConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.Mrenclave) i = encodeVarintConfig(dAtA, i, uint64(len(m.Mrenclave))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 + } + if m.LcpServiceDialTimeout != 0 { + i = encodeVarintConfig(dAtA, i, uint64(m.LcpServiceDialTimeout)) + i-- + dAtA[i] = 0x18 } if len(m.LcpServiceAddress) > 0 { i -= len(m.LcpServiceAddress) @@ -231,6 +240,9 @@ func (m *ProverConfig) Size() (n int) { if l > 0 { n += 1 + l + sovConfig(uint64(l)) } + if m.LcpServiceDialTimeout != 0 { + n += 1 + sovConfig(uint64(m.LcpServiceDialTimeout)) + } l = len(m.Mrenclave) if l > 0 { n += 1 + l + sovConfig(uint64(l)) @@ -367,6 +379,25 @@ func (m *ProverConfig) Unmarshal(dAtA []byte) error { m.LcpServiceAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LcpServiceDialTimeout", wireType) + } + m.LcpServiceDialTimeout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.LcpServiceDialTimeout |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Mrenclave", wireType) } @@ -398,7 +429,7 @@ func (m *ProverConfig) Unmarshal(dAtA []byte) error { } m.Mrenclave = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field AllowedQuoteStatuses", wireType) } @@ -430,7 +461,7 @@ func (m *ProverConfig) Unmarshal(dAtA []byte) error { } m.AllowedQuoteStatuses = append(m.AllowedQuoteStatuses, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field AllowedAdvisoryIds", wireType) } @@ -462,7 +493,7 @@ func (m *ProverConfig) Unmarshal(dAtA []byte) error { } m.AllowedAdvisoryIds = append(m.AllowedAdvisoryIds, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex - case 6: + case 7: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field KeyExpiration", wireType) } @@ -481,7 +512,7 @@ func (m *ProverConfig) Unmarshal(dAtA []byte) error { break } } - case 7: + case 8: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ElcClientId", wireType) } @@ -513,7 +544,7 @@ func (m *ProverConfig) Unmarshal(dAtA []byte) error { } m.ElcClientId = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 8: + case 9: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field MessageAggregation", wireType) } @@ -533,7 +564,7 @@ func (m *ProverConfig) Unmarshal(dAtA []byte) error { } } m.MessageAggregation = bool(v != 0) - case 9: + case 10: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field MessageAggregationBatchSize", wireType) } diff --git a/relay/prover.go b/relay/prover.go index fa897e0..fca3786 100644 --- a/relay/prover.go +++ b/relay/prover.go @@ -48,9 +48,10 @@ func NewProver(config ProverConfig, originChain core.Chain, originProver core.Pr config.LcpServiceAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(), + grpc.WithTimeout(config.GetDialTimeout()), ) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to connect to LCP service: %w", err) } return &Prover{config: config, originChain: originChain, originProver: originProver, lcpServiceClient: NewLCPServiceClient(conn)}, nil }