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 migration and orm changes for additional lgs fields and delegate #10722

2 changes: 2 additions & 0 deletions core/config/docs/core.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ FeedsManager = true # Default
LogPoller = false # Default
# UICSAKeys enables CSA Keys in the UI.
UICSAKeys = false # Default
# EAL (Enterprise Abstraction Layer) exposes API endpoints for reading and writing to blockchains.
EAL = false # Default
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it an acronym?


[Database]
# DefaultIdleInTxSessionTimeout is the maximum time allowed for a transaction to be open and idle before timing out. See Postgres `idle_in_transaction_session_timeout` for more details.
Expand Down
1 change: 1 addition & 0 deletions core/config/feature_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ type Feature interface {
FeedsManager() bool
UICSAKeys() bool
LogPoller() bool
EAL() bool
}
4 changes: 4 additions & 0 deletions core/config/toml/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ type Feature struct {
FeedsManager *bool
LogPoller *bool
UICSAKeys *bool
EAL *bool
}

func (f *Feature) setFrom(f2 *Feature) {
Expand All @@ -298,6 +299,9 @@ func (f *Feature) setFrom(f2 *Feature) {
if v := f2.UICSAKeys; v != nil {
f.UICSAKeys = v
}
if v := f2.EAL; v != nil {
f.EAL = v
}
}

type Database struct {
Expand Down
14 changes: 8 additions & 6 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ require (
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.2 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/huin/goupnp v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down Expand Up @@ -299,6 +299,8 @@ require (
github.com/shirou/gopsutil/v3 v3.23.8 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect
github.com/smartcontractkit/capital-markets-projects v0.0.0-20230926155417-a3ac6c7f5bea // indirect
github.com/smartcontractkit/capital-markets-projects/lib v0.0.0-20230926155417-a3ac6c7f5bea // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc47 // indirect
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230926113942-a871b2976dc1 // indirect
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca // indirect
Expand Down Expand Up @@ -350,16 +352,16 @@ require (
go.uber.org/ratelimit v0.2.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/arch v0.4.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230717213848-3f92550aa753 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230717213848-3f92550aa753 // indirect
Expand Down
28 changes: 16 additions & 12 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,8 @@ github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e h1:pIYdhNkDh+YENVNi3gt
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e/go.mod h1:j9cQbcqHQujT0oKJ38PylVfqohClLr3CvDC+Qcg+lhU=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.2 h1:TXKcSGc2WaxPD2+bmzAsVthL4+pEN0YwXcL5qED83vk=
github.com/holiman/uint256 v1.2.2/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o=
github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
Expand Down Expand Up @@ -1452,6 +1452,10 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo=
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/capital-markets-projects v0.0.0-20230926155417-a3ac6c7f5bea h1:20YSrEi88NimVAKuDiwmbI4xbcGEvBb4MlW1vig0euU=
github.com/smartcontractkit/capital-markets-projects v0.0.0-20230926155417-a3ac6c7f5bea/go.mod h1:5G+3CGpX2DYoVOfcrp9IZy7CPTCpL0+pCOmB/3R7t7k=
github.com/smartcontractkit/capital-markets-projects/lib v0.0.0-20230926155417-a3ac6c7f5bea h1:R/e1SuWpEooOxr8F+1kA6PK5vZ9mW3F3BNwg2W6aREE=
github.com/smartcontractkit/capital-markets-projects/lib v0.0.0-20230926155417-a3ac6c7f5bea/go.mod h1:6sAI/Wb424wYzwCa2tn+r+eup2JtxZvY/On3Ct38xp0=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc47 h1:vdieOW3CZGdD2R5zvCSMS+0vksyExPN3/Fa1uVfld/A=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc47/go.mod h1:xMwqRdj5vqYhCJXgKVqvyAwdcqM6ZAEhnwEQ4Khsop8=
github.com/smartcontractkit/chainlink-relay v0.1.7-0.20230926113942-a871b2976dc1 h1:Db333w+fSm2e18LMikcIQHIZqgxZruW9uCUGJLUC9mI=
Expand Down Expand Up @@ -1734,8 +1738,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1835,8 +1839,8 @@ golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1962,8 +1966,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -1974,8 +1978,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -2050,8 +2054,8 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
25 changes: 24 additions & 1 deletion core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keeper"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
lgsservice "github.com/smartcontractkit/chainlink/v2/core/services/legacygasstation"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrbootstrap"
Expand Down Expand Up @@ -103,6 +104,8 @@ type Application interface {
ID() uuid.UUID

SecretGenerator() SecretGenerator

LegacyGasStationRequestRouter() lgsservice.RequestRouter
}

// ChainlinkApplication contains fields for the JobSubscriber, Scheduler,
Expand Down Expand Up @@ -135,6 +138,7 @@ type ChainlinkApplication struct {
secretGenerator SecretGenerator
profiler *pyroscope.Profiler
loopRegistry *plugins.LoopRegistry
lgsRequestRouter lgsservice.RequestRouter

started bool
startStopMu sync.Mutex
Expand Down Expand Up @@ -322,8 +326,22 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
legacyEVMChains,
keyStore.Eth(),
globalLogger),
job.LegacyGasStationServer: lgsservice.NewServerDelegate(
globalLogger,
legacyEVMChains,
keyStore.Eth(),
db,
cfg.Database(),
),
job.LegacyGasStationSidecar: lgsservice.NewSidecarDelegate(
globalLogger,
legacyEVMChains,
keyStore.Eth(),
db,
),
}
webhookJobRunner = delegates[job.Webhook].(*webhook.Delegate).WebhookJobRunner()
lgsRequestRouter = delegates[job.LegacyGasStationServer].(*lgsservice.Delegate).RequestRouter()
)

// Flux monitor requires ethereum just to boot, silence errors with a null delegate
Expand Down Expand Up @@ -474,7 +492,8 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
profiler: profiler,
loopRegistry: loopRegistry,

sqlxDB: opts.SqlxDB,
sqlxDB: opts.SqlxDB,
lgsRequestRouter: lgsRequestRouter,

// NOTE: Can keep things clean by putting more things in srvcs instead of manually start/closing
srvcs: srvcs,
Expand Down Expand Up @@ -654,6 +673,10 @@ func (app *ChainlinkApplication) SecretGenerator() SecretGenerator {
return app.secretGenerator
}

func (app *ChainlinkApplication) LegacyGasStationRequestRouter() lgsservice.RequestRouter {
return app.lgsRequestRouter
}

// WakeSessionReaper wakes up the reaper to do its reaping.
func (app *ChainlinkApplication) WakeSessionReaper() {
app.SessionReaper.WakeUp()
Expand Down
4 changes: 4 additions & 0 deletions core/services/chainlink/config_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ func (f *featureConfig) LogPoller() bool {
func (f *featureConfig) UICSAKeys() bool {
return *f.c.UICSAKeys
}

func (f *featureConfig) EAL() bool {
return *f.c.EAL
}
1 change: 1 addition & 0 deletions core/services/chainlink/config_general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestTOMLGeneralConfig_Defaults(t *testing.T) {
assert.False(t, config.CosmosEnabled())
assert.False(t, config.SolanaEnabled())
assert.False(t, config.StarkNetEnabled())
assert.False(t, config.Feature().EAL())
assert.Equal(t, false, config.JobPipeline().ExternalInitiatorsEnabled())
assert.Equal(t, 15*time.Minute, config.WebServer().SessionTimeout().Duration())
}
Expand Down
2 changes: 2 additions & 0 deletions core/services/chainlink/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func TestConfig_Marshal(t *testing.T) {
FeedsManager: ptr(true),
LogPoller: ptr(true),
UICSAKeys: ptr(true),
EAL: ptr(true),
}
full.Database = toml.Database{
DefaultIdleInTxSessionTimeout: models.MustNewDuration(time.Minute),
Expand Down Expand Up @@ -654,6 +655,7 @@ Headers = ['Authorization: token', 'X-SomeOther-Header: value with spaces | and
FeedsManager = true
LogPoller = true
UICSAKeys = true
EAL = true
`},
{"Database", Config{Core: toml.Core{Database: full.Database}}, `[Database]
DefaultIdleInTxSessionTimeout = '1m0s'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ShutdownGracePeriod = '5s'
FeedsManager = true
LogPoller = false
UICSAKeys = false
EAL = false

[Database]
DefaultIdleInTxSessionTimeout = '1h0m0s'
Expand Down
1 change: 1 addition & 0 deletions core/services/chainlink/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ShutdownGracePeriod = '10s'
FeedsManager = true
LogPoller = true
UICSAKeys = true
EAL = true

[Database]
DefaultIdleInTxSessionTimeout = '1m0s'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ShutdownGracePeriod = '5s'
FeedsManager = true
LogPoller = false
UICSAKeys = false
EAL = false

[Database]
DefaultIdleInTxSessionTimeout = '1h0m0s'
Expand Down
117 changes: 117 additions & 0 deletions core/services/eal/blockchain_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package eal

import (
"context"
"math/big"

"github.com/pkg/errors"

"github.com/ethereum/go-ethereum"
gethcommon "github.com/ethereum/go-ethereum/common"
libcommon "github.com/smartcontractkit/capital-markets-projects/lib/common"

Check failure on line 11 in core/services/eal/blockchain_client.go

View workflow job for this annotation

GitHub Actions / Analyze go

no required module provides package github.com/smartcontractkit/capital-markets-projects/lib/common; to add it:

Check failure on line 11 in core/services/eal/blockchain_client.go

View workflow job for this annotation

GitHub Actions / lint

github.com/smartcontractkit/capital-markets-projects/[email protected]: invalid version: git ls-remote -q origin in /home/runner/go/pkg/mod/cache/vcs/0d879dda4c56802137cdda30667e29275a00f12c284af4b9d992dcbd9794df43: exit status 128:
"github.com/smartcontractkit/capital-markets-projects/lib/web/jsonrpc"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
)

var _ libcommon.BlockchainClientInterface = &BlockchainClient{}

type BlockchainClient struct {
lggr logger.Logger
txm txmgr.TxManager
gethks keystore.Eth
fromAddresses []ethkey.EIP55Address
chainID uint64
maxGasLimit uint32
client client.Client
}

func NewBlockchainClient(
lggr logger.Logger,
txm txmgr.TxManager,
gethks keystore.Eth,
fromAddresses []ethkey.EIP55Address,
chainID uint64,
cfg config.EVM,
client client.Client,
) (*BlockchainClient, error) {
return &BlockchainClient{
lggr: lggr,
txm: txm,
gethks: gethks,
fromAddresses: fromAddresses,
chainID: chainID,
maxGasLimit: cfg.GasEstimator().LimitMax(),
client: client,
}, nil
}

func (c *BlockchainClient) EstimateGas(
ctx context.Context,
address gethcommon.Address,
payload []byte,
) (uint32, error) {
fromAddresses := c.sendingKeys()
fromAddress, err := c.gethks.GetRoundRobinAddress(big.NewInt(0).SetUint64(c.chainID), fromAddresses...)
if err != nil {
return 0, err
}
c.lggr.Debugw("estimate gas details",
"toAddress", address,
"fromAddress", fromAddress,
)
gasLimit, err := c.client.EstimateGas(ctx, ethereum.CallMsg{
From: fromAddress,
To: &address,
Data: payload,
})
if err != nil {
return 0, err
}

if gasLimit > uint64(c.maxGasLimit) {
return 0, errors.New(jsonrpc.EstimateGasExceededErrorMsg)
}
// safe cast because gas estimator limit max is uint32
return uint32(gasLimit), nil
}

// SimulateTransaction makes eth_call to simulate transaction
// TODO: look into accepting optional parameters (gas, gasPrice, value)
func (c *BlockchainClient) SimulateTransaction(
ctx context.Context,
address gethcommon.Address,
payload []byte,
gasLimit uint32,
) error {
fromAddresses := c.sendingKeys()
fromAddress, err := c.gethks.GetRoundRobinAddress(big.NewInt(0).SetUint64(c.chainID), fromAddresses...)
if err != nil {
return err
}
c.lggr.Debugw("eth_call details",
"toAddress", address,
"fromAddress", fromAddress,
"gasLimit", gasLimit,
)
_, err = c.client.CallContract(ctx, ethereum.CallMsg{
To: &address,
From: fromAddress,
Data: payload,
Gas: uint64(gasLimit),
}, nil /*blocknumber*/)

return err
}

func (c *BlockchainClient) sendingKeys() []gethcommon.Address {
var addresses []gethcommon.Address
for _, a := range c.fromAddresses {
addresses = append(addresses, a.Address())
}
return addresses
}
Loading
Loading