Skip to content

Commit

Permalink
filter out non burn messages
Browse files Browse the repository at this point in the history
  • Loading branch information
bd21 committed Nov 25, 2023
1 parent 4c43f8a commit 1a295ac
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func StartProcessor(cfg config.Config, logger log.Logger, processingQueue chan *
// if a filter's condition is met, mark as filtered
if filterDisabledCCTPRoutes(cfg, logger, msg) ||
filterInvalidDestinationCallers(cfg, logger, msg) ||
filterNonWhitelistedChannels(cfg, logger, msg) {
filterNonWhitelistedChannels(cfg, logger, msg) ||
filterMessages(cfg, logger, msg) {
msg.Status = types.Filtered
}

Expand Down Expand Up @@ -230,6 +231,12 @@ func filterNonWhitelistedChannels(cfg config.Config, logger log.Logger, msg *typ
return true
}

// filterMessages filters out non-burn messages. It returns true if the message is not a burn.
func filterMessages(_ config.Config, logger log.Logger, msg *types.MessageState) bool {
logger.Info(fmt.Sprintf("Filtered tx %s because it's a not a burn", msg.SourceTxHash))
return msg.Type != types.Mint
}

func LookupKey(sourceTxHash string, messageType string) string {
return fmt.Sprintf("%s-%s", sourceTxHash, messageType)
}
Expand Down
27 changes: 27 additions & 0 deletions cmd/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,30 @@ func TestProcessNonWhitelistedChannel(t *testing.T) {
require.Equal(t, types.Filtered, actualState.Status)

}

// created message -> not \ -> filtered
func TestProcessNonBurnMessageWhenDisabled(t *testing.T) {
setupTest()

go cmd.StartProcessor(cfg, logger, processingQueue, sequenceMap)

emptyBz := make([]byte, 32)
expectedState := &types.MessageState{
SourceTxHash: "123",
Type: "",
IrisLookupId: "a404f4155166a1fc7ffee145b5cac6d0f798333745289ab1db171344e226ef0c",
Status: types.Created,
SourceDomain: 0,
DestDomain: 4,
DestinationCaller: emptyBz,
}

processingQueue <- expectedState

time.Sleep(2 * time.Second)

actualState, ok := cmd.State.Load(cmd.LookupKey(expectedState.SourceTxHash, expectedState.Type))
require.True(t, ok)
require.Equal(t, types.Filtered, actualState.Status)

}
1 change: 0 additions & 1 deletion types/message_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func EvmLogToMessageState(abi abi.ABI, messageSent abi.Event, log *ethtypes.Log)

messageState = &MessageState{
IrisLookupId: hashedHexStr,
Type: Mint,
Status: Created,
SourceDomain: message.SourceDomain,
DestDomain: message.DestinationDomain,
Expand Down

0 comments on commit 1a295ac

Please sign in to comment.