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
Show file tree
Hide file tree
Changes from 7 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
}
2 changes: 1 addition & 1 deletion multinode/multi_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
var (
// PromMultiNodeRPCNodeStates reports current RPC node state
PromMultiNodeRPCNodeStates = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "multi_node_states",
Name: "multinode_states",
Help: "The number of RPC nodes currently in the given state for the given chain",
}, []string{"network", "chainId", "state"})
ErrNodeError = fmt.Errorf("no live nodes available")
Expand Down
6 changes: 3 additions & 3 deletions multinode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ var errInvalidChainID = errors.New("invalid chain id")

var (
promPoolRPCNodeVerifies = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_verifies",
Name: "multinode_pool_rpc_node_verifies",
Help: "The total number of chain ID verifications for the given RPC node",
}, []string{"network", "chainID", "nodeName"})
promPoolRPCNodeVerifiesFailed = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_verifies_failed",
Name: "multinode_pool_rpc_node_verifies_failed",
Help: "The total number of failed chain ID verifications for the given RPC node",
}, []string{"network", "chainID", "nodeName"})
promPoolRPCNodeVerifiesSuccess = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_verifies_success",
Name: "multinode_pool_rpc_node_verifies_success",
Help: "The total number of successful chain ID verifications for the given RPC node",
}, []string{"network", "chainID", "nodeName"})
)
Expand Down
14 changes: 7 additions & 7 deletions multinode/node_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ import (

var (
promPoolRPCNodeTransitionsToAlive = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_transitions_to_alive",
Name: "multinode_pool_rpc_node_num_transitions_to_alive",
Help: transitionString(nodeStateAlive),
}, []string{"chainID", "nodeName"})
promPoolRPCNodeTransitionsToInSync = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_transitions_to_in_sync",
Name: "multinode_pool_rpc_node_num_transitions_to_in_sync",
Help: fmt.Sprintf("%s to %s", transitionString(nodeStateOutOfSync), nodeStateAlive),
}, []string{"chainID", "nodeName"})
promPoolRPCNodeTransitionsToOutOfSync = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_transitions_to_out_of_sync",
Name: "multinode_pool_rpc_node_num_transitions_to_out_of_sync",
Help: transitionString(nodeStateOutOfSync),
}, []string{"chainID", "nodeName"})
promPoolRPCNodeTransitionsToUnreachable = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_transitions_to_unreachable",
Name: "multinode_pool_rpc_node_num_transitions_to_unreachable",
Help: transitionString(nodeStateUnreachable),
}, []string{"chainID", "nodeName"})
promPoolRPCNodeTransitionsToInvalidChainID = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_transitions_to_invalid_chain_id",
Name: "multinode_pool_rpc_node_num_transitions_to_invalid_chain_id",
Help: transitionString(nodeStateInvalidChainID),
}, []string{"chainID", "nodeName"})
promPoolRPCNodeTransitionsToUnusable = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_transitions_to_unusable",
Name: "multinode_pool_rpc_node_num_transitions_to_unusable",
Help: transitionString(nodeStateUnusable),
}, []string{"chainID", "nodeName"})
promPoolRPCNodeTransitionsToSyncing = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_transitions_to_syncing",
Name: "multinode_pool_rpc_node_num_transitions_to_syncing",
Help: transitionString(nodeStateSyncing),
}, []string{"chainID", "nodeName"})
)
Expand Down
12 changes: 6 additions & 6 deletions multinode/node_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import (

var (
promPoolRPCNodeHighestSeenBlock = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "pool_rpc_node_highest_seen_block",
Name: "multinode_pool_rpc_node_highest_seen_block",
Help: "The highest seen block for the given RPC node",
}, []string{"chainID", "nodeName"})
promPoolRPCNodeHighestFinalizedBlock = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "pool_rpc_node_highest_finalized_block",
Name: "multinode_pool_rpc_node_highest_finalized_block",
Help: "The highest seen finalized block for the given RPC node",
}, []string{"chainID", "nodeName"})
promPoolRPCNodeNumSeenBlocks = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_num_seen_blocks",
Name: "multinode_pool_rpc_node_num_seen_blocks",
Help: "The total number of new blocks seen by the given RPC node",
}, []string{"chainID", "nodeName"})
promPoolRPCNodePolls = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_polls_total",
Name: "multinode_pool_rpc_node_polls_total",
Help: "The total number of poll checks for the given RPC node",
}, []string{"chainID", "nodeName"})
promPoolRPCNodePollsFailed = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_polls_failed",
Name: "multinode_pool_rpc_node_polls_failed",
Help: "The total number of failed poll checks for the given RPC node",
}, []string{"chainID", "nodeName"})
promPoolRPCNodePollsSuccess = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pool_rpc_node_polls_success",
Name: "multinode_pool_rpc_node_polls_success",
Help: "The total number of successful poll checks for the given RPC node",
}, []string{"chainID", "nodeName"})
)
Expand Down
2 changes: 1 addition & 1 deletion multinode/transaction_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
var (
// PromMultiNodeInvariantViolations reports violation of our assumptions
PromMultiNodeInvariantViolations = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "multi_node_invariant_violations",
Name: "multinode_transaction_sender_invariant_violations",
Help: "The number of invariant violations",
}, []string{"network", "chainId", "invariant"})
)
Expand Down
Loading