Skip to content

Commit

Permalink
Implement ChainSet LatestHead
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 committed Sep 10, 2024
1 parent 638ba8a commit 9e48b12
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/pelletier/go-toml/v2 v2.2.0
github.com/prometheus/client_golang v1.17.0
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910221017-268a136b2e03
github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.17.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
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/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-common v0.2.2-0.20240910221017-268a136b2e03 h1:Rh+mJZgOVSfcMwuZitSeiWQJ7djRWcOSbcrMJsEf0Nw=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910221017-268a136b2e03/go.mod h1:D/qaCoq0SxXzg5NRN5FtBRv98VBf+D2NOC++RbvvuOc=
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-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/uuid v1.6.0
github.com/lib/pq v1.10.9
github.com/rs/zerolog v1.31.0
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910154010-ed9f50de7322
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910221017-268a136b2e03
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240621143432-85370a54b141
github.com/smartcontractkit/chainlink-cosmos/ops v0.0.0-20231206164210-03f8b219402e
github.com/smartcontractkit/chainlink-testing-framework v1.33.0
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/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-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-common v0.2.2-0.20240910221017-268a136b2e03 h1:Rh+mJZgOVSfcMwuZitSeiWQJ7djRWcOSbcrMJsEf0Nw=
github.com/smartcontractkit/chainlink-common v0.2.2-0.20240910221017-268a136b2e03/go.mod h1:D/qaCoq0SxXzg5NRN5FtBRv98VBf+D2NOC++RbvvuOc=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240702145022-37a2c3a742d1 h1:dsTmitRaVizHxoYFoGz4+y/zVa8XnvKUiTaZdx+6t9M=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240702145022-37a2c3a742d1/go.mod h1:6DgCnHMGdBaIh0bLs1dK0MtdeMZfeNhc/nvBUN6KIUg=
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240522213638-159fb2d99917 h1:MD80ZRCTvxxJ8PBmhtrKoTnky8cVNYrCrIBLVRbrOM0=
Expand Down
20 changes: 20 additions & 0 deletions pkg/cosmos/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math/big"
"strconv"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -189,6 +190,24 @@ func (c *chain) HealthReport() map[string]error {
return m
}

func (c *chain) LatestHead(_ context.Context) (types.Head, error) {
reader, err := c.Reader("")
if err != nil {
return types.Head{}, err
}

latestBlock, err := reader.LatestBlock()
if err != nil {
return types.Head{}, err
}

return types.Head{
Identifier: strconv.FormatInt(latestBlock.SdkBlock.Header.Height, 10),
Hash: latestBlock.BlockId.Hash,
Timestamp: uint64(latestBlock.SdkBlock.Header.Time.Unix()),
}, nil
}

// ChainService interface
func (c *chain) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
toml, err := c.cfg.TOMLString()
Expand All @@ -201,6 +220,7 @@ func (c *chain) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
Config: toml,
}, nil
}

func (c *chain) ListNodeStatuses(ctx context.Context, pageSize int32, pageToken string) (stats []types.NodeStatus, nextPageToken string, total int, err error) {
return chains.ListNodeStatuses(int(pageSize), pageToken, c.listNodeStatuses)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/cosmos/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func (r *Relayer) HealthReport() map[string]error {
return hp
}

func (r *Relayer) LatestHead(ctx context.Context) (types.Head, error) {
return r.chain.LatestHead(ctx)
}

func (r *Relayer) GetChainStatus(ctx context.Context) (types.ChainStatus, error) {
return r.chain.GetChainStatus(ctx)
}
Expand Down

0 comments on commit 9e48b12

Please sign in to comment.