diff --git a/multinode/config/config.go b/multinode/config/config.go index b56eb57..73555e0 100644 --- a/multinode/config/config.go +++ b/multinode/config/config.go @@ -4,8 +4,6 @@ import ( "time" "github.com/smartcontractkit/chainlink-common/pkg/config" - - "github.com/smartcontractkit/chainlink-framework/multinode" ) // MultiNodeConfig is a wrapper to provide required functions while keeping configs Public @@ -24,6 +22,7 @@ type MultiNode struct { SyncThreshold *uint32 NodeIsSyncingEnabled *bool LeaseDuration *config.Duration + NewHeadsPollInterval *config.Duration FinalizedBlockPollInterval *config.Duration EnforceRepeatableRead *bool DeathDeclarationDelay *config.Duration @@ -62,6 +61,10 @@ func (c *MultiNodeConfig) NodeIsSyncingEnabled() bool { func (c *MultiNodeConfig) LeaseDuration() time.Duration { return c.MultiNode.LeaseDuration.Duration() } +func (c *MultiNodeConfig) NewHeadsPollInterval() time.Duration { + return c.MultiNode.NewHeadsPollInterval.Duration() +} + func (c *MultiNodeConfig) FinalizedBlockPollInterval() time.Duration { return c.MultiNode.FinalizedBlockPollInterval.Duration() } @@ -86,73 +89,6 @@ func (c *MultiNodeConfig) FinalityTagEnabled() bool { return *c.MultiNode.Finali func (c *MultiNodeConfig) FinalizedBlockOffset() uint32 { return *c.MultiNode.FinalizedBlockOffset } -func (c *MultiNodeConfig) SetDefaults() { - // MultiNode is disabled as it's not fully implemented yet: BCFR-122 - if c.MultiNode.Enabled == nil { - c.MultiNode.Enabled = ptr(false) - } - - /* Node Configs */ - // Failure threshold for polling set to 5 to tolerate some polling failures before taking action. - if c.MultiNode.PollFailureThreshold == nil { - c.MultiNode.PollFailureThreshold = ptr(uint32(5)) - } - // Poll interval is set to 15 seconds to ensure timely updates while minimizing resource usage. - if c.MultiNode.PollInterval == nil { - c.MultiNode.PollInterval = config.MustNewDuration(15 * time.Second) - } - // Selection mode defaults to priority level to enable using node priorities - if c.MultiNode.SelectionMode == nil { - c.MultiNode.SelectionMode = ptr(multinode.NodeSelectionModePriorityLevel) - } - // The sync threshold is set to 10 to allow for some flexibility in node synchronization before considering it out of sync. - if c.MultiNode.SyncThreshold == nil { - c.MultiNode.SyncThreshold = ptr(uint32(10)) - } - // Lease duration is set to 1 minute by default to allow node locks for a reasonable amount of time. - if c.MultiNode.LeaseDuration == nil { - c.MultiNode.LeaseDuration = config.MustNewDuration(time.Minute) - } - // Node syncing is not relevant for Solana and is disabled by default. - if c.MultiNode.NodeIsSyncingEnabled == nil { - c.MultiNode.NodeIsSyncingEnabled = ptr(false) - } - // The finalized block polling interval is set to 5 seconds to ensure timely updates while minimizing resource usage. - if c.MultiNode.FinalizedBlockPollInterval == nil { - c.MultiNode.FinalizedBlockPollInterval = config.MustNewDuration(5 * time.Second) - } - // Repeatable read guarantee should be enforced by default. - if c.MultiNode.EnforceRepeatableRead == nil { - c.MultiNode.EnforceRepeatableRead = ptr(true) - } - // The delay before declaring a node dead is set to 20 seconds to give nodes time to recover from temporary issues. - if c.MultiNode.DeathDeclarationDelay == nil { - c.MultiNode.DeathDeclarationDelay = config.MustNewDuration(20 * time.Second) - } - - /* Chain Configs */ - // Threshold for no new heads is set to 20 seconds, assuming that heads should update at a reasonable pace. - if c.MultiNode.NodeNoNewHeadsThreshold == nil { - c.MultiNode.NodeNoNewHeadsThreshold = config.MustNewDuration(20 * time.Second) - } - // Similar to heads, finalized heads should be updated within 20 seconds. - if c.MultiNode.NoNewFinalizedHeadsThreshold == nil { - c.MultiNode.NoNewFinalizedHeadsThreshold = config.MustNewDuration(20 * time.Second) - } - // Finality tags are used in Solana and enabled by default. - if c.MultiNode.FinalityTagEnabled == nil { - c.MultiNode.FinalityTagEnabled = ptr(true) - } - // Finality depth will not be used since finality tags are enabled. - if c.MultiNode.FinalityDepth == nil { - c.MultiNode.FinalityDepth = ptr(uint32(0)) - } - // Finalized block offset allows for RPCs to be slightly behind the finalized block. - if c.MultiNode.FinalizedBlockOffset == nil { - c.MultiNode.FinalizedBlockOffset = ptr(uint32(50)) - } -} - func (c *MultiNodeConfig) SetFrom(f *MultiNodeConfig) { if f.MultiNode.Enabled != nil { c.MultiNode.Enabled = f.MultiNode.Enabled @@ -177,6 +113,9 @@ func (c *MultiNodeConfig) SetFrom(f *MultiNodeConfig) { if f.MultiNode.LeaseDuration != nil { c.MultiNode.LeaseDuration = f.MultiNode.LeaseDuration } + if f.MultiNode.NewHeadsPollInterval != nil { + c.MultiNode.NewHeadsPollInterval = f.MultiNode.NewHeadsPollInterval + } if f.MultiNode.FinalizedBlockPollInterval != nil { c.MultiNode.FinalizedBlockPollInterval = f.MultiNode.FinalizedBlockPollInterval } @@ -204,7 +143,3 @@ func (c *MultiNodeConfig) SetFrom(f *MultiNodeConfig) { c.MultiNode.FinalizedBlockOffset = f.MultiNode.FinalizedBlockOffset } } - -func ptr[T any](t T) *T { - return &t -}