Skip to content
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

Conversation

GMKrieger
Copy link
Contributor

#41

@GMKrieger GMKrieger added this to the 1.1.0 milestone Aug 23, 2023
@GMKrieger GMKrieger requested review from renan061 and a team August 23, 2023 13:34
@GMKrieger GMKrieger self-assigned this Aug 23, 2023
@GMKrieger GMKrieger force-pushed the feature/remove-claims-dispatcher branch from ab8f1df to bdd2837 Compare August 24, 2023 17:08
@GMKrieger GMKrieger force-pushed the feature/refactor-eth-input-reader branch 2 times, most recently from d5cf8f7 to eb1b900 Compare August 24, 2023 17:25
@GMKrieger GMKrieger force-pushed the feature/remove-claims-dispatcher branch 2 times, most recently from e33f069 to 4c92ad6 Compare August 28, 2023 17:26
@GMKrieger GMKrieger force-pushed the feature/refactor-eth-input-reader branch from eb1b900 to 568311c Compare August 28, 2023 17:30
@GMKrieger GMKrieger force-pushed the feature/remove-claims-dispatcher branch from 4c92ad6 to 9ed8c8e Compare August 28, 2023 18:01
@GMKrieger GMKrieger force-pushed the feature/refactor-eth-input-reader branch from 568311c to 4e3dc50 Compare August 28, 2023 18:04
@gligneul gligneul linked an issue Sep 4, 2023 that may be closed by this pull request
2 tasks
CHANGELOG.md Outdated Show resolved Hide resolved
offchain/eth-input-reader/src/setup.rs Outdated Show resolved Hide resolved
@GMKrieger GMKrieger force-pushed the feature/refactor-eth-input-reader branch 2 times, most recently from a81e2ba to 3ce9ad1 Compare September 12, 2023 17:38
Copy link
Contributor

@gligneul gligneul left a 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`
Copy link
Contributor

@gligneul gligneul Sep 19, 2023

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.

Copy link
Contributor

@gligneul gligneul Sep 20, 2023

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)]
Copy link
Contributor

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.

Copy link
Contributor

@GCdePaula GCdePaula Oct 27, 2023

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.

Copy link
Contributor

@GCdePaula GCdePaula Oct 27, 2023

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,
Copy link
Contributor

@gligneul gligneul Sep 20, 2023

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

offchain/eth-input-reader/src/config.rs Show resolved Hide resolved
Comment on lines 8 to 9
use eth_state_fold_types::Block;
use ethers::types::Address;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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")
Copy link
Contributor

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
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@gligneul
Copy link
Contributor

@GCdePaula, if you have some spare time, could you look at this PR?

@GMKrieger GMKrieger force-pushed the feature/refactor-eth-input-reader branch from 3ce9ad1 to ce5a4be Compare September 27, 2023 17:08
@gligneul gligneul modified the milestones: 1.1.0, 1.2.0 Sep 28, 2023
@GMKrieger GMKrieger force-pushed the feature/remove-claims-dispatcher branch from 9ed8c8e to 52030b1 Compare October 25, 2023 17:46
@GMKrieger GMKrieger force-pushed the feature/refactor-eth-input-reader branch 2 times, most recently from c081e5d to bf27f7c Compare October 25, 2023 18:22
Copy link
Contributor

@GCdePaula GCdePaula left a 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(
Copy link
Contributor

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)]
Copy link
Contributor

@GCdePaula GCdePaula Oct 27, 2023

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)]
Copy link
Contributor

@GCdePaula GCdePaula Oct 27, 2023

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")]
Copy link
Contributor

@GCdePaula GCdePaula Oct 27, 2023

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};
Copy link
Contributor

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?

Copy link
Contributor Author

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),
Copy link
Contributor

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)

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 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
Copy link
Contributor

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.

Copy link
Contributor Author

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)]
Copy link
Contributor

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)]
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@GMKrieger GMKrieger force-pushed the feature/refactor-eth-input-reader branch from bf27f7c to 8ec82d5 Compare October 31, 2023 19:17
Copy link
Contributor

@GCdePaula GCdePaula left a 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.

Comment on lines +41 to +46
impl Stream<
Item = Result<
BlockStreamItem,
SubscriptionError<InputProvider>,
>,
> + std::marker::Unpin,
Copy link
Contributor

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>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this too?

@GMKrieger GMKrieger merged commit 4f36d4a into feature/remove-claims-dispatcher Nov 3, 2023
3 of 5 checks passed
@GMKrieger GMKrieger deleted the feature/refactor-eth-input-reader branch November 3, 2023 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Change how the state-fold is used in the dispatcher
4 participants