Skip to content

Commit

Permalink
fix destination caller log
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Mar 22, 2024
1 parent 0c4a797 commit c637692
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ func filterInvalidDestinationCallers(registeredDomains map[types.Domain]types.Ch
logger.Error("No chain registered for domain", "domain", msg.DestDomain)
return true
}
validCaller := chain.IsDestinationCaller(msg.DestinationCaller)
validCaller, address := chain.IsDestinationCaller(msg.DestinationCaller)

if validCaller {
// we do not want to filter this message if valid caller
return false
}

logger.Info(fmt.Sprintf("Filtered tx %s from %d to %d due to destination caller: %s)",
msg.SourceTxHash, msg.SourceDomain, msg.DestDomain, msg.DestinationCaller))
msg.SourceTxHash, msg.SourceDomain, msg.DestDomain, address))
return true
}

Expand Down
12 changes: 8 additions & 4 deletions ethereum/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,24 @@ func (e *Ethereum) LastFlushedBlock() uint64 {
return e.lastFlushedBlock
}

func (e *Ethereum) IsDestinationCaller(destinationCaller []byte) bool {
func (e *Ethereum) IsDestinationCaller(destinationCaller []byte) (isCaller bool, readableAddress string) {
zeroByteArr := make([]byte, 32)

decodedMinter, err := hex.DecodeString(strings.ReplaceAll(e.minterAddress, "0x", ""))
if err != nil && bytes.Equal(destinationCaller, zeroByteArr) {
return true
return true, ""
}

decodedMinterPadded := make([]byte, 32)
copy(decodedMinterPadded[12:], decodedMinter)

return bytes.Equal(destinationCaller, zeroByteArr) || bytes.Equal(destinationCaller, decodedMinterPadded)
}
encodedCaller := "0x" + hex.EncodeToString(destinationCaller)[24:]

if bytes.Equal(destinationCaller, zeroByteArr) || bytes.Equal(destinationCaller, decodedMinterPadded) {
return true, encodedCaller
}
return false, encodedCaller
}
func (e *Ethereum) InitializeClients(ctx context.Context, logger log.Logger) error {
var err error

Expand Down
8 changes: 4 additions & 4 deletions noble/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ func (n *Noble) LastFlushedBlock() uint64 {
return n.lastFlushedBlock
}

func (n *Noble) IsDestinationCaller(destinationCaller []byte) bool {
func (n *Noble) IsDestinationCaller(destinationCaller []byte) (isCaller bool, readableAddress string) {
zeroByteArr := make([]byte, 32)

if bytes.Equal(destinationCaller, zeroByteArr) {
return true
return true, ""
}

bech32DestinationCaller, err := decodeDestinationCaller(destinationCaller)
if err != nil {
return false
return false, bech32DestinationCaller
}

return bech32DestinationCaller == n.minterAddress
return bech32DestinationCaller == n.minterAddress, bech32DestinationCaller
}

// DecodeDestinationCaller transforms an encoded Noble cctp address into a noble bech32 address
Expand Down
5 changes: 3 additions & 2 deletions types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ type Chain interface {
LastFlushedBlock() uint64

// IsDestinationCaller returns true if the specified destination caller is the minter for the specified domain OR
// if destination caller is a zero byte array(left empty in deposit for burn message)
IsDestinationCaller(destinationCaller []byte) bool
// if destination caller is a zero byte array(left empty in deposit for burn message). It also returns a human readable
// version of the destination caller address provided in the message.
IsDestinationCaller(destinationCaller []byte) (isCaller bool, readableAddress string)

// InitializeClients initializes the rpc and or websocket clients.
InitializeClients(
Expand Down

0 comments on commit c637692

Please sign in to comment.