Skip to content

Commit

Permalink
bump libocr; remove P2P.V1; drop libp2p (#10872)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored and Borja Aranda committed Dec 14, 2023
1 parent c22b082 commit 5bfe1fa
Show file tree
Hide file tree
Showing 68 changed files with 173 additions and 2,282 deletions.
4 changes: 3 additions & 1 deletion core/cmd/jobs_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/cli"
Expand Down Expand Up @@ -368,7 +369,8 @@ func TestShell_CreateJobV2(t *testing.T) {
app := startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.Database.Listener.FallbackPollInterval = models.MustNewDuration(100 * time.Millisecond)
c.OCR.Enabled = ptr(true)
c.P2P.V1.Enabled = ptr(true)
c.P2P.V2.Enabled = ptr(true)
c.P2P.V2.ListenAddresses = &[]string{fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t))}
c.P2P.PeerID = &cltest.DefaultP2PPeerID
c.EVM[0].Enabled = ptr(true)
c.EVM[0].NonceAutoSync = ptr(false)
Expand Down
4 changes: 1 addition & 3 deletions core/cmd/ocr-bootstrap-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ contractAddress = "0x27548a32b9aD5D64c5945EaE9Da5337bc3169D15"
externalJobID = "%s"
name = "%s"
evmChainID = "0"
p2pBootstrapPeers = [
"/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju",
]
p2pv2Bootstrappers = ["[email protected]:5001"]
isBootstrapPeer = true
5 changes: 3 additions & 2 deletions core/cmd/shell_remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/hashicorp/consul/sdk/freeport"
"github.com/kylelemons/godebug/diff"
"github.com/pelletier/go-toml"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -62,7 +63,6 @@ func startNewApplicationV2(t *testing.T, overrideFn func(c *chainlink.Config, s
c.JobPipeline.HTTPRequest.DefaultTimeout = models.MustNewDuration(30 * time.Millisecond)
f := false
c.EVM[0].Enabled = &f
c.P2P.V1.Enabled = &f
c.P2P.V2.Enabled = &f

if overrideFn != nil {
Expand Down Expand Up @@ -567,7 +567,8 @@ func TestShell_RunOCRJob_HappyPath(t *testing.T) {
app := startNewApplicationV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
c.EVM[0].Enabled = ptr(true)
c.OCR.Enabled = ptr(true)
c.P2P.V1.Enabled = ptr(true)
c.P2P.V2.Enabled = ptr(true)
c.P2P.V2.ListenAddresses = &[]string{fmt.Sprintf("127.0.0.1:%d", freeport.GetOne(t))}
c.P2P.PeerID = &cltest.DefaultP2PPeerID
c.EVM[0].GasEstimator.Mode = ptr("FixedPrice")
}, func(opts *startOptions) {
Expand Down
52 changes: 1 addition & 51 deletions core/config/docs/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,7 @@ CaptureEATelemetry = false # Default
# TraceLogging enables trace level logging.
TraceLogging = false # Default

# P2P supports multiple networking stack versions. You may configure `[P2P.V1]`, `[P2P.V2]`, or both to run simultaneously.
# If both are configured, then for each link with another peer, V2 networking will be preferred. If V2 does not work, the link will
# automatically fall back to V1. If V2 starts working again later, it will automatically be preferred again. This is useful
# for migrating networks without downtime. Note that the two networking stacks _must not_ be configured to bind to the same IP/port.
#
# Note: P2P.V1 is deprecated will be removed in the future.
#
# P2P has a versioned networking stack. Currenly only `[P2P.V2]` is supported.
# All nodes in the OCR network should share the same networking stack.
[P2P]
# IncomingMessageBufferSize is the per-remote number of incoming
Expand All @@ -419,50 +413,6 @@ PeerID = '12D3KooWMoejJznyDuEk5aX6GvbjaG12UzeornPCBNzMRqdwrFJw' # Example
# TraceLogging enables trace level logging.
TraceLogging = false # Default

# P2P.V1 is deprecated and will be removed in a future version.
[P2P.V1]
# Enabled enables P2P V1.
Enabled = false # Default
# AnnounceIP should be set as the externally reachable IP address of the Chainlink node.
AnnounceIP = '1.2.3.4' # Example
# AnnouncePort should be set as the externally reachable port of the Chainlink node.
AnnouncePort = 1337 # Example
# BootstrapCheckInterval is the interval at which nodes check connections to bootstrap nodes and reconnect if any of them is lost.
# Setting this to a small value would allow newly joined bootstrap nodes to get more connectivity
# more quickly, which helps to make bootstrap process faster. The cost of this operation is relatively
# cheap. We set this to 1 minute during our test.
BootstrapCheckInterval = '20s' # Default
# DefaultBootstrapPeers is the default set of bootstrap peers.
DefaultBootstrapPeers = ['/dns4/example.com/tcp/1337/p2p/12D3KooWMHMRLQkgPbFSYHwD3NBuwtS1AmxhvKVUrcfyaGDASR4U', '/ip4/1.2.3.4/tcp/9999/p2p/12D3KooWLZ9uTC3MrvKfDpGju6RAQubiMDL7CuJcAgDRTYP7fh7R'] # Example
# DHTAnnouncementCounterUserPrefix can be used to restore the node's
# ability to announce its IP/port on the P2P network after a database
# rollback. Make sure to only increase this value, and *never* decrease it.
# Don't use this variable unless you really know what you're doing, since you
# could semi-permanently exclude your node from the P2P network by
# misconfiguring it.
DHTAnnouncementCounterUserPrefix = 0 # Default
# **ADVANCED**
# DHTLookupInterval is the interval between which we do the expensive peer
# lookup using DHT.
#
# Every DHTLookupInterval failures to open a stream to a peer, we will
# attempt to lookup its IP from DHT
DHTLookupInterval = 10 # Default
# ListenIP is the default IP address to bind to.
ListenIP = '0.0.0.0' # Default
# ListenPort is the port to listen on. If left blank, the node randomly selects a different port each time it boots. It is highly recommended to set this to a static value to avoid network instability.
ListenPort = 1337 # Example
# **ADVANCED**
# NewStreamTimeout is the maximum length of time to wait to open a
# stream before we give up.
# We shouldn't hit this in practice since libp2p will give up fast if
# it can't get a connection, but it is here anyway as a failsafe.
# Set to 0 to disable any timeout on top of what libp2p gives us by default.
NewStreamTimeout = '10s' # Default
# **ADVANCED**
# PeerstoreWriteInterval controls how often the peerstore for the OCR V1 networking stack is persisted to the database.
PeerstoreWriteInterval = '5m' # Default

[P2P.V2]
# Enabled enables P2P V2.
# Note: V1.Enabled is true by default, so it must be set false in order to run V2 only.
Expand Down
4 changes: 0 additions & 4 deletions core/config/p2p_config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package config

import (
ocrnetworking "github.com/smartcontractkit/libocr/networking"

"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
)

type P2P interface {
V2() V2
V1() V1
NetworkStack() (n ocrnetworking.NetworkingStack)
PeerID() p2pkey.PeerID
IncomingMessageBufferSize() int
OutgoingMessageBufferSize() int
Expand Down
20 changes: 0 additions & 20 deletions core/config/p2p_v1_config.go

This file was deleted.

74 changes: 0 additions & 74 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"go.uber.org/zap/zapcore"

ocrcommontypes "github.com/smartcontractkit/libocr/commontypes"
ocrnetworking "github.com/smartcontractkit/libocr/networking"

"github.com/smartcontractkit/chainlink/v2/core/build"
"github.com/smartcontractkit/chainlink/v2/core/config"
Expand Down Expand Up @@ -1040,23 +1039,9 @@ type P2P struct {
PeerID *p2pkey.PeerID
TraceLogging *bool

V1 P2PV1 `toml:",omitempty"`
V2 P2PV2 `toml:",omitempty"`
}

func (p *P2P) NetworkStack() ocrnetworking.NetworkingStack {
v1, v2 := *p.V1.Enabled, *p.V2.Enabled
switch {
case v1 && v2:
return ocrnetworking.NetworkingStackV1V2
case v2:
return ocrnetworking.NetworkingStackV2
case v1:
return ocrnetworking.NetworkingStackV1
}
return ocrnetworking.NetworkingStack(0)
}

func (p *P2P) setFrom(f *P2P) {
if v := f.IncomingMessageBufferSize; v != nil {
p.IncomingMessageBufferSize = v
Expand All @@ -1071,68 +1056,9 @@ func (p *P2P) setFrom(f *P2P) {
p.TraceLogging = v
}

p.V1.setFrom(&f.V1)
p.V2.setFrom(&f.V2)
}

type P2PV1 struct {
Enabled *bool
AnnounceIP *net.IP
AnnouncePort *uint16
BootstrapCheckInterval *models.Duration
DefaultBootstrapPeers *[]string
DHTAnnouncementCounterUserPrefix *uint32
DHTLookupInterval *int64
ListenIP *net.IP
ListenPort *uint16
NewStreamTimeout *models.Duration
PeerstoreWriteInterval *models.Duration
}

func (p *P2PV1) ValidateConfig() (err error) {
//TODO or empty?
if p.AnnouncePort != nil && p.AnnounceIP == nil {
err = multierr.Append(err, configutils.ErrMissing{Name: "AnnounceIP", Msg: fmt.Sprintf("required when AnnouncePort is set: %d", *p.AnnouncePort)})
}
return
}

func (p *P2PV1) setFrom(f *P2PV1) {
if v := f.Enabled; v != nil {
p.Enabled = v
}
if v := f.AnnounceIP; v != nil {
p.AnnounceIP = v
}
if v := f.AnnouncePort; v != nil {
p.AnnouncePort = v
}
if v := f.BootstrapCheckInterval; v != nil {
p.BootstrapCheckInterval = v
}
if v := f.DefaultBootstrapPeers; v != nil {
p.DefaultBootstrapPeers = v
}
if v := f.DHTAnnouncementCounterUserPrefix; v != nil {
p.DHTAnnouncementCounterUserPrefix = v
}
if v := f.DHTLookupInterval; v != nil {
p.DHTLookupInterval = v
}
if v := f.ListenIP; v != nil {
p.ListenIP = v
}
if v := f.ListenPort; v != nil {
p.ListenPort = v
}
if v := f.NewStreamTimeout; v != nil {
p.NewStreamTimeout = v
}
if v := f.PeerstoreWriteInterval; v != nil {
p.PeerstoreWriteInterval = v
}
}

type P2PV2 struct {
Enabled *bool
AnnounceAddresses *[]string
Expand Down
2 changes: 1 addition & 1 deletion core/internal/cltest/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func MustInsertOffchainreportingOracleSpec(t *testing.T, db *sqlx.DB, transmitte

ocrKeyID := models.MustSha256HashFromHex(DefaultOCRKeyBundleID)
spec := job.OCROracleSpec{}
require.NoError(t, db.Get(&spec, `INSERT INTO ocr_oracle_specs (created_at, updated_at, contract_address, p2p_bootstrap_peers, is_bootstrap_peer, encrypted_ocr_key_bundle_id, transmitter_address, observation_timeout, blockchain_timeout, contract_config_tracker_subscribe_interval, contract_config_tracker_poll_interval, contract_config_confirmations, database_timeout, observation_grace_period, contract_transmitter_transmit_timeout, evm_chain_id) VALUES (
require.NoError(t, db.Get(&spec, `INSERT INTO ocr_oracle_specs (created_at, updated_at, contract_address, p2pv2_bootstrappers, is_bootstrap_peer, encrypted_ocr_key_bundle_id, transmitter_address, observation_timeout, blockchain_timeout, contract_config_tracker_subscribe_interval, contract_config_tracker_poll_interval, contract_config_confirmations, database_timeout, observation_grace_period, contract_transmitter_transmit_timeout, evm_chain_id) VALUES (
NOW(),NOW(),$1,'{}',false,$2,$3,0,0,0,0,0,0,0,0,0
) RETURNING *`, NewEIP55Address(), &ocrKeyID, &transmitterAddress))
return spec
Expand Down
2 changes: 1 addition & 1 deletion core/internal/cltest/job_factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
contractAddress = "%s"
evmChainID = "0"
p2pPeerID = "%s"
p2pBootstrapPeers = ["/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju"]
p2pv2Bootstrappers = ["[email protected]:5001"]
isBootstrapPeer = false
transmitterAddress = "%s"
keyBundleID = "%s"
Expand Down
Loading

0 comments on commit 5bfe1fa

Please sign in to comment.