Browse Source

darkfid: cleaned up all slot references

skoupidi 2 years ago
parent
commit
eaecebf47c

+ 2 - 2
bin/darkfid/src/error.rs

@@ -27,7 +27,7 @@ pub enum RpcError {
 
     // State-related errors,
     NotSynced = -32120,
-    UnknownSlot = -32121,
+    UnknownBlockHeight = -32121,
 
     // Parsing errors
     ParseError = -32190,
@@ -46,7 +46,7 @@ fn to_tuple(e: RpcError) -> (i32, String) {
         RpcError::TxBroadcastFail => "Failed broadcasting transaction",
         // State-related errors
         RpcError::NotSynced => "Blockchain is not synced",
-        RpcError::UnknownSlot => "Did not find slot",
+        RpcError::UnknownBlockHeight => "Did not find block height",
         // Parsing errors
         RpcError::ParseError => "Parse error",
         // Contract-related errors

+ 3 - 6
bin/darkfid/src/proto/protocol_sync.rs

@@ -40,10 +40,8 @@ const BATCH: u64 = 10;
 /// Auxiliary structure used for blockchain syncing.
 #[derive(Debug, SerialEncodable, SerialDecodable)]
 pub struct SyncRequest {
-    /// Slot UID
-    pub slot: u64,
-    /// Block headerhash of that slot
-    pub block: blake3::Hash,
+    /// Block height
+    pub height: u64,
 }
 
 impl_p2p_message!(SyncRequest, "syncrequest");
@@ -107,8 +105,7 @@ impl ProtocolSync {
                 continue
             }
 
-            let key = request.slot;
-            let blocks = match self.validator.blockchain.get_blocks_after(key, BATCH) {
+            let blocks = match self.validator.blockchain.get_blocks_after(request.height, BATCH) {
                 Ok(v) => v,
                 Err(e) => {
                     error!(

+ 2 - 2
bin/darkfid/src/rpc.rs

@@ -57,9 +57,9 @@ impl RequestHandler for Darkfid {
             // ==================
             // Blockchain methods
             // ==================
-            "blockchain.get_slot" => return self.blockchain_get_slot(req.id, req.params).await,
+            "blockchain.get_block" => return self.blockchain_get_block(req.id, req.params).await,
             "blockchain.get_tx" => return self.blockchain_get_tx(req.id, req.params).await,
-            "blockchain.last_known_slot" => return self.blockchain_last_known_slot(req.id, req.params).await,
+            "blockchain.last_known_block" => return self.blockchain_last_known_block(req.id, req.params).await,
             "blockchain.lookup_zkas" => return self.blockchain_lookup_zkas(req.id, req.params).await,
             "blockchain.subscribe_blocks" => return self.blockchain_subscribe_blocks(req.id, req.params).await,
             "blockchain.subscribe_txs" =>  return self.blockchain_subscribe_txs(req.id, req.params).await,

+ 14 - 14
bin/darkfid/src/rpc_blockchain.rs

@@ -36,39 +36,39 @@ use crate::{server_error, Darkfid, RpcError};
 
 impl Darkfid {
     // RPCAPI:
-    // Queries the blockchain database for a block in the given slot.
+    // Queries the blockchain database for a block in the given height.
     // Returns a readable block upon success.
     //
     // **Params:**
-    // * `array[0]`: `u64` slot ID (as string)
+    // * `array[0]`: `u64` Block height (as string)
     //
     // **Returns:**
     // * [`BlockInfo`](https://darkrenaissance.github.io/darkfi/development/darkfi/consensus/block/struct.BlockInfo.html)
     //   struct serialized into base64.
     //
-    // --> {"jsonrpc": "2.0", "method": "blockchain.get_slot", "params": ["0"], "id": 1}
+    // --> {"jsonrpc": "2.0", "method": "blockchain.get_block", "params": ["0"], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": {...}, "id": 1}
-    pub async fn blockchain_get_slot(&self, id: u16, params: JsonValue) -> JsonResult {
+    pub async fn blockchain_get_block(&self, id: u16, params: JsonValue) -> JsonResult {
         let params = params.get::<Vec<JsonValue>>().unwrap();
         if params.len() != 1 || !params[0].is_string() {
             return JsonError::new(InvalidParams, None, id).into()
         }
 
-        let slot = match params[0].get::<String>().unwrap().parse::<u64>() {
+        let block_height = match params[0].get::<String>().unwrap().parse::<u64>() {
             Ok(v) => v,
             Err(_) => return JsonError::new(ParseError, None, id).into(),
         };
 
-        let blocks = match self.validator.blockchain.get_blocks_by_heights(&[slot]) {
+        let blocks = match self.validator.blockchain.get_blocks_by_heights(&[block_height]) {
             Ok(v) => v,
             Err(e) => {
-                error!(target: "darkfid::rpc::blockchain_get_slot", "Failed fetching block by slot: {}", e);
+                error!(target: "darkfid::rpc::blockchain_get_block", "Failed fetching block by height: {}", e);
                 return JsonError::new(InternalError, None, id).into()
             }
         };
 
         if blocks.is_empty() {
-            return server_error(RpcError::UnknownSlot, id, None)
+            return server_error(RpcError::UnknownBlockHeight, id, None)
         }
 
         let block = base64::encode(&serialize_async(&blocks[0]).await);
@@ -117,28 +117,28 @@ impl Darkfid {
     }
 
     // RPCAPI:
-    // Queries the blockchain database to find the last known slot
+    // Queries the blockchain database to find the last known block
     //
     // **Params:**
     // * `None`
     //
     // **Returns:**
-    // * `u64` ID of the last known slot, as string
+    // * `u64` Height of the last known block, as string
     //
-    // --> {"jsonrpc": "2.0", "method": "blockchain.last_known_slot", "params": [], "id": 1}
+    // --> {"jsonrpc": "2.0", "method": "blockchain.last_known_block", "params": [], "id": 1}
     // <-- {"jsonrpc": "2.0", "result": "1234", "id": 1}
-    pub async fn blockchain_last_known_slot(&self, id: u16, params: JsonValue) -> JsonResult {
+    pub async fn blockchain_last_known_block(&self, id: u16, params: JsonValue) -> JsonResult {
         let params = params.get::<Vec<JsonValue>>().unwrap();
         if !params.is_empty() {
             return JsonError::new(InvalidParams, None, id).into()
         }
 
         let blockchain = self.validator.blockchain.clone();
-        let Ok(last_slot) = blockchain.last() else {
+        let Ok(last_block_height) = blockchain.last() else {
             return JsonError::new(InternalError, None, id).into()
         };
 
-        JsonResponse::new(JsonValue::Number(last_slot.0 as f64), id).into()
+        JsonResponse::new(JsonValue::Number(last_block_height.0 as f64), id).into()
     }
 
     // RPCAPI:

+ 1 - 1
bin/darkfid/src/task/sync.rs

@@ -59,7 +59,7 @@ pub async fn sync_task(node: &Darkfid) -> Result<()> {
     info!(target: "darkfid::task::sync_task", "Last known block: {:?} - {:?}", last.0, last.1);
     loop {
         // Node creates a `SyncRequest` and sends it
-        let request = SyncRequest { slot: last.0, block: last.1 };
+        let request = SyncRequest { height: last.0 };
         channel.send(&request).await?;
 
         // TODO: add a timeout here to retry