Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add avalanche support #1

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4357c91
init avalanche support
n0cte Apr 4, 2023
b73066d
fix port number calculation
n0cte Apr 4, 2023
1d0d7eb
optimize port and certs generation
n0cte Apr 7, 2023
abaae7f
add dummy implementation for SendIBCTransfer
n0cte Apr 7, 2023
232496f
add logic for different internal chains
n0cte Apr 10, 2023
6b80506
add subnet configuration
n0cte Apr 10, 2023
406e1c7
add chain initialization with subnet
n0cte Apr 10, 2023
a9af612
add avalanche utils
n0cte Apr 10, 2023
78d129f
change subnet configuration
n0cte Apr 11, 2023
a57c46a
add containers creation
n0cte Apr 21, 2023
de3e545
change file locations
n0cte Apr 21, 2023
9833ba7
add logic avalanche chain
n0cte Apr 25, 2023
2e8aa73
change port locations
n0cte Apr 25, 2023
378b15c
remove debug log level, use default info level
ramilexe Apr 25, 2023
e72f531
fix staking port
ramilexe Apr 25, 2023
79b4d49
all nodes look to zero node
n0cte Apr 25, 2023
7f2ff5a
specify public ip
n0cte Apr 25, 2023
6033a21
tidy initial avalanche impl
agouin Apr 28, 2023
c9e130c
Merge pull request #2 from strangelove-ventures/andrew/initial_avalan…
ramilexe Apr 28, 2023
1c2f6a6
add permissions for reading files from container
n0cte Apr 28, 2023
f7333ed
add avalanche subnet support (#3)
n0cte May 5, 2023
d73429a
Merge branch 'main' into avalanche-support
ramilexe May 5, 2023
1f83213
go mod tidy
ramilexe May 5, 2023
9682243
Add subnets tracking (#4)
n0cte May 10, 2023
a76763a
fix timeouts
ramilexe May 10, 2023
018bcae
add types to interact with different chains (#5)
n0cte Oct 24, 2023
47b612d
fix genesis construction (#6)
n0cte Oct 31, 2023
33b9b2e
fix eth address calculation (#7)
n0cte Nov 7, 2023
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
26 changes: 26 additions & 0 deletions chain/avalanche/clientc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package avalanche

import (
"context"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
)

type CChainClient struct {
}

func NewCChainClient(rpcHost string, pk string) (ibc.AvalancheSubnetClient, error) {
return new(CChainClient), nil
}

func (cchain *CChainClient) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error {
panic("not implemented")
}

func (cchain *CChainClient) Height(ctx context.Context) (uint64, error) {
panic("not implemented")
}

func (cchain *CChainClient) GetBalance(ctx context.Context, address string, denom string) (int64, error) {
panic("not implemented")
}
27 changes: 27 additions & 0 deletions chain/avalanche/clientp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package avalanche

import (
"context"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
)

type PChainClient struct {
}

func NewPChainClient(rpcHost string, pk string) (ibc.AvalancheSubnetClient, error) {
return new(PChainClient), nil
}

func (pchain *PChainClient) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error {
panic("not implemented")
}

func (pchain *PChainClient) Height(ctx context.Context) (uint64, error) {
//platformvm.NewClient(fmt.Sprintf("http://127.0.0.1:%s", n.RPCPort())).GetHeight(ctx)
panic("not implemented")
}

func (pchain *PChainClient) GetBalance(ctx context.Context, address string, denom string) (int64, error) {
panic("not implemented")
}
26 changes: 26 additions & 0 deletions chain/avalanche/clientx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package avalanche

import (
"context"

"github.com/strangelove-ventures/interchaintest/v7/ibc"
)

type XChainClient struct {
}

func NewXChainClient(rpcHost string, pk string) (ibc.AvalancheSubnetClient, error) {
return new(XChainClient), nil
}

func (xchain *XChainClient) SendFunds(ctx context.Context, keyName string, amount ibc.WalletAmount) error {
panic("not implemented")
}

func (xchain *XChainClient) Height(ctx context.Context) (uint64, error) {
panic("not implemented")
}

func (xchain *XChainClient) GetBalance(ctx context.Context, address string, denom string) (int64, error) {
panic("not implemented")
}
38 changes: 38 additions & 0 deletions chain/avalanche/lib/chain_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package lib

import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"
)

type ChainID struct {
Name string
Number uint32
}

var (
FormatChainID = regexp.MustCompile(`^([a-zA-Z]+)-(\d+)$`)
ErrBadChainID = errors.New("networkID has bad format")
)

func (cid ChainID) String() string {
return fmt.Sprintf("%d", cid.Number)
}

func ParseChainID(str string) (*ChainID, error) {
if !FormatChainID.Match([]byte(str)) {
return nil, ErrBadChainID
}
raw := strings.Split(str, "-")
num, err := strconv.ParseUint(raw[1], 10, 0)
if err != nil {
return nil, ErrBadChainID
}
return &ChainID{
Name: raw[0],
Number: uint32(num),
}, nil
}
83 changes: 83 additions & 0 deletions chain/avalanche/lib/network.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package lib

import (
"context"
"errors"
"fmt"
"io"
"net"
"syscall"
"time"

"github.com/ava-labs/avalanchego/api/info"
"go.uber.org/zap"
)

func IsOpened(host string, port string) bool {
conn, err := net.DialTimeout("tcp", net.JoinHostPort(host, port), time.Second)
if err != nil {
return false
}

if conn != nil {
conn.Close()
return true
}

return false
}

func WaitPort(ctx context.Context, host, port string) error {
var err error
for done := false; !done && err == nil; {
select {
case <-ctx.Done():
err = fmt.Errorf("WaitPort(%s, %s) context closed", host, port)
default:
done = IsOpened(host, port)
}
}
return err
}

func WaitNode(ctx context.Context, host, port string, logger *zap.Logger) error {
err := WaitPort(ctx, host, port)
if err != nil {
return err
}

time.Sleep(10 * time.Second)

client := info.NewClient(fmt.Sprintf("http://%s:%s", host, port))
for done := false; !done && err == nil; {
select {
case <-ctx.Done():
return fmt.Errorf("context closed")
default:
xdone, xerr := client.IsBootstrapped(ctx, "X")
if errors.Is(xerr, io.EOF) || errors.Is(xerr, syscall.ECONNREFUSED) {
xerr = nil
}
pdone, perr := client.IsBootstrapped(ctx, "P")
if errors.Is(perr, io.EOF) || errors.Is(perr, syscall.ECONNREFUSED) {
perr = nil
}
cdone, cerr := client.IsBootstrapped(ctx, "C")
if errors.Is(cerr, io.EOF) || errors.Is(cerr, syscall.ECONNREFUSED) {
cerr = nil
}
logger.Info(
"bootstrap status",
zap.Boolp("x", &xdone),
zap.Boolp("p", &pdone),
zap.Boolp("c", &cdone),
)

done = xdone && pdone && cdone
err = errors.Join(xerr, perr, cerr)
time.Sleep(5 * time.Second)
}
}

return err
}
Loading