perf+sec: 15 improvements across consensus, DB, network, sync

CONSENSUS SECURITY (main.cpp):
- Re-enable PoS kernel verification post-IBD (was unconditionally disabled)
- Re-enable coinstake reward validation post-IBD (was commented out)
- Re-enable anti-spam difficulty check (was if(false && ...))

SYNC PERFORMANCE (main.cpp):
- Batch address index writes in ConnectBlock (hundreds of DB ops → one per address)
- Throttle IBD printfs (per-block → per-10K-blocks or fDebug-gated)

DATABASE (txdb-rocksdb.cpp/h, txdb-base.cpp):
- Non-batched WriteRaw: WAL sync=false (was fsync per write)
- UTXO cache: FIFO eviction → true LRU with access-order tracking
- RocksDB memtable: 64MB → 256MB + max_write_buffer_number=4
- pendingBatch: std::map → std::unordered_map (O(log n) → O(1))
- max_open_files: 1000 → unlimited

NETWORK (net.cpp, netbase.cpp):
- TCP_NODELAY on all sockets (disable Nagle's algorithm)
- SO_KEEPALIVE on all sockets (faster dead-peer detection)
- Adaptive MilliSleep: 1ms during IBD, 10ms otherwise
- writev() scatter-gather I/O for send() coalescing (up to 16 msgs/syscall)
- O(1) CountInFlight counter (was O(n) scan of entire header map)
This commit is contained in:
Krystie
2026-06-27 18:17:59 -07:00
parent 34f65eb836
commit b623396186
7 changed files with 239 additions and 71 deletions
+13 -3
View File
@@ -32,6 +32,15 @@ namespace fs = std::filesystem;
// the same way the LevelDB backend shares its txdb singleton.
static rocksdb::DB* g_rocksdb = nullptr;
// Non-batched writes bypass WAL fsync. The TxnCommit path handles durability;
// crash recovery replays from block files anyway. Default WriteOptions may
// vary across RocksDB versions, so we pin sync=false explicitly.
static const rocksdb::WriteOptions g_fastWriteOpts = []{
rocksdb::WriteOptions wo;
wo.sync = false;
return wo;
}();
namespace {
// rocksdb::DB::Open shipped a raw DB** overload for years; newer releases
@@ -71,8 +80,9 @@ static rocksdb::Options GetRocksOptions()
rocksdb::Options opts;
opts.create_if_missing = false;
opts.compression = rocksdb::kSnappyCompression;
opts.max_open_files = 1000;
opts.write_buffer_size = 64 * 1048576;
opts.max_open_files = -1;
opts.write_buffer_size = 256 * 1048576;
opts.max_write_buffer_number = 4;
opts.IncreaseParallelism(); // Multi-threaded compaction.
opts.OptimizeLevelStyleCompaction(); // Sensible defaults for a LSM workload.
@@ -263,7 +273,7 @@ bool CRocksTxDB::WriteRaw(const std::string& key, const std::string& value)
pendingBatch[key] = value;
return true;
}
rocksdb::Status status = pdb->Put(rocksdb::WriteOptions(), key, value);
rocksdb::Status status = pdb->Put(g_fastWriteOpts, key, value);
if (!status.ok()) {
printf("RocksDB write failure: %s\n", status.ToString().c_str());
return false;