Skip to content

Commit 3c6f24d

Browse files
authored
Merge pull request #764 from ava-labs/throttle-account-txs
Throttle account txs
2 parents 8a5f7e9 + 3283272 commit 3c6f24d

File tree

11 files changed

+198
-133
lines changed

11 files changed

+198
-133
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ The most complicated example case that can arise above is that a feature depends
4040

4141
Publishing all of the commits mentioned above to GitHub branches will enable running E2E tests through the CI.
4242

43-
> [!TIP]
44-
> Running the tests locally doesn't require publishing the `subnet-evm` commit since `./scripts/e2e_test.sh` takes a flag specifying a local checkout of the `subnet-evm` repository.
45-
4643
## Releases
4744
GoReleaser is used to build the binaries of the services and also Docker images with those binaries. The monorepo feature of GoReleaser Pro is used to automate the release flow in response to tags like `signature-aggregator/v0.0.0`. The release actions in .github/workflows automate this, but the release build can also be run locally. Be sure to install the "pro" distribution of the command line utility, so that it can parse the `monorepo` key. For example:
4845

messages/off-chain-registry/message_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (m *messageHandler) SendMessage(
192192
return common.Hash{}, err
193193
}
194194

195-
txHash, err := m.destinationClient.SendTx(
195+
receipt, err := m.destinationClient.SendTx(
196196
signedMessage,
197197
m.registryAddress.Hex(),
198198
addProtocolVersionGasLimit,
@@ -206,7 +206,7 @@ func (m *messageHandler) SendMessage(
206206
return common.Hash{}, err
207207
}
208208
m.logger.Info("Sent message to destination chain")
209-
return txHash, nil
209+
return receipt.TxHash, nil
210210
}
211211

212212
func (m *messageHandler) LoggerWithContext(logger logging.Logger) logging.Logger {

messages/teleporter/message_handler.go

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"github.com/ava-labs/icm-services/messages"
2020
pbDecider "github.com/ava-labs/icm-services/proto/pb/decider"
2121
"github.com/ava-labs/icm-services/relayer/config"
22-
"github.com/ava-labs/icm-services/utils"
2322
"github.com/ava-labs/icm-services/vms"
2423
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
2524
"github.com/ava-labs/subnet-evm/core/types"
@@ -289,7 +288,7 @@ func (m *messageHandler) SendMessage(
289288
return common.Hash{}, err
290289
}
291290

292-
txHash, err := m.destinationClient.SendTx(
291+
receipt, err := m.destinationClient.SendTx(
293292
signedMessage,
294293
m.protocolAddress.Hex(),
295294
gasLimit,
@@ -300,37 +299,34 @@ func (m *messageHandler) SendMessage(
300299
return common.Hash{}, err
301300
}
302301

303-
// Wait for the message to be included in a block before returning
304-
receipt, err := m.waitForReceipt(signedMessage, m.destinationClient, txHash, m.teleporterMessageID)
305-
if err != nil {
306-
return common.Hash{}, err
307-
}
302+
txHash := receipt.TxHash
303+
308304
if receipt.Status != types.ReceiptStatusSuccessful {
309305
// Check if the message has already been delivered to the destination chain
310306
delivered, err := m.getTeleporterMessenger().MessageReceived(&bind.CallOpts{}, m.teleporterMessageID)
311307
if err != nil {
312308
m.logger.Error(
313309
"Failed to check if message has been delivered to destination chain.",
314310
zap.Error(err),
315-
zap.String("txID", txHash.String()),
311+
zap.Stringer("txID", txHash),
316312
)
317313
return common.Hash{}, fmt.Errorf("failed to check if message has been delivered: %w", err)
318314
}
319315
if delivered {
320-
m.logger.Info("Execution reverted: message already delivered to destination.", zap.String("txID", txHash.String()))
316+
m.logger.Info("Execution reverted: message already delivered to destination.", zap.Stringer("txID", txHash))
321317
return txHash, nil
322318
}
323319

324320
m.logger.Error(
325321
"Transaction failed",
326-
zap.String("txID", txHash.String()),
322+
zap.Stringer("txID", txHash),
327323
)
328324
return common.Hash{}, fmt.Errorf("transaction failed with status: %d", receipt.Status)
329325
}
330326

331327
m.logger.Info(
332328
"Delivered message to destination chain",
333-
zap.String("txID", txHash.String()),
329+
zap.Stringer("txID", txHash),
334330
)
335331
return txHash, nil
336332
}
@@ -339,30 +335,6 @@ func (m *messageHandler) LoggerWithContext(logger logging.Logger) logging.Logger
339335
return logger.With(m.logFields...)
340336
}
341337

342-
func (m *messageHandler) waitForReceipt(
343-
signedMessage *warp.Message,
344-
destinationClient vms.DestinationClient,
345-
txHash common.Hash,
346-
teleporterMessageID ids.ID,
347-
) (*types.Receipt, error) {
348-
var receipt *types.Receipt
349-
operation := func() (err error) {
350-
callCtx, callCtxCancel := context.WithTimeout(context.Background(), utils.DefaultRPCTimeout)
351-
defer callCtxCancel()
352-
receipt, err = destinationClient.Client().(ethclient.Client).TransactionReceipt(callCtx, txHash)
353-
return err
354-
}
355-
err := utils.WithRetriesTimeout(m.logger, operation, destinationClient.TxInclusionTimeout(), "waitForReceipt")
356-
if err != nil {
357-
m.logger.Error(
358-
"Failed to get transaction receipt",
359-
zap.Error(err),
360-
)
361-
return nil, err
362-
}
363-
return receipt, nil
364-
}
365-
366338
// parseTeleporterMessage returns the Warp message's corresponding Teleporter message from the cache if it exists.
367339
// Otherwise parses the Warp message payload.
368340
func (f *factory) parseTeleporterMessage(

messages/teleporter/message_handler_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package teleporter
66
import (
77
"math/big"
88
"testing"
9-
"time"
109

1110
"github.com/ava-labs/avalanchego/ids"
1211
"github.com/ava-labs/avalanchego/utils/logging"
@@ -326,19 +325,10 @@ func TestSendMessageAlreadyDelivered(t *testing.T) {
326325
mockClient.EXPECT().
327326
Client().
328327
Return(mockEthClient).
329-
Times(2)
330-
331-
mockClient.EXPECT().
332-
TxInclusionTimeout().
333-
Return(time.Second * 1).
334328
Times(1)
335329

336330
mockClient.EXPECT().
337331
SendTx(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
338-
Times(1)
339-
340-
mockEthClient.EXPECT().
341-
TransactionReceipt(gomock.Any(), gomock.Any()).
342332
Return(
343333
&types.Receipt{
344334
Status: types.ReceiptStatusFailed,

relayer/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,16 @@ If your temporary directory is not writable, the unit tests may fail with messag
436436

437437
### E2E Tests
438438

439-
E2E tests are ran as part of CI, but can also be ran locally with the `--local` flag. To run the E2E tests locally, you'll need to install Gingko following the instructions [here](https://onsi.github.io/ginkgo/#installing-ginkgo)
440-
441-
Next, provide the path to the `subnet-evm` repository and the path to a writeable data directory (this example uses `~/subnet-evm` and `~/tmp/e2e-test`) to use for the tests:
439+
To run the E2E tests locally, you'll need to install Gingko following the instructions [here](https://onsi.github.io/ginkgo/#installing-ginkgo). Run the tests using the dedicated script:
442440

443441
```bash
444-
./scripts/e2e_test.sh --local --subnet-evm ~/subnet-evm --data-dir ~/tmp/e2e-test
442+
./scripts/e2e_test.sh
445443
```
446444

447445
To run a specific E2E test, specify the environment variable `GINKGO_FOCUS`, which will then look for [test descriptions](./tests/e2e_test.go#L68) that match the provided input. For example, to run the `Basic Relay` test:
448446

449447
```bash
450-
GINKGO_FOCUS="Basic" ./scripts/e2e_test.sh --local --subnet-evm ~/subnet-evm --data-dir ~/tmp/e2e-test
448+
GINKGO_FOCUS="Basic" ./scripts/e2e_test.sh
451449
```
452450

453451
The E2E tests use the `TeleporterMessenger` contract deployment transaction specified in the following files:

relayer/api/relay_message.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,22 @@ func relayMessageAPIHandler(logger logging.Logger, messageCoordinator *relayer.M
6363
return
6464
}
6565

66+
if !common.IsHexAddress(req.SourceAddress) {
67+
logger.Warn("Invalid source address")
68+
http.Error(w, "invalid source address", http.StatusBadRequest)
69+
return
70+
}
71+
address := common.HexToAddress(req.SourceAddress)
72+
6673
warpMessageInfo := &types.WarpMessageInfo{
67-
SourceAddress: common.HexToAddress(req.SourceAddress),
74+
SourceAddress: address,
6875
UnsignedMessage: unsignedMessage,
6976
}
70-
77+
logger.Info(
78+
"Processing manual warp message",
79+
zap.Stringer("sourceAddress", address),
80+
zap.Stringer("messageID", unsignedMessage.ID()),
81+
)
7182
txHash, err := messageCoordinator.ProcessWarpMessage(warpMessageInfo)
7283
if err != nil {
7384
logger.Error("Error processing message", zap.Error(err))

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ go build -o tests/cmd/decider/decider ./tests/cmd/decider/
3737

3838
"$root"/scripts/generate.sh
3939

40-
go test -tags testing $VERBOSE ./...
40+
go test -tags testing -timeout 30s $VERBOSE ./...

vms/destination_client.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ package vms
77

88
import (
99
"fmt"
10-
"time"
1110

1211
"github.com/ava-labs/avalanchego/ids"
1312
"github.com/ava-labs/avalanchego/utils/logging"
1413
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
1514
"github.com/ava-labs/icm-services/relayer/config"
1615
"github.com/ava-labs/icm-services/vms/evm"
16+
"github.com/ava-labs/subnet-evm/core/types"
1717
"github.com/ethereum/go-ethereum/common"
1818
"go.uber.org/zap"
1919
)
@@ -25,7 +25,7 @@ type DestinationClient interface {
2525
// SendTx constructs the transaction from warp primitives, and sends to the configured destination chain endpoint.
2626
// Returns the hash of the sent transaction.
2727
// TODO: Make generic for any VM.
28-
SendTx(signedMessage *warp.Message, toAddress string, gasLimit uint64, callData []byte) (common.Hash, error)
28+
SendTx(signedMessage *warp.Message, toAddress string, gasLimit uint64, callData []byte) (*types.Receipt, error)
2929

3030
// Client returns the underlying client for the destination chain
3131
Client() interface{}
@@ -38,9 +38,6 @@ type DestinationClient interface {
3838

3939
// BlockGasLimit returns destination blockchain block gas limit
4040
BlockGasLimit() uint64
41-
42-
// TxInclusionTimeout returns the timeout for waiting for a transaction to be included on the destination chain
43-
TxInclusionTimeout() time.Duration
4441
}
4542

4643
func NewDestinationClient(

0 commit comments

Comments
 (0)