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

Refactor Genesis Code #807

Merged
merged 1 commit into from
Mar 17, 2022
Merged

Refactor Genesis Code #807

merged 1 commit into from
Mar 17, 2022

Conversation

666lcz
Copy link
Contributor

@666lcz 666lcz commented Mar 12, 2022

It is confusing to see the usage of genesis_ctx and pre_loaded_modules in both /sui/genesis path and sui/start path. This PR remove the usage of genesis related code from the /sui/start code path.

sui/sui/src/rest_server.rs

Lines 279 to 325 in 13c4e9f

async fn sui_start(
rqctx: Arc<RequestContext<ServerContext>>,
) -> Result<HttpResponseOk<String>, HttpError> {
let server_context = rqctx.context();
let network_config_path = &server_context.network_config_path;
let network_config = NetworkConfig::read_or_create(&PathBuf::from(network_config_path))
.map_err(|error| {
custom_http_error(
StatusCode::CONFLICT,
format!("Unable to read network config: {error}"),
)
})?;
if network_config.authorities.is_empty() {
return Err(custom_http_error(
StatusCode::CONFLICT,
String::from("No authority configured for the network, please make a POST request to the `sui/genesis` endpoint."),
));
}
{
if !(*server_context.authority_handles.lock().unwrap()).is_empty() {
return Err(custom_http_error(
StatusCode::FORBIDDEN,
String::from("Sui network is already running."),
));
}
}
let committee = Committee::new(
network_config
.authorities
.iter()
.map(|info| (*info.key_pair.public_key_bytes(), info.stake))
.collect(),
);
let mut handles = FuturesUnordered::new();
for authority in &network_config.authorities {
let server = sui_commands::make_server(
authority,
&committee,
vec![],
&[],
network_config.buffer_size,
)

sui/sui/src/sui_commands.rs

Lines 248 to 265 in 13c4e9f

pub async fn make_server(
authority: &AuthorityPrivateInfo,
committee: &Committee,
preload_modules: Vec<Vec<CompiledModule>>,
preload_objects: &[Object],
buffer_size: usize,
) -> SuiResult<AuthorityServer> {
let mut genesis_ctx = genesis::get_genesis_context();
make_server_with_genesis_ctx(
authority,
committee,
preload_modules,
preload_objects,
buffer_size,
&mut genesis_ctx,
)
.await
}

@666lcz 666lcz force-pushed the chris/refactor-genesis branch 2 times, most recently from dd6c317 to 86e3e89 Compare March 12, 2022 20:52
Copy link
Contributor

@patrickkuo patrickkuo left a comment

Choose a reason for hiding this comment

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

just one comment on start_server function name

sui/src/sui_commands.rs Outdated Show resolved Hide resolved
) -> Self {
let state = AuthorityState::new_without_genesis(committee, name, secret, store).await;

for genesis_modules in genesis_packages {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In PR #835 I point out (and fix) a bug in this logic: we need to check that the database is empty before calling again the logic to init it. You should be able to land this and I will rebase.

@666lcz 666lcz force-pushed the chris/refactor-genesis branch 2 times, most recently from 8b454f8 to b36aedb Compare March 16, 2022 18:17
@666lcz 666lcz force-pushed the chris/refactor-genesis branch from b36aedb to 44413f9 Compare March 16, 2022 22:52
@666lcz 666lcz merged commit 24650d0 into main Mar 17, 2022
@666lcz 666lcz deleted the chris/refactor-genesis branch March 17, 2022 03:13
mwtian pushed a commit to mwtian/sui that referenced this pull request Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants