From 3745640b156f62e4ef7faf11f681b5f6bf6bcd84 Mon Sep 17 00:00:00 2001 From: aalu1418 <50029043+aalu1418@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:55:28 -0600 Subject: [PATCH] add ComputeUnitLimitDefault to config + config cleanup --- pkg/monitoring/types/txdetails.go | 2 +- pkg/solana/config/config.go | 100 +++++++++++++----------------- pkg/solana/config/mocks/config.go | 18 ++++++ pkg/solana/config/toml.go | 4 ++ 4 files changed, 67 insertions(+), 57 deletions(-) diff --git a/pkg/monitoring/types/txdetails.go b/pkg/monitoring/types/txdetails.go index f5149677a..73c5cabd6 100644 --- a/pkg/monitoring/types/txdetails.go +++ b/pkg/monitoring/types/txdetails.go @@ -144,7 +144,7 @@ func ParseTx(tx *solanaGo.Transaction, programAddr solanaGo.PublicKey) (TxDetail } // find compute budget program instruction - if tx.Message.AccountKeys[instruction.ProgramIDIndex] == solanaGo.MustPublicKeyFromBase58(fees.ComputeBudgetProgram) { + if tx.Message.AccountKeys[instruction.ProgramIDIndex] == fees.ComputeBudgetProgram { // parsing compute unit price var err error txDetails.ComputeUnitPrice, err = fees.ParseComputeUnitPrice(instruction.Data) diff --git a/pkg/solana/config/config.go b/pkg/solana/config/config.go index 28698c7c3..023b72cc1 100644 --- a/pkg/solana/config/config.go +++ b/pkg/solana/config/config.go @@ -10,25 +10,26 @@ import ( ) // Global solana defaults. -var defaultConfigSet = configSet{ - BalancePollPeriod: 5 * time.Second, // poll period for balance monitoring - ConfirmPollPeriod: 500 * time.Millisecond, // polling for tx confirmation - OCR2CachePollPeriod: time.Second, // cache polling rate - OCR2CacheTTL: time.Minute, // stale cache deadline - TxTimeout: time.Minute, // timeout for send tx method in client - TxRetryTimeout: 10 * time.Second, // duration for tx rebroadcasting to RPC node - TxConfirmTimeout: 30 * time.Second, // duration before discarding tx as unconfirmed - SkipPreflight: true, // to enable or disable preflight checks - Commitment: rpc.CommitmentConfirmed, - MaxRetries: new(uint), // max number of retries (default = *new(uint) = 0). when config.MaxRetries < 0, interpreted as MaxRetries = nil and rpc node will do a reasonable number of retries +var defaultConfigSet = Chain{ + BalancePollPeriod: config.MustNewDuration(5 * time.Second), // poll period for balance monitoring + ConfirmPollPeriod: config.MustNewDuration(500 * time.Millisecond), // polling for tx confirmation + OCR2CachePollPeriod: config.MustNewDuration(time.Second), // cache polling rate + OCR2CacheTTL: config.MustNewDuration(time.Minute), // stale cache deadline + TxTimeout: config.MustNewDuration(time.Minute), // timeout for send tx method in client + TxRetryTimeout: config.MustNewDuration(10 * time.Second), // duration for tx rebroadcasting to RPC node + TxConfirmTimeout: config.MustNewDuration(30 * time.Second), // duration before discarding tx as unconfirmed + SkipPreflight: ptr(true), // to enable or disable preflight checks + Commitment: ptr(string(rpc.CommitmentConfirmed)), + MaxRetries: ptr(int64(0)), // max number of retries (default = 0). when config.MaxRetries < 0), interpreted as MaxRetries = nil and rpc node will do a reasonable number of retries // fee estimator - FeeEstimatorMode: "fixed", - ComputeUnitPriceMax: 1_000, - ComputeUnitPriceMin: 0, - ComputeUnitPriceDefault: 0, - FeeBumpPeriod: 3 * time.Second, // set to 0 to disable fee bumping - BlockHistoryPollPeriod: 5 * time.Second, + FeeEstimatorMode: ptr("fixed"), + ComputeUnitPriceMax: ptr(uint64(1_000)), + ComputeUnitPriceMin: ptr(uint64(0)), + ComputeUnitPriceDefault: ptr(uint64(0)), + FeeBumpPeriod: config.MustNewDuration(3 * time.Second), // set to 0 to disable fee bumping + BlockHistoryPollPeriod: config.MustNewDuration(5 * time.Second), + ComputeUnitLimitDefault: ptr(uint32(200_000)), } //go:generate mockery --name Config --output ./mocks/ --case=underscore --filename config.go @@ -51,27 +52,7 @@ type Config interface { ComputeUnitPriceDefault() uint64 FeeBumpPeriod() time.Duration BlockHistoryPollPeriod() time.Duration -} - -// opt: remove -type configSet struct { - BalancePollPeriod time.Duration - ConfirmPollPeriod time.Duration - OCR2CachePollPeriod time.Duration - OCR2CacheTTL time.Duration - TxTimeout time.Duration - TxRetryTimeout time.Duration - TxConfirmTimeout time.Duration - SkipPreflight bool - Commitment rpc.CommitmentType - MaxRetries *uint - - FeeEstimatorMode string - ComputeUnitPriceMax uint64 - ComputeUnitPriceMin uint64 - ComputeUnitPriceDefault uint64 - FeeBumpPeriod time.Duration - BlockHistoryPollPeriod time.Duration + ComputeUnitLimitDefault() uint32 } type Chain struct { @@ -91,57 +72,60 @@ type Chain struct { ComputeUnitPriceDefault *uint64 FeeBumpPeriod *config.Duration BlockHistoryPollPeriod *config.Duration + ComputeUnitLimitDefault *uint32 } func (c *Chain) SetDefaults() { if c.BalancePollPeriod == nil { - c.BalancePollPeriod = config.MustNewDuration(defaultConfigSet.BalancePollPeriod) + c.BalancePollPeriod = defaultConfigSet.BalancePollPeriod } if c.ConfirmPollPeriod == nil { - c.ConfirmPollPeriod = config.MustNewDuration(defaultConfigSet.ConfirmPollPeriod) + c.ConfirmPollPeriod = defaultConfigSet.ConfirmPollPeriod } if c.OCR2CachePollPeriod == nil { - c.OCR2CachePollPeriod = config.MustNewDuration(defaultConfigSet.OCR2CachePollPeriod) + c.OCR2CachePollPeriod = defaultConfigSet.OCR2CachePollPeriod } if c.OCR2CacheTTL == nil { - c.OCR2CacheTTL = config.MustNewDuration(defaultConfigSet.OCR2CacheTTL) + c.OCR2CacheTTL = defaultConfigSet.OCR2CacheTTL } if c.TxTimeout == nil { - c.TxTimeout = config.MustNewDuration(defaultConfigSet.TxTimeout) + c.TxTimeout = defaultConfigSet.TxTimeout } if c.TxRetryTimeout == nil { - c.TxRetryTimeout = config.MustNewDuration(defaultConfigSet.TxRetryTimeout) + c.TxRetryTimeout = defaultConfigSet.TxRetryTimeout } if c.TxConfirmTimeout == nil { - c.TxConfirmTimeout = config.MustNewDuration(defaultConfigSet.TxConfirmTimeout) + c.TxConfirmTimeout = defaultConfigSet.TxConfirmTimeout } if c.SkipPreflight == nil { - c.SkipPreflight = &defaultConfigSet.SkipPreflight + c.SkipPreflight = defaultConfigSet.SkipPreflight } if c.Commitment == nil { - c.Commitment = (*string)(&defaultConfigSet.Commitment) + c.Commitment = defaultConfigSet.Commitment } - if c.MaxRetries == nil && defaultConfigSet.MaxRetries != nil { - i := int64(*defaultConfigSet.MaxRetries) - c.MaxRetries = &i + if c.MaxRetries == nil { + c.MaxRetries = defaultConfigSet.MaxRetries } if c.FeeEstimatorMode == nil { - c.FeeEstimatorMode = &defaultConfigSet.FeeEstimatorMode + c.FeeEstimatorMode = defaultConfigSet.FeeEstimatorMode } if c.ComputeUnitPriceMax == nil { - c.ComputeUnitPriceMax = &defaultConfigSet.ComputeUnitPriceMax + c.ComputeUnitPriceMax = defaultConfigSet.ComputeUnitPriceMax } if c.ComputeUnitPriceMin == nil { - c.ComputeUnitPriceMin = &defaultConfigSet.ComputeUnitPriceMin + c.ComputeUnitPriceMin = defaultConfigSet.ComputeUnitPriceMin } if c.ComputeUnitPriceDefault == nil { - c.ComputeUnitPriceDefault = &defaultConfigSet.ComputeUnitPriceDefault + c.ComputeUnitPriceDefault = defaultConfigSet.ComputeUnitPriceDefault } if c.FeeBumpPeriod == nil { - c.FeeBumpPeriod = config.MustNewDuration(defaultConfigSet.FeeBumpPeriod) + c.FeeBumpPeriod = defaultConfigSet.FeeBumpPeriod } if c.BlockHistoryPollPeriod == nil { - c.BlockHistoryPollPeriod = config.MustNewDuration(defaultConfigSet.BlockHistoryPollPeriod) + c.BlockHistoryPollPeriod = defaultConfigSet.BlockHistoryPollPeriod + } + if c.ComputeUnitLimitDefault == nil { + c.ComputeUnitLimitDefault = defaultConfigSet.ComputeUnitLimitDefault } } @@ -162,3 +146,7 @@ func (n *Node) ValidateConfig() (err error) { } return } + +func ptr[T any](t T) *T { + return &t +} diff --git a/pkg/solana/config/mocks/config.go b/pkg/solana/config/mocks/config.go index 712850f70..56b1cca98 100644 --- a/pkg/solana/config/mocks/config.go +++ b/pkg/solana/config/mocks/config.go @@ -68,6 +68,24 @@ func (_m *Config) Commitment() rpc.CommitmentType { return r0 } +// ComputeUnitLimitDefault provides a mock function with given fields: +func (_m *Config) ComputeUnitLimitDefault() uint32 { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for ComputeUnitLimitDefault") + } + + var r0 uint32 + if rf, ok := ret.Get(0).(func() uint32); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(uint32) + } + + return r0 +} + // ComputeUnitPriceDefault provides a mock function with given fields: func (_m *Config) ComputeUnitPriceDefault() uint64 { ret := _m.Called() diff --git a/pkg/solana/config/toml.go b/pkg/solana/config/toml.go index 90657fd2c..1910dd01d 100644 --- a/pkg/solana/config/toml.go +++ b/pkg/solana/config/toml.go @@ -277,6 +277,10 @@ func (c *TOMLConfig) BlockHistoryPollPeriod() time.Duration { return c.Chain.BlockHistoryPollPeriod.Duration() } +func (c *TOMLConfig) ComputeUnitLimitDefault() uint32 { + return *c.Chain.ComputeUnitLimitDefault +} + func (c *TOMLConfig) ListNodes() Nodes { return c.Nodes }