Skip to content

Commit

Permalink
Change tx.meta to pointers
Browse files Browse the repository at this point in the history
Send secondary tx even if primary fails
  • Loading branch information
george-dorin committed Nov 13, 2024
1 parent bd51049 commit 0efa3be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions common/txmgr/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ type TxMeta[ADDR types.Hashable, TX_HASH types.Hashable] struct {
SeqNumbers []uint64 `json:"SeqNumbers,omitempty"`

// Dual Broadcast
DualBroadcast bool `json:"DualBroadcast,omitempty"`
DualBroadcastParams string `json:"DualBroadcastParams,omitempty"`
DualBroadcast *bool `json:"DualBroadcast,omitempty"`
DualBroadcastParams *string `json:"DualBroadcastParams,omitempty"`
}

type TxAttempt[
Expand Down
19 changes: 11 additions & 8 deletions core/services/ocrcommon/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocrcommon

import (
"context"
errors2 "errors"
"math/big"
"net/url"
"slices"
Expand Down Expand Up @@ -227,20 +228,21 @@ type ocr2FeedsDualTransmission struct {

func (t *ocr2FeedsDualTransmission) CreateEthTransaction(ctx context.Context, toAddress common.Address, payload []byte, txMeta *txmgr.TxMeta) error {
// Primary transmission
err := t.transmitter.CreateEthTransaction(ctx, toAddress, payload, txMeta)
if err != nil {
return err
}
errPrimary := t.transmitter.CreateEthTransaction(ctx, toAddress, payload, txMeta)
errPrimary = errors.Wrap(errPrimary, "skipped primary transmission")

if txMeta == nil {
txMeta = &txmgr.TxMeta{}
}

txMeta.DualBroadcast = true
txMeta.DualBroadcastParams = t.urlParams()
dualBroadcast := true
dualBroadcastParams := t.urlParams()

txMeta.DualBroadcast = &dualBroadcast
txMeta.DualBroadcastParams = &dualBroadcastParams

// Secondary transmission
_, err = t.transmitter.txm.CreateTransaction(ctx, txmgr.TxRequest{
_, errSecondary := t.transmitter.txm.CreateTransaction(ctx, txmgr.TxRequest{
FromAddress: t.secondaryFromAddress,
ToAddress: t.secondaryContractAddress,
EncodedPayload: payload,
Expand All @@ -250,7 +252,8 @@ func (t *ocr2FeedsDualTransmission) CreateEthTransaction(ctx context.Context, to
Meta: txMeta,
})

return errors.Wrap(err, "skipped secondary transmission")
errSecondary = errors.Wrap(errSecondary, "skipped secondary transmission")
return errors2.Join(errPrimary, errSecondary)
}

func (t *ocr2FeedsDualTransmission) FromAddress(ctx context.Context) common.Address {
Expand Down
4 changes: 2 additions & 2 deletions core/services/ocrcommon/transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ func Test_DualTransmitter(t *testing.T) {
case secondaryFromAddress:
// Secondary transmission
assert.Equal(t, tx.ToAddress, secondaryContractAddress, "unexpected secondary toAddress")
assert.True(t, tx.Meta.DualBroadcast, "DualBroadcast should be true")
assert.Equal(t, "key1=value1&key2=value2&key2=value3&key3=value4&key3=value5&key3=value6", tx.Meta.DualBroadcastParams, "DualBroadcastParams not equal")
assert.True(t, *tx.Meta.DualBroadcast, "DualBroadcast should be true")
assert.Equal(t, "key1=value1&key2=value2&key2=value3&key3=value4&key3=value5&key3=value6", *tx.Meta.DualBroadcastParams, "DualBroadcastParams not equal")
secondaryTxConfirmed = true
default:
// Should never be reached
Expand Down

0 comments on commit 0efa3be

Please sign in to comment.