-
Notifications
You must be signed in to change notification settings - Fork 64
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
Update state-fold use on eth-input-reader #59
Update state-fold use on eth-input-reader #59
Conversation
ab8f1df
to
bdd2837
Compare
d5cf8f7
to
eb1b900
Compare
e33f069
to
4c92ad6
Compare
eb1b900
to
568311c
Compare
4c92ad6
to
9ed8c8e
Compare
568311c
to
4e3dc50
Compare
a81e2ba
to
3ce9ad1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do a full review tomorrow.
CHANGELOG.md
Outdated
@@ -10,13 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
### Added | |||
|
|||
- Added authority claimer service to support reader mode | |||
- Added `SFConfig`, `BHConfig` and `subscription_depth` configuration to `eth-input-reader` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The internal names are not helpful for those who use the node. We should add the full env var names here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is my proposal to the changelog:
### Changed
- Replaced the state-server with the state-fold library in the eth-input-reader
- Moved `SF_*` and `BH_*` environment variables from state-server config to the eth-input-reader
### Removed
- Removed the state-server from the node
- Removed SS_MAX_DECODING_MESSAGE_SIZE environment variable from eth-input-reader because it doesn't use gRPC anymore
@@ -43,25 +45,28 @@ pub struct EthInputReaderEnvCLIConfig { | |||
/// Duration of rollups epoch in seconds, for which eth-input-reader will make claims. | |||
#[arg(long, env, default_value = "604800")] | |||
pub rd_epoch_duration: u64, | |||
|
|||
/// Depth on the blockchain the reader will be listening to | |||
#[arg(long, env)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put the default value here, like the other variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Furthermore, the chain_id
has to be verified. Either one should just gets it from the blockchain, no configuration needed, or one gets it from the config but validates it nonetheless. Although I lean more towards the latter, here I think either is acceptable because we're not sending transactions.
Also, a default value would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, why do we need the chain_id
? For metrics?
Signing needs it, but I'm not sure this component does.
|
||
pub dapp_deployment: DappDeployment, | ||
pub rollups_deployment: RollupsDeployment, | ||
pub epoch_duration: u64, | ||
pub priority: Priority, | ||
pub subscription_depth: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the equivalent of the former variable SC_DEFAULT_CONFIRMATIONS
? I think it is, but I'm not sure. If it is, we should use the same name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, I changed because SC_DEFAULT_CONFIRMATIONS
is a terrible (and deprecated) name. SC stands for State Client, which we no longer use, and default confirmations really poorly instructs the user that we are asking which depth we should be reading, imho. It can be another name other than this, but I really think we should change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it makes sense. Could you add this change to the backlog?
use eth_state_fold_types::Block; | ||
use ethers::types::Address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get this change. Why do we need to change this type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type isn't changed, but before the state-fold-types re-exported the ethers crate, and we called the ethers types from inside state-fold-types. With the refactoring, we use state-fold-types only for the types defined in it, and import the ethers types directly from itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The state-fold is an abstraction on top of ethers, so it makes sense to use the re-exported type instead of importing it from ethers directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me and Renan have been refactoring to stop this using ethers from inside state-fold, he was very adamant about it. I can change it back, no problem, but it's going diverge from the rest of the refactoring. I think it's worth to have a talk between the three of us to understand why this should change/remain the same. @renan061
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd be really cautious about not using reexported ethers-rs
.
.await | ||
.context(StateServerSnafu)? | ||
.expect("should get genesis block") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should handle errors properly with Snafu instead of using expect.
@@ -10,13 +10,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |||
### Added | |||
|
|||
- Added authority claimer service to support reader mode | |||
- Added `SFConfig`, `BHConfig` and `subscription_depth` configuration to `eth-input-reader` | |||
|
|||
### Changed | |||
|
|||
- Renamed `dispatcher` service to `eth-input-reader` | |||
|
|||
### Removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the state-server from the repository in this PR because it won't be used anymore.
config.sf_config.genesis_block, | ||
config.sf_config.query_limit_error_codes.clone(), | ||
config.sf_config.concurrent_events_fetch, | ||
10000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this magic number? We should at least create a local const magic_number = 10000
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got this magic number directly from state-server, where is just as magical, you can check on the state-server/src/lib.rs at line 92. I checked the StateFoldEnvironment and copied the comment from there above the const inside the setup.
@GCdePaula, if you have some spare time, could you look at this PR? |
3ce9ad1
to
ce5a4be
Compare
9ed8c8e
to
52030b1
Compare
c081e5d
to
bf27f7c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I left a few comments. Also, I'm not sure what's the timeline here, and there's the Go node stuff. So maybe some of the comments are not really relevant. Feel free to ignore the minor and more abstract comments.
.query_state(initial_state, block.hash) | ||
.await | ||
.context(StateServerSnafu)?; | ||
let state = RollupsState::get_state_for_block( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe with this change you don't need the whole RollupsState
, instead just the InputBox
.
@@ -43,25 +45,28 @@ pub struct EthInputReaderEnvCLIConfig { | |||
/// Duration of rollups epoch in seconds, for which eth-input-reader will make claims. | |||
#[arg(long, env, default_value = "604800")] | |||
pub rd_epoch_duration: u64, | |||
|
|||
/// Depth on the blockchain the reader will be listening to | |||
#[arg(long, env)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Furthermore, the chain_id
has to be verified. Either one should just gets it from the blockchain, no configuration needed, or one gets it from the config but validates it nonetheless. Although I lean more towards the latter, here I think either is acceptable because we're not sending transactions.
Also, a default value would be nice.
@@ -43,25 +45,28 @@ pub struct EthInputReaderEnvCLIConfig { | |||
/// Duration of rollups epoch in seconds, for which eth-input-reader will make claims. | |||
#[arg(long, env, default_value = "604800")] | |||
pub rd_epoch_duration: u64, | |||
|
|||
/// Depth on the blockchain the reader will be listening to | |||
#[arg(long, env)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally, why do we need the chain_id
? For metrics?
Signing needs it, but I'm not sure this component does.
pub chain_id: Option<u64>, | ||
|
||
/// Depth on the blockchain the reader will be listening to | ||
#[arg(long, env, default_value = "7")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be larger. Current value makes nobody happy; 7
is neither safe nor fast. I think maybe 12
? Or 0
.
@@ -2,10 +2,11 @@ | |||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | |||
|
|||
use axum::http::uri::InvalidUri; | |||
use eth_state_client_lib::error::StateServerError; | |||
use ethers::providers::{Http, Provider, RetryClient}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be extremely careful about not using the reexported ethers-rs
. Is there a good reason for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No good reason I can explain well. Renan was pretty adamant about not doing it this way, and at the time Rust would still be the main project going forward. I can change it back, no problem.
&state_server, | ||
config.sc_config.default_confirmations, | ||
let mut block_subscription = create_subscription( | ||
Arc::clone(&block_subscriber), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reconsider the need of this clone
.
@@ -1,88 +1,116 @@ | |||
// (c) Cartesi and individual authors (see AUTHORS) | |||
// SPDX-License-Identifier: Apache-2.0 (see LICENSE) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think many functions in this file could be joined into a single one, returning just what the start
function needs.
broker: &impl BrokerStatus, | ||
dapp_metadata: DAppMetadata, | ||
metrics: EthInputReaderMetrics, | ||
) -> Result<Context, EthInputReaderError> { | ||
let genesis_timestamp: u64 = block_server | ||
.query_block(config.dapp_deployment.deploy_block_hash) | ||
let genesis_timestamp: u64 = block_subscriber |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this makes sense. I think you should use the provider instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do I use the provider to get the genesis timestamp of a block?
@@ -10,7 +10,7 @@ pub mod built_info { | |||
include!(concat!(env!("OUT_DIR"), "/built.rs")); | |||
} | |||
|
|||
#[derive(Debug, Parser)] | |||
#[derive(Debug, Parser, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider whether the cases you're cloning the config could instead just borrow.
@@ -346,7 +346,7 @@ pub enum BrokerError { | |||
InvalidPayload { source: serde_json::Error }, | |||
} | |||
|
|||
#[derive(Debug, Parser)] | |||
#[derive(Debug, Parser, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider whether the cases you're cloning the config could instead just borrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The borrow requires a lifetime specifier, the flatten command also complains, and the other configs from block-history and state-fold are cloned, so I just kept the pattern.
bf27f7c
to
8ec82d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just some minor comments on style.
impl Stream< | ||
Item = Result< | ||
BlockStreamItem, | ||
SubscriptionError<InputProvider>, | ||
>, | ||
> + std::marker::Unpin, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a type alias.
SubscriptionError<InputProvider>, | ||
>, | ||
> + std::marker::Unpin, | ||
StateFoldEnvironment<InputProvider, Mutex<UserData>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this too?
4f36d4a
into
feature/remove-claims-dispatcher
#41