Skip to content

Commit

Permalink
Merge branch 'txmv2_stuck_tx_detection' into txmv2_enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
dimriou committed Nov 19, 2024
2 parents 6828e38 + b16643d commit 3ba3a31
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions core/chains/evm/config/chain_scoped_txmv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ func (t *txmv2Config) BlockTime() *time.Duration {
return &d
}

func (t *txmv2Config) CustomUrl() *url.URL {
return t.c.CustomUrl.URL()
func (t *txmv2Config) CustomURL() *url.URL {
return t.c.CustomURL.URL()
}
2 changes: 1 addition & 1 deletion core/chains/evm/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type ClientErrors interface {
type TxmV2 interface {
Enabled() bool
BlockTime() *time.Duration
CustomUrl() *url.URL
CustomURL() *url.URL
}

type Transactions interface {
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (c *Chain) ValidateConfig() (err error) {
type TxmV2 struct {
Enabled *bool `toml:",omitempty"`
BlockTime *commonconfig.Duration `toml:",omitempty"`
CustomUrl *commonconfig.URL `toml:",omitempty"`
CustomURL *commonconfig.URL `toml:",omitempty"`
}

func (t *TxmV2) setFrom(f *TxmV2) {
Expand All @@ -489,8 +489,8 @@ func (t *TxmV2) setFrom(f *TxmV2) {
t.BlockTime = f.BlockTime
}

if v := f.CustomUrl; v != nil {
t.CustomUrl = f.CustomUrl
if v := f.CustomURL; v != nil {
t.CustomURL = f.CustomURL
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/txm/clientwrappers/dual_broadcast_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ type DualBroadcastClientKeystore interface {
type DualBroadcastClient struct {
c client.Client
keystore DualBroadcastClientKeystore
customUrl *url.URL
customURL *url.URL
}

func NewDualBroadcastClient(c client.Client, keystore DualBroadcastClientKeystore, customUrl *url.URL) *DualBroadcastClient {
func NewDualBroadcastClient(c client.Client, keystore DualBroadcastClientKeystore, customURL *url.URL) *DualBroadcastClient {
return &DualBroadcastClient{
c: c,
keystore: keystore,
customUrl: customUrl,
customURL: customURL,
}
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func (d *DualBroadcastClient) SendTransaction(ctx context.Context, tx *types.Tra

func (d *DualBroadcastClient) signAndPostMessage(ctx context.Context, address common.Address, body []byte, urlParams string) (result string, err error) {
bodyReader := bytes.NewReader(body)
postReq, err := http.NewRequestWithContext(ctx, http.MethodPost, d.customUrl.String()+"?"+urlParams, bodyReader)
postReq, err := http.NewRequestWithContext(ctx, http.MethodPost, d.customURL.String()+"?"+urlParams, bodyReader)
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txm/storage/inmemory_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestDeleteAttemptForUnconfirmedTx(t *testing.T) {
err = m.DeleteAttemptForUnconfirmedTx(nonce, attempt)
assert.NoError(t, err)

assert.Len(t, tx.Attempts, 0)
assert.Empty(t, tx.Attempts)
})
}

Expand Down
24 changes: 12 additions & 12 deletions core/chains/evm/txm/stuck_tx_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type StuckTxDetectorConfig struct {
BlockTime time.Duration
StuckTxBlockThreshold uint32
DetectionApiUrl string
DetectionURL string
}

type stuckTxDetector struct {
Expand Down Expand Up @@ -60,22 +60,22 @@ func (s *stuckTxDetector) timeBasedDetection(tx *types.Transaction) bool {
return false
}

type ApiResponse struct {
type APIResponse struct {
Status string `json:"status,omitempty"`
Hash common.Hash `json:"hash,omitempty"`
}

const (
ApiStatusPending = "PENDING"
ApiStatusIncluded = "INCLUDED"
ApiStatusFailed = "FAILED"
ApiStatusCancelled = "CANCELLED"
ApiStatusUnknown = "UNKNOWN"
APIStatusPending = "PENDING"
APIStatusIncluded = "INCLUDED"
APIStatusFailed = "FAILED"
APIStatusCancelled = "CANCELLED"
APIStatusUnknown = "UNKNOWN"
)

func (s *stuckTxDetector) dualBroadcastDetection(ctx context.Context, tx *types.Transaction) (bool, error) {
for _, attempt := range tx.Attempts {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, s.config.DetectionApiUrl+attempt.Hash.String(), nil)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, s.config.DetectionURL+attempt.Hash.String(), nil)
if err != nil {
return false, fmt.Errorf("failed to make request for txID: %v, attemptHash: %v - %w", tx.ID, attempt.Hash, err)
}
Expand All @@ -93,19 +93,19 @@ func (s *stuckTxDetector) dualBroadcastDetection(ctx context.Context, tx *types.
return false, err
}

var apiResponse ApiResponse
var apiResponse APIResponse
err = json.Unmarshal(body, &apiResponse)
if err != nil {
return false, fmt.Errorf("failed to unmarshal response for txID: %v, attemptHash: %v - %w: %s", tx.ID, attempt.Hash, err, string(body))
}
switch apiResponse.Status {
case ApiStatusPending, ApiStatusIncluded:
case APIStatusPending, APIStatusIncluded:
return false, nil
case ApiStatusFailed, ApiStatusCancelled:
case APIStatusFailed, APIStatusCancelled:
s.lggr.Debugf("TxID: %v with attempHash: %v was marked as failed/cancelled by the RPC. Transaction is now considered stuck and will be purged.",
tx.ID, attempt.Hash)
return true, nil
case ApiStatusUnknown:
case APIStatusUnknown:
continue
default:
continue
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/txm/txm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestLifecycle(t *testing.T) {
txStore := storage.NewInMemoryStoreManager(lggr, testutils.FixtureChainID)
assert.NoError(t, txStore.Add(addresses...))
txm := NewTxm(lggr, testutils.FixtureChainID, client, ab, txStore, nil, config, keystore)
var nonce uint64 = 0
var nonce uint64
// Start
client.On("PendingNonceAt", mock.Anything, address1).Return(nonce, nil).Once()
client.On("PendingNonceAt", mock.Anything, address2).Return(nonce, nil).Once()
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestTrigger(t *testing.T) {
ab := mocks.NewAttemptBuilder(t)
config := Config{BlockTime: 1 * time.Minute, RetryBlockThreshold: 10}
txm := NewTxm(lggr, testutils.FixtureChainID, client, ab, txStore, nil, config, keystore)
var nonce uint64 = 0
var nonce uint64
// Start
client.On("PendingNonceAt", mock.Anything, address).Return(nonce, nil).Once()
servicetest.Run(t, txm)
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/txmgr/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func NewTxmV2(
stuckTxDetectorConfig := txm.StuckTxDetectorConfig{
BlockTime: *txmV2Config.BlockTime(),
StuckTxBlockThreshold: *txConfig.AutoPurge().Threshold(),
DetectionApiUrl: txConfig.AutoPurge().DetectionApiUrl().String(),
DetectionURL: txConfig.AutoPurge().DetectionApiUrl().String(),
}
stuckTxDetector = txm.NewStuckTxDetector(lggr, chainConfig.ChainType(), stuckTxDetectorConfig)
}
Expand All @@ -137,7 +137,7 @@ func NewTxmV2(
}
var c txm.Client
if chainConfig.ChainType() == chaintype.ChainDualBroadcast {
c = clientwrappers.NewDualBroadcastClient(client, keyStore, txmV2Config.CustomUrl())
c = clientwrappers.NewDualBroadcastClient(client, keyStore, txmV2Config.CustomURL())
} else {
c = clientwrappers.NewChainClient(client)
}
Expand Down
4 changes: 2 additions & 2 deletions core/config/docs/chains-evm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ ResendAfterThreshold = '1m' # Default
Enabled = false # Default
# BlockTime controls the frequency of the backfill loop of TxmV2.
BlockTime = '10s' # Example
# CustomUrl configures the base url of a custom endpoint used by the ChainDualBroadcast chain type.
CustomUrl = 'https://example.api.io' # Example
# CustomURL configures the base url of a custom endpoint used by the ChainDualBroadcast chain type.
CustomURL = 'https://example.api.io' # Example

[EVM.Transactions.AutoPurge]
# Enabled enables or disables automatically purging transactions that have been idenitified as terminally stuck (will never be included on-chain). This feature is only expected to be used by ZK chains.
Expand Down
8 changes: 4 additions & 4 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9290,7 +9290,7 @@ ResendAfterThreshold controls how long to wait before re-broadcasting a transact
[EVM.TxmV2]
Enabled = false # Default
BlockTime = '10s' # Example
CustomUrl = 'https://example.api.io' # Example
CustomURL = 'https://example.api.io' # Example
```


Expand All @@ -9306,11 +9306,11 @@ BlockTime = '10s' # Example
```
BlockTime controls the frequency of the backfill loop of TxmV2.

### CustomUrl
### CustomURL
```toml
CustomUrl = 'https://example.api.io' # Example
CustomURL = 'https://example.api.io' # Example
```
CustomUrl configures the base url of a custom endpoint used by the ChainDualBroadcast chain type.
CustomURL configures the base url of a custom endpoint used by the ChainDualBroadcast chain type.

## EVM.Transactions.AutoPurge
```toml
Expand Down

0 comments on commit 3ba3a31

Please sign in to comment.