Skip to content

Commit a62d73d

Browse files
committed
fix bug
1 parent 8c36887 commit a62d73d

File tree

8 files changed

+72
-48
lines changed

8 files changed

+72
-48
lines changed

executor/batch/utils.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
77
sdk "github.com/cosmos/cosmos-sdk/types"
88
"github.com/cosmos/gogoproto/proto"
9+
910
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
11+
"github.com/initia-labs/opinit-bots-go/txutils"
1012
)
1113

1214
// prependLength prepends the length of the data to the data.
@@ -20,7 +22,8 @@ func prependLength(data []byte) []byte {
2022
// to decrease the size of the batch.
2123
func (bs *BatchSubmitter) emptyOracleData(pbb *cmtproto.Block) ([]byte, error) {
2224
for i, txBytes := range pbb.Data.GetTxs() {
23-
tx, err := bs.node.MustGetBroadcaster().DecodeTx(txBytes)
25+
txConfig := bs.node.GetTxConfig()
26+
tx, err := txutils.DecodeTx(txConfig, txBytes)
2427
if err != nil {
2528
// ignore not registered tx in codec
2629
continue
@@ -33,11 +36,11 @@ func (bs *BatchSubmitter) emptyOracleData(pbb *cmtproto.Block) ([]byte, error) {
3336

3437
if msg, ok := msgs[0].(*opchildtypes.MsgUpdateOracle); ok {
3538
msg.Data = []byte{}
36-
tx, err := bs.node.MustGetBroadcaster().ChangeMsgsFromTx(tx, []sdk.Msg{msg})
39+
tx, err := txutils.ChangeMsgsFromTx(txConfig, tx, []sdk.Msg{msg})
3740
if err != nil {
3841
return nil, err
3942
}
40-
convertedTxBytes, err := bs.node.MustGetBroadcaster().EncodeTx(tx)
43+
convertedTxBytes, err := txutils.EncodeTx(txConfig, tx)
4144
if err != nil {
4245
return nil, err
4346
}

executor/celestia/node.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
sdk "github.com/cosmos/cosmos-sdk/types"
99

1010
btypes "github.com/initia-labs/opinit-bots-go/node/broadcaster/types"
11+
"github.com/initia-labs/opinit-bots-go/txutils"
1112
celestiatypes "github.com/initia-labs/opinit-bots-go/types/celestia"
1213
)
1314

@@ -52,7 +53,8 @@ func (c *Celestia) BuildTxWithMessages(
5253
}
5354

5455
tx := txb.GetTx()
55-
txBytes, err = b.EncodeTx(tx)
56+
txConfig := c.node.GetTxConfig()
57+
txBytes, err = txutils.EncodeTx(txConfig, tx)
5658
if err != nil {
5759
return nil, "", err
5860
}
@@ -73,11 +75,11 @@ func (c *Celestia) BuildTxWithMessages(
7375
func (c *Celestia) PendingTxToProcessedMsgs(
7476
txBytes []byte,
7577
) ([]sdk.Msg, error) {
76-
b := c.node.MustGetBroadcaster()
78+
txConfig := c.node.GetTxConfig()
7779

7880
blobTx := &celestiatypes.BlobTx{}
7981
if err := blobTx.Unmarshal(txBytes); err == nil {
80-
pfbTx, err := b.DecodeTx(blobTx.Tx)
82+
pfbTx, err := txutils.DecodeTx(txConfig, blobTx.Tx)
8183
if err != nil {
8284
return nil, err
8385
}
@@ -91,7 +93,7 @@ func (c *Celestia) PendingTxToProcessedMsgs(
9193
}, nil
9294
}
9395

94-
tx, err := b.DecodeTx(txBytes)
96+
tx, err := txutils.DecodeTx(txConfig, txBytes)
9597
if err != nil {
9698
return nil, err
9799
}

executor/child/msgs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ func (ch Child) GetMsgFinalizeTokenDeposit(
1515
data []byte,
1616
) (sdk.Msg, error) {
1717
sender, err := ch.node.MustGetBroadcaster().GetAddressString()
18+
if err != nil {
19+
return nil, err
20+
}
21+
1822
msg := opchildtypes.NewMsgFinalizeTokenDeposit(
1923
sender,
2024
from,
@@ -37,6 +41,10 @@ func (ch Child) GetMsgUpdateOracle(
3741
data []byte,
3842
) (sdk.Msg, error) {
3943
sender, err := ch.node.MustGetBroadcaster().GetAddressString()
44+
if err != nil {
45+
return nil, err
46+
}
47+
4048
msg := opchildtypes.NewMsgUpdateOracle(
4149
sender,
4250
height,

executor/executor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (ex *Executor) makeDANode(bridgeId int64) (executortypes.DANode, error) {
177177
ex.cfg.Version, false, ex.cfg.DANodeConfig(ex.homePath),
178178
ex.db.WithPrefix([]byte(executortypes.DAHostNodeName)),
179179
ex.logger.Named(executortypes.DAHostNodeName),
180-
ex.homePath, batchInfo.BatchInfo.Submitter,
180+
ex.cfg.DABech32Prefix, batchInfo.BatchInfo.Submitter,
181181
)
182182
if ex.host.GetAddress().Equals(da.GetAddress()) {
183183
return ex.host, nil
@@ -189,7 +189,7 @@ func (ex *Executor) makeDANode(bridgeId int64) (executortypes.DANode, error) {
189189
da := celestia.NewDACelestia(ex.cfg.Version, ex.cfg.DANodeConfig(ex.homePath),
190190
ex.db.WithPrefix([]byte(executortypes.DACelestiaNodeName)),
191191
ex.logger.Named(executortypes.DACelestiaNodeName),
192-
ex.homePath, batchInfo.BatchInfo.Submitter,
192+
ex.cfg.DABech32Prefix, batchInfo.BatchInfo.Submitter,
193193
)
194194
da.Initialize(ex.batch, bridgeId)
195195
da.RegisterDAHandlers()

node/broadcaster/tx.go

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919
sdk "github.com/cosmos/cosmos-sdk/types"
2020
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
2121
"github.com/cosmos/cosmos-sdk/types/tx/signing"
22-
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
2322

2423
btypes "github.com/initia-labs/opinit-bots-go/node/broadcaster/types"
24+
"github.com/initia-labs/opinit-bots-go/txutils"
2525

2626
opchildtypes "github.com/initia-labs/OPinit/x/opchild/types"
2727
)
@@ -226,7 +226,7 @@ func (b Broadcaster) buildSimTx(info *keyring.Record, txf tx.Factory, msgs ...sd
226226
return nil, err
227227
}
228228

229-
return b.EncodeTx(txb.GetTx())
229+
return txutils.EncodeTx(b.txConfig, txb.GetTx())
230230
}
231231

232232
func (b *Broadcaster) enqueueLocalPendingTx(tx btypes.PendingTxInfo) {
@@ -257,36 +257,8 @@ func (b *Broadcaster) dequeueLocalPendingTx() {
257257
b.pendingTxs = b.pendingTxs[1:]
258258
}
259259

260-
func (b Broadcaster) EncodeTx(tx authsigning.Tx) ([]byte, error) {
261-
txBytes, err := b.txConfig.TxEncoder()(tx)
262-
if err != nil {
263-
return nil, err
264-
}
265-
return txBytes, nil
266-
}
267-
268-
func (b Broadcaster) DecodeTx(txBytes []byte) (authsigning.Tx, error) {
269-
tx, err := b.txConfig.TxDecoder()(txBytes)
270-
if err != nil {
271-
return nil, err
272-
}
273-
return tx.(authsigning.Tx), nil
274-
}
275-
276-
func (n Broadcaster) ChangeMsgsFromTx(tx authsigning.Tx, msgs []sdk.Msg) (authsigning.Tx, error) {
277-
builder, err := n.txConfig.WrapTxBuilder(tx)
278-
if err != nil {
279-
return nil, err
280-
}
281-
err = builder.SetMsgs(msgs...)
282-
if err != nil {
283-
return nil, err
284-
}
285-
return builder.GetTx(), nil
286-
}
287-
288260
// buildTxWithMessages creates a transaction from the given messages.
289-
func (b Broadcaster) DefaultBuildTxWithMessages(
261+
func (b *Broadcaster) DefaultBuildTxWithMessages(
290262
ctx context.Context,
291263
msgs []sdk.Msg,
292264
) (
@@ -311,17 +283,17 @@ func (b Broadcaster) DefaultBuildTxWithMessages(
311283
}
312284

313285
tx := txb.GetTx()
314-
txBytes, err = b.EncodeTx(tx)
286+
txBytes, err = txutils.EncodeTx(b.txConfig, tx)
315287
if err != nil {
316288
return nil, "", err
317289
}
318290
return txBytes, btypes.TxHash(txBytes), nil
319291
}
320292

321-
func (b Broadcaster) DefaultPendingTxToProcessedMsgs(
293+
func (b *Broadcaster) DefaultPendingTxToProcessedMsgs(
322294
txBytes []byte,
323295
) ([]sdk.Msg, error) {
324-
tx, err := b.DecodeTx(txBytes)
296+
tx, err := txutils.DecodeTx(b.txConfig, txBytes)
325297
if err != nil {
326298
return nil, err
327299
}

node/broadcaster/types/config.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ func (bc BroadcasterConfig) Validate() error {
5151
return fmt.Errorf("failed to parse gas price: %s", bc.GasPrice)
5252
}
5353

54-
if bc.GasPrice == "" {
55-
return fmt.Errorf("gas price is empty")
56-
}
57-
5854
if bc.Bech32Prefix == "" {
5955
return fmt.Errorf("bech32 prefix is empty")
6056
}
@@ -78,7 +74,7 @@ func (bc BroadcasterConfig) GetKeyringRecord(cdc codec.Codec, chainID string) (k
7874
return nil, nil, fmt.Errorf("failed to get key base")
7975
}
8076

81-
keyringRecord, err := bc.KeyringConfig.GetKeyRecord(keyBase, "")
77+
keyringRecord, err := bc.KeyringConfig.GetKeyRecord(keyBase, bc.Bech32Prefix)
8278
if err != nil {
8379
return nil, nil, err
8480
} else if keyringRecord == nil {

node/node.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func (n Node) GetHeight() uint64 {
160160
return n.lastProcessedBlockHeight + 1
161161
}
162162

163+
func (n Node) GetTxConfig() client.TxConfig {
164+
return n.txConfig
165+
}
166+
163167
func (n Node) HasBroadcaster() bool {
164168
return n.broadcaster != nil
165169
}

txutils/utils.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package txutils
2+
3+
import (
4+
"github.com/cosmos/cosmos-sdk/client"
5+
sdk "github.com/cosmos/cosmos-sdk/types"
6+
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
7+
)
8+
9+
func EncodeTx(txConfig client.TxConfig, tx authsigning.Tx) ([]byte, error) {
10+
txBytes, err := txConfig.TxEncoder()(tx)
11+
if err != nil {
12+
return nil, err
13+
}
14+
15+
return txBytes, nil
16+
}
17+
18+
func DecodeTx(txConfig client.TxConfig, txBytes []byte) (authsigning.Tx, error) {
19+
tx, err := txConfig.TxDecoder()(txBytes)
20+
if err != nil {
21+
return nil, err
22+
}
23+
24+
return tx.(authsigning.Tx), nil
25+
}
26+
27+
func ChangeMsgsFromTx(txConfig client.TxConfig, tx authsigning.Tx, msgs []sdk.Msg) (authsigning.Tx, error) {
28+
builder, err := txConfig.WrapTxBuilder(tx)
29+
if err != nil {
30+
return nil, err
31+
}
32+
33+
err = builder.SetMsgs(msgs...)
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
return builder.GetTx(), nil
39+
}

0 commit comments

Comments
 (0)