Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pkg/txm/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,20 @@
toAddress = tx.ToAddress
}

var dualBroadcastParams *string
if meta != nil && meta.DualBroadcast != nil && *meta.DualBroadcast {
dualBroadcastParams = meta.DualBroadcastParams
}

message := &svrv1.TxMessage{
Hash: txHash.String(),
FromAddress: fromAddress.String(),
ToAddress: toAddress.String(),
Nonce: strconv.FormatUint(*tx.Nonce, 10),
CreatedAt: time.Now().UnixMicro(),
ChainId: m.chainID.String(),
FeedAddress: destAddress,
Hash: txHash.String(),
FromAddress: fromAddress.String(),
ToAddress: toAddress.String(),
Nonce: strconv.FormatUint(*tx.Nonce, 10),
CreatedAt: time.Now().UnixMicro(),
ChainId: m.chainID.String(),
FeedAddress: destAddress,
DualBroadcastParams: dualBroadcastParams,

Check failure on line 150 in pkg/txm/metrics.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unknown field DualBroadcastParams in struct literal of type "github.com/smartcontractkit/chainlink-protos/svr/v1".TxMessage

Check failure on line 150 in pkg/txm/metrics.go

View workflow job for this annotation

GitHub Actions / build-test-matrix (., true, false)

unknown field DualBroadcastParams in struct literal of type "github.com/smartcontractkit/chainlink-protos/svr/v1".TxMessage
}

messageBytes, err := proto.Marshal(message)
Expand Down
83 changes: 83 additions & 0 deletions pkg/txm/metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package txm

import (
"encoding/json"
"strconv"
"testing"

Expand All @@ -10,6 +11,7 @@
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/beholder/beholdertest"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-evm/pkg/testutils"
"github.com/smartcontractkit/chainlink-evm/pkg/txm/types"
svrv1 "github.com/smartcontractkit/chainlink-protos/svr/v1"
Expand Down Expand Up @@ -115,6 +117,87 @@
assert.Equal(t, expectedChain.String(), actualMessage.ChainId)
assert.Equal(t, "", actualMessage.FeedAddress)
})

t.Run("populates dual_broadcast_params when tx is a dual-broadcast secondary tx", func(t *testing.T) {
// GIVEN
ctx := t.Context()
beholderTester := beholdertest.NewObserver(t)

toAddress := testutils.NewAddress()
fromAddress := testutils.NewAddress()
expectedNonce := uint64(7)
expectedChain := testutils.FixtureChainID
expectedParams := "hint=calldata&hint=logs&builder=flashbots"
isDualBroadcast := true

metaBytes, err := json.Marshal(types.TxMeta{
DualBroadcast: &isDualBroadcast,
DualBroadcastParams: &expectedParams,
})
require.NoError(t, err)
meta := sqlutil.JSON(metaBytes)

txmMetrics, err := NewTxmMetrics(expectedChain)
require.NoError(t, err)

tx := &types.Transaction{
IsPurgeable: false,
FromAddress: fromAddress,
ToAddress: toAddress,
Nonce: &expectedNonce,
Meta: &meta,
}

// WHEN
err = txmMetrics.EmitTxMessage(ctx, common.Hash{}, fromAddress, tx)
require.NoError(t, err)

// THEN
messages := beholderTester.Messages(t)
assert.Len(t, messages, 1)

var actualMessage svrv1.TxMessage
err = proto.Unmarshal(messages[0].Body, &actualMessage)
require.NoError(t, err)

require.NotNil(t, actualMessage.DualBroadcastParams)

Check failure on line 163 in pkg/txm/metrics_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

actualMessage.DualBroadcastParams undefined (type "github.com/smartcontractkit/chainlink-protos/svr/v1".TxMessage has no field or method DualBroadcastParams)
assert.Equal(t, expectedParams, *actualMessage.DualBroadcastParams)

Check failure on line 164 in pkg/txm/metrics_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

actualMessage.DualBroadcastParams undefined (type "github.com/smartcontractkit/chainlink-protos/svr/v1".TxMessage has no field or method DualBroadcastParams)
})

t.Run("does not set dual_broadcast_params for a primary (non-dual-broadcast) tx", func(t *testing.T) {
// GIVEN
ctx := t.Context()
beholderTester := beholdertest.NewObserver(t)

toAddress := testutils.NewAddress()
fromAddress := testutils.NewAddress()
expectedNonce := uint64(3)
expectedChain := testutils.FixtureChainID

txmMetrics, err := NewTxmMetrics(expectedChain)
require.NoError(t, err)

tx := &types.Transaction{
IsPurgeable: false,
FromAddress: fromAddress,
ToAddress: toAddress,
Nonce: &expectedNonce,
}

// WHEN
err = txmMetrics.EmitTxMessage(ctx, common.Hash{}, fromAddress, tx)
require.NoError(t, err)

// THEN
messages := beholderTester.Messages(t)
assert.Len(t, messages, 1)

var actualMessage svrv1.TxMessage
err = proto.Unmarshal(messages[0].Body, &actualMessage)
require.NoError(t, err)

assert.Nil(t, actualMessage.DualBroadcastParams)

Check failure on line 199 in pkg/txm/metrics_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

actualMessage.DualBroadcastParams undefined (type "github.com/smartcontractkit/chainlink-protos/svr/v1".TxMessage has no field or method DualBroadcastParams) (typecheck)
})
}

func TestReachedMaxAttempts(t *testing.T) {
Expand Down
Loading