Przeglądaj źródła

faucetd: Register p2p protocols on all sessions.

parazyd 4 lat temu
rodzic
commit
e5f1df1144
2 zmienionych plików z 54 dodań i 25 usunięć
  1. 27 7
      bin/faucetd/faucetd_config.toml
  2. 27 18
      bin/faucetd/src/main.rs

+ 27 - 7
bin/faucetd/faucetd_config.toml

@@ -2,16 +2,36 @@
 ##
 ## Please make sure you go through all the settings so you can configure
 ## your daemon properly.
+##
+## The default values are left commented. They can be overridden either by
+## uncommenting, or by using the command-line.
 
-# Path to the client database
-#database_path = "~/.config/darkfi/darkfid_client.db"
+# Chain to use (testnet, mainnet)
+chain = "testnet"
 
 # Path to the wallet database
-#wallet_path = "~/.config/darkfi/darkfid_wallet.db"
+wallet_path = "~/.config/darkfi/faucetd_wallet.db"
 
-# Wallet password
+# Password for the wallet database
 wallet_pass = "changeme"
 
-# JSON-RPC listening url
-#rpc_listen = "tcp://127.0.0.1:5397"
-#rpc_listen = "tls://127.0.0.1:5397"
+# Path to the blockchain database directory
+database = "~/.config/darkfi/faucetd_blockchain"
+
+# JSON-RPC listen URL
+rpc_listen = "tcp://127.0.0.1:8981"
+
+# P2P accept address for the syncing protocol
+sync_p2p_accept = "0.0.0.0:8342"
+
+# P2P external address for the syncing protocol
+sync_p2p_external = "0.0.0.0:8342"
+
+# Connection slots for the syncing protocol
+sync_slots = 8
+
+# Seed nodes to connect to for the syncing protocol
+sync_seed = []
+
+# Peers to connect to for the syncing protocol
+sync_peer = []

+ 27 - 18
bin/faucetd/src/main.rs

@@ -84,24 +84,24 @@ struct Args {
     rpc_listen: Url,
 
     #[structopt(long)]
-    /// P2P accept address
-    p2p_accept: Option<SocketAddr>,
+    /// P2P accept address for the syncing protocol
+    sync_p2p_accept: Option<SocketAddr>,
 
     #[structopt(long)]
-    /// P2P external address
-    p2p_external: Option<SocketAddr>,
+    /// P2P external address for the syncing protocol
+    sync_p2p_external: Option<SocketAddr>,
 
     #[structopt(long, default_value = "8")]
-    /// Connection slots
-    slots: u32,
+    /// Connection slots for the syncing protocol
+    sync_slots: u32,
 
     #[structopt(long)]
-    /// Connect to seed (repeatable flag)
-    seed: Vec<SocketAddr>,
+    /// Connect to seed for the syncing protocol (repeatable flag)
+    sync_seed: Vec<SocketAddr>,
 
     #[structopt(long)]
-    /// Connect to peer (repeatable flag)
-    peer: Vec<SocketAddr>,
+    /// Connect to peer for the syncing protocol (repeatable flag)
+    sync_peer: Vec<SocketAddr>,
 
     #[structopt(long, default_value = "600")]
     /// Airdrop timeout limit in seconds
@@ -114,6 +114,10 @@ struct Args {
     #[structopt(short, parse(from_occurrences))]
     /// Increase verbosity (-vvv supported)
     verbose: u8,
+
+    #[structopt(short)]
+    /// Genesis time
+    genesis_time: i64,
 }
 
 pub struct Faucetd {
@@ -213,6 +217,11 @@ impl Faucetd {
         };
         drop(map);
 
+        if *self.synced.lock().await == false {
+            error!("airdrop(): Blockchain is not yet synced");
+            return jsonrpc::error(InternalError, None, id).into()
+        }
+
         // TODO: Token ID decision
         // TODO: Rename this function to tx build
         let tx = match self
@@ -291,7 +300,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
 
     // Initialize validator state
     // TODO: genesis_ts should be some hardcoded constant
-    let genesis_ts = Timestamp(1650103269);
+    let genesis_ts = Timestamp(args.genesis_time);
     let genesis_data = match args.chain.as_str() {
         "mainnet" => *MAINNET_GENESIS_HASH_BYTES,
         "testnet" => *TESTNET_GENESIS_HASH_BYTES,
@@ -311,11 +320,11 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
     // P2P network. The faucet doesn't participate in consensus, so we only
     // build the sync protocol.
     let network_settings = net::Settings {
-        inbound: args.p2p_accept,
-        outbound_connections: args.slots,
-        external_addr: args.p2p_external,
-        peers: args.peer.clone(),
-        seeds: args.seed.clone(),
+        inbound: args.sync_p2p_accept,
+        outbound_connections: args.sync_slots,
+        external_addr: args.sync_p2p_external,
+        peers: args.sync_peer.clone(),
+        seeds: args.sync_seed.clone(),
         ..Default::default()
     };
 
@@ -325,7 +334,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
     info!("Registering block sync P2P protocols...");
     let _state = state.clone();
     registry
-        .register(!net::SESSION_SEED, move |channel, p2p| {
+        .register(net::SESSION_ALL, move |channel, p2p| {
             let state = _state.clone();
             async move { ProtocolSync::init(channel, state, p2p, false).await.unwrap() }
         })
@@ -333,7 +342,7 @@ async fn realmain(args: Args, ex: Arc<Executor<'_>>) -> Result<()> {
 
     let _state = state.clone();
     registry
-        .register(!net::SESSION_SEED, move |channel, p2p| {
+        .register(net::SESSION_ALL, move |channel, p2p| {
             let state = _state.clone();
             async move { ProtocolTx::init(channel, state, p2p).await.unwrap() }
         })