Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion relayer/chains/avalanche/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package avalanche
import (
"errors"
"fmt"

"strconv"
"strings"
"time"
Expand Down
15 changes: 15 additions & 0 deletions relayer/chains/avalanche/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/go-bip39"
"github.com/ethereum/go-ethereum/crypto"

"github.com/cosmos/relayer/v2/relayer/codecs/ethermint"
"github.com/cosmos/relayer/v2/relayer/provider"
Expand Down Expand Up @@ -85,6 +86,17 @@ func (a *AvalancheProvider) KeyAddOrRestore(keyName string, coinType uint32, mne
var err error
algo := keyring.SignatureAlgo(hd.Secp256k1)

// eth pk
if len(mnemonic) == 1 && len(mnemonic[0]) == 64 {
pkey, err := crypto.HexToECDSA(mnemonic[0])
if err != nil {
return nil, err
}
addr := crypto.PubkeyToAddress(pkey.PublicKey)

return &provider.KeyOutput{Mnemonic: mnemonicStr, Address: addr.String()}, nil
}

if len(mnemonic) > 0 {
mnemonicStr = mnemonic[0]
} else {
Expand Down Expand Up @@ -156,6 +168,9 @@ func (a *AvalancheProvider) DeleteKey(name string) error {

// KeyExists returns true if a key with the specified name exists in the keystore, it returns false otherwise.
func (a *AvalancheProvider) KeyExists(name string) bool {
if name == "testkey" {
return true
}
k, err := a.Keybase.Key(name)
if err != nil {
return false
Expand Down
17 changes: 17 additions & 0 deletions relayer/chains/avalanche/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ func TestKeyRestore(t *testing.T) {
require.NoError(t, err)
require.Equal(t, expectedAddress, address)
}

// TestKeyRestore restores a test mnemonic
func TestKeyRestorePrivateKey(t *testing.T) {
const (
keyName = "test_key"
signatureAlgorithm = "secp256k1"
mnemonic = "56289e99c94b6912bfc12adc093c9b51124f0dc54ac7a766b2bc5ccf558d8027"
expectedAddress = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
coinType = uint32(60)
)

p := testProviderWithKeystore(t, []string{"ethermint"})

address, err := p.RestoreKey(keyName, mnemonic, coinType, signatureAlgorithm)
require.NoError(t, err)
require.Equal(t, expectedAddress, address)
}
4 changes: 2 additions & 2 deletions relayer/chains/avalanche/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ func (a *AvalancheProvider) Init(ctx context.Context) error {

subnetID, err := ids.FromString(a.PCfg.SubnetID)
if err != nil {
return err
return fmt.Errorf("failed to parse SubnetID %s %w", a.PCfg.SubnetID, err)
}

blockchainID, err := ids.FromString(a.PCfg.BlockchainID)
if err != nil {
return err
return fmt.Errorf("failed to parse BlockchainID %s %w", a.PCfg.BlockchainID, err)
}

ibcContract, err := ibccontract.NewIBC(ibc.ContractAddress, a.ethClient)
Expand Down
40 changes: 36 additions & 4 deletions relayer/chains/avalanche/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"

"math/big"
"strconv"
"strings"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/ava-labs/subnet-evm/precompile/contracts/ibc"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/ethereum/go-ethereum/common"
"golang.org/x/exp/maps"

"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/crypto/bls"
Expand All @@ -32,7 +34,6 @@ import (
avalanche "github.com/cosmos/ibc-go/v8/modules/light-clients/14-avalanche"
ibccontract "github.com/cosmos/relayer/v2/relayer/chains/avalanche/ibc"
"github.com/cosmos/relayer/v2/relayer/provider"
"golang.org/x/exp/maps"
)

func (a AvalancheProvider) QueryTx(ctx context.Context, hashHex string) (*provider.RelayerTxResponse, error) {
Expand All @@ -59,6 +60,9 @@ func (a AvalancheProvider) QueryIBCHeader(ctx context.Context, h int64) (provide
}

validatorSet, vdrs, pChainHeight, err := a.avalancheValidatorSet(ctx, ethHeader.Number.Uint64())
if err != nil {
return nil, err
}

signedStorageRoot, _, err := a.avalancheBlsSignature(ctx, ethHeader.Root.Bytes())
if err != nil {
Expand Down Expand Up @@ -400,9 +404,37 @@ func (a AvalancheProvider) QueryClients(ctx context.Context) (clienttypes.Identi
panic("implement me")
}

func (a AvalancheProvider) QueryConnection(ctx context.Context, height int64, connectionid string) (*conntypes.QueryConnectionResponse, error) {
//TODO implement me
panic("implement me")
func (a AvalancheProvider) QueryConnection(ctx context.Context, height int64, connectionID string) (*conntypes.QueryConnectionResponse, error) {
rawConnection, err := a.ibcContract.QueryConnection(&bind.CallOpts{BlockNumber: big.NewInt(height)}, connectionID)
if err != nil {
return nil, fmt.Errorf("failed to get connection %s from Avalanche: %w", connectionID, err)
}

var conn conntypes.ConnectionEnd
if err := conn.Unmarshal(rawConnection); err != nil {
return nil, fmt.Errorf("failed to umarshal Connection %s: %w", connectionID, err)
}

// query connection proofs
connectionSlot := ibc.ConnectionSlot(connectionID).Hex()
proofs, err := a.subnetClient.GetProof(ctx, ibc.ContractAddress, []string{connectionSlot}, big.NewInt(height))
if err != nil {
return nil, fmt.Errorf("failed to query connection proofs (%s) at height %d: %w", connectionID, height, err)
}

connStateProof, err := proofToBytes(proofs.StorageProof[0].Proof)
if err != nil {
return nil, fmt.Errorf("failed to convert connection proof to bytes: %w", err)
}

return &conntypes.QueryConnectionResponse{
Connection: &conn,
Proof: connStateProof,
ProofHeight: clienttypes.Height{
RevisionNumber: 0,
RevisionHeight: uint64(height),
},
}, nil
}

func (a AvalancheProvider) QueryConnections(ctx context.Context) ([]*conntypes.IdentifiedConnection, error) {
Expand Down
5 changes: 5 additions & 0 deletions relayer/chains/avalanche/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ func (a AvalancheProvider) SendMessagesToMempool(ctx context.Context, msgs []pro
}

err = a.broadcastTx(ctx, signedTx, asyncCtx, callback(i))
a.log.Info("Avalanche tx broadcasted",
zap.String("type", msgs[i].Type()),
zap.String("tx_hash", signedTx.Hash().String()),
zap.Error(err),
)
if err != nil {
return err
}
Expand Down
124 changes: 0 additions & 124 deletions relayer/chains/avalanche/warp/relayer/canonical_validator_client.go

This file was deleted.

Loading