fn main()

in fastpay/src/server.rs [157:240]


fn main() {
    env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();
    let options = ServerOpt::from_args();

    let server_config_path = &options.server;

    match options.cmd {
        ServerCommands::Run {
            buffer_size,
            cross_shard_queue_size,
            committee,
            initial_accounts,
            shard,
        } => {
            // Run the server
            let servers = match shard {
                Some(shard) => {
                    info!("Running shard number {}", shard);
                    let server = make_shard_server(
                        "0.0.0.0", // Allow local IP address to be different from the public one.
                        server_config_path,
                        &committee,
                        &initial_accounts,
                        buffer_size,
                        cross_shard_queue_size,
                        shard,
                    );
                    vec![server]
                }
                None => {
                    info!("Running all shards");
                    make_servers(
                        "0.0.0.0", // Allow local IP address to be different from the public one.
                        server_config_path,
                        &committee,
                        &initial_accounts,
                        buffer_size,
                        cross_shard_queue_size,
                    )
                }
            };

            let mut rt = Runtime::new().unwrap();
            let mut handles = Vec::new();
            for server in servers {
                handles.push(async move {
                    let spawned_server = match server.spawn().await {
                        Ok(server) => server,
                        Err(err) => {
                            error!("Failed to start server: {}", err);
                            return;
                        }
                    };
                    if let Err(err) = spawned_server.join().await {
                        error!("Server ended with an error: {}", err);
                    }
                });
            }
            rt.block_on(join_all(handles));
        }

        ServerCommands::Generate {
            protocol,
            host,
            port,
            shards,
        } => {
            let (address, key) = get_key_pair();
            let authority = AuthorityConfig {
                network_protocol: protocol,
                address,
                host,
                base_port: port,
                num_shards: shards,
            };
            let server = AuthorityServerConfig { authority, key };
            server
                .write(server_config_path)
                .expect("Unable to write server config file");
            info!("Wrote server config file");
            server.authority.print();
        }
    }
}