Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

chore: make the evm client and relayer testable #85

Merged
merged 5 commits into from
Feb 6, 2023

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Jan 30, 2023

Overview

This PR refactors the relayer and EVM client to make them testable.

It mainly makes the eth client and transaction opts pluggable so that we can simulate them using geth simulated backend.

Contributes to: #55

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

@rach-id rach-id added relayer relayer related testing labels Jan 30, 2023
@rach-id rach-id requested a review from rahulghangas January 30, 2023 14:48
@rach-id rach-id requested a review from evan-forbes as a code owner January 30, 2023 14:48
@rach-id rach-id self-assigned this Jan 30, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2023

Codecov Report

Merging #85 (83b33ed) into main (c13c1c9) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main      #85   +/-   ##
=======================================
  Coverage   59.75%   59.75%           
=======================================
  Files           6        6           
  Lines         164      164           
=======================================
  Hits           98       98           
  Misses         53       53           
  Partials       13       13           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

mind elaborating a bit on how this makes it more testable? just by using the testops?

time.Sleep(2 * time.Second)
continue
}
ethClient.Close()
Copy link
Member

Choose a reason for hiding this comment

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

[blocking question]
should this close be deferred? it looks like we could end up spinning up many of these, should we only be spinning up 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

should this close be deferred?

I prefered to close it everytime not to leave hanging rpc connections. This is because we don't know how much time there will be between every attestation relay.

For example, now with the default 400block and 15sec block time, data commitments will be relayed every 1hour and a half. For valsets, that depends on the network.

That's why I chose to use the connection then close it immediatly.

it looks like we could end up spinning up many of these, should we only be spinning up 1?

Only one will be spinned up because relaying attestations is sequential, there is no way to parallelize it.

Copy link
Member

Choose a reason for hiding this comment

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

okay cool, good to know

I prefered to close it everytime not to leave hanging rpc connections.

yeah that's what I was worried about with potentially spinning one up in each loop. why not only open a single one before we start the loop and then defer to close? atm, it look like we will spin up many if we receive an error on line 99

Copy link
Member

Choose a reason for hiding this comment

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

I prefered to close it everytime not to leave hanging rpc connections.

opening once before the loop starts and defering the close should guarantee that we do not do this, and as a bonus, its very flexible for future changes, and follows the standard practices of go

Copy link
Member Author

Choose a reason for hiding this comment

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

got it 👍 change incoming

Copy link
Member Author

Choose a reason for hiding this comment

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

return nil, err
ec.logger.Debug("waiting for transaction to be confirmed", "hash", tx.Hash().String())

receipt, err := bind.WaitMined(ctx, backend, tx)
Copy link
Member

Choose a reason for hiding this comment

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

[blocking question]
do we know if we should still be using WaitMined given eth is no longer PoW?

Copy link
Member Author

Choose a reason for hiding this comment

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

I checked the repo and no changes have been done to it. Probably they should rename it but they still didn't.
Anyway, it's not related to the underlying consensus, it just keeps polling if the transaction was included in some block.

@rach-id
Copy link
Member Author

rach-id commented Feb 1, 2023

mind elaborating a bit on how this makes it more testable? just by using the testops?

Yes, when running tests, we will use the simulated backend ops. However, when we use a real network, we will pass the real opts created using an EthClient.

@rach-id rach-id requested a review from evan-forbes February 1, 2023 20:49
privateKey: privateKey,
evmRPC: evmRPC,
gasLimit: gasLimit,
Wrapper: wrapper,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I've seen different names for the wrapper somewhere (I'll double check). If yes, we might want to be consistent throughout

Copy link
Member Author

Choose a reason for hiding this comment

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

#98

@rach-id rach-id merged commit 3d8a7cd into celestiaorg:main Feb 6, 2023
@rach-id rach-id deleted the update_evm_client_to_be_testable branch February 6, 2023 17:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
relayer relayer related testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants