-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename integration tests, write one for burning on noble, create list…
…ener/broadcaster/minter
- Loading branch information
Showing
11 changed files
with
363 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package ethereum | ||
|
||
import ( | ||
"context" | ||
"cosmossdk.io/log" | ||
"encoding/hex" | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
ctypes "github.com/cometbft/cometbft/rpc/core/types" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
"github.com/cosmos/cosmos-sdk/types/bech32" | ||
"github.com/strangelove-ventures/noble-cctp-relayer/config" | ||
"github.com/strangelove-ventures/noble-cctp-relayer/types" | ||
"io" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// Broadcast broadcasts a message to Ethereum | ||
func Broadcast( | ||
cfg config.Config, | ||
logger log.Logger, | ||
msg *types.MessageState, | ||
sequenceMap *types.SequenceMap, | ||
) (*ctypes.ResultBroadcastTx, error) { | ||
|
||
// build txn | ||
attestationBytes, err := hex.DecodeString(msg.Attestation[2:]) | ||
if err != nil { | ||
return nil, errors.New("unable to decode message attestation") | ||
} | ||
|
||
// get priv key | ||
ethereumAddress := cfg.Networks.Minters[0].MinterAddress | ||
keyBz, _ := hex.DecodeString(cfg.Networks.Minters[4].MinterPrivateKey) | ||
privKey := secp256k1.PrivKey{Key: keyBz} | ||
|
||
// sign tx | ||
addr, _ := bech32.ConvertAndEncode("noble", privKey.PubKey().Address()) | ||
if addr != ethereumAddress { | ||
return nil, fmt.Errorf("private key (%s) does not match noble address (%s)", addr, ethereumAddress) | ||
} | ||
|
||
// set up eth client | ||
|
||
// broadcast txn | ||
|
||
for attempt := 0; attempt <= cfg.Networks.Destination.Ethereum.BroadcastRetries; attempt++ { | ||
logger.Debug(fmt.Sprintf( | ||
"Broadcasting %s message from %d to %d: with source tx hash %s", | ||
msg.Type, | ||
msg.SourceDomain, | ||
msg.DestDomain, | ||
msg.SourceTxHash)) | ||
|
||
// TODO Account sequence lock is implemented but gets out of sync with remote. | ||
// accountSequence := sequenceMap.Next(cfg.Networks.Destination.Noble.DomainId) | ||
nonce, err := GetEthereumAccountNonce(cfg.Networks.Destination.Ethereum.RPC, ethereumAddress) | ||
if err != nil { | ||
logger.Error("unable to retrieve account nonce") | ||
} | ||
|
||
// broadcast txn | ||
// TODO do for Erh | ||
rpcResponse, err := rpcClient.BroadcastTxSync(context.Background(), txBytes) | ||
if err == nil && rpcResponse.Code == 0 { | ||
msg.Status = types.Complete | ||
return rpcResponse, nil | ||
} | ||
if err != nil { | ||
logger.Error(fmt.Sprintf("error during broadcast: %s", err.Error())) | ||
logger.Info(fmt.Sprintf("Retrying in %d seconds", cfg.Networks.Destination.Noble.BroadcastRetryInterval)) | ||
time.Sleep(time.Duration(cfg.Networks.Destination.Noble.BroadcastRetryInterval) * time.Second) | ||
continue | ||
} | ||
// check tx response code | ||
logger.Error(fmt.Sprintf("received non zero : %d - %s", rpcResponse.Code, rpcResponse.Log)) | ||
logger.Info(fmt.Sprintf("Retrying in %d seconds", cfg.Networks.Destination.Noble.BroadcastRetryInterval)) | ||
time.Sleep(time.Duration(cfg.Networks.Destination.Noble.BroadcastRetryInterval) * time.Second) | ||
} | ||
msg.Status = types.Failed | ||
|
||
return nil, errors.New("reached max number of broadcast attempts") | ||
} | ||
|
||
// TODO | ||
func GetEthereumAccountNonce(urlBase string, address string) (int64, error) { | ||
rawResp, err := http.Get(fmt.Sprintf("%s/cosmos/auth/v1beta1/accounts/%s", urlBase, address)) | ||
if err != nil { | ||
return 0, errors.New("unable to fetch account number, sequence") | ||
} | ||
body, _ := io.ReadAll(rawResp.Body) | ||
var resp types.AccountResp | ||
err = json.Unmarshal(body, &resp) | ||
if err != nil { | ||
return 0, errors.New("unable to parse account number, sequence") | ||
} | ||
accountNumber, _ := strconv.ParseInt(resp.AccountNumber, 10, 0) | ||
accountSequence, _ := strconv.ParseInt(resp.Sequence, 10, 0) | ||
|
||
return accountNumber, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package noble | ||
|
||
import ( | ||
"cosmossdk.io/log" | ||
"fmt" | ||
"github.com/strangelove-ventures/noble-cctp-relayer/config" | ||
"github.com/strangelove-ventures/noble-cctp-relayer/types" | ||
) | ||
|
||
func StartListener(cfg config.Config, logger log.Logger, processingQueue chan *types.MessageState) { | ||
// set up client | ||
|
||
logger.Info(fmt.Sprintf( | ||
"Starting Noble listener at block %d looking back %d blocks", | ||
cfg.Networks.Source.Noble.StartBlock, | ||
cfg.Networks.Source.Noble.LookbackPeriod)) | ||
|
||
// constantly query for blocks | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package noble | ||
|
||
import ( | ||
"cosmossdk.io/log" | ||
"github.com/rs/zerolog" | ||
"github.com/strangelove-ventures/noble-cctp-relayer/config" | ||
"github.com/strangelove-ventures/noble-cctp-relayer/types" | ||
"github.com/stretchr/testify/require" | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
var cfg config.Config | ||
var logger log.Logger | ||
var processingQueue chan *types.MessageState | ||
|
||
func init() { | ||
cfg = config.Parse("../../.ignore/unit_tests.yaml") | ||
|
||
logger = log.NewLogger(os.Stdout, log.LevelOption(zerolog.ErrorLevel)) | ||
processingQueue = make(chan *types.MessageState, 10000) | ||
} | ||
|
||
// TODO | ||
func TestStartListener(t *testing.T) { | ||
|
||
cfg.Networks.Source.Noble.StartBlock = 9702735 | ||
cfg.Networks.Source.Noble.LookbackPeriod = 0 | ||
go StartListener(cfg, logger, processingQueue) | ||
|
||
time.Sleep(5 * time.Second) | ||
|
||
msg := <-processingQueue | ||
|
||
expectedMsg := &types.MessageState{ | ||
IrisLookupId: "a404f4155166a1fc7ffee145b5cac6d0f798333745289ab1db171344e226ef0c", | ||
Type: "mint", | ||
Status: "created", | ||
SourceDomain: 0, | ||
DestDomain: 4, | ||
SourceTxHash: "0xe1d7729de300274ee3a2fd20ba179b14a8e3ffcd9d847c506b06760f0dad7802", | ||
} | ||
require.Equal(t, expectedMsg.IrisLookupId, msg.IrisLookupId) | ||
require.Equal(t, expectedMsg.Type, msg.Type) | ||
require.Equal(t, expectedMsg.Status, msg.Status) | ||
require.Equal(t, expectedMsg.SourceDomain, msg.SourceDomain) | ||
require.Equal(t, expectedMsg.DestDomain, msg.DestDomain) | ||
require.Equal(t, expectedMsg.SourceTxHash, msg.SourceTxHash) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.