Skip to content

Commit

Permalink
[BCF-3381] - Implement changeset LatestHead #521 (#14394)
Browse files Browse the repository at this point in the history
* Implement ChainSet LatestHead

* Update relayer references

* lint

* Add changest

* Update Solana ref

* Change Latest Head to use latestChain.BlockNumber() for Head Identifier

* Handle potential nil value in LatestHead

* Update common and feeds refs

* Update ccip and common refs

* Update relayers refs

* Update solana ref

* minor fix

* minor fix

* Update cosmos ref

* Update relayers and common refs

* run generate
  • Loading branch information
ilija42 authored Sep 11, 2024
1 parent bd62d0d commit 28989b3
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 75 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-numbers-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#internal Implement LatestHead for ChainService
5 changes: 5 additions & 0 deletions core/chains/chain_kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func (s *testChainService) HealthReport() map[string]error {
return map[string]error{}
}

// Implement [types.LatestHead] interface
func (s *testChainService) LatestHead(_ context.Context) (head types.Head, err error) {
return
}

// Implement [types.ChainService] interface
func (s *testChainService) GetChainStatus(ctx context.Context) (stat types.ChainStatus, err error) {
return
Expand Down
14 changes: 14 additions & 0 deletions core/chains/legacyevm/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"strconv"

gotoml "github.com/pelletier/go-toml/v2"
"go.uber.org/multierr"
Expand Down Expand Up @@ -393,6 +394,19 @@ func (c *chain) SendTx(ctx context.Context, from, to string, amount *big.Int, ba
return c.Transact(ctx, from, to, amount, balanceCheck)
}

func (c *chain) LatestHead(_ context.Context) (types.Head, error) {
latestChain := c.headTracker.LatestChain()
if latestChain == nil {
return types.Head{}, errors.New("latest chain not found")
}

return types.Head{
Height: strconv.FormatInt(latestChain.BlockNumber(), 10),
Hash: latestChain.Hash.Bytes(),
Timestamp: uint64(latestChain.Timestamp.Unix()),
}, nil
}

func (c *chain) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
toml, err := c.cfg.EVM().TOMLString()
if err != nil {
Expand Down
56 changes: 56 additions & 0 deletions core/chains/legacyevm/mocks/chain.go

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

12 changes: 6 additions & 6 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/prometheus/client_golang v1.20.0
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240911181800-d00d5184ffaa
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240717100443-f6226e09bee7
github.com/spf13/cobra v1.8.1
Expand Down Expand Up @@ -270,13 +270,13 @@ require (
github.com/sethvargo/go-retry v0.2.4 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shirou/gopsutil/v3 v3.24.3 // indirect
github.com/smartcontractkit/chain-selectors v1.0.21 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240910072312-810030689426 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240910210931-638ba8a76227 // indirect
github.com/smartcontractkit/chain-selectors v1.0.23 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240910161529-a7050b5193cd // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240910163253-2a5c9ab97de3 // indirect
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664 // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240911194142-506bc469d8ae // indirect
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 // indirect
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 // indirect
Expand Down
24 changes: 12 additions & 12 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1075,24 +1075,24 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/chain-selectors v1.0.21 h1:KCR9SA7PhOexaBzFieHoLv1WonwhVOPtOStpqTmLC4E=
github.com/smartcontractkit/chain-selectors v1.0.21/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnjjIQAEBnutCtksPzVDY=
github.com/smartcontractkit/chain-selectors v1.0.23/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240910072312-810030689426 h1:siC6AoTs4889FwiqgEp0sC6S8nFlDzVTZAmUX7cV7aM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240910072312-810030689426/go.mod h1:v8hmGodMN1s1TQnvZepZ3Pbo+PyzWVdXag7JzJnvrkI=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322 h1:9SkeP9lpTMDqtqDd+BKPQhkPcylSoYi63L9YFdbzbEo=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322/go.mod h1:D/qaCoq0SxXzg5NRN5FtBRv98VBf+D2NOC++RbvvuOc=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240910210931-638ba8a76227 h1:xow5cYrWxRmzTwhz2AjWOlnI9WRF4O5b84bXm1k292E=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240910210931-638ba8a76227/go.mod h1:DUFantPYoBGwBSkNVt2k4ZJi0jPKRRrZVVlAzcZwreA=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978 h1:BPuehkAQ8R112SlTitukSdKYRJMY3zkvaQS4VSTNn0Q=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978/go.mod h1:X1f4CKlR1RilSgzArQv5HNvMrVSt+Zloihm3REwxhdQ=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240911181800-d00d5184ffaa h1:vG4aRggHzNDFTmMFemhhUAzqTfG159w0+RYjO7/cJ5E=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240911181800-d00d5184ffaa/go.mod h1:sjiiPwd4KsYOCf68MwL86EKphdXeT66EY7j53WH5DCc=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7/go.mod h1:BMYE1vC/pGmdFSsOJdPrAA0/4gZ0Xo0SxTMdGspBtRo=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc h1:tRmTlaoAt+7FakMXXgeCuRPmzzBo5jsGpeCVvcU6KMc=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc/go.mod h1:PwPcmQNAzVmU8r8JWKrDRgvXesDwxnqbMD6DvYt/Z7M=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f h1:p4p3jBT91EQyLuAMvHD+zNJsuAYI/QjJbzuGUJ7wIgg=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f/go.mod h1:FLlWBt2hwiMVgt9AcSo6wBJYIRd/nsc8ENbV1Wir1bw=
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240910161529-a7050b5193cd h1:+RFI4mgXSGEcn847e7bavhQCqaBiW142g1XfGzijFoY=
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240910161529-a7050b5193cd/go.mod h1:Ou79geDZKg87CgRi0BTQpRhUT3U6LcrQWuGQveDRvlg=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240910163253-2a5c9ab97de3 h1:Tkl0/SB1hxjBgphslHf1E6iXp+4QAejuCLIT+8zvX3Y=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240910163253-2a5c9ab97de3/go.mod h1:mkuwCChesVqzMQpYQWRwckmQobJLwG4XCsw7KB8UCKY=
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664 h1:JPs35oSO07PK3Qv7Kyv0GJHVLacIE1IkrvefaPyBjKs=
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664/go.mod h1:iJ9DKYo0F64ue7IogAIELwU2DfrhEAh76eSmZOilT8A=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240911194142-506bc469d8ae h1:d+B8y2Nd/PrnPMNoaSPn3eDgUgxcVcIqAxGrvYu/gGw=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240911194142-506bc469d8ae/go.mod h1:ec/a20UZ7YRK4oxJcnTBFzp1+DBcJcwqEaerUMsktMs=
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-20240717100443-f6226e09bee7 h1:e38V5FYE7DA1JfKXeD5Buo/7lczALuVXlJ8YNTAUxcw=
Expand Down
4 changes: 4 additions & 0 deletions core/services/ocr2/plugins/generic/relayerset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ func (t *TestRelayer) NewContractReader(_ context.Context, _ []byte) (types.Cont
panic("implement me")
}

func (t *TestRelayer) LatestHead(_ context.Context) (types.Head, error) {
panic("implement me")
}

func (t *TestRelayer) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
panic("implement me")
}
Expand Down
3 changes: 3 additions & 0 deletions core/services/relay/dummy/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (r *relayer) NewLLOProvider(ctx context.Context, rargs types.RelayArgs, par
}
return NewLLOProvider(r.lggr, cp, transmitter, cdc), nil
}
func (r *relayer) LatestHead(_ context.Context) (types.Head, error) {
return types.Head{}, nil
}
func (r *relayer) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
return types.ChainStatus{}, nil
}
Expand Down
56 changes: 56 additions & 0 deletions core/services/relay/evm/mocks/loop_relay_adapter.go

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

