From 73f12976f3e6e3f506753fac0ec127449abe6a02 Mon Sep 17 00:00:00 2001 From: dongrie <126585618+dongrie@users.noreply.github.com> Date: Thu, 29 Feb 2024 10:27:04 +0900 Subject: [PATCH] Limit the number of items retrieved in one EventQuery (#36) * Add blocks_per_query Signed-off-by: Dongri Jin * * Change blocks_per_query to blocks_per_event_query * Apply findSentPackets, findRecvPacketEvents, findWriteAckEvents * Fix loop count logic Signed-off-by: Dongri Jin --------- Signed-off-by: Dongri Jin --- pkg/relay/ethereum/config.go | 3 +- pkg/relay/ethereum/config.pb.go | 146 +++++++++++------- pkg/relay/ethereum/events.go | 89 ++++++----- .../chains/ethereum/config/config.proto | 2 + 4 files changed, 142 insertions(+), 98 deletions(-) diff --git a/pkg/relay/ethereum/config.go b/pkg/relay/ethereum/config.go index a489cc1..a807902 100644 --- a/pkg/relay/ethereum/config.go +++ b/pkg/relay/ethereum/config.go @@ -4,10 +4,11 @@ import ( "encoding/hex" "errors" "fmt" - "github.com/datachainlab/ethereum-ibc-relay-chain/pkg/utils" "math/big" "strings" + "github.com/datachainlab/ethereum-ibc-relay-chain/pkg/utils" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/ethereum/go-ethereum/common" "github.com/hyperledger-labs/yui-relayer/core" diff --git a/pkg/relay/ethereum/config.pb.go b/pkg/relay/ethereum/config.pb.go index 195300f..664d3ed 100644 --- a/pkg/relay/ethereum/config.pb.go +++ b/pkg/relay/ethereum/config.pb.go @@ -38,11 +38,12 @@ type ChainConfig struct { // option for ibc-solidity ADR-001 // if set, the relayer updates a LC contract directly if possible // if null, the relayer updates a LC contract via the handler - AllowLcFunctions *AllowLCFunctionsConfig `protobuf:"bytes,11,opt,name=allow_lc_functions,json=allowLcFunctions,proto3" json:"allow_lc_functions,omitempty"` - GasEstimateRate *Fraction `protobuf:"bytes,12,opt,name=gas_estimate_rate,json=gasEstimateRate,proto3" json:"gas_estimate_rate,omitempty"` - MaxGasLimit uint64 `protobuf:"varint,13,opt,name=max_gas_limit,json=maxGasLimit,proto3" json:"max_gas_limit,omitempty"` - TxType string `protobuf:"bytes,14,opt,name=tx_type,json=txType,proto3" json:"tx_type,omitempty"` - DynamicTxGasConfig *DynamicTxGasConfig `protobuf:"bytes,15,opt,name=dynamic_tx_gas_config,json=dynamicTxGasConfig,proto3" json:"dynamic_tx_gas_config,omitempty"` + AllowLcFunctions *AllowLCFunctionsConfig `protobuf:"bytes,11,opt,name=allow_lc_functions,json=allowLcFunctions,proto3" json:"allow_lc_functions,omitempty"` + GasEstimateRate *Fraction `protobuf:"bytes,12,opt,name=gas_estimate_rate,json=gasEstimateRate,proto3" json:"gas_estimate_rate,omitempty"` + MaxGasLimit uint64 `protobuf:"varint,13,opt,name=max_gas_limit,json=maxGasLimit,proto3" json:"max_gas_limit,omitempty"` + TxType string `protobuf:"bytes,14,opt,name=tx_type,json=txType,proto3" json:"tx_type,omitempty"` + DynamicTxGasConfig *DynamicTxGasConfig `protobuf:"bytes,15,opt,name=dynamic_tx_gas_config,json=dynamicTxGasConfig,proto3" json:"dynamic_tx_gas_config,omitempty"` + BlocksPerEventQuery uint64 `protobuf:"varint,16,opt,name=blocks_per_event_query,json=blocksPerEventQuery,proto3" json:"blocks_per_event_query,omitempty"` } func (m *ChainConfig) Reset() { *m = ChainConfig{} } @@ -209,59 +210,61 @@ func init() { } var fileDescriptor_a8a57ab2f9f14837 = []byte{ - // 832 bytes of a gzipped FileDescriptorProto + // 862 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xcd, 0x6e, 0x1b, 0x37, - 0x10, 0xb6, 0x62, 0x57, 0x96, 0xa8, 0x28, 0x3f, 0x84, 0x1d, 0xaf, 0xdd, 0x46, 0x15, 0x74, 0x52, - 0xd1, 0x78, 0x05, 0xa4, 0x68, 0x50, 0xf4, 0xa6, 0x28, 0x55, 0x9a, 0xc2, 0x05, 0x8c, 0xad, 0x4e,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9b, 0x9a, 0xe2, 0xb1, 0x5c, 0x27, 0x15, 0x07, 0x7f, - 0x8d, 0x3a, 0x3c, 0x0d, 0x46, 0x60, 0x4c, 0xf4, 0x85, 0xf7, 0x42, 0x3c, 0xf5, 0x5e, 0x60, 0x0c, - 0x7e, 0x81, 0x4e, 0xb8, 0xe4, 0x96, 0x53, 0x41, 0x0c, 0xc8, 0x8c, 0xb0, 0x05, 0xb0, 0xab, 0x52, - 0x71, 0x69, 0xa3, 0xa6, 0x2f, 0xeb, 0xb8, 0x82, 0x7f, 0x03, 0x99, 0x4d, 0x6a, 0x70, 0x57, 0xa7, - 0x81, 0x5d, 0xef, 0xea, 0x0e, 0xef, 0xe8, 0x12, 0x60, 0xd7, 0x3b, 0xba, 0x67, 0x08, 0x83, 0xa4, - 0xa9, 0x00, 0x92, 0x41, 0xba, 0xcc, 0x89, 0xd5, 0x94, 0x41, 0xd4, 0xea, 0x37, 0x86, 0xad, 0xe4, - 0x51, 0x40, 0x5e, 0x39, 0x60, 0xe6, 0xe2, 0xf8, 0x7b, 0x74, 0x42, 0xaf, 0x41, 0xd3, 0x1c, 0x48, - 0x2a, 0x14, 0xbb, 0x22, 0x96, 0x17, 0x40, 0x0a, 0x03, 0x2c, 0x6a, 0xfb, 0x2c, 0x47, 0x15, 0xfc, - 0xd2, 0xa1, 0x33, 0x5e, 0xc0, 0xaf, 0x06, 0x98, 0x93, 0x15, 0x74, 0x45, 0x34, 0x58, 0xbd, 0x26, - 0x73, 0xa5, 0x09, 0x97, 0x4c, 0x2c, 0x0d, 0x57, 0x32, 0x42, 0x41, 0x56, 0xd0, 0x55, 0xe2, 0xd0, - 0xa9, 0xd2, 0x6f, 0x36, 0x18, 0xce, 0x10, 0xa6, 0x42, 0xa8, 0xb7, 0x44, 0x30, 0x32, 0x5f, 0x4a, - 0x66, 0xb9, 0x92, 0x26, 0xea, 0xf8, 0x6b, 0x7e, 0x11, 0x7f, 0x7c, 0x60, 0xe2, 0xb1, 0x53, 0x5e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 0xdb, 0xc5, 0x32, - 0x8d, 0x99, 0x2a, 0x46, 0x19, 0xb5, 0xd4, 0xf7, 0x25, 0x68, 0x5a, 0xff, 0x4d, 0x9c, 0xf3, 0x94, - 0x9d, 0xfb, 0xae, 0xcf, 0x3d, 0x36, 0x2a, 0xaf, 0xf2, 0x91, 0x3f, 0xd7, 0x94, 0xb4, 0xe9, 0x1f, - 0xd9, 0xef, 0xfe, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x07, 0x03, 0x08, 0x83, 0x6b, 0x06, 0x00, 0x00, + 0x10, 0xb6, 0x62, 0x57, 0x96, 0xa8, 0x28, 0x71, 0x58, 0xff, 0xac, 0xdd, 0x46, 0x15, 0x74, 0x52, + 0xd1, 0x78, 0x05, 0x24, 0x68, 0x50, 0xf4, 0xa6, 0x28, 0x51, 0x9a, 0xc2, 0x05, 0xdc, 0xad, 0x4e, + 0xbd, 0x10, 0x5c, 0xee, 0x68, 0x45, 0x98, 0x4b, 0x6e, 0x49, 0xca, 0xd1, 0xbe, 0x45, 0x1f, 0xa0, + 0x0f, 0x94, 0x63, 0x2e, 0x05, 0x7a, 0x6c, 0xed, 0x17, 0x29, 0x48, 0xea, 0xcf, 0x48, 0xd1, 0x20, + 0x27, 0x89, 0xf3, 0xfd, 0xcc, 0x0c, 0x39, 0xe4, 0xa2, 0x6f, 0x34, 0x08, 0x5a, 0x81, 0x1e, 0xb0, + 0x19, 0xe5, 0xd2, 0x0c, 0xc0, 0xce, 0x40, 0xc3, 0xbc, 0x18, 0x30, 0x25, 0xa7, 0x3c, 0x5f, 0xfe, + 0xc4, 0xa5, 0x56, 0x56, 0xe1, 0xce, 0x92, 0x1c, 0x07, 0x72, 0xbc, 0x22, 0xc7, 0x81, 0x75, 0x76, + 0x98, 0xab, 0x5c, 0x79, 0xea, 0xc0, 0xfd, 0x0b, 0xaa, 0xb3, 0xd3, 0x5c, 0xa9, 0x5c, 0xc0, 0xc0, + 0xaf, 0xd2, 0xf9, 0x74, 0x40,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, 0x68, 0x9a, 0x03, 0x49, + 0x85, 0x62, 0x57, 0xc4, 0xf2, 0x02, 0x48, 0x61, 0x80, 0x45, 0x4d, 0x9f, 0xe5, 0x70, 0x09, 0xbf, + 0x70, 0xe8, 0x84, 0x17, 0xf0, 0x93, 0x01, 0xe6, 0x64, 0x05, 0x5d, 0x10, 0x0d, 0x56, 0x57, 0x64, + 0xaa, 0x34, 0xe1, 0x92, 0x89, 0xb9, 0xe1, 0x4a, 0x46, 0x28, 0xc8, 0x0a, 0xba, 0x48, 0x1c, 0x3a, + 0x56, 0xfa, 0xcd, 0x0a, 0xc3, 0x19, 0xc2, 0x54, 0x08, 0xf5, 0x96, 0x08, 0x46, 0xa6, 0x73, 0xc9, + 0x2c, 0x57, 0xd2, 0x44, 0x2d, 0xbf, 0xcd, 0xcf, 0xe3, 0xff, 0x1f, 0x98, 0x78, 0xe8, 0x94, 0x17, + 0xa3, 0xf1, 0x4a, 0x17, 0xc6, 0x20, 0x39, 0xf0, 0x8e, 0x17, 0x6c, 0x1d, 0xc7, 0x13, 0xf4, 0x28, + 0xa7, 0x86, 0x80, 0xb1, 0xbc, 0xa0, 0x16, 0x88, 0xa6, 0x16, 0xa2, 0xfb, 0x3e, 0x49, 0xff, 0x63, + 0x49, 0xc6, 0x9a, 0x7a, 0x97, 0xe4, 0x61, 0x4e, 0xcd, 0xab, 0xa5, 0x43, 0x42, 0x2d, 0xe0, 0x1e, + 0x6a, 0xbb, 0x96, 0x9d, 0xb3, 0xe0, 0x05, 0xb7, 0x51, 0xdb, 0x37, 0xda, 0x2a, 0xe8, 0xe2, 0x35, + 0x35, 0x17, 0x2e, 0x84, 0x4f, 0xd0, 0xbe, 0x5d, 0x10, 0x5b, 0x95, 0x10, 0x3d, 0xf0, 0x83, 0x50, + 0xb7, 0x8b, 0x49, 0x55, 0x02, 0x06, 0x74, 0x94, 0x55, 0x92, 0x16, 0x9c, 0x11, 0x1b, 0x3c, 0x42, + 0xbe, 0xe8, 0xa1, 0x2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x0a, 0x15, 0x6d, 0x17, 0x12, 0x1e, + 0x9f, 0x07, 0x1e, 0xd8, 0x14, 0x70, 0x81, 0xda, 0x29, 0x35, 0xb0, 0x49, 0xbe, 0xf7, 0x89, 0xc9, + 0x5b, 0x4e, 0xbe, 0x4a, 0x3c, 0x44, 0x8f, 0x9d, 0xd1, 0x8c, 0x1b, 0xab, 0x74, 0x45, 0x34, 0xbc, + 0xa5, 0x3a, 0x73, 0x15, 0x30, 0x90, 0x96, 0x0b, 0xf0, 0xaf, 0x56, 0x3b, 0x39, 0x9b, 0x02, 0xfc, + 0x10, 0x38, 0x89, 0xa7, 0x5c, 0xae, 0x19, 0xf8, 0x3b, 0x74, 0x7a, 0xf7, 0xc2, 0x6f, 0x19, 0xfa, + 0x77, 0xac, 0x9d, 0x1c, 0x6d, 0x5d, 0xf9, 0xf1, 0xda, 0xe9, 0x05, 0x7d, 0xf7, 0x4f, 0x67, 0xe7, + 0xdd, 0x4d, 0xa7, 0xf6, 0xfe, 0xa6, 0x53, 0xfb, 0xfb, 0xa6, 0x53, 0xfb, 0xfd, 0xb6, 0xb3, 0xf3, + 0xfe, 0xb6, 0xb3, 0xf3, 0xd7, 0x6d, 0x67, 0xe7, 0xd7, 0x51, 0xce, 0xed, 0x6c, 0x9e, 0xc6, 0x4c, + 0x15, 0x83, 0x8c, 0x5a, 0xea, 0xfb, 0x12, 0x34, 0x5d, 0x7f, 0x5b, 0xce, 0x79, 0xca, 0xce, 0x7d, + 0xd7, 0xe7, 0x1e, 0x1b, 0x94, 0x57, 0xf9, 0xc0, 0xaf, 0xd7, 0x94, 0xb4, 0xee, 0x5f, 0xe6, 0x67, + 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x82, 0x80, 0xcd, 0x56, 0xa0, 0x06, 0x00, 0x00, } func (m *ChainConfig) Marshal() (dAtA []byte, err error) { @@ -284,6 +287,13 @@ func (m *ChainConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.BlocksPerEventQuery != 0 { + i = encodeVarintConfig(dAtA, i, uint64(m.BlocksPerEventQuery)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x80 + } if m.DynamicTxGasConfig != nil { { size, err := m.DynamicTxGasConfig.MarshalToSizedBuffer(dAtA[:i]) @@ -626,6 +636,9 @@ func (m *ChainConfig) Size() (n int) { l = m.DynamicTxGasConfig.Size() n += 1 + l + sovConfig(uint64(l)) } + if m.BlocksPerEventQuery != 0 { + n += 2 + sovConfig(uint64(m.BlocksPerEventQuery)) + } return n } @@ -1138,6 +1151,25 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 16: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BlocksPerEventQuery", wireType) + } + m.BlocksPerEventQuery = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BlocksPerEventQuery |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipConfig(dAtA[iNdEx:]) diff --git a/pkg/relay/ethereum/events.go b/pkg/relay/ethereum/events.go index 233d8c7..1090327 100644 --- a/pkg/relay/ethereum/events.go +++ b/pkg/relay/ethereum/events.go @@ -10,12 +10,17 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/hyperledger-labs/yui-relayer/core" "github.com/hyperledger-labs/yui-relayer/log" "github.com/datachainlab/ethereum-ibc-relay-chain/pkg/contract/ibchandler" ) +const ( + BlocksPerEventQueryDefault = 1000 +) + var ( abiGeneratedClientIdentifier, abiGeneratedConnectionIdentifier, @@ -61,24 +66,11 @@ func (chain *Chain) findSentPackets(ctx core.QueryContext, fromHeight uint64) (c dstPortID = channel.Counterparty.PortId dstChannelID = channel.Counterparty.ChannelId } - - query := ethereum.FilterQuery{ - FromBlock: big.NewInt(int64(fromHeight)), - ToBlock: big.NewInt(int64(ctx.Height().GetRevisionHeight())), - Addresses: []common.Address{ - chain.config.IBCAddress(), - }, - Topics: [][]common.Hash{{ - abiSendPacket.ID, - }}, - } - - logs, err := chain.client.FilterLogs(ctx.Context(), query) + logs, err := chain.filterLogs(ctx, fromHeight, abiSendPacket) if err != nil { logger.Error("failed to filter logs", err) return nil, err } - defer logger.TimeTrack(now, "findSentPackets", "num_logs", len(logs)) var packets core.PacketInfoList @@ -158,22 +150,10 @@ func (chain *Chain) findReceivedPackets(ctx core.QueryContext, fromHeight uint64 } func (chain *Chain) findRecvPacketEvents(ctx core.QueryContext, fromHeight uint64) ([]*ibchandler.IbchandlerRecvPacket, error) { - query := ethereum.FilterQuery{ - FromBlock: big.NewInt(int64(fromHeight)), - ToBlock: big.NewInt(int64(ctx.Height().GetRevisionHeight())), - Addresses: []common.Address{ - chain.config.IBCAddress(), - }, - Topics: [][]common.Hash{{ - abiRecvPacket.ID, - }}, - } - - logs, err := chain.client.FilterLogs(ctx.Context(), query) + logs, err := chain.filterLogs(ctx, fromHeight, abiRecvPacket) if err != nil { return nil, err } - var events []*ibchandler.IbchandlerRecvPacket for _, log := range logs { event, err := chain.ibcHandler.ParseRecvPacket(log) @@ -187,22 +167,10 @@ func (chain *Chain) findRecvPacketEvents(ctx core.QueryContext, fromHeight uint6 } func (chain *Chain) findWriteAckEvents(ctx core.QueryContext, fromHeight uint64) ([]*ibchandler.IbchandlerWriteAcknowledgement, error) { - query := ethereum.FilterQuery{ - FromBlock: big.NewInt(int64(fromHeight)), - ToBlock: big.NewInt(int64(ctx.Height().GetRevisionHeight())), - Addresses: []common.Address{ - chain.config.IBCAddress(), - }, - Topics: [][]common.Hash{{ - abiWriteAcknowledgement.ID, - }}, - } - - logs, err := chain.client.FilterLogs(ctx.Context(), query) + logs, err := chain.filterLogs(ctx, fromHeight, abiWriteAcknowledgement) if err != nil { return nil, err } - var events []*ibchandler.IbchandlerWriteAcknowledgement for _, log := range logs { event, err := chain.ibcHandler.ParseWriteAcknowledgement(log) @@ -225,3 +193,44 @@ func (chain *Chain) GetChannelLogger() *log.RelayLogger { channelID := chain.Path().ChannelID return logger.WithChannel(chainID, portID, channelID) } + +func (chain *Chain) filterLogs(ctx core.QueryContext, fromHeight uint64, event abi.Event) ([]types.Log, error) { + blocksPerEventQuery := chain.config.BlocksPerEventQuery + if blocksPerEventQuery == 0 { + blocksPerEventQuery = BlocksPerEventQueryDefault + } + + toHeight := ctx.Height().GetRevisionHeight() + totalBlocks := toHeight - fromHeight + 1 + loopCount := totalBlocks / blocksPerEventQuery + if totalBlocks%blocksPerEventQuery != 0 { + loopCount++ + } + var logs []types.Log + for i := uint64(0); i < loopCount; i++ { + var endBlockNum uint64 + if i == loopCount-1 { + endBlockNum = toHeight + } else { + endBlockNum = fromHeight + (i+1)*blocksPerEventQuery - 1 + } + startBlock := big.NewInt(int64(fromHeight + i*blocksPerEventQuery)) + endBlock := big.NewInt(int64(endBlockNum)) + query := ethereum.FilterQuery{ + FromBlock: startBlock, + ToBlock: endBlock, + Addresses: []common.Address{ + chain.config.IBCAddress(), + }, + Topics: [][]common.Hash{{ + event.ID, + }}, + } + filterLogs, err := chain.client.FilterLogs(ctx.Context(), query) + if err != nil { + return nil, err + } + logs = append(logs, filterLogs...) + } + return logs, nil +} diff --git a/proto/relayer/chains/ethereum/config/config.proto b/proto/relayer/chains/ethereum/config/config.proto index d54a82b..11c4e28 100644 --- a/proto/relayer/chains/ethereum/config/config.proto +++ b/proto/relayer/chains/ethereum/config/config.proto @@ -34,6 +34,8 @@ message ChainConfig { string tx_type = 14; DynamicTxGasConfig dynamic_tx_gas_config = 15; + + uint64 blocks_per_event_query = 16; } message AllowLCFunctionsConfig {