Skip to content

Commit 544db8f

Browse files
authored
Merge pull request #9 from icon-project/add-gas-limit-option
Add gas limit option
2 parents c8d38ad + 02c00c7 commit 544db8f

File tree

3 files changed

+64
-22
lines changed

3 files changed

+64
-22
lines changed

chain/eth2/client/execution.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *ExecutionLayer) GetBackend() bind.ContractBackend {
4747
return c.client
4848
}
4949

50-
func (c *ExecutionLayer) NewTransactOpts(k *ecdsa.PrivateKey) (*bind.TransactOpts, error) {
50+
func (c *ExecutionLayer) NewTransactOpts(k *ecdsa.PrivateKey, gasLimit uint64) (*bind.TransactOpts, error) {
5151
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
5252
defer cancel()
5353
txo, err := bind.NewKeyedTransactorWithChainID(k, c.chainID)
@@ -63,6 +63,11 @@ func (c *ExecutionLayer) NewTransactOpts(k *ecdsa.PrivateKey) (*bind.TransactOpt
6363
rewards.Add(rewards, r[0])
6464
}
6565
txo.GasTipCap = rewards.Div(rewards, big.NewInt(int64(len(fh.Reward))))
66+
if gasLimit != 0 {
67+
txo.GasLimit = gasLimit
68+
} else {
69+
txo.GasLimit = DefaultGasLimit
70+
}
6671

6772
return txo, nil
6873
}

chain/eth2/sender.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ func (r *request) Format(f fmt.State, c rune) {
8484
switch c {
8585
case 'v', 's':
8686
if f.Flag('+') {
87-
fmt.Fprintf(f, "request{id=%d txHash=%#x txPendingCount=%d)", r.ID(), r.txHash, r.txPendingCount)
87+
fmt.Fprintf(f, "request{id=%s txHash=%#x txPendingCount=%d)", r.ID(), r.txHash, r.txPendingCount)
8888
} else {
89-
fmt.Fprintf(f, "request{%d %#x %d)", r.ID(), r.txHash, r.txPendingCount)
89+
fmt.Fprintf(f, "request{%s %#x %d)", r.ID(), r.txHash, r.txPendingCount)
9090
}
9191
}
9292
}
@@ -103,6 +103,8 @@ type sender struct {
103103
cl *client.ConsensusLayer
104104
el *client.ExecutionLayer
105105
bmc *client.BMCClient
106+
107+
gasLimit uint64
106108
}
107109

108110
func newSender(src, dst types.BtpAddress, w types.Wallet, endpoint string, opt map[string]interface{}, l log.Logger) types.Sender {
@@ -118,15 +120,20 @@ func newSender(src, dst types.BtpAddress, w types.Wallet, endpoint string, opt m
118120
if err != nil {
119121
l.Panicf("fail to connect to %s, %v", endpoint, err)
120122
}
121-
s.cl, err = client.NewConsensusLayer(opt["consensus_endpoint"].(string), l)
122-
if err != nil {
123-
l.Panicf("fail to connect to %s, %v", opt["consensus_endpoint"].(string), err)
123+
l.Debugf("Sender options %+v", opt)
124+
if clEndpoint, ok := opt["consensus_endpoint"].(string); ok {
125+
s.cl, err = client.NewConsensusLayer(clEndpoint, l)
126+
if err != nil {
127+
l.Panicf("fail to connect to %s, %v", clEndpoint, err)
128+
}
124129
}
125130
txUrl, _ := opt["execution_tx_endpoint"].(string)
126131
s.bmc, err = client.NewBMCClient(common.HexToAddress(s.dst.ContractAddress()), s.el.GetBackend(), txUrl, l)
127132
if err != nil {
128133
l.Panicf("fail to connect to BMC %s, %v", s.dst.ContractAddress(), err)
129134
}
135+
gasLimit, _ := opt["gas_limit"].(float64)
136+
s.gasLimit = uint64(gasLimit)
130137
return s
131138
}
132139

@@ -154,8 +161,8 @@ func (s *sender) Relay(rm types.RelayMessage) (string, error) {
154161
}
155162

156163
func (s *sender) relay(rm types.RelayMessage) (*etypes.Transaction, error) {
157-
s.l.Debugf("relay src address:%s rm id:%d", s.src.String(), rm.Id())
158-
t, err := s.el.NewTransactOpts(s.w.(*wallet.EvmWallet).Skey)
164+
s.l.Debugf("relay src address:%s rm id:%s", s.src.String(), rm.Id())
165+
t, err := s.el.NewTransactOpts(s.w.(*wallet.EvmWallet).Skey, s.gasLimit)
159166
if err != nil {
160167
return nil, err
161168
}
@@ -243,9 +250,9 @@ func (s *sender) checkRelayResult(to uint64) {
243250
if pending {
244251
s.l.Debugf("TX %#x is not yet executed.", req.TxHash())
245252
if req.IncTxPendingCount() == txPendingMAX {
246-
s.l.Debugf("resend rm %d", req.ID())
253+
s.l.Debugf("resend rm %s", req.ID())
247254
if tx, err := s.relay(req.RelayMessage()); err != nil {
248-
s.l.Errorf("fail to resend relay message %d", req.ID())
255+
s.l.Errorf("fail to resend relay message %s", req.ID())
249256
} else {
250257
req.SetTxHash(tx.Hash())
251258
req.SetTxPendingCount(0)

e2edemo/relay.sh

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,54 @@ else
4040
fi
4141
DST_OPTIONS=$(cat ${CHAIN_CONFIG} | jq -r '.chains.'${DST}'.options // empty')
4242

43+
SRC_NETWORK_NAME=$(echo ${SRC_NETWORK} | cut -d. -f2)
44+
DST_NETWORK_NAME=$(echo ${DST_NETWORK} | cut -d. -f2)
45+
# Assume src is always an ICON chain
46+
if [ $SRC_NETWORK_NAME != icon ]; then
47+
echo "Source network is not an ICON-compatible chain: $SRC_NETWORK_NAME"
48+
exit 1
49+
fi
50+
# Determine src type
4351
if [ "x$BMV_BRIDGE" = xtrue ]; then
4452
echo "Using Bridge mode"
53+
SRC_TYPE="icon-bridge"
4554
else
4655
echo "Using BTPBlock mode"
47-
BMV_BRIDGE=false
56+
SRC_TYPE="icon-btpblock"
57+
fi
58+
# Determine dst type
59+
if [ $DST_NETWORK_NAME == icon ]; then
60+
DST_TYPE="icon-btpblock"
61+
else
62+
DST_TYPE="eth2-v2.0"
4863
fi
4964

65+
get_config() {
66+
if [ $# -gt 5 -a ${#6} -gt 0 ]; then
67+
echo '{
68+
"address": "'$1'",
69+
"endpoint": "'$2'",
70+
"key_store": "'$3'",
71+
"key_password": "'$4'",
72+
"type": "'$5'",
73+
"options": '$6'
74+
}' | tr -d [:space:]
75+
else
76+
echo '{
77+
"address": "'$1'",
78+
"endpoint": "'$2'",
79+
"key_store": "'$3'",
80+
"key_password": "'$4'",
81+
"type": "'$5'"
82+
}' | tr -d [:space:]
83+
fi
84+
}
85+
SRC_CONFIG=$(get_config "$SRC_ADDRESS" "$SRC_ENDPOINT" "$SRC_KEY_STORE" "$SRC_KEY_PASSWORD" "$SRC_TYPE" "$SRC_OPTIONS")
86+
DST_CONFIG=$(get_config "$DST_ADDRESS" "$DST_ENDPOINT" "$DST_KEY_STORE" "$DST_KEY_PASSWORD" "$DST_TYPE" "$DST_OPTIONS")
87+
5088
${RELAY_BIN} \
89+
--base_dir .relay \
5190
--direction both \
52-
--src.address ${SRC_ADDRESS} \
53-
--src.endpoint ${SRC_ENDPOINT} \
54-
--src.key_store ${SRC_KEY_STORE} \
55-
--src.key_password ${SRC_KEY_PASSWORD} \
56-
--src.bridge_mode=${BMV_BRIDGE} \
57-
${SRC_OPTIONS:+--dst.options $SRC_OPTIONS} \
58-
--dst.address ${DST_ADDRESS} \
59-
--dst.endpoint ${DST_ENDPOINT} \
60-
--dst.key_store ${DST_KEY_STORE} \
61-
--dst.key_password ${DST_KEY_PASSWORD} \
62-
${DST_OPTIONS:+--dst.options $DST_OPTIONS} \
91+
--src_config ${SRC_CONFIG} \
92+
--dst_config ${DST_CONFIG} \
6393
start

0 commit comments

Comments
 (0)