856 Commits

Author SHA1 Message Date
parazyd
b5d7c52191 chore: Update crate dependencies 2025-01-21 14:21:32 +01:00
kalm
3777279499 explorer: update Makefile to add bundle src contracts target to .PHONY and update clean target
This commit enhances the Makefile by adding the bundle_contracts_src as a phony target and adding clean-up for bundled contract code.

Summary of Updates:
- Added `bundle_contracts_src` to `.PHONY`
- Updated the `clean` target to remove the `native_contracts_src` directory
2025-01-16 09:56:09 -08:00
kalm
c58fd56041 explorer: native contract source code UI
This commit introduces functionality for displaying native contract source code in the DarkFi explorer application, enabling users to view available contracts from the home page, access associated source files, and examine native contract Rust code and zk proofs. This enhancement provides accessibility to native contract information. To support these updates, we have added new pages to the UI, updated styles for rendering source-related pages, and implemented new RPC routes to facilitate contract-related code retrieval.

Additionally, we have restructured the application into Flask blueprints to address the growing complexity of the explorer and adhere to best practices, as app.py was becoming large with diverging functionality. This proactive change prepares us for future expansions, including better organization of graph functionalities. The organization also mirrors the rest of the explorer codebase by maintaining separate pages for contracts, transactions, and blocks, as well as corresponding RPC and service rust modules.

UI Support for Native Contract Source Code

- We have added source code functionality to the UI, Flask blueprints, and RPC routes defined in rpc.py, along with updated styles to effectively render source-related pages.

Style Updates:
- Expanded the color palette for rendering source files.
- Enhanced styles for displaying contract IDs and names in the native contracts table.
- Implemented layout elements for proper display of source code lists and content.
- Added styles for source file list links, including hover effects.

RPC Routes:
- New routes have been added to facilitate requests to the DarkFi daemon for retrieving native contracts, source code paths, and contract source.

UI Enhancements:
- A native contract section has been introduced on the explorer home page to display native contracts.
- A contract source list page allows users to view and click on source code files associated with a native contract.
- A dedicated contract source page renders the source for a specific path associated with a given contract.

Introducing Flask Blueprints

To better manage the growing complexity of the application, we introduced Flask blueprints that organize routes according to their functionality. This restructuring not only enhances readability but also aligns with best practices for Flask applications, facilitating future development.

App.py Updates:
- Routes have been moved to their respective blueprints.

