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

Implement new Interfaces for Multinode #13184

Draft
wants to merge 21 commits into
base: BCI-3160-EVM-MultiNode-PoC
Choose a base branch
from

Conversation

DylanTinianov
Copy link
Contributor

@DylanTinianov DylanTinianov commented May 13, 2024

Node and Multinode interfaces

Copy link
Contributor

I see you updated files related to core. Please run pnpm changeset in the root directory to add a changeset as well as in the text include at least one of the following tags:

  • #added For any new functionality added.
  • #breaking_change For any functionality that requires manual action for the node to boot.
  • #bugfix For bug fixes.
  • #changed For any change to the existing functionality.
  • #db_update For any feature that introduces updates to database schema.
  • #deprecation_notice For any upcoming deprecation functionality.
  • #internal For changesets that need to be excluded from the final changelog.
  • #nops For any feature that is NOP facing and needs to be in the official Release Notes for the release.
  • #removed For any functionality/config that is removed.
  • #updated For any functionality that is updated.
  • #wip For any change that is not ready yet and external communication about it should be held off till it is feature complete.

@DylanTinianov DylanTinianov changed the title Multinode Interface Implement new Interfaces for Multinode May 14, 2024
Copy link
Collaborator

@dhaidashenko dhaidashenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice progress!

common/client/multi_node.go Outdated Show resolved Hide resolved
common/client/multi_node.go Show resolved Hide resolved
common/client/multi_node.go Outdated Show resolved Hide resolved
common/client/multi_node.go Show resolved Hide resolved
common/client/multi_node.go Outdated Show resolved Hide resolved
common/client/types.go Show resolved Hide resolved
common/client/types.go Outdated Show resolved Hide resolved
core/chains/evm/client/chain_client.go Outdated Show resolved Hide resolved
if err != nil {
return nil, err
}
return rpc.LatestBlockHeight(ctx)
}

func (c *chainClient) NodeStates() map[string]string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to change the signature to this method to also use NodeState. Unless it significantly increases scope of the PR

core/chains/evm/client/chain_client.go Show resolved Hide resolved
common/client/multi_node.go Show resolved Hide resolved
common/client/multi_node.go Outdated Show resolved Hide resolved
if n.State() != nodeStateAlive {
continue
}
if do(ctx, n.RPC(), false) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should abort DoAll if do returned false

common/client/multi_node.go Outdated Show resolved Hide resolved
return nil
}

func (c *multiNode[CHAIN_ID, BLOCK_HASH, HEAD, RPC_CLIENT]) NodeStates() map[string]string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use map[string]NodeState as a return value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, plan on changing this after fixing tests

common/client/node.go Outdated Show resolved Hide resolved
common/client/node.go Outdated Show resolved Hide resolved
@@ -13,10 +12,10 @@ import (

// RPCClient includes all the necessary generalized RPC methods along with any additional chain-specific methods.
//
//go:generate mockery --quiet --name RPCClient --output ./mocks --case=underscore
//go:generate mockery --quiet --name RPCClient --structname MockRPCClient --filename "mock_rpc_client_test.go" --inpackage --case=underscore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to avoid public mocks as they cause redundant dependencies between packages.
If someone needs to mock implementation of the RPCClient, they should generate their own

n.declareUnreachable()
return
}
// TODO: nit fix. If multinode switches primary node before we set sub as AliveSub, sub will be closed and we'll
// falsely transition this node to unreachable state
n.rpc.SetAliveLoopSub(sub)
n.aliveLoopSub = sub
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix this TODO.
We should lock aliveLoopSub on assignment and when unsubscribing

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it might be good idea to add to common/types.Subscription doc, that we should be able to call Unsubscribe multiple times

@@ -138,42 +139,47 @@ func (n *node[CHAIN_ID, HEAD, RPC]) aliveLoop() {
lggr.Debug("Polling disabled")
}

var pollFinalizedHeadCh <-chan time.Time
var finalizedHeadCh <-chan HEAD
var finalizedHeadSub types.Subscription
if n.chainCfg.FinalityTagEnabled() && n.nodePoolCfg.FinalizedBlockPollInterval() > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, FinalizedBlockPollInterval setting is specific to the EVM. We should remove the check here.
The evm's RPC Client should handle it.
If the FinalizedBlockPollInterval=0 RPC Client should log an error and return nil channel

lggr logger.SugaredLogger
selectionMode string
// noNewHeadsThreshold time.Duration TODO: Move this?
nodeSelector NodeSelector[CHAIN_ID, HEAD, RPC_CLIENT]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After deeper review it seems to be possible to drop Head and BlockHash generic parameters without need to move nodeSelector creation

@@ -30,6 +30,47 @@ import (
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)

//go:generate mockery --quiet --name EvmRpcClient --structname MockEvmRpcClient --filename "mock_evm_rpc_client_test.go" --inpackage --case=underscore
type EvmRpcClient interface {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to avoid including parts of package path into type name.
What do you think of renaming this to ChainClientRPC (seems like we only use it there)?
Another option is to rollback change of making RpcClient public and name the interface as RpcClient

core/chains/evm/client/rpc_client.go Outdated Show resolved Hide resolved
core/chains/evm/gas/models.go Outdated Show resolved Hide resolved
@DylanTinianov DylanTinianov marked this pull request as ready for review May 31, 2024 15:09
@DylanTinianov DylanTinianov requested review from a team as code owners May 31, 2024 15:09
@DylanTinianov DylanTinianov marked this pull request as draft May 31, 2024 15:09
@cl-sonarqube-production
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube

Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants