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

Refactor EVM ORMs #11899

Merged
merged 123 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
30cf88b
Initial commit
DylanTinianov Jan 25, 2024
216fea0
Refactor headtracker orm
DylanTinianov Jan 25, 2024
438fd43
Remove unused loggers
DylanTinianov Jan 25, 2024
f774cb9
Remove comments
DylanTinianov Jan 25, 2024
a0c67a3
Add timeout
DylanTinianov Jan 25, 2024
4c5ab6a
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Jan 25, 2024
43eeb27
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Jan 25, 2024
a856849
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Jan 26, 2024
a10dff2
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 8, 2024
3f9ee21
Refactor log_poller ORM
DylanTinianov Feb 9, 2024
1bf19ea
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 13, 2024
bbcf2f2
Refactor logpoller ORM
DylanTinianov Feb 14, 2024
9b0f2a1
Fix logpoller tests
DylanTinianov Feb 14, 2024
c970083
Update logpoller orm
DylanTinianov Feb 15, 2024
ec7d2e7
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 15, 2024
e90ee08
Use EventSig
DylanTinianov Feb 15, 2024
90c4d8e
update logpoller orm
DylanTinianov Feb 15, 2024
3598fb9
Update orm.go
DylanTinianov Feb 15, 2024
3794e2f
Update logpoller_wrapper_test.go
DylanTinianov Feb 15, 2024
99eb21c
Update log_poller_test.go
DylanTinianov Feb 15, 2024
85bcfb4
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 15, 2024
0d830ec
Remove query
DylanTinianov Feb 15, 2024
0dbc609
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 15, 2024
85f46f2
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 15, 2024
cc2ecd2
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 16, 2024
e912ff1
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 20, 2024
3eab4d4
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 20, 2024
d71d0e9
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 21, 2024
2c027a9
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 21, 2024
c44abcf
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 21, 2024
759a2fc
Remove ORM timeouts
DylanTinianov Feb 21, 2024
0d76360
Add context
DylanTinianov Feb 21, 2024
c3269cb
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 21, 2024
76910bb
Use testutils for context
DylanTinianov Feb 21, 2024
2e6da02
Use testutils context
DylanTinianov Feb 21, 2024
76ab35c
Use testutils context
DylanTinianov Feb 21, 2024
e55455e
Use ctx
DylanTinianov Feb 21, 2024
57453b0
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 21, 2024
3183b21
Refactor forwarder ORM
DylanTinianov Feb 21, 2024
21cb891
Generate tidy
DylanTinianov Feb 21, 2024
8cb57e5
Merge branch 'BCI-2644-refactor-evm-orms' into BCI-2644-refactor-forw…
DylanTinianov Feb 21, 2024
f9b166a
Fix logpoller mocks
DylanTinianov Feb 21, 2024
73930e0
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 21, 2024
6085cb0
Remove pg dependency
DylanTinianov Feb 21, 2024
007a348
Fix mock calls
DylanTinianov Feb 21, 2024
22e83f9
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 21, 2024
dc58bd8
Merge branch 'BCI-2644-refactor-evm-orms' of https://github.com/smart…
DylanTinianov Feb 21, 2024
c8c0f30
Fix mock calls
DylanTinianov Feb 22, 2024
d3f2787
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 22, 2024
66050eb
Fix mock calls
DylanTinianov Feb 22, 2024
b1a7c57
Use request context
DylanTinianov Feb 22, 2024
8de9cc1
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 22, 2024
920af7e
Merge branch 'BCI-2644-refactor-evm-orms' of https://github.com/smart…
DylanTinianov Feb 22, 2024
bae605b
Update context
DylanTinianov Feb 22, 2024
b0c1e6f
Update contexts
DylanTinianov Feb 22, 2024
edb8ac0
Fix mock call args
DylanTinianov Feb 22, 2024
2e85e93
Merge branch 'BCI-2644-refactor-evm-orms' of https://github.com/smart…
DylanTinianov Feb 22, 2024
bcd1516
Unexport orm
DylanTinianov Feb 23, 2024
eeda137
Merge pull request #12131 from smartcontractkit/BCI-2644-refactor-for…
DylanTinianov Feb 23, 2024
9a5acac
Fix arg name
DylanTinianov Feb 23, 2024
9e9f23d
merge develop
DylanTinianov Feb 29, 2024
24da79f
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
DylanTinianov Feb 29, 2024
f61e89a
update logpoller
DylanTinianov Feb 29, 2024
d1f5404
unexport orm
DylanTinianov Feb 29, 2024
88b67e1
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 29, 2024
8c096da
Use query
DylanTinianov Feb 29, 2024
985105f
fix tests
DylanTinianov Feb 29, 2024
c5dd049
fix imports
DylanTinianov Feb 29, 2024
23d4a0d
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 29, 2024
8c62b25
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Feb 29, 2024
8f58126
Use pkgerrors
DylanTinianov Mar 4, 2024
29d1616
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 4, 2024
9f7653f
Use registry ctx
DylanTinianov Mar 4, 2024
e70065d
Use context
DylanTinianov Mar 4, 2024
d3e3c4f
Use ctx
DylanTinianov Mar 4, 2024
b3f02dd
Use ctx
DylanTinianov Mar 4, 2024
596f9b4
Update orm.go
DylanTinianov Mar 4, 2024
271b892
Use context
DylanTinianov Mar 4, 2024
2606a0f
Use context
DylanTinianov Mar 4, 2024
aecda9c
Use context
DylanTinianov Mar 4, 2024
5e0d3fc
Propagate context
DylanTinianov Mar 4, 2024
1e1be7d
Propagate context
DylanTinianov Mar 4, 2024
0340a8c
Update listener_test.go
DylanTinianov Mar 4, 2024
f580740
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 4, 2024
f564a48
Fix context
DylanTinianov Mar 4, 2024
9249eed
Merge branch 'BCI-2644-refactor-evm-orms' of https://github.com/smart…
DylanTinianov Mar 4, 2024
67a57a8
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 4, 2024
78680a2
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 5, 2024
3c0da11
Export DbORM struct
DylanTinianov Mar 5, 2024
a58457c
Merge branch 'BCI-2644-refactor-evm-orms' of https://github.com/smart…
DylanTinianov Mar 5, 2024
a889f7f
Update orm.go
DylanTinianov Mar 5, 2024
f585fa3
Pass context
DylanTinianov Mar 5, 2024
6798f8d
Pass context
DylanTinianov Mar 5, 2024
4116ba2
Update orm.go
DylanTinianov Mar 5, 2024
1263bf1
Use testcontext
DylanTinianov Mar 5, 2024
a1e313b
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 5, 2024
d3dcbb9
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 5, 2024
e161e51
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 6, 2024
5859e8e
Initialize context
DylanTinianov Mar 6, 2024
79613c4
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 6, 2024
e227019
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 6, 2024
ffa57ce
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 7, 2024
e83c048
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 11, 2024
0e1fe26
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 12, 2024
a163cda
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 12, 2024
2c7b1ad
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 12, 2024
1269d73
Update context
DylanTinianov Mar 13, 2024
8823302
Propagate context
DylanTinianov Mar 13, 2024
942f687
core/services/chainlink: start using sqlutil.DB instead of pg.Q (#12386)
jmank88 Mar 13, 2024
87519d4
Check bind errors
DylanTinianov Mar 13, 2024
d5f15b8
Merge branch 'BCI-2644-refactor-evm-orms' of https://github.com/smart…
DylanTinianov Mar 13, 2024
bea4b3f
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 13, 2024
8b9d2f4
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 13, 2024
12adced
Add close timeout
DylanTinianov Mar 13, 2024
0e876bc
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
DylanTinianov Mar 13, 2024
58b36ab
Merge branch 'develop' of https://github.com/smartcontractkit/chainli…
DylanTinianov Mar 13, 2024
88d901a
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 14, 2024
38ede16
Add changeset
DylanTinianov Mar 14, 2024
7004e3f
Merge branch 'BCI-2644-refactor-evm-orms' of https://github.com/smart…
DylanTinianov Mar 14, 2024
9aae6a3
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 14, 2024
c6e4451
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 14, 2024
d80b5c4
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 14, 2024
2fb4038
Merge branch 'develop' into BCI-2644-refactor-evm-orms
DylanTinianov Mar 14, 2024
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
5 changes: 5 additions & 0 deletions .changeset/strong-ears-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Refactor EVM ORMs to remove pg dependency
15 changes: 7 additions & 8 deletions core/chains/evm/forwarders/forwarder_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
"github.com/ethereum/go-ethereum/core/types"
pkgerrors "github.com/pkg/errors"

"github.com/jmoiron/sqlx"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/utils"

evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
Expand All @@ -23,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/authorized_forwarder"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/authorized_receiver"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/offchain_aggregator_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
)

var forwardABI = evmtypes.MustGetABI(authorized_forwarder.AuthorizedForwarderABI).Methods["forward"]
Expand Down Expand Up @@ -56,13 +54,13 @@ type FwdMgr struct {
wg sync.WaitGroup
}

func NewFwdMgr(db *sqlx.DB, client evmclient.Client, logpoller evmlogpoller.LogPoller, l logger.Logger, cfg Config, dbConfig pg.QConfig) *FwdMgr {
func NewFwdMgr(db sqlutil.DB, client evmclient.Client, logpoller evmlogpoller.LogPoller, l logger.Logger, cfg Config) *FwdMgr {
lggr := logger.Sugared(logger.Named(l, "EVMForwarderManager"))
fwdMgr := FwdMgr{
logger: lggr,
cfg: cfg,
evmClient: client,
ORM: NewORM(db, lggr, dbConfig),
ORM: NewORM(db),
logpoller: logpoller,
sendersCache: make(map[common.Address][]common.Address),
}
Expand All @@ -80,7 +78,7 @@ func (f *FwdMgr) Start(ctx context.Context) error {
f.logger.Debug("Initializing EVM forwarder manager")
chainId := f.evmClient.ConfiguredChainID()

fwdrs, err := f.ORM.FindForwardersByChain(big.Big(*chainId))
fwdrs, err := f.ORM.FindForwardersByChain(ctx, big.Big(*chainId))
if err != nil {
return pkgerrors.Wrapf(err, "Failed to retrieve forwarders for chain %d", chainId)
}
Expand Down Expand Up @@ -113,7 +111,7 @@ func FilterName(addr common.Address) string {

func (f *FwdMgr) ForwarderFor(addr common.Address) (forwarder common.Address, err error) {
// Gets forwarders for current chain.
fwdrs, err := f.ORM.FindForwardersByChain(big.Big(*f.evmClient.ConfiguredChainID()))
fwdrs, err := f.ORM.FindForwardersByChain(f.ctx, big.Big(*f.evmClient.ConfiguredChainID()))
if err != nil {
return common.Address{}, err
}
Expand Down Expand Up @@ -211,6 +209,7 @@ func (f *FwdMgr) subscribeSendersChangedLogs(addr common.Address) error {
}

err := f.logpoller.RegisterFilter(
f.ctx,
evmlogpoller.Filter{
Name: FilterName(addr),
EventSigs: []common.Hash{authChangedTopic},
Expand Down Expand Up @@ -251,11 +250,11 @@ func (f *FwdMgr) runLoop() {
}

logs, err := f.logpoller.LatestLogEventSigsAddrsWithConfs(
f.ctx,
f.latestBlock,
[]common.Hash{authChangedTopic},
addrs,
evmlogpoller.Confirmations(f.cfg.FinalityDepth()),
pg.WithParentCtx(f.ctx),
DylanTinianov marked this conversation as resolved.
Show resolved Hide resolved
)
if err != nil {
f.logger.Errorw("Failed to retrieve latest log round", "err", err)
Expand Down
29 changes: 16 additions & 13 deletions core/chains/evm/forwarders/forwarder_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"

"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand All @@ -26,7 +28,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
)

var GetAuthorisedSendersABI = evmtypes.MustGetABI(authorized_receiver.AuthorizedReceiverABI).Methods["getAuthorizedSenders"]
Expand All @@ -39,6 +40,7 @@ func TestFwdMgr_MaybeForwardTransaction(t *testing.T) {
cfg := configtest.NewTestGeneralConfig(t)
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
owner := testutils.MustNewSimTransactor(t)
ctx := testutils.Context(t)

ec := backends.NewSimulatedBackend(map[common.Address]core.GenesisAccount{
owner.From: {
Expand Down Expand Up @@ -68,13 +70,13 @@ func TestFwdMgr_MaybeForwardTransaction(t *testing.T) {
RpcBatchSize: 2,
KeepFinalizedBlocksDepth: 1000,
}
lp := logpoller.NewLogPoller(logpoller.NewORM(testutils.FixtureChainID, db, lggr, pgtest.NewQConfig(true)), evmClient, lggr, lpOpts)
fwdMgr := forwarders.NewFwdMgr(db, evmClient, lp, lggr, evmcfg.EVM(), evmcfg.Database())
fwdMgr.ORM = forwarders.NewORM(db, logger.Test(t), cfg.Database())
lp := logpoller.NewLogPoller(logpoller.NewORM(testutils.FixtureChainID, db, lggr), evmClient, lggr, lpOpts)
fwdMgr := forwarders.NewFwdMgr(db, evmClient, lp, lggr, evmcfg.EVM())
fwdMgr.ORM = forwarders.NewORM(db)

fwd, err := fwdMgr.ORM.CreateForwarder(forwarderAddr, ubig.Big(*testutils.FixtureChainID))
fwd, err := fwdMgr.ORM.CreateForwarder(ctx, forwarderAddr, ubig.Big(*testutils.FixtureChainID))
require.NoError(t, err)
lst, err := fwdMgr.ORM.FindForwardersByChain(ubig.Big(*testutils.FixtureChainID))
lst, err := fwdMgr.ORM.FindForwardersByChain(ctx, ubig.Big(*testutils.FixtureChainID))
require.NoError(t, err)
require.Equal(t, len(lst), 1)
require.Equal(t, lst[0].Address, forwarderAddr)
Expand All @@ -87,22 +89,23 @@ func TestFwdMgr_MaybeForwardTransaction(t *testing.T) {
require.NoError(t, err)

cleanupCalled := false
cleanup := func(tx pg.Queryer, evmChainId int64, addr common.Address) error {
cleanup := func(tx sqlutil.DB, evmChainId int64, addr common.Address) error {
require.Equal(t, testutils.FixtureChainID.Int64(), evmChainId)
require.Equal(t, forwarderAddr, addr)
require.NotNil(t, tx)
cleanupCalled = true
return nil
}

err = fwdMgr.ORM.DeleteForwarder(fwd.ID, cleanup)
err = fwdMgr.ORM.DeleteForwarder(ctx, fwd.ID, cleanup)
assert.NoError(t, err)
assert.True(t, cleanupCalled)
}

func TestFwdMgr_AccountUnauthorizedToForward_SkipsForwarding(t *testing.T) {
lggr := logger.Test(t)
db := pgtest.NewSqlxDB(t)
ctx := testutils.Context(t)
cfg := configtest.NewTestGeneralConfig(t)
evmcfg := evmtest.NewChainScopedConfig(t, cfg)
owner := testutils.MustNewSimTransactor(t)
Expand All @@ -128,13 +131,13 @@ func TestFwdMgr_AccountUnauthorizedToForward_SkipsForwarding(t *testing.T) {
RpcBatchSize: 2,
KeepFinalizedBlocksDepth: 1000,
}
lp := logpoller.NewLogPoller(logpoller.NewORM(testutils.FixtureChainID, db, lggr, pgtest.NewQConfig(true)), evmClient, lggr, lpOpts)
fwdMgr := forwarders.NewFwdMgr(db, evmClient, lp, lggr, evmcfg.EVM(), evmcfg.Database())
fwdMgr.ORM = forwarders.NewORM(db, logger.Test(t), cfg.Database())
lp := logpoller.NewLogPoller(logpoller.NewORM(testutils.FixtureChainID, db, lggr), evmClient, lggr, lpOpts)
fwdMgr := forwarders.NewFwdMgr(db, evmClient, lp, lggr, evmcfg.EVM())
fwdMgr.ORM = forwarders.NewORM(db)

_, err = fwdMgr.ORM.CreateForwarder(forwarderAddr, ubig.Big(*testutils.FixtureChainID))
_, err = fwdMgr.ORM.CreateForwarder(ctx, forwarderAddr, ubig.Big(*testutils.FixtureChainID))
require.NoError(t, err)
lst, err := fwdMgr.ORM.FindForwardersByChain(ubig.Big(*testutils.FixtureChainID))
lst, err := fwdMgr.ORM.FindForwardersByChain(ctx, ubig.Big(*testutils.FixtureChainID))
require.NoError(t, err)
require.Equal(t, len(lst), 1)
require.Equal(t, lst[0].Address, forwarderAddr)
Expand Down
90 changes: 46 additions & 44 deletions core/chains/evm/forwarders/mocks/orm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading