Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NewHeadsPollInterval #6

Merged
merged 9 commits into from
Jan 15, 2025
Merged
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
81 changes: 8 additions & 73 deletions multinode/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Loading