Skip to content
Merged
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
18 changes: 11 additions & 7 deletions integration-tests/templates/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,32 @@ PublicKey = ""
[[Aptos.Nodes]]
Name = 'primary'
URL = "http://chainlink-aptos.devnet:8080/v1"
MaxConcurrentRequests = 500
Timeout = '30s'

[Aptos.BalanceMonitor]
BalancePollPeriod = '10s'

# TODO: migrate config types as time.Duration ('10s') instead of number (10)
# TODO: missing configs are not merged with defaults: https://smartcontract-it.atlassian.net/browse/NONEVM-810
[Aptos.TransactionManager]
BroadcastChanSize = 100
ConfirmPollSecs = 2
ConfirmPollInterval = '2s'
DefaultMaxGasAmount = 200000
MaxSimulateAttempts = 5
MaxSubmitRetryAttempts = 10
SubmitDelayDuration = 3 # seconds
TxExpirationSecs = 10 # seconds
SubmitRetryDelay = '3s'
TxExpirationTimeout = '10s'
MaxTxRetryAttempts = 5
PruneIntervalSecs = 14400 # 60 * 60 * 4 = 4 hours
PruneTxExpirationSecs = 7200 # 60 * 60 * 2 = 2 hours
PruneInterval = '4h'
PruneTxExpiration = '2h'

[Aptos.WriteTargetCap]
ConfirmerPollPeriod = '300ms'
ConfirmerTimeout = '10s'

[Aptos.AptosService]
SubmitPollTimeout = '10s'
SimulateTx = true

[[EVM]]
ChainID = '1337'
MinContractPayment = '0'
Expand Down
10 changes: 4 additions & 6 deletions relayer/aptos_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"math/big"
"time"

