Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/consensus/proof_of_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class GlobalProofOfHistory {
static ProofOfHistory& instance();
static bool initialize(const PohConfig& config = {});
static void shutdown();
static bool is_initialized();

// Convenience methods
static uint64_t mix_transaction(const Hash& tx_hash);
Expand Down
11 changes: 10 additions & 1 deletion src/consensus/proof_of_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,11 @@ void GlobalProofOfHistory::shutdown() {
}
}

bool GlobalProofOfHistory::is_initialized() {
std::lock_guard<std::mutex> lock(instance_mutex_);
return instance_ != nullptr;
}

uint64_t GlobalProofOfHistory::mix_transaction(const Hash& tx_hash) {
return instance().mix_data(tx_hash);
}
Expand All @@ -667,7 +672,11 @@ PohEntry GlobalProofOfHistory::get_current_entry() {
}

Slot GlobalProofOfHistory::get_current_slot() {
return instance().get_current_slot();
std::lock_guard<std::mutex> lock(instance_mutex_);
if (!instance_) {
return 0; // Return default slot if not initialized
}
return instance_->get_current_slot();
}

} // namespace consensus
Expand Down
23 changes: 15 additions & 8 deletions src/validator/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ common::Result<bool> ValidatorCore::start() {
std::cout << "Starting validator core" << std::endl;

// Access the already initialized Proof of History instance
if (!consensus::GlobalProofOfHistory::is_initialized()) {
return common::Result<bool>("GlobalProofOfHistory not initialized");
}
auto& poh = consensus::GlobalProofOfHistory::instance();

// Set up PoH callbacks for metrics
Expand Down Expand Up @@ -341,11 +344,13 @@ void ValidatorCore::process_block(const ledger::Block& block) {

auto validation_result = block_validator_->validate_block(block);
if (validation_result.is_ok()) {
// Mix block hash into PoH for timestamping
auto& poh = consensus::GlobalProofOfHistory::instance();
uint64_t poh_sequence = poh.mix_data(block.block_hash);

std::cout << "Mixed block hash into PoH at sequence " << poh_sequence << std::endl;
// Mix block hash into PoH for timestamping (if available)
if (consensus::GlobalProofOfHistory::is_initialized()) {
auto& poh = consensus::GlobalProofOfHistory::instance();
uint64_t poh_sequence = poh.mix_data(block.block_hash);

std::cout << "Mixed block hash into PoH at sequence " << poh_sequence << std::endl;
}

fork_choice_->add_block(block);

Expand All @@ -363,7 +368,7 @@ void ValidatorCore::process_block(const ledger::Block& block) {
monitoring::GlobalConsensusMetrics::instance().increment_blocks_processed();

std::cout << "Processed and stored block at slot " << block.slot
<< " (total processing time: " << processing_time * 1000 << "ms, PoH sequence: " << poh_sequence << ")" << std::endl;
<< " (total processing time: " << processing_time * 1000 << "ms)" << std::endl;

if (impl_->block_callback_) {
impl_->block_callback_(block);
Expand Down Expand Up @@ -418,8 +423,10 @@ bool ValidatorCore::is_running() const {
common::Slot ValidatorCore::get_current_slot() const {
// Return the PoH-driven current slot for RPC queries
// This represents the current time-based slot progression, not the blockchain state
auto& poh = consensus::GlobalProofOfHistory::instance();
return poh.get_current_slot();
if (!consensus::GlobalProofOfHistory::is_initialized()) {
return 0; // Return default slot if PoH not initialized
}
return consensus::GlobalProofOfHistory::get_current_slot();
}

common::Slot ValidatorCore::get_blockchain_head_slot() const {
Expand Down