Skip to content

Commit

Permalink
Refactor: Cleanup logging, add more tx caching
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Oct 30, 2024
1 parent c029116 commit 80550df
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 124 deletions.
1 change: 1 addition & 0 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ require (
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.0 // indirect
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20241024132041-a3eb2e31b4c4 // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.1.1-0.20241017135645-176a23722fd8 // indirect
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.12
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 // indirect
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20241009055228-33d0c0bf38de // indirect
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20241009055228-33d0c0bf38de // indirect
Expand Down
2 changes: 2 additions & 0 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,8 @@ github.com/smartcontractkit/chainlink-solana v1.1.1-0.20241024132041-a3eb2e31b4c
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20241024132041-a3eb2e31b4c4/go.mod h1:iZugccCLpPWtcGiR/8gurre2j3RtyKnqd1FcVR0NzQw=
github.com/smartcontractkit/chainlink-starknet/relayer v0.1.1-0.20241017135645-176a23722fd8 h1:B4DFdk6MGcQnoCjjMBCx7Z+GWQpxRWJ4O8W/dVJyWGA=
github.com/smartcontractkit/chainlink-starknet/relayer v0.1.1-0.20241017135645-176a23722fd8/go.mod h1:WkBqgBo+g34Gm5vWkDDl8Fh3Mzd7bF5hXp7rryg0t5o=
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.12 h1:B3+KM0cNxEtynbKnvixHnW5oUCq1Dv3b0gTKYRt3dOs=
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.12/go.mod h1:Mi8q2e6gSnBhVdYehNesfh3aJMibGpS/nzgfN1yHoFY=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7/go.mod h1:FX7/bVdoep147QQhsOPkYsPEXhGZjeYx6lBSaSXtZOA=
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12 h1:NzZGjaqez21I3DU7objl3xExTH4fxYvzTqar8DC6360=
Expand Down
60 changes: 56 additions & 4 deletions core/scripts/keystone/src/01_provision_keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ func (g *provisionKeystone) Run(args []string) {
}

if *preprovison {
fmt.Printf("Preprovisioning crib with %d nodes per set\n", *nodeSetSize)
fmt.Println()
fmt.Println()
fmt.Println("========================")
fmt.Println("Writing Preprovisioning Config")
fmt.Println("========================")
fmt.Println()
fmt.Println()
writePreprovisionConfig(*nodeSetSize, filepath.Join(*artefactsDir, *preprovisionConfigName))
return
}
Expand Down Expand Up @@ -82,16 +88,16 @@ func (g *provisionKeystone) Run(args []string) {
os.Setenv("INSECURE_SKIP_VERIFY", "true")
env := helpers.SetupEnv(false)


provisionStreamsDON(
env,
nodeSets.StreamsTrigger,
*chainID,
*p2pPort,
*ocrConfigFile,
*artefactsDir,
)

reg := provisionCapabillitiesRegistry(
reg := provisionCapabilitiesRegistry(
env,
nodeSets,
*chainID,
Expand All @@ -108,29 +114,68 @@ func (g *provisionKeystone) Run(args []string) {
reg,
)

fmt.Println()
fmt.Println()
fmt.Println("========================")
fmt.Println("Writing Postprovision Config")
fmt.Println("========================")
fmt.Println()
fmt.Println()

writePostProvisionConfig(
nodeSets,
*chainID,
*capabilitiesP2PPort,
onchainMeta.ForwarderContract.Address().Hex(),
onchainMeta.Forwarder.Address().Hex(),
onchainMeta.CapabilitiesRegistry.Address().Hex(),
filepath.Join(*artefactsDir, *postprovisionConfigName),
)
}

func provisionCapabilitiesRegistry(
env helpers.Environment,
nodeSets NodeSets,
chainID int64,
artefactsDir string,
) kcr.CapabilitiesRegistryInterface {
fmt.Println()
fmt.Println()
fmt.Println("========================")
fmt.Println("Provisioning Capabilities Registry DON")
fmt.Println("========================")
fmt.Println()
fmt.Println()
reg := provisionCapabillitiesRegistry(
env,
nodeSets,
chainID,
artefactsDir,
)
return reg
}

func provisionStreamsDON(
env helpers.Environment,
nodeSet NodeSet,
chainID int64,
p2pPort int64,
ocrConfigFilePath string,
artefactsDir string,
) {
fmt.Println()
fmt.Println()
fmt.Println("========================")
fmt.Println("Provisioning streams DON")
fmt.Println("========================")
fmt.Println()
fmt.Println()
setupStreamsTrigger(
env,
nodeSet,
chainID,
p2pPort,
ocrConfigFilePath,
artefactsDir,
)
}

Expand All @@ -143,6 +188,13 @@ func provisionWorkflowDON(
artefactsDir string,
reg kcr.CapabilitiesRegistryInterface,
) (onchainMeta *onchainMeta) {
fmt.Println()
fmt.Println()
fmt.Println("========================")
fmt.Println("Provisioning workflow DON")
fmt.Println("========================")
fmt.Println()
fmt.Println()
deployForwarder(env, artefactsDir)

onchainMeta, _ = provisionOCR3(
Expand Down
18 changes: 14 additions & 4 deletions core/scripts/keystone/src/02_fund_transmitters.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package src

import (
"context"
"flag"
"fmt"
"math/big"
"os"
"context"

helpers "github.com/smartcontractkit/chainlink/core/scripts/common"
"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink-testing-framework/lib/utils/conversions"
helpers "github.com/smartcontractkit/chainlink/core/scripts/common"
)

type fundTransmitters struct{}
Expand Down Expand Up @@ -53,7 +55,8 @@ func (g *fundTransmitters) Run(args []string) {
func distributeFunds(nodeSet NodeSet, env helpers.Environment) {
fmt.Println("Funding transmitters...")
transmittersStr := []string{}
minThreshold := big.NewInt(50000000000000000) // 0.05 ETH
fundingAmount := big.NewInt(500000000000000000) // 0.5 ETH
minThreshold := big.NewInt(50000000000000000) // 0.05 ETH

for _, n := range nodeSet.NodeKeys {
balance, err := getBalance(n.EthAddress, env)
Expand All @@ -62,12 +65,19 @@ func distributeFunds(nodeSet NodeSet, env helpers.Environment) {
continue
}
if balance.Cmp(minThreshold) < 0 {
fmt.Printf(
"Transmitter %s has insufficient funds, funding with %s ETH. Current balance: %s, threshold: %s\n",
n.EthAddress,
conversions.WeiToEther(fundingAmount).String(),
conversions.WeiToEther(balance).String(),
conversions.WeiToEther(minThreshold).String(),
)
transmittersStr = append(transmittersStr, n.EthAddress)
}
}

if len(transmittersStr) > 0 {
helpers.FundNodes(env, transmittersStr, minThreshold)
helpers.FundNodes(env, transmittersStr, fundingAmount)
} else {
fmt.Println("All transmitters have sufficient funds.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (c *provisionCR) Run(args []string) {
}

func provisionCapabillitiesRegistry(env helpers.Environment, nodeSets NodeSets, chainID int64, artefactsDir string) kcr.CapabilitiesRegistryInterface {
fmt.Printf("Provisioning capabilities registry on chain %d\n", chainID)
ctx := context.Background()
reg := deployCR(ctx, artefactsDir, env)
crProvisioner := NewCapabilityRegistryProvisioner(reg, env)
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/keystone/src/02_provision_crib.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (g *postprovisionCrib) Run(args []string) {
nodeSets,
*chainID,
*capabilitiesP2PPort,
contracts.ForwarderContract.Address().Hex(),
contracts.Forwarder.Address().Hex(),
contracts.CapabilitiesRegistry.Address().Hex(),
*outputPath,
)
Expand Down
5 changes: 3 additions & 2 deletions core/scripts/keystone/src/02_provision_forwarder_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ func deployForwarder(
artefacts string,
) {
o := LoadOnchainMeta(artefacts, env)
if o.ForwarderContract != nil {
if o.Forwarder != nil {
fmt.Println("Forwarder contract already deployed, skipping")
return
}

fmt.Println("Deploying forwarder contract...")
forwarderContract := DeployForwarder(env)
o.ForwarderContract = forwarderContract
o.Forwarder = forwarderContract
WriteOnchainMeta(o, artefacts)
}

Expand Down
12 changes: 6 additions & 6 deletions core/scripts/keystone/src/02_provision_ocr3_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ func deployOCR3Contract(
env.ChainID,
)

if o.OCRContract != nil {
if o.OCR3 != nil {
// types.ConfigDigestPrefixKeystoneOCR3Capability
fmt.Println("OCR3 Contract already deployed, checking config...")
latestConfigDigestBytes, err := o.OCRContract.LatestConfigDetails(nil)
latestConfigDigestBytes, err := o.OCR3.LatestConfigDetails(nil)
PanicErr(err)
latestConfigDigest, err := types.BytesToConfigDigest(latestConfigDigestBytes.ConfigDigest[:])

cc := ocrConfToContractConfig(ocrConf, latestConfigDigestBytes.ConfigCount)
digester := evm.OCR3CapabilityOffchainConfigDigester{
ChainID: uint64(env.ChainID),
ContractAddress: o.OCRContract.Address(),
ContractAddress: o.OCR3.Address(),
}
digest, err := digester.ConfigDigest(context.Background(), cc)
PanicErr(err)
Expand All @@ -134,7 +134,7 @@ func deployOCR3Contract(
_, tx, ocrContract, err := ocr3_capability.DeployOCR3Capability(env.Owner, env.Ec)
PanicErr(err)
helpers.ConfirmContractDeployed(context.Background(), env.Ec, tx, env.ChainID)
o.OCRContract = ocrContract
o.OCR3 = ocrContract
setOCRConfig(o, env, ocrConf, artefacts)

return o, true
Expand All @@ -149,7 +149,7 @@ func generateOCR3Config(nodeSet NodeSet, configFile string, chainID int64) ksdep
}

func setOCRConfig(o *onchainMeta, env helpers.Environment, ocrConf ksdeploy.Orc2drOracleConfig, artefacts string) {
tx, err := o.OCRContract.SetConfig(env.Owner,
tx, err := o.OCR3.SetConfig(env.Owner,
ocrConf.Signers,
ocrConf.Transmitters,
ocrConf.F,
Expand All @@ -170,7 +170,7 @@ func deployOCR3JobSpecsTo(
artefactsDir string,
onchainMeta *onchainMeta,
) {
ocrAddress := onchainMeta.OCRContract.Address().Hex()
ocrAddress := onchainMeta.OCR3.Address().Hex()
nodeKeys := nodeSet.NodeKeys
nodes := nodeSet.Nodes

Expand Down
Loading

0 comments on commit 80550df

Please sign in to comment.