Skip to content

Commit

Permalink
more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Jan 16, 2024
1 parent b8ae30b commit d12db36
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
11 changes: 6 additions & 5 deletions cmd/circle/attestation.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package circle

import (
"cosmossdk.io/log"
"encoding/json"
"fmt"
"github.com/strangelove-ventures/noble-cctp-relayer/config"
"github.com/strangelove-ventures/noble-cctp-relayer/types"
"io"
"net/http"
"time"

"cosmossdk.io/log"
"github.com/strangelove-ventures/noble-cctp-relayer/config"
"github.com/strangelove-ventures/noble-cctp-relayer/types"
)

// CheckAttestation checks the iris api for attestation status and returns true if attestation is complete
func CheckAttestation(cfg config.Config, logger log.Logger, irisLookupId string) *types.AttestationResponse {
logger.Debug(fmt.Sprintf("Checking attestation for %s%s%s", cfg.Circle.AttestationBaseUrl, "0x", irisLookupId))
func CheckAttestation(cfg config.Config, logger log.Logger, irisLookupId string, txHash string, sourceDomain, destDomain uint32) *types.AttestationResponse {
logger.Debug(fmt.Sprintf("Checking attestation for %s%s%s for source tx %s from %d to %d", cfg.Circle.AttestationBaseUrl, "0x", irisLookupId, txHash, sourceDomain, destDomain))

client := http.Client{Timeout: 2 * time.Second}

Expand Down
9 changes: 5 additions & 4 deletions cmd/circle/attestation_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package circle_test

import (
"os"
"testing"

"cosmossdk.io/log"
"github.com/rs/zerolog"
"github.com/strangelove-ventures/noble-cctp-relayer/cmd/circle"
"github.com/strangelove-ventures/noble-cctp-relayer/config"
"github.com/stretchr/testify/require"
"os"
"testing"
)

var cfg config.Config
Expand All @@ -19,12 +20,12 @@ func init() {
}

func TestAttestationIsReady(t *testing.T) {
resp := circle.CheckAttestation(cfg, logger, "85bbf7e65a5992e6317a61f005e06d9972a033d71b514be183b179e1b47723fe")
resp := circle.CheckAttestation(cfg, logger, "85bbf7e65a5992e6317a61f005e06d9972a033d71b514be183b179e1b47723fe", "", 0, 4)
require.NotNil(t, resp)
require.Equal(t, "complete", resp.Status)
}

func TestAttestationNotFound(t *testing.T) {
resp := circle.CheckAttestation(cfg, logger, "not an attestation")
resp := circle.CheckAttestation(cfg, logger, "not an attestation", "", 0, 4)
require.Nil(t, resp)
}
1 change: 1 addition & 0 deletions cmd/noble/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func StartListener(cfg config.Config, logger log.Logger, processingQueue chan *t
for _, tx := range response.Result.Txs {
parsedMsgs, err := types.NobleLogToMessageState(tx)
if err != nil {
logger.Error("unable to parse Noble log to message state", "err", err.Error())
continue
}
for _, parsedMsg := range parsedMsgs {
Expand Down
2 changes: 1 addition & 1 deletion cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func StartProcessor(cfg config.Config, logger log.Logger, processingQueue chan *

// if the message is burned or pending, check for an attestation
if msg.Status == types.Created || msg.Status == types.Pending {
response := circle.CheckAttestation(cfg, logger, msg.IrisLookupId)
response := circle.CheckAttestation(cfg, logger, msg.IrisLookupId, msg.SourceTxHash, msg.SourceDomain, msg.DestDomain)
if response != nil {
if msg.Status == types.Created && response.Status == "pending_confirmations" {
logger.Debug("Attestation is created but still pending confirmations for 0x" + msg.IrisLookupId + ". Retrying...")
Expand Down
15 changes: 10 additions & 5 deletions types/message_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,25 @@ func EvmLogToMessageState(abi abi.ABI, messageSent abi.Event, log *ethtypes.Log)
}

// NobleLogToMessageState transforms a Noble log into a messageState
func NobleLogToMessageState(tx Tx) (messageStates []*MessageState, err error) {
func NobleLogToMessageState(tx Tx) ([]*MessageState, error) {
var eventsList []struct {
Events []Event `json:"events"`
}
err = json.Unmarshal([]byte(tx.TxResult.Log), &eventsList)
if err != nil {
if err := json.Unmarshal([]byte(tx.TxResult.Log), &eventsList); err != nil {
return nil, errors.New("unable to parse log events")
}

for _, log := range eventsList {
for _, event := range log.Events {
var messageStates []*MessageState

for i, log := range eventsList {
for j, event := range log.Events {
if event.Type == "circle.cctp.v1.MessageSent" {
fmt.Printf("Saw cctp message %s - %d:%d\n", tx.Hash, i, j)
var parsed bool
var parseErrs error
for _, attr := range event.Attributes {
if attr.Key == "message" {
fmt.Printf("Saw message attribute %s - %d:%d\n", tx.Hash, i, j)
encoded := attr.Value[1 : len(attr.Value)-1]
rawMessageSentBytes, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
Expand Down Expand Up @@ -129,6 +132,8 @@ func NobleLogToMessageState(tx Tx) (messageStates []*MessageState, err error) {
}

messageStates = append(messageStates, messageState)

fmt.Printf("Appended transfer from 4 to %d\n", msg.DestinationDomain)
}
}
if !parsed {
Expand Down

0 comments on commit d12db36

Please sign in to comment.