Skip to content

Commit 58a228e

Browse files
Refactor dual broadcast clients (#114)
* Refactor dual broadcast clients * Fix DetectionURL * Add verification * More changes * Update metaclient params * Add control check * Add metacalldata unpacking for verification * Nit * Add tests * Update client * Fix send transaction bug * Add fuzzing tests * Don't broadcast without SOPs * Use mapstructure for unpacking input tuple to go struct * Tidy --------- Co-authored-by: Eric Fornaciari <eric.fornaciari@smartcontract.com>
1 parent f190212 commit 58a228e

8 files changed

Lines changed: 630 additions & 20 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/kylelemons/godebug v1.1.0
1414
github.com/leanovate/gopter v0.2.11
1515
github.com/lib/pq v1.10.9
16+
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4
1617
github.com/onsi/gomega v1.36.2
1718
github.com/pelletier/go-toml/v2 v2.2.4
1819
github.com/pkg/errors v0.9.1
@@ -125,7 +126,6 @@ require (
125126
github.com/mattn/go-colorable v0.1.14 // indirect
126127
github.com/mattn/go-isatty v0.0.20 // indirect
127128
github.com/mattn/go-runewidth v0.0.16 // indirect
128-
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect
129129
github.com/mitchellh/pointerstructure v1.2.0 // indirect
130130
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
131131
github.com/modern-go/reflect2 v1.0.2 // indirect

pkg/config/toml/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,6 @@ func (c *Transactions) ValidateConfig() (err error) {
509509
if c.AutoPurge.Enabled != nil && !*c.AutoPurge.Enabled {
510510
err = multierr.Append(err, commonconfig.ErrInvalid{Name: "AutoPurge.Enabled", Value: false, Msg: "cannot be false if DualBroadcast is enabled"})
511511
}
512-
if c.AutoPurge.DetectionApiUrl == nil {
513-
err = multierr.Append(err, commonconfig.ErrMissing{Name: "AutoPurge.DetectionApiUrl", Msg: "must be set if DualBroadcast is enabled"})
514-
}
515512
if c.AutoPurge.Threshold == nil {
516513
err = multierr.Append(err, commonconfig.ErrMissing{Name: "AutoPurge.Threshold", Msg: "needs to be set if auto-purge feature is enabled"})
517514
} else if *c.AutoPurge.Threshold == 0 {

pkg/txm/clientwrappers/dual_broadcast_client.go renamed to pkg/txm/clientwrappers/dualbroadcast/flashbots_client.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package clientwrappers
1+
package dualbroadcast
22

33
import (
44
"bytes"
@@ -17,28 +17,31 @@ import (
1717

1818
"github.com/smartcontractkit/chainlink-evm/pkg/client"
1919
"github.com/smartcontractkit/chainlink-evm/pkg/keys"
20+
"github.com/smartcontractkit/chainlink-evm/pkg/txm"
2021
"github.com/smartcontractkit/chainlink-evm/pkg/txm/types"
2122
)
2223

23-
type DualBroadcastClient struct {
24+
var _ txm.Client = &FlashbotsClient{}
25+
26+
type FlashbotsClient struct {
2427
c client.Client
2528
keystore keys.MessageSigner
2629
customURL *url.URL
2730
}
2831

29-
func NewDualBroadcastClient(c client.Client, keystore keys.MessageSigner, customURL *url.URL) *DualBroadcastClient {
30-
return &DualBroadcastClient{
32+
func NewFlashbotsClient(c client.Client, keystore keys.MessageSigner, customURL *url.URL) *FlashbotsClient {
33+
return &FlashbotsClient{
3134
c: c,
3235
keystore: keystore,
3336
customURL: customURL,
3437
}
3538
}
3639

37-
func (d *DualBroadcastClient) NonceAt(ctx context.Context, address common.Address, blockNumber *big.Int) (uint64, error) {
40+
func (d *FlashbotsClient) NonceAt(ctx context.Context, address common.Address, blockNumber *big.Int) (uint64, error) {
3841
return d.c.NonceAt(ctx, address, blockNumber)
3942
}
4043

41-
func (d *DualBroadcastClient) PendingNonceAt(ctx context.Context, address common.Address) (uint64, error) {
44+
func (d *FlashbotsClient) PendingNonceAt(ctx context.Context, address common.Address) (uint64, error) {
4245
body := []byte(fmt.Sprintf(`{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["%s","pending"], "id":1}`, address.String()))
4346
response, err := d.signAndPostMessage(ctx, address, body, "")
4447
if err != nil {
@@ -52,7 +55,7 @@ func (d *DualBroadcastClient) PendingNonceAt(ctx context.Context, address common
5255
return nonce, nil
5356
}
5457

55-
func (d *DualBroadcastClient) SendTransaction(ctx context.Context, tx *types.Transaction, attempt *types.Attempt) error {
58+
func (d *FlashbotsClient) SendTransaction(ctx context.Context, tx *types.Transaction, attempt *types.Attempt) error {
5659
meta, err := tx.GetMeta()
5760
if err != nil {
5861
return err
@@ -75,7 +78,7 @@ func (d *DualBroadcastClient) SendTransaction(ctx context.Context, tx *types.Tra
7578
return d.c.SendTransaction(ctx, attempt.SignedTransaction)
7679
}
7780

78-
func (d *DualBroadcastClient) signAndPostMessage(ctx context.Context, address common.Address, body []byte, urlParams string) (result string, err error) {
81+
func (d *FlashbotsClient) signAndPostMessage(ctx context.Context, address common.Address, body []byte, urlParams string) (result string, err error) {
7982
bodyReader := bytes.NewReader(body)
8083
postReq, err := http.NewRequestWithContext(ctx, http.MethodPost, d.customURL.String()+"?"+urlParams, bodyReader)
8184
if err != nil {

0 commit comments

Comments
 (0)