aptos_sdk "github.com/aptos-labs/aptos-go-sdk"
"github.com/aptos-labs/aptos-go-sdk/bcs"
Expand Down Expand Up @@ -228,7 +227,7 @@ func (s *aptosService) SubmitTransaction(ctx context.Context, req commonaptos.Su
},
publicKey,
entryFn,
true, // simulateTx
*s.chain.Config().AptosService.SimulateTx,
// TODO: add expected simulation failures to save gas on reported transmissions
)
if enqueueErr != nil {
Expand All @@ -237,11 +236,10 @@ func (s *aptosService) SubmitTransaction(ctx context.Context, req commonaptos.Su
}
s.logger.Infow("SubmitTransaction: enqueued successfully", "txID", txID)

// TODO: dont use txmgr config, create and use workflow/cre config PLEX-2598
maximumWaitTime := time.Duration(*s.chain.Config().TransactionManager.TxExpirationSecs) * time.Second
s.logger.Infow("SubmitTransaction: polling for status", "txID", txID, "maximumWaitTime", maximumWaitTime)
pollTimeout := s.chain.Config().AptosService.SubmitPollTimeout.Duration()
s.logger.Infow("SubmitTransaction: polling for status", "txID", txID, "pollTimeout", pollTimeout)

retryCtx, cancel := context.WithTimeout(ctx, maximumWaitTime)
retryCtx, cancel := context.WithTimeout(ctx, pollTimeout)
defer cancel()
txStatus, err := retry.Do(retryCtx, s.logger, func(_ context.Context) (commonaptos.TransactionStatus, error) {
txStatus, txStatusErr := s.chain.TxManager().GetStatus(txID)
Expand Down
34 changes: 34 additions & 0 deletions relayer/aptosservice/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package aptosservice

import (
"time"

"github.com/smartcontractkit/chainlink-common/pkg/config"
)

func ptr[T any](v T) *T { return &v }

// Config defines the Aptos service configuration.
// Pointer fields are used for TOML deserialization — nil means "not set by user".
// After calling Resolve(), all fields are guaranteed non-nil.
type Config struct {
SubmitPollTimeout *config.Duration `toml:"SubmitPollTimeout"`
SimulateTx *bool `toml:"SimulateTx"`
}

// DefaultConfigSet is the default configuration for the Aptos service.
var DefaultConfigSet = Config{
SubmitPollTimeout: config.MustNewDuration(10 * time.Second),
SimulateTx: ptr(true),
}

// Resolve fills nil fields with defaults. After calling Resolve, all fields are guaranteed non-nil.
func (c *Config) Resolve() {
if c.SubmitPollTimeout == nil {
v := *DefaultConfigSet.SubmitPollTimeout
c.SubmitPollTimeout = &v
}
if c.SimulateTx == nil {
c.SimulateTx = ptr(*DefaultConfigSet.SimulateTx)
}
}
43 changes: 43 additions & 0 deletions relayer/aptosservice/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package aptosservice

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestResolve_AllDefaults(t *testing.T) {
t.Parallel()

cfg := Config{}
cfg.Resolve()

assert.Equal(t, DefaultConfigSet.SubmitPollTimeout, cfg.SubmitPollTimeout)
assert.Equal(t, DefaultConfigSet.SimulateTx, cfg.SimulateTx)
}

func TestResolve_PartialOverride(t *testing.T) {
t.Parallel()

cfg := Config{
SimulateTx: ptr(false),
}
cfg.Resolve()

assert.Equal(t, false, *cfg.SimulateTx)
assert.Equal(t, 10*time.Second, cfg.SubmitPollTimeout.Duration())
}

func TestResolve_ExplicitFalse(t *testing.T) {
t.Parallel()

cfg := Config{
SimulateTx: ptr(false),
}
cfg.Resolve()

assert.Equal(t, false, *cfg.SimulateTx,
"explicit false must not be overwritten by default true")
assert.Equal(t, DefaultConfigSet.SubmitPollTimeout, cfg.SubmitPollTimeout)
}
5 changes: 2 additions & 3 deletions relayer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"strconv"
"sync"
"time"

"github.com/aptos-labs/aptos-go-sdk"
"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -252,8 +251,8 @@ func (c *chain) GetClient() (aptos.AptosRpcClient, error) {
rateLimitedClient := ratelimit.NewRateLimitedClient(client,
chainInfo,
urlStr,
500, // max requests in-flight
30*time.Second, // timeout
*node.MaxConcurrentRequests,
node.Timeout.Duration(),
)
c.clientCache[urlStr] = rateLimitedClient
c.lggr.Debugw("Created and cached client", "name", node.Name, "url", node.URL)
Expand Down
9 changes: 6 additions & 3 deletions relayer/chainreader/chainreader_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ func runGetLatestValueTest(t *testing.T, logger logger.Logger, rpcUrl string, ac
Address: accountAddress.String(),
}

logPoller, err := logpoller.NewLogPoller(logger, chainInfo, getClient, nil, nil)
lpCfg := logpoller.DefaultConfigSet
logPoller, err := logpoller.NewLogPoller(logger, chainInfo, getClient, nil, &lpCfg)
require.NoError(t, err)

chainReader := NewChainReader(logger, rateLimitedClient, config, nil, logPoller)
Expand Down Expand Up @@ -590,7 +591,8 @@ func runQueryKeyPersistentTest(t *testing.T, logger logger.Logger, rpcUrl string
},
}

logPoller, err := logpoller.NewLogPoller(logger, chainInfo, getClient, db, nil)
lpCfg := logpoller.DefaultConfigSet
logPoller, err := logpoller.NewLogPoller(logger, chainInfo, getClient, db, &lpCfg)
require.NoError(t, err)
err = logPoller.Start(context.Background())
require.NoError(t, err)
Expand Down Expand Up @@ -979,7 +981,8 @@ func TestLoopChainReaderPersistent(t *testing.T) {
setupTestDatabase(t, db)

// Create ChainReader with persistence enabled.
logPoller, err := logpoller.NewLogPoller(lg, chainInfo, getClient, db, nil)
lpCfg := logpoller.DefaultConfigSet
logPoller, err := logpoller.NewLogPoller(lg, chainInfo, getClient, db, &lpCfg)
require.NoError(t, err)
err = logPoller.Start(context.Background())
require.NoError(t, err)
Expand Down
56 changes: 35 additions & 21 deletions relayer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"errors"
"fmt"
"strings"
"time"

"github.com/aptos-labs/aptos-go-sdk"
"github.com/pelletier/go-toml/v2"

"github.com/smartcontractkit/chainlink-common/pkg/config"

"github.com/smartcontractkit/chainlink-aptos/relayer/aptosservice"
"github.com/smartcontractkit/chainlink-aptos/relayer/logpoller"
"github.com/smartcontractkit/chainlink-aptos/relayer/monitor"
"github.com/smartcontractkit/chainlink-aptos/relayer/txm"
Expand All @@ -19,23 +20,9 @@ import (
// Name of the chain family (e.g., "ethereum", "solana", "aptos")
const ChainFamilyName = "aptos"

var DefaultConfigSet = ConfigSet{
TransactionManager: txm.DefaultConfigSet,
LogPoller: logpoller.DefaultConfigSet,
BalanceMonitor: monitor.DefaultBalanceConfig,
WriteTargetCap: write_target.DefaultConfigSet,
}

type ConfigSet struct { //nolint:revive
TransactionManager txm.Config
LogPoller logpoller.Config
BalanceMonitor monitor.GenericBalanceConfig
WriteTargetCap write_target.Config
}

type WorkflowConfig struct {
ForwarderAddress string
// FromAddress string
// FromAddress string
PublicKey string
}

Expand All @@ -45,11 +32,31 @@ type Chain struct {
BalanceMonitor *monitor.GenericBalanceConfig `toml:"BalanceMonitor"`
WriteTargetCap *write_target.Config `toml:"WriteTargetCap"`
Workflow *WorkflowConfig `toml:"Workflow"`
AptosService *aptosservice.Config `toml:"AptosService"`
}

func ptr[T any](v T) *T { return &v }

var DefaultNodeConfig = Node{
MaxConcurrentRequests: ptr(int64(500)),
Timeout: config.MustNewDuration(30 * time.Second),
}

type Node struct {
Name *string
URL *config.URL
Name *string `toml:"Name"`
URL *config.URL `toml:"URL"`
MaxConcurrentRequests *int64 `toml:"MaxConcurrentRequests"`
Timeout *config.Duration `toml:"Timeout"`
}

func (n *Node) Resolve() {
if n.MaxConcurrentRequests == nil {
n.MaxConcurrentRequests = ptr(*DefaultNodeConfig.MaxConcurrentRequests)
}
if n.Timeout == nil {
v := *DefaultNodeConfig.Timeout
n.Timeout = &v
}
}

func (n *Node) ValidateConfig() (err error) {
Expand Down Expand Up @@ -105,6 +112,15 @@ func (cfg *TOMLConfig) applyDefaults() {
}
cfg.WriteTargetCap.Resolve()

if cfg.AptosService == nil {
cfg.AptosService = &aptosservice.Config{}
}
cfg.AptosService.Resolve()

for _, node := range cfg.Nodes {
node.Resolve()
}

// Set network name defaults
if cfg.NetworkName == "" {
network, err := GetNetworkConfig(cfg.ChainID)
Expand Down Expand Up @@ -156,9 +172,7 @@ func (c *TOMLConfig) ValidateConfig() (err error) {

// If network name is set, ensure it matches a known network if chain ID is known
if c.NetworkName != "" {
var network aptos.NetworkConfig
network, err = GetNetworkConfig(c.ChainID)
if err == nil && c.NetworkName != network.Name {
if network, lookupErr := GetNetworkConfig(c.ChainID); lookupErr == nil && c.NetworkName != network.Name {
err = errors.Join(err, config.ErrInvalid{Name: "NetworkName", Value: c.NetworkName, Msg: fmt.Sprintf("does not match known network (%s) for chain ID", network.Name)})
}
}
Expand Down
Loading
Loading