Skip to content

Commit

Permalink
Add blocks_per_query
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie committed Feb 14, 2024
1 parent cde672f commit 6321dd6
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 66 deletions.
3 changes: 2 additions & 1 deletion pkg/relay/ethereum/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
136 changes: 84 additions & 52 deletions pkg/relay/ethereum/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 40 additions & 13 deletions pkg/relay/ethereum/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
BlocksPerQueryDefault = 1000
)

var (
abiGeneratedClientIdentifier,
abiGeneratedConnectionIdentifier,
Expand Down Expand Up @@ -62,21 +67,43 @@ func (chain *Chain) findSentPackets(ctx core.QueryContext, fromHeight uint64) (c
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,
}},
blocksPerQuery := chain.config.BlocksPerQuery
if blocksPerQuery == 0 {
blocksPerQuery = BlocksPerQueryDefault
}

logs, err := chain.client.FilterLogs(ctx.Context(), query)
if err != nil {
logger.Error("failed to filter logs", err)
return nil, err
toHeight := ctx.Height().GetRevisionHeight()
totalBlocks := toHeight - fromHeight
loopCount := totalBlocks / blocksPerQuery
if totalBlocks%blocksPerQuery != 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)*blocksPerQuery - 1
}
startBlock := big.NewInt(int64(fromHeight + i*blocksPerQuery))
endBlock := big.NewInt(int64(endBlockNum))
query := ethereum.FilterQuery{
FromBlock: startBlock,
ToBlock: endBlock,
Addresses: []common.Address{
chain.config.IBCAddress(),
},
Topics: [][]common.Hash{{
abiSendPacket.ID,
}},
}
filterLogs, err := chain.client.FilterLogs(ctx.Context(), query)
if err != nil {
logger.Error("failed to filter logs", err)
return nil, err
}
logs = append(logs, filterLogs...)
}

defer logger.TimeTrack(now, "findSentPackets", "num_logs", len(logs))
Expand Down
2 changes: 2 additions & 0 deletions proto/relayer/chains/ethereum/config/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ message ChainConfig {

string tx_type = 14;
DynamicTxGasConfig dynamic_tx_gas_config = 15;

uint64 blocks_per_query = 16;
}

message AllowLCFunctionsConfig {
Expand Down

0 comments on commit 6321dd6

Please sign in to comment.