Skip to content

Commit

Permalink
fix chain params for solana
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 committed Jul 3, 2024
1 parent 87b52e2 commit 60be21c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
1 change: 0 additions & 1 deletion cmd/zetae2e/config/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, account confi
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("solana rpc is empty")
}
solanaClient := rpc.New(conf.RPCs.SolanaRPC)
fmt.Printf("solana client URL: %s\n", conf.RPCs.SolanaRPC)
if solanaClient == nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get solana client")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"

"github.com/davecgh/go-spew/spew"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/runner"
)
Expand All @@ -19,7 +18,7 @@ func RunnerFromConfig(
logger *runner.Logger,
opts ...runner.E2ERunnerOption,
) (*runner.E2ERunner, error) {
spew.Dump("RunnerFromConfig conf struct", conf)
//spew.Dump("RunnerFromConfig conf struct", conf)
// initialize clients
btcRPCClient,
solanaClient,
Expand Down
48 changes: 38 additions & 10 deletions e2e/txserver/zeta_tx_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txserver

import (
"context"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
Expand Down Expand Up @@ -189,6 +190,11 @@ func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes
return nil, err
}

{
tx := txBuilder.GetTx()
fmt.Printf("txBuilder.GetTx(): fee %s, gas %d", tx.GetFee().String(), tx.GetGas())
}

// Sign tx
err = tx.Sign(zts.txFactory, account, txBuilder, true)
if err != nil {
Expand All @@ -202,6 +208,7 @@ func (zts ZetaTxServer) BroadcastTx(account string, msg sdktypes.Msg) (*sdktypes
}

func broadcastWithBlockTimeout(zts ZetaTxServer, txBytes []byte) (*sdktypes.TxResponse, error) {
fmt.Printf("broadcasting tx:\n%s\n", base64.StdEncoding.EncodeToString(txBytes))
res, err := zts.clientCtx.BroadcastTx(txBytes)
if err != nil {
if res == nil {
Expand All @@ -222,11 +229,13 @@ func broadcastWithBlockTimeout(zts ZetaTxServer, txBytes []byte) (*sdktypes.TxRe
for {
select {
case <-exitAfter:
return nil, fmt.Errorf("timed out after waiting for tx to get included in the block: %d", zts.blockTimeout)
return nil, fmt.Errorf("timed out after waiting for tx to get included in the block: %d; tx hash %s", zts.blockTimeout, res.TxHash)
case <-time.After(time.Millisecond * 100):
resTx, err := zts.clientCtx.Client.Tx(context.TODO(), hash, false)

if err == nil {
return mkTxResult(zts.clientCtx, resTx)
txr, err := mkTxResult(zts.clientCtx, resTx)
return txr, err
}
}
}
Expand Down Expand Up @@ -367,14 +376,33 @@ func (zts ZetaTxServer) DeploySystemContractsAndZRC20(
return "", "", "", "", "", fmt.Errorf("failed to deploy btc zrc20: %s", err.Error())
}

//chainParams := getNewEVMChainParams(newRunner)
//adminAddr, err := newRunner.ZetaTxServer.GetAccountAddressFromName(utils.FungibleAdminName)
//require.NoError(r, err)
//
//_, err = zts.BroadcastTx(utils.FungibleAdminName, observertypes.NewMsgUpdateChainParams(
// adminAddr,
// chainParams,
//))
// FIXME: config this
chainParams := observertypes.ChainParams{
ChainId: chains.SolanaLocalnet.ChainId,
IsSupported: true,
GatewayAddress: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d",
BallotThreshold: sdktypes.MustNewDecFromStr("0.66"),
ConfirmationCount: 32,
GasPriceTicker: 100,
InboundTicker: 5,
OutboundTicker: 5,
OutboundScheduleInterval: 10,
OutboundScheduleLookahead: 10,
MinObserverDelegation: sdktypes.MustNewDecFromStr("1"),
}
msg := observertypes.NewMsgUpdateChainParams(
addr.String(),
&chainParams,
)
err = msg.ValidateBasic()
if err != nil {
return "", "", "", "", "", fmt.Errorf("failed to validate chain params: %s", err.Error())
}
_, err = zts.BroadcastTx(account, msg)
if err != nil {
fmt.Printf("failed to update chain params: %s\n", err.Error())
return "", "", "", "", "", fmt.Errorf("failed to update chain params (FungibleAdminName): %s", err.Error())
}
//require.NoError(r, err)

// deploy sol zrc20
Expand Down
7 changes: 7 additions & 0 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func DecodeAddressFromChainID(chainID int64, addr string, additionalChains []Cha
return ethcommon.HexToAddress(addr).Bytes(), nil
case IsBitcoinChain(chainID, additionalChains):
return []byte(addr), nil
case IsSolanaChain(chainID, additionalChains):
return []byte(addr), nil
default:
return nil, fmt.Errorf("chain (%d) not supported", chainID)
}
Expand All @@ -112,6 +114,11 @@ func IsBitcoinChain(chainID int64, additionalChains []Chain) bool {
return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_bitcoin, additionalChains))
}

// IsSolanaChain returns true if the chain is a Solana chain
func IsSolanaChain(chainID int64, additionalChains []Chain) bool {
return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_solana_consensus, additionalChains))
}

// IsEthereumChain returns true if the chain is an Ethereum chain
// additionalChains is a list of additional chains to search from
// in practice, it is used in the protocol to dynamically support new chains without doing an upgrade
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/solana/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (o *Observer) ObserveInbound() error {
Memo []byte
}
transaction, _ := tx.Transaction.GetTransaction()
instruction := transaction.Message.Instructions[0] // TODO: parse not only the first instruction
instruction := transaction.Message.Instructions[0] // FIXME: parse not only the first instruction
data := instruction.Data
pk, _ := transaction.Message.Program(instruction.ProgramIDIndex)
log.Info().Msgf("Program ID: %s", pk)
Expand Down

0 comments on commit 60be21c

Please sign in to comment.