6 changes: 3 additions & 3 deletions core/services/relay/evm/read/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ func (b *EventBinding) decodeLogsIntoSequences(ctx context.Context, logs []logpo
sequences[idx] = commontypes.Sequence{
Cursor: fmt.Sprintf("%s-%s-%d", logs[idx].BlockHash, logs[idx].TxHash, logs[idx].LogIndex),
Head: commontypes.Head{
Identifier: fmt.Sprint(logs[idx].BlockNumber),
Hash: logs[idx].BlockHash.Bytes(),
Timestamp: uint64(logs[idx].BlockTimestamp.Unix()),
Height: fmt.Sprint(logs[idx].BlockNumber),
Hash: logs[idx].BlockHash.Bytes(),
Timestamp: uint64(logs[idx].BlockTimestamp.Unix()),
},
}

Expand Down
4 changes: 4 additions & 0 deletions core/services/relay/evm/relayer_extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ type ChainRelayerExt struct {

var _ EVMChainRelayerExtender = &ChainRelayerExt{}

func (s *ChainRelayerExt) LatestHead(ctx context.Context) (commontypes.Head, error) {
return s.chain.LatestHead(ctx)
}

func (s *ChainRelayerExt) GetChainStatus(ctx context.Context) (commontypes.ChainStatus, error) {
return s.chain.GetChainStatus(ctx)
}
Expand Down
5 changes: 5 additions & 0 deletions core/web/testutils/mock_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type MockRelayer struct {
Head commontypes.Head
ChainStatus commontypes.ChainStatus
NodeStatuses []commontypes.NodeStatus
}
Expand Down Expand Up @@ -40,6 +41,10 @@ func (m MockRelayer) NewContractReader(_ context.Context, _ []byte) (commontypes
panic("not implemented")
}

func (m MockRelayer) LatestHead(_ context.Context) (commontypes.Head, error) {
return m.Head, nil
}

func (m MockRelayer) GetChainStatus(ctx context.Context) (commontypes.ChainStatus, error) {
return m.ChainStatus, nil
}
Expand Down
1 change: 1 addition & 0 deletions go.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ flowchart LR
click wsrpc href "https://github.com/smartcontractkit/wsrpc"
chainlink-automation --> chainlink-common
chainlink-automation --> libocr
chainlink-ccip --> chain-selectors
chainlink-ccip --> chainlink-common
chainlink-ccip --> libocr
chainlink-common --> grpc-proxy
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ require (
github.com/scylladb/go-reflectx v1.0.1
github.com/shirou/gopsutil/v3 v3.24.3
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chain-selectors v1.0.21
github.com/smartcontractkit/chain-selectors v1.0.23
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240910072312-810030689426
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240910210931-638ba8a76227
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240911145028-d346e3ace978
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240911181800-d00d5184ffaa
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240906125718-9f0a98d32fbc
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240910161529-a7050b5193cd
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240910163253-2a5c9ab97de3
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20240911182932-3c609a6ac664
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240911194142-506bc469d8ae
github.com/smartcontractkit/libocr v0.0.0-20240717100443-f6226e09bee7
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1
Expand Down
Loading

0 comments on commit 28989b3

Please sign in to comment.