Skip to content

Commit

Permalink
Codebase cleanup & polish #2
Browse files Browse the repository at this point in the history
  • Loading branch information
krebernisak committed Dec 29, 2021
1 parent 67a7df1 commit d817e34
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 29 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ jobs:
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
# TODO: we probably want cachix enabled here
# - name: Setup cachix
# uses: cachix/cachix-action@v10
# with:
# name: nix-cargo-integration
# authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
# TODO: We probably want cachix enabled heres
# https://github.com/smartcontractkit/chainlink-terra/issues/15

- name: Run unit tests
run: nix develop -c cargo unit-test --locked
Expand Down Expand Up @@ -64,16 +60,12 @@ jobs:
extra_nix_config: |
experimental-features = nix-command flakes
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
# - name: Run cargo clippy
# run: nix develop -c cargo clippy --all-targets -- -D warnings
# ^ currently has issues on CI
# TODO: Run cargo clippy
# https://github.com/smartcontractkit/chainlink-terra/issues/16

- name: Run cargo fmt
run: nix develop -c cargo fmt --all -- --check

# TODO: we should check
# CHANGES_IN_REPO=$(git status --porcelain)
# after this, but I don't know how
# - name: Generate Schema
# run: nix develop -c cargo schema --locked
# TODO: Add schema checks
# https://github.com/smartcontractkit/chainlink-terra/issues/17
3 changes: 2 additions & 1 deletion contracts/deviation-flagging-validator/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use cosmwasm_std::Addr;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

// TODO: deduplicate
// TODO: Deduplicate (also declared in 'contracts/ocr2/src/state.rs')
// https://github.com/smartcontractkit/chainlink-terra/issues/18
pub mod bignum {
use serde::{self, Deserialize, Deserializer, Serializer};

Expand Down
1 change: 1 addition & 0 deletions contracts/ocr2/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ fn transmit_happy_path() {
);

// TODO: test repeated withdrawal to check for no-op
// https://github.com/smartcontractkit/chainlink-terra/issues/19

// -- now trigger set_config again which should clear the state and pay out remaining oracles

Expand Down
5 changes: 2 additions & 3 deletions pkg/terra/contract_config_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (ct *Contract) LatestConfig(ctx context.Context, changedInBlock uint64) (ty
return types.ContractConfig{}, fmt.Errorf("No transactions found for block %d", changedInBlock)
}

// fetch event and process (use first tx and first log set)
// fetch event and process (use first tx and \first log set)
if len(res.Txs[0].TxResult.Events) == 0 {
return types.ContractConfig{}, fmt.Errorf("No events found for tx %s", res.Txs[0].Hash)
}
Expand All @@ -122,6 +122,7 @@ func (ct *Contract) LatestConfig(ctx context.Context, changedInBlock uint64) (ty
if event.Type == "wasm-set_config" {
output := types.ContractConfig{}
// TODO: is there a better way to parse an array of structs to an struct
// https://github.com/smartcontractkit/chainlink-terra/issues/21
for _, attr := range event.Attributes {
key, value := string(attr.Key), string(attr.Value)
switch key {
Expand All @@ -137,15 +138,13 @@ func (ct *Contract) LatestConfig(ctx context.Context, changedInBlock uint64) (ty
}
output.ConfigCount = uint64(i)
case "signers":
// TODO: verify parsing to [][]byte
// this assumes the value will be a hex encoded string which each signer 32 bytes and each signer will be a separate parameter
var v []byte
if err := HexToByteArray(value, &v); err != nil {
return types.ContractConfig{}, err
}
output.Signers = append(output.Signers, v)
case "transmitters":
// TODO: verify parsing to []string
// this assumes the return value be a string for each transmitter and each transmitter will be separate
output.Transmitters = append(output.Transmitters, types.Account(attr.Value))
case "f":
Expand Down
3 changes: 3 additions & 0 deletions pkg/terra/median_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (ct *Contract) LatestTransmissionDetails(
)
if err != nil {
// TODO: Verify if this is still necessary
// https://github.com/smartcontractkit/chainlink-terra/issues/23
// Handle the 500 error that occurs when there has not been a submission
// "rpc error: code = Unknown desc = ocr2::state::Transmission not found: contract query failed"
if strings.Contains(fmt.Sprint(err), "ocr2::state::Transmission not found") {
Expand Down Expand Up @@ -105,9 +106,11 @@ func (ct *Contract) LatestRoundRequested(ctx context.Context, lookback time.Dura
err = fmt.Errorf("No events found for tx %s", res.Txs[index].Hash)
return
}

for _, event := range res.Txs[index].TxResult.Events {
if event.Type == "wasm-new_round" {
// TODO: confirm event parameters
// https://github.com/smartcontractkit/chainlink-terra/issues/22
for _, attr := range event.Attributes {
key, value := string(attr.Key), string(attr.Value)
switch key {
Expand Down
10 changes: 0 additions & 10 deletions pkg/terra/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ type OCR2Spec struct {

type Relayer struct {
lggr Logger
//connections Connections
}

// Note: constructed in core
func NewRelayer(lggr Logger) *Relayer {
return &Relayer{
lggr: lggr,
//connections: Connections{},
}
}

Expand All @@ -62,8 +60,6 @@ func (r *Relayer) Start() error {

// Close will close all open subservices
func (r *Relayer) Close() error {
// close all open network client connections
//return r.connections.Close()
return nil
}

Expand All @@ -74,7 +70,6 @@ func (r *Relayer) Ready() error {

// Healthy only if all subservices are healthy
func (r *Relayer) Healthy() error {
// TODO: are all open WS connections healthy?
return nil
}

Expand All @@ -85,7 +80,6 @@ func (r *Relayer) NewOCR2Provider(externalJobID uuid.UUID, s interface{}) (relay
return provider, errors.New("unsuccessful cast to 'terra.OCR2Spec'")
}

// TODO: re-use ws connections
client, err := NewClient(spec, r.lggr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -128,13 +122,10 @@ type ocr2Provider struct {
}

func (p ocr2Provider) Start() error {
// TODO: start all needed subservices
return nil
}

func (p ocr2Provider) Close() error {
// TODO: close all subservices
// TODO: close client WS connection if not used/shared anymore
return nil
}

Expand All @@ -144,7 +135,6 @@ func (p ocr2Provider) Ready() error {
}

func (p ocr2Provider) Healthy() error {
// TODO: only if all subservices are healthy
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/terra/terra.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func (c *Client) ensureWsConnection() error {
mu: &sync.Mutex{},
}
// TODO: does the websocket connection need a close handler to resubscribe?
// https://github.com/smartcontractkit/chainlink-terra/issues/24

// start listening
go c.listen()
Expand Down Expand Up @@ -328,6 +329,7 @@ func (c *Client) subscribe(ctx context.Context, jobID string, filterQuery []stri
// listen is the message
func (c *Client) listen() {
// TODO: Need a way to prevent "use of closed network connection" error when closing connection
// https://github.com/smartcontractkit/chainlink-terra/issues/25
for {
_, messageBytes, err := c.ws.conn.ReadMessage()
if err != nil {
Expand Down

0 comments on commit d817e34

Please sign in to comment.