Skip to content

Commit

Permalink
Merge pull request #53 from dai1975/lo5087-check-maxsize
Browse files Browse the repository at this point in the history
Check txMaxSize.
  • Loading branch information
siburu authored Sep 20, 2024
2 parents b2579e9 + e3a4d20 commit 59edbc5
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 58 deletions.
11 changes: 11 additions & 0 deletions pkg/relay/ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Chain struct {
ibcHandler *ibchandler.Ibchandler
multicall3 *multicall3.Multicall3

txMaxSize uint64

ethereumSigner EthereumSigner

errorRepository ErrorRepository
Expand All @@ -59,6 +61,8 @@ type Chain struct {
var _ core.Chain = (*Chain)(nil)

func NewChain(config ChainConfig) (*Chain, error) {
logger := GetModuleLogger()

id := big.NewInt(int64(config.EthChainId))
client, err := client.NewETHClient(
config.RpcAddr,
Expand Down Expand Up @@ -105,6 +109,11 @@ func NewChain(config ChainConfig) (*Chain, error) {
if err != nil {
return nil, fmt.Errorf("failed to create error repository: %v", err)
}
txMaxSize := config.GetTxMaxSize()
if txMaxSize == 0 {
txMaxSize = 128 * 1024 // go-ethereum/core/txpool/legacypool/legacypool.go
logger.Info(fmt.Sprintf("txMaxSize is zero. set to %v", txMaxSize));
}

return &Chain{
config: config,
Expand All @@ -118,6 +127,8 @@ func NewChain(config ChainConfig) (*Chain, error) {

errorRepository: errorRepository,

txMaxSize: txMaxSize,

allowLCFunctions: alfs,
}, nil
}
Expand Down
207 changes: 150 additions & 57 deletions pkg/relay/ethereum/config.pb.go

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

1 change: 1 addition & 0 deletions pkg/relay/ethereum/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
logAttrRawErrorData = "raw_error_data"
logAttrRawTxData = "raw_tx_data"
logAttrTxHash = "tx_hash"
logAttrTxSize = "tx_size"
logAttrBlockHash = "block_hash"
logAttrBlockNumber = "block_number"
logAttrTxIndex = "tx_index"
Expand Down
9 changes: 8 additions & 1 deletion pkg/relay/ethereum/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) {
break
} else {
logger = iter.updateLoggerMessageInfo(logger, from, built.count)
logger = &log.RelayLogger{Logger: logger.With(logAttrTxHash, built.tx.Hash())}
logger = &log.RelayLogger{Logger: logger.With(
logAttrTxHash, built.tx.Hash(),
logAttrTxSize, built.tx.Size(),
)}
}

if rawTxData, err := built.tx.MarshalBinary(); err != nil {
Expand Down Expand Up @@ -747,6 +750,10 @@ func (iter *CallIter) buildMultiTx(ctx context.Context, c *Chain) (*CallIterBuil
return err
}

if 1 < count && c.txMaxSize < multiTx.Size() {
return fmt.Errorf("tx size exceeds txMaxSize: tx=%v, max=%v", multiTx.Size(), c.txMaxSize)
}

txGasLimit, err := estimateGas(ctx, c, multiTx, 1 == count, logger)
if err != nil {
return err
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 @@ -40,6 +40,8 @@ message ChainConfig {
repeated string abi_paths = 17;

string multicall3_address = 18;

optional uint64 tx_max_size = 19;
}

message AllowLCFunctionsConfig {
Expand Down

0 comments on commit 59edbc5

Please sign in to comment.