Skip to content

Commit

Permalink
Problem: send raw tx is not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed May 8, 2024
1 parent 1dccb34 commit dde6e9c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* [\#11](https://github.com/crypto-org-chain/relayer/pull/11) Fix gasFeeCap and gasPrice when new evm tx.
* [\#1455](https://github.com/cosmos/relayer/pull/1455) Allow retry for pathEnd to avoid packet message get removed before open channel.
* [\#14](https://github.com/crypto-org-chain/relayer/pull/14) Support batch EVM transactions.
* [\#](https://github.com/crypto-org-chain/relayer/pull/) Support send raw EVM transactions.

## v0.9.3

Expand Down
63 changes: 38 additions & 25 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ type jsonrpcMessage struct {
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Error *jsonError `json:"error,omitempty"`
Result hexutil.Uint `json:"result,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
}

// SendMessagesToMempool simulates and broadcasts a transaction with the given msgs and memo.
Expand Down Expand Up @@ -228,30 +228,33 @@ func (cc *CosmosProvider) SendMessagesToMempool(
var fees sdk.Coins
if len(cc.PCfg.PrecompiledContractAddress) > 0 {
txBytes, sequence, fees, err = cc.buildEvmMessages(ctx, txf, txb)
if _, err := cc.call(ctx, []hexutil.Bytes{hexutil.Bytes(txBytes)}, "eth_sendRawTransaction"); err != nil {
return err
}
} else {
txBytes, sequence, fees, err = cc.buildMessages(ctx, txf, txb, txSignerKey)
}
done()
if err != nil {
// Account sequence mismatch errors can happen on the simulated transaction also.
if strings.Contains(err.Error(), legacyerrors.ErrWrongSequence.Error()) {
cc.handleAccountSequenceMismatchError(sequenceGuard, err)
done()
if err != nil {
// Account sequence mismatch errors can happen on the simulated transaction also.
if strings.Contains(err.Error(), legacyerrors.ErrWrongSequence.Error()) {
cc.handleAccountSequenceMismatchError(sequenceGuard, err)
}

return err
}

return err
err = cc.broadcastTx(
ctx,
txBytes,
msgs,
fees,
asyncCtx,
defaultBroadcastWaitTimeout,
asyncCallbacks,
dynamicFee,
)
}

err = cc.broadcastTx(
ctx,
txBytes,
msgs,
fees,
asyncCtx,
defaultBroadcastWaitTimeout,
asyncCallbacks,
dynamicFee,
)

if err != nil {
if strings.Contains(err.Error(), legacyerrors.ErrWrongSequence.Error()) {
cc.handleAccountSequenceMismatchError(sequenceGuard, err)
Expand Down Expand Up @@ -1998,19 +2001,19 @@ func (cc *CosmosProvider) SetWithExtensionOptions(txf tx.Factory) (tx.Factory, e
return txf.WithExtensionOptions(extOpts...), nil
}

func (cc *CosmosProvider) calculateEvmGas(ctx context.Context, arg *evmtypes.TransactionArgs) (uint64, error) {
params, err := json.Marshal([]*evmtypes.TransactionArgs{arg})
func (cc *CosmosProvider) call(ctx context.Context, arg interface{}, method string) (json.RawMessage, error) {
params, err := json.Marshal(arg)
if err != nil {
return 0, err
return nil, err
}
req := jsonrpcMessage{
Version: "2.0",
Method: "eth_estimateGas",
Method: method,
Params: params,
ID: []byte("1"),
}

var gas uint64
var result json.RawMessage
if err = retry.Do(func() error {
var buf sysbytes.Buffer
err = json.NewEncoder(&buf).Encode(req)
Expand All @@ -2037,11 +2040,21 @@ func (cc *CosmosProvider) calculateEvmGas(ctx context.Context, arg *evmtypes.Tra
if res.Error != nil {
return fmt.Errorf("res err %s", res.Error.Message)
}
gas = uint64(res.Result)
result = res.Result
return nil
}, retry.Context(ctx), rtyAtt, rtyDel, rtyErr); err != nil {
return nil, err
}
return result, nil
}

func (cc *CosmosProvider) calculateEvmGas(ctx context.Context, arg *evmtypes.TransactionArgs) (uint64, error) {
res, err := cc.call(ctx, []*evmtypes.TransactionArgs{arg}, "eth_estimateGas")
var result hexutil.Uint
if err = json.Unmarshal(res, &result); err != nil {
return 0, err
}
gas := uint64(result)
return gas, nil
}

Expand Down

0 comments on commit dde6e9c

Please sign in to comment.