Added Blueprints:
- `__init__.py` file initializes the explorer blueprint package and exposes various blueprints used by the application.
- `block.py` module defines a blueprint for handling block-related functionality.
- `contract.py` module defines a blueprint for managing contract-related functionality.
- explore.py` module manages general functionality related to the home page and search features.
- `transaction.py` module handles transaction-related functionality.

Python Documentation:

- We documented the Python code and updated existing documentation to adhere to Python's best practices for using docstrings, enhancing usability and integration with documentation tools.

Testing:

- Manual testing has been conducted through the UI to verify the functionality of the new RPC methods, ensuring they correctly retrieve and display contract-related information.
2025-01-15 14:21:24 -08:00
kalm
14e38bfa28 explorer: contract RPC module to handle explorerd requests
This commit introduces a new RPC contract module to the Explorerd implementation. The module adds three RPC methods to enhance the functionality of the explorer service:

- `contracts.get_native_contracts`: Retrieves the native contracts deployed in the DarkFi network.

- `contracts.get_contract_source_code_paths`: Fetches the source code paths for a specified contract.

- `contracts.get_contract_source`: Retrieves the source code content for a given contract and source path.

These additions will allow users to retrieve contract-related information more through the RPC interface, enhancing the overall functionality of the explorer.

### Testing
Manual testing has been performed through the UI to verify the correct functionality of the new RPC methods, ensuring they properly retrieve and display contract-related information.

We opted for manual testing because the underlying service and data layer already have reliable unit tests, providing confidence in the core functionality. This approach sufficiently validates the functionality of the new RPC methods within the overall explorer context.
2025-01-15 13:57:03 -08:00
kalm
7c877b270e explorer: contract module for managing metadata and source code
This commit introduces a new module that enhances the functionality of the ExplorerService by adding functions for managing and retrieving contract-related data. The new methods include capabilities to retrieve contracts and native contracts, transforming them into ContractRecords suitable for handling by the RPC layer. In addition, we added functionality to handle contract metadata and source code.

Contract Metadata

The new module introduces functions to manage ContractMetadata, including fetching metadata for a given ContractId and adding ContractId and ContractMetaData pairs to the contract metadata store.

Contract Source Code

The module also handles operations on contract source code, such as fetching a list of source code file paths for a given ContractId, retrieving source code content for a specified ContractId and path, and adding source code for a ContractId from a provided tar file. The latter function extracts the tar archive and stores each source file with its path prefixed by the ContractId.

Auxiliary Functions

New auxiliary functions have been added for transforming contract details into a form suitable for the RPC layer, filtering contracts based on their ContractId using a provided function, and extracting source code files from a TAR archive.

Updates to Explorer Startup Sequence

The Explorer startup sequence has been updated to include the loading of native contract source code and metadata. This ensures the explorer prepared with the necessary contract data before beginning its operations.

Bundling Native Contract Source Code On Build

This commit introduces bundling of native contract source code during the build process. a new make target bundle_contracts_src to bundle native contract source code into tar files. This allows the explorer to load the latest native contract source code at startup, enhancing its ability to manage and display contract-related information. The current implementation redirects certain tar output to /dev/null to suppress verbose output. Future improvements will explore more elegant ways to manage this output in a subsequent commit.

Test Functions

We added test coverage to validate functionality across various scenarios, such as loading, storage, retrieval, and validation of contract metadata and contract source code. The primary goal is to validate the core service functionality to ensure the ExplorerService is properly handling contract-related data.
- test_add_metadata: Verifies the addition of ContractMetaData, ensuring the inserted metadata can be correctly retrieved and matches the expected values.
- test_load_native_contract_metadata: Ensures that native contract metadata can be loaded and correctly retrieved for all pre-defined native contract IDs.
- test_load_native_contracts: Validates both the loading and retrieval of native contract source code. It checks that the source paths and contents match the expected results in the corresponding tar archives.
- test_to_contract_record: Tests the transformation of contract details suitable for the RPC layer.

Auxiliary Test Functions
- setup: Sets up a temporary environment for testing by initializing an ExplorerService instance with an isolated sled database.
- verify_source_paths: Confirms that the source paths extracted from a contract tar archive match the source paths retrieved from the store a given ContractId.
- verify_source_content: Validates that the content of files from a contract tar archive matches the content retrieved from the store for a given ContractId.

Running Tests
cargo test contracts::tests
2025-01-15 13:39:23 -08:00
kalm
f633df8bd6 explorer: introducing contract metadata store
This commit introduces a **Contract Metadata Store**, serving as a data layer API for managing contract metadata and associated source code files. The storage utilizes a Sled database and organizes data into separate trees, including primary metadata storage for contract details and a tree for contract source code, organized by file paths prefixed with a `ContractId`. The implementation follows an overlay pattern for write operations, enabling unified management of metadata and source code by delegating tasks such as adding, updating, and deleting records to the `ContractMetadataStoreOverlay`.

Furthermore, this commit adds the `ContractMetaData` struct, which is used to store additional information for contracts that is not available on-chain. This data is indexed by `ContractId`. The struct encapsulates basic metadata fields, such as the name and description of a contract, and provides methods for creating new metadata instances.

In addition, the `ContractSourceFile` struct was added, which represents a source file containing its file path and its contents.

Finally, we added test coverage to validate functionality across various scenarios, such as metadata insertion and retrieval, source code insertion, and fetching source paths and contents.

Introduced Core Structures and Methods:

ContractMetadataStore:
  - Created the `ContractMetadataStore` struct to manage contract metadata and source code storage, providing an API for fetching and inserting associated data, all backed by a Sled database.

ContractMetadataStoreOverlay:
  - Developed the `ContractMetadataStoreOverlay` to facilitate write operations, including adding metadata and source code, as well as deleting existing source code.

ContractMetaData:
  - Introduced the `ContractMetaData` struct, which represents contract metadata, containing additional contract information that is not stored on-chain.

ContractSourceFile:
  - Introduced the `ContractSourceFile` struct to encapsulate contract source code, containing its file path and its content.

Added Test Functions:
- `test_add_contract_source`: Verifies the correctness of storing contract source code.
- `test_get_contract_source`: Validates the retrieval of a contract source code from the store.
- `test_add_metadata`: Tests the addition of contract metadata to the store.

Added Load Test Data Functions:
- `load_source_code`:Loads the source code test data.

Running Tests:
cargo test contract_meta_store::tests
2025-01-15 13:31:24 -08:00
kalm
1020627ebe explorer: initial UI re-themed to match Darkfi Book
This commit updates the Explorer application’s UI, providing a preliminary re-theming inspired by the Darkfi Book site. The updated design offers a familiar and visually appealing interface, along with improvements to responsiveness and usability on larger displays. These updates include changes to styling, layout, and modifications to key pages, such as the home page, block page, and transaction page.

This implementation represents the initial stage of improving the UI, making it more appealing for development and demos. It is not final, as further improvements will be made iteratively.
2025-01-15 11:44:47 -08:00
kalm
95244396e4 explorer: introducing explorer service
This commit introduces the ExplorerService, a dedicated service layer for the Explorer application that acts as a bridge between the JSON-RPC and database layers. It encapsulates application logic, orchestrates operations, and transforms database data into structured responses suitable for RPC callers, as well as other use cases.

As the Explorer application is growing in complexity, we’ve observed that blending RPC functionality with the database layer (ExplorerDb) introduces functionality into these layers that is not cohesively aligned. To address this, ExplorerService refines the application’s architecture by clearly defining and organizing application-specific responsibilities. This ensures that transformations, operation orchestration, contract source code processing, gas calculations, and other operations are performed within their appropriate layers, fostering a more cohesive and maintainable architecture over time.
2025-01-15 11:35:17 -08:00
kalm
0f67f19701 explorer: introduce initial makefile for building/installing explorer
This commit introduces an initial Makefile that facilitates the building and installation of the block explorer. The target directory for copying files is currently set to the blockchain-explorer directory but will be updated to the `darkfi` project directory once the explorer is integrated into the Darkfi workspace.
2025-01-15 11:22:21 -08:00
kalm
5e2116610d explorer/site: enhance explorer UI to display total network and trx gas consumption
This comment introduces UI updates to display total network gas consumption statistics across all transactions, as well as individual transaction gas consumption. These updates enhance the understanding of gas consumption by providing insights that can help users set appropriate gas limits, identify peak usage and anomalies, manage costs, and optimize blockchain performance.

Update Summary:

- Explorer Home Page: The `index.html` file has been updated to include a new section that displays total network gas consumption statistics, covering total gas, WASM gas, ZK circuits gas, signatures gas, and deployments, along with their average, minimum, and maximum values.

- Transaction Details Page: The `transaction.html` file has been updated to include gas consumption metrics and timestamp for individual transactions.

- Index Route: The index route in `app.py` has been modified to retrieve metrics statistics.

- RPC Module: The `rpc.py` file has been updated by introducing a new function to retrieve metrics statistics from the blockchain-explorer daemon.
2025-01-15 10:14:54 -08:00
kalm
81b6e2acac explorer: incorporate metrics into the explorer backend code
This commit integrates metrics capabilities into the explorer backend. The provided metrics include the average, minimum, and maximum values for the following:
- Total Gas Usage: Represents overall gas consumption.
- WASM Gas Usage: Pertains to gas usage for WASM contract calls.
- ZK Circuits Gas Usage: Indicates specific gas usage for ZK circuit operations.
- Signatures Gas Usage: Covers gas usage for transaction signatures.
- Deployments Gas Usage: Covers gas usage for transaction deployments.

Summary of Updates

Blocks Module:
- Updated `put_block` to store metrics for each transaction found in the block

Main Binary Crate:
- Added `calculate_tx_gas_data` to the `ExplorerDb` implementation, which calculates the gas data for a given transaction
- Introduced `get_latest_metrics`, which fetches the most current metrics from the metrics store
- Added code to deploy native contracts need to calculate transaction gas data

RPC Module:
- Added `statistics.get_metric_statistics` request to the RPC request handler

RPC Statistics Module:
- Implemented `statistics_get_metric_statistics` function that returns the latest metrics for the UI

Statistics Module:
- Introduced the `MetricStatistics` structure to represent gas data metrics in the service layer
- Implemented a constructor for `MetricStatistics` to initialize it with `GasMetrics`
- Updated the `to_json_array` method to convert `MetricStatistics` into a JSON array for UI data representation
- Implemented the `get_metrics_statistics` function in the `ExplorerDb` struct to fetch the most recent metrics from the database

Transaction Module:
- Added metrics and timestamp fields to the existing `TransactionRecord` struct
- Updated the `to_json_array` method of `TransactionRecord` to include conversions for metrics and timestamp
- Replaced the previous TransactionRecord From implementation with a ExplorerDb implementation `to_tx_record`, which converts a `Transaction` to a `TransactionRecord`
- Updated all uses of `TransactionRecord::from` to use `to_tx_record`
- Added auxiliary ExplorerDb implements to support metrics:
  - `get_tx_block_info`: Retrieves the `BlockInfo` associated with a given transaction hash
  - `get_block_info`: Fetches the `BlockInfo` associated with a given `HeaderHash`
2025-01-15 10:04:26 -08:00
kalm
54137ac43c explorer: introducing metrics store
This commit introduces a metrics store that serves as entry point for managing metrics, providing an API for fetching, inserting, and resetting metric data backed by a Sled database. The store organizes data into separate trees, including main storage for gas metrics by a defined time interval, a tree containing metrics by height for handling reorgs, and a transaction-specific gas data tree. It uses an overlay pattern for write operations, enabling unified management of metrics by delegating tasks such as adding metrics and handling reorgs to the MetricsStoreOverlay.

Additionally, the commit introduces the GasMetrics struct, which is used for managing gas metrics across all transactions in the metrics store. This struct maintains running totals, min/max extrema, and transaction counts, allowing efficient calculations of total gas, WASM gas, ZK circuit gas, and signature gas without needing to iterate through previous transactions. With O(1) performance for calculating averages and updating min/max values, GasMetrics builds a comprehensive view of gas metrics throughout the blockchain's history. It includes methods for creating new instances, calculating average gas usage, and adding new gas data in real-time.

Furthermore, the GasMetricsKey struct is introduced to facilitate storing and retrieving metrics by time interval. The initial implementation stores metrics on an hourly basis, with flexibility for future adjustments to different intervals with minimal code changes. This struct provides methods for creating, serializing, and deserializing keys from various time representations, including [Timestamp], u64 timestamps, and &str timestamps. It also features conversion methods to ensure compatibility with the Sled database.

Test coverage has been added to validate functionality across various scenarios. Tests include inserting gas metrics, searching metrics by hour, fetching metrics by timestamp string, transaction gas usage, and resetting metrics under different conditions. Additionally, functions were added to load test data, simulating random, fixed, and reset scenarios while generating varied gas data.

Core Updates Summary:

- Created the `MetricsStore` struct to manage metric storage, providing an API for fetching, inserting, and resetting metrics backed by a Sled database.
- Developed `MetricsStoreOverlay` to facilitate write operations, including adding and reverting metrics for handling reorgs.
- Introduced the `GasMetrics` struct to encapsulate gas metrics across transactions, with methods to efficiently add data and compute extrema and averages.
- Implemented `GasMetricsKey` for storing and retrieving fee metrics based on hourly intervals.
- Introduced the `GasMetricsKeySource` trait for unified key creation using various time representations: `[Timestamp]`, `u64` timestamps, or `&str` timestamps.

Test Functions:
- `test_insert_gas_metrics`: Verifies correctness of inserted gas metrics into the main tree.
- `test_insert_by_height_gas_metrics`: Tests gas metrics insertion into the metrics by height tree.
- `test_search_metrics_by_hour`: Validates searching gas metrics by hour.
- `test_get_metrics_by_timestamp_str`: Ensures correct retrieval of metrics by timestamp string.
- `test_tx_gas_data`: Verifies transaction gas data insertion and retrieval, including handling of non-existent transactions.
- `test_reset_metrics_within_height_range`: Tests resetting metrics within a specified height range.
- `test_reset_metrics_height_to_0`: Ensures graceful handling of resetting the metrics store to height 0.
- `test_reset_metrics_beyond_height`: Validates behavior when resetting beyond available metrics.
- `test_reset_metrics_at_height`: Tests resetting metrics at the last available height.
- `test_reset_empty_store`: Confirms that resetting an empty store is handled without errors.

Test Data Load Functions:
- `load_random_metrics`: Simulates loading random gas metrics data at hourly intervals from height 0 as the genesis block.
- `load_fixed_metrics`: Loads fixed test data with timestamps.
- `load_reset_metrics`: Returns accumulated gas metrics at a specified reset height.
- `load_tx_gas_data`: Loads test transaction gas data, returning pairs of transaction hashes and gas data.
- `random_gas_data`: Generates varied gas data based on a provided seed value.
2025-01-14 09:02:36 -08:00
skoupidi
a76b9526bc misc: use ~/.local/share/darkfi for app storage 2025-01-13 15:25:15 +02:00
skoupidi
bc22307e8b rcp/server: generalize RequestHandler so we can create multiple instances of it 2024-12-05 16:22:43 +02:00
kalm
402a508d51 explorer/test_util: add initial implementation of test_util module for reusable testing utilities
This commit introduces the initial implementation a test_util module, providing reusable testing utilities for the explorer.

The first version includes a function to initialize logging for test cases, which aids in debugging issues encountered during testing. This module will be expanded as we progress with both unit and integration testing.

Summary of Updates:
- Added the init_logger function that configures the logger based on a provided list of targets to ignore and the desired log level
2024-12-04 14:26:31 +02:00
skoupidi
7739d8a40e blockchain: use sled-overlay record parsing functions 2024-12-03 15:27:10 +02:00
skoupidi
9f490a09d3 darkfid: replaced finalization term with confirmation 2024-12-02 15:08:01 +02:00
skoupidi
a51211c037 Cargo.toml: updated sled-overlay version 2024-12-02 15:08:01 +02:00
darkfi
ca3faeb5b3 evgrd: change darkfi-serial from path=... to version=0.4.2 2024-11-23 17:59:26 +01:00
skoupidi
a990ed03cc (WIP)script/research: blocks storage measuring script added 2024-11-15 16:20:02 +02:00
skoupidi
3153069aad bin/darkfid/rpc: also return the hash of the last known(finalized) block 2024-11-14 13:12:04 +02:00
skoupidi
92f5b05cee script/research/blockchain-explorer: minor code beatifications 2024-11-06 10:54:36 +02:00
kalm
6a8743b667 explorer: transition from SQL to sled-based implementation
This commit request introduces a sled-backed Block Explorer, replacing the SQL-based implementation.

Summary of updates:
- Transitioned the block explorer from SQL to a sled-based database implementation
- Introduced BlockExplorerDb struct that handles explorer database operations
- Established sled-based darkfid block synchronization for startup and subscription sync
- Removed rusqlite dependency
- Removed SQL create table scripts
- Updated app.py to handle not found as empty results instead of a thrown exception when calling rpc.get_block_transactions
2024-11-05 13:01:09 -08:00
skoupidi
67439844e7 script/research/blockchain-explorer: fixed building 2024-10-24 16:08:20 +03:00
dasman
b118567613 script/ping: fix darkfi-serial dependency 2024-10-23 00:29:29 +03:00
skoupidi
ea87f3767d chore: updated sled-overlay to new version 2024-10-15 18:18:29 +03:00
parazyd
fbe6937a20 chore: Update crate dependencies 2024-10-15 16:08:54 +02:00
dasman
f9d3600e0c evgrd: update to fully use millis 2024-10-02 12:39:48 +03:00
parazyd
242fe81658 chore: Update crate dependencies 2024-10-01 14:15:03 +02:00
dasman
86afe8d896 event_graph and evgrd: use INITIAL_GENESIS as seconds in for prune task as well 2024-09-27 21:22:27 +03:00
darkfi
a8751d4212 wallet/evgrd: flush on every write so tor works properly 2024-09-25 14:39:12 +02:00
darkfi
204de13e63 wallet/evgrd: add more debug and error handling to net interfaces. 2024-09-25 13:23:19 +02:00
darkfi
61b55002bf evgrd: allow listening for rpc on multiple inbound addrs 2024-09-24 14:17:42 +02:00
dasman
47833e5415 evgrd: fix version number and add seed nodes 2024-09-23 13:37:41 +03:00
darkfi
4661036ed9 evgrd: add missing file for last commit: example/send.rs 2024-09-23 11:42:38 +02:00
darkfi
958b3e049b evgrd: move bin/test.rs to example/recv.rs and add example/send.rs 2024-09-23 11:39:14 +02:00
darkfi
0ec8969b2d evgrd: add code to branch on app versions and send corrected timestamp. 2024-09-23 09:10:34 +02:00
darkfi
804c3e7549 wallet: darkirc backend broadcast p2p events 2024-09-22 17:01:00 +02:00
darkfi
d5ba88e099 wallet: send msgs from the UI 2024-09-22 14:36:21 +02:00
darkfi
ac53cae94a evgrd: add SENTEVENT to protocol 2024-09-22 12:32:30 +02:00
darkfi
131d18588b evgrd: enable build-daemon feature which adds missing deps when compiling the daemon 2024-09-22 12:32:30 +02:00
darkfi
4aa44b36a0 wallet: tor-dirmgr tries to pull sqlite3, which on android has a missing symbol __extenddftf2 due to missing compiler builtins. We therefore link against clang_rt.builtins for each target_arch on android using a build.rs. See the code comment for more details. 2024-09-21 15:28:03 +02:00
darkfi
1bbb3bddcc evgrd: change path for test client so it's not using the same data dir as the daemon itself ;) 2024-09-19 18:24:29 +02:00
darkfi
a915e34d66 evgrd: deserialize and print privmsg on new event 2024-09-19 18:22:35 +02:00
dasman
a63d628ec5 script/evgrd: fill in required LocalEventGraph fields and methods, and present a working test module 2024-09-19 18:23:49 +03:00
skoupidi
19eb32f29b src/net/protorocl/protocol_generic: added response action 2024-09-17 16:41:46 +03:00
dasman
15c02253a8 script/evgrd: fetch successors of requested tips 2024-09-10 17:35:09 +03:00
dasman
9718ab96e1 script/evgrd: add .gitignore 2024-09-10 14:50:43 +03:00
darkfi
0cb3824544 evgrd: add missing JSON-RPC modules so dnet and deg work. 2024-09-10 10:41:38 +02:00
darkfi
ee738a1a32 evgrd: enable event graph 2024-09-10 10:25:16 +02:00