This commit integrates blockchain reorg functionality into the explorer’s block syncing and subscriptions, addressing inconsistencies and aligning the explorer state with a Darkfi node. Key improvements include reorg detection and handling in block synchronization and subscriptions, consolidated and refined logging for better observability, state reset methods to reliably handle reorg scenarios, and enhanced safeguards to ensure consistency before starting subscriptions. Summary of Updates: ## Blocks Module - Added `get_block_by_height` to retrieve blocks by height to support reorg handling - Added `reset_to_height` function to reset blocks and related transactions to a specific height, enabling transactional resets. This function was introduced because the blockchain layer's equivalent function could not be reused due to the absence of `StateDiffs` on the explorer side. - Changed the log level of `reset_blocks` to `debug` to streamline reorg-related logging ## Transaction Module - Changed the log level of `reset_blocks` to `debug` to streamline reorg-related logging ## Binary Crate (main.rs) - Added `reset_explorer_state` to reset the explorer state to a given height or to genesis. This ensures consistency across blocks, transactions, and metrics during resets or reorgs - Updated logging to include transaction count during ExplorerDb initialization ## Rpc Blocks Module - Refined variable and function names with "darkfid" for improved readability ### Block Sync Reorgs - Implemented block sync reorg handling to detect and resolve inconsistencies between the Darkfid node and the explorer - Introduced reorg detection logic based on mismatched block hashes and heights - Added support for handling reorg scenarios, including genesis related cases - Extended logging to report detected reorgs and re-alignments - Updated the `reset` flag handling to purge and resync the explorer state from scratch when enabled - Added `process_sync_blocks_reorg` to identify mismatched blocks and realign the explorer's blockchain state to the correct height ## Subscription Sync Reorgs - Added reorg handling in the subscription process to detect reorgs through block height mismatches and reset the explorer state as needed - Improved safeguards against mismatched last synced and last confirmed blocks before initiating the subscription process These updates provide explorer nodes the ability to handle blockchain reorgs and ensure alignment with the canonical chain from Darkfi nodes.
DarkFi - Anonymous, Uncensored, Sovereign
We aim to proliferate anonymous digital markets by means of strong cryptography and peer-to-peer networks. We are establishing an online zone of freedom that is resistant to the surveillance state.
Unfortunately, the law hasn’t kept pace with technology, and this disconnect has created a significant public safety problem. We call it "Going Dark".
James Comey, FBI director
So let there be dark.
About DarkFi
DarkFi is a new Layer 1 blockchain, designed with anonymity at the forefront. It offers flexible private primitives that can be wielded to create any kind of application. DarkFi aims to make anonymous engineering highly accessible to developers.
DarkFi uses advances in zero-knowledge cryptography and includes a contracting language and developer toolkits to create uncensorable code.
In the open air of a fully dark, anonymous system, cryptocurrency has the potential to birth new technological concepts centered around sovereignty. This can be a creative, regenerative space - the dawn of a Dark Renaissance.
Connect to DarkFi IRC
Follow the installation instructions for the P2P IRC daemon.
Build
This project requires the Rust compiler to be installed. Please visit Rustup for instructions.
You have to install a native toolchain, which is set up during Rust installation, nightly toolchain and wasm32 target. To install nightly toolchain, execute:
% rustup toolchain install nightly
To install wasm32 target, execute:
% rustup target add wasm32-unknown-unknown
% rustup target add wasm32-unknown-unknown --toolchain nightly
Minimum Rust version supported is 1.77.0 (nightly).
The following dependencies are also required:
| Dependency | Debian-based |
|---|---|
| git | git |
| cmake | cmake |
| make | make |
| gcc | gcc |
| g++ | g++ |
| pkg-config | pkg-config |
| alsa-lib | libasound2-dev |
| clang | libclang-dev |
| fontconfig | libfontconfig1-dev |
| lzma | liblzma-dev |
| openssl | libssl-dev |
| sqlcipher | libsqlcipher-dev |
| sqlite3 | libsqlite3-dev |
| wabt | wabt |
Users of Debian-based systems (e.g. Ubuntu) can simply run the following to install the required dependencies:
# apt-get update
# apt-get install -y git cmake make gcc g++ pkg-config libasound2-dev libclang-dev libfontconfig1-dev liblzma-dev libssl-dev libsqlcipher-dev libsqlite3-dev wabt
Alternatively, users can try using the automated script under contrib
folder by executing:
% sh contrib/dependency_setup.sh
The script will try to recognize which system you are running, and install dependencies accordingly. In case it does not find your package manager, please consider adding support for it into the script and sending a patch.
To build the necessary binaries, we can just clone the repo, and use the provided Makefile to build the project:
% git clone https://codeberg.org/darkrenaissance/darkfi
% cd darkfi
% make
Development
If you want to hack on the source code, make sure to read some introductory advice in the DarkFi book.
Living on the cutting edge
Since the project uses the nightly toolchain, breaking changes are bound to happen from time to time. As a workaround, we can configure an older nightly version, which was known to work:
% rustup toolchain install nightly-2024-12-05
% rustup target add wasm32-unknown-unknown --toolchain nightly-2024-12-05
Now we can use that toolchain in make directly:
% make CARGO="cargo +nightly-2024-12-05" {target}
Or, if we are lazy, we can modify the Makefile to always use that:
% sed -i Makefile -e "s|nightly|nightly-2024-12-05|g"
Under no circumstances commit or push the Makefile change.
When using cargo directly, you have to add the +nightly-2024-12-05 flag,
in order for it to use the older nightly version.
Install
This will install the binaries on your system (/usr/local by
default). The configuration files for the binaries are bundled with the
binaries and contain sane defaults. You'll have to run each daemon once
in order for them to spawn a config file, which you can then review.
# make install
Examples and usage
See the DarkFi book
Go Dark
Let's liberate people from the claws of big tech and create the democratic paradigm of technology.
Self-defense is integral to any organism's survival and growth.
Power to the minuteman.