2024-03-27 00:46:32 +00:00
|
|
|
//! TODO
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------- Import
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use curve25519_dalek::edwards::EdwardsPoint;
|
|
|
|
use monero_serai::{
|
|
|
|
block::Block,
|
|
|
|
transaction::{Timelock, Transaction},
|
|
|
|
};
|
|
|
|
|
|
|
|
#[cfg(feature = "borsh")]
|
|
|
|
use borsh::{BorshDeserialize, BorshSerialize};
|
|
|
|
#[cfg(feature = "serde")]
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------- ExtendedBlockHeader
|
|
|
|
/// TODO
|
|
|
|
#[derive(Copy, Clone, Default, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
|
|
#[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
|
|
|
|
pub struct ExtendedBlockHeader {
|
|
|
|
/// TODO
|
|
|
|
/// This is a `cuprate_consensus::HardFork`.
|
|
|
|
pub version: u8,
|
|
|
|
/// TODO
|
|
|
|
/// This is a `cuprate_consensus::HardFork`.
|
|
|
|
pub vote: u8,
|
|
|
|
/// TODO
|
|
|
|
pub timestamp: u64,
|
|
|
|
/// TODO
|
|
|
|
pub cumulative_difficulty: u128,
|
|
|
|
/// TODO
|
|
|
|
pub block_weight: usize,
|
|
|
|
/// TODO
|
|
|
|
pub long_term_weight: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------- TransactionVerificationData
|
|
|
|
/// TODO
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] // FIXME: monero_serai
|
|
|
|
// #[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
|
|
|
|
pub struct TransactionVerificationData {
|
|
|
|
/// TODO
|
|
|
|
pub tx: Transaction,
|
|
|
|
/// TODO
|
|
|
|
pub tx_blob: Vec<u8>,
|
|
|
|
/// TODO
|
|
|
|
pub tx_weight: usize,
|
|
|
|
/// TODO
|
|
|
|
pub fee: u64,
|
|
|
|
/// TODO
|
|
|
|
pub tx_hash: [u8; 32],
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------- VerifiedBlockInformation
|
|
|
|
/// TODO
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] // FIXME: monero_serai
|
|
|
|
// #[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
|
|
|
|
pub struct VerifiedBlockInformation {
|
|
|
|
/// TODO
|
|
|
|
pub block: Block,
|
|
|
|
/// TODO
|
|
|
|
pub txs: Vec<Arc<TransactionVerificationData>>,
|
|
|
|
/// TODO
|
|
|
|
pub block_hash: [u8; 32],
|
|
|
|
/// TODO
|
|
|
|
pub pow_hash: [u8; 32],
|
|
|
|
/// TODO
|
|
|
|
pub height: u64,
|
|
|
|
/// TODO
|
|
|
|
pub generated_coins: u64,
|
|
|
|
/// TODO
|
|
|
|
pub weight: usize,
|
|
|
|
/// TODO
|
|
|
|
pub long_term_weight: usize,
|
|
|
|
/// TODO
|
|
|
|
pub cumulative_difficulty: u128,
|
database: implement `ops/` (#102)
* ops: add `trait MoneroR{o,w}`
* update `trait MoneroR{o,w}` bounds
* types: add `BlockInfoLatest` type alias
* block: impl most core functions
* types: fix https://github.com/Cuprate/cuprate/pull/91#discussion_r1527668916
* fix table type test
* cargo.toml: add `{cuprate-types, monero-serai}`
* add_block: add all other block data
* ops: remove unneeded `block` functions
* env: add `EnvInner::open_db_rw_all()`
* types: fix test
* block: `&mut TxRw` -> `&TxRw`, use `open_db_rw_all()`
* add `trait Tables[Mut]` and use it in `EnvInner`
* block: use `TablesMut`
* tables: replace manual impl with `define_trait_tables!()`
* tables: docs for `trait Tables[Mut]`
* tables: doc functions
* create `call_fn_on_all_tables_or_early_return!()` macro
* block: cleanup signatures + bodies
* block: more fn's, docs
* block: add `doc_{error,single,bulk}!()`
* remove `ops/monero.rs`
* move `height()` to `ops/blockchain.rs`
* add `ops/macros.rs`
* tx: add fn signatures
* output: fix fn signatures
* ops: expose `_inner()` functions
* block: add `add_block_header{_bulk, _inner}()`
* ops: remove doc_{fn,inner}!()`
* ops: remove `_{inner,bulk}()`, lifetime + generics
* update lib/mod docs
* ops: add and use `doc_add_block_inner_invariant!()`
* ops: add docs/return to inner `add_block()` functions
* add_block(): extract and use fn for {key_image, output}
* ops: more fn body impl + `add_block()`
* cargo: add `monero-pruning`
* ops: extract out `tx` functions from `add_block()`
* property: add `db_version()`
* ops: `pop_block()` body, remove other `pop_block` fn's
* types: add `block_blob: Vec<u8>` to `VerifiedBlockInformation`
* block: put `block_blob`, pass `Tables` to sub-functions
`impl TablesMut` can't mutably pass multiple tables since
it takes `&mut self`, so all functions unfortunately have to
take a full `&mut impl TablesMut` even though they only need
a few tables.
* database: add `DatabaseRw::take()`
useful for `pop_block()` where we need the value afterwards
* block: deserialize tx's from `block_blobs` in `pop_block()`
* blockchain: `height()` -> `chain_height()`
* output: fix `amount_index`
* ops: fix unlock_time, chain_height
* `BlockInfoV{1,2,3}` -> `BlockInfo`
* constants: add `DATABASE_VERSION`
* database: add `DatabaseRw::update()`
* output: use `DatabaseRw::update()` in `remove_output()`
* add `TxBlobs` table, ignore pruning tables
* block: mostly impl `add_block()` body
* ops: comments
* add_block: miner v2 tx commitment, height cast
* block: impl `pop_block()`
* block: mostly impl `get_block()`
* block: impl `get_block_{from_height,header,header_from_height}`
* add `OutputFlags` bitflags
* add_block: u32::try_into(height: u32), use `OutputFlags`
* tx: impl `get_{tx,tx_from_id}()`
* tx: move docs tests to `#[test]`
testing everything in 1 go is more natural since e.g:
`add_tx()` is followed by `get_tx()`
* tables: add `trait TablesIter`, `all_tables_empty()`
This allows `TablesMut` to be a superset of `Tables`
and use all its accessor functions.
* use cuprate-test-utils, fix tx tests
* block: `add_block()` take block by ref
* tx: use all txs in tests
* output: add `all_tx_functions()` test
* add_block: check current height against input
* block: map more fields in `get_block()`
* block: remove `get_block()`, doc tests, fix `get_block_header()`
* block: dummy values in test
* heed: use `last/first()` instead of `unsafe` cursors
We no longer have DUP semantics and also hard to debug errors
were popping up on `del_current()`...
* heed: fix `DatabaseRw::delete`
Ok(true) means the key did not exist, so we must return
Err(RuntimeError::KeyNotFound)
* block: `add_block()` (dummy value) test
* ops: `key_image` tests
* cleanup, docs, tests
* backend: test `take()` & `update()`
* docs
* remove `OutputFlags::NONE`
* add_block(): add asserts, panic docs, `should_panic` tests
* backend: remove `Ok(())` in `Database::delete` if already deleted
redb already does this, so heed so match
* block: move block operations after tx/outputs
* `amount == 0` -> `amount == 1`
* Nit: StorableVec::wrap_ref
* `saturating_sub(1)` -> `- 1`
* add `TxOutputs` table
* add_block(): add to `tx_outputs` table
* fix `DatabaseRo::update`
* add_tx(): take `block_height` as input
* tx: add/remove from `TxOutputs` table
* output: remove if `amount == 1` -> `amount_index == 0`
* output: fix `add_output()`'s `amount_index` calculation
* output: fix `add_output()`'s `amount_index` calculation again
* output: tests for `amount_index/num_outputs`
* block: `num_outputs - 1` and `take()` -> `get()`
We don't need to `take()` since the call afterwards to
`remove_output()` removes the entry
* block: swap `get_block_extended_header[_from_height]()`
* move `{key_image,output}` handling `add_block()` -> `add_tx()`
* blockchain: add doc to `top_block_height()`
* block: manual panic -> `assert_eq!()`
* test-utils: add `block_blob` to `VerifiedBlockInformation`
field introduced in this PR
* ops: use real block/tx data in tests
* block: `total_generated_coins` -> `cumulative_generated_coins`
* fix clippy, docs, TODOs
* `cumulative_generated_coins()`: `block/` -> `blockchain/`
* blockchain: add `cumulative_generated_coins()` tests
* Update database/src/ops/block.rs
Co-authored-by: Boog900 <boog900@tutanota.com>
* `cumulative_generated_coins()` docs for pre-block-0 special case
---------
Co-authored-by: Boog900 <boog900@tutanota.com>
2024-04-23 01:53:29 +00:00
|
|
|
/// TODO
|
|
|
|
/// <https://github.com/Cuprate/cuprate/pull/102#discussion_r1556694072>
|
|
|
|
/// <https://github.com/serai-dex/serai/blob/93be7a30674ecedfb325b6d09dc22d550d7c13f8/coins/monero/src/block.rs#L110>
|
|
|
|
pub block_blob: Vec<u8>,
|
2024-03-27 00:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------- OutputOnChain
|
|
|
|
/// An already approved previous transaction output.
|
|
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
|
|
// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] // FIXME: monero_serai
|
|
|
|
// #[cfg_attr(feature = "borsh", derive(BorshSerialize, BorshDeserialize))]
|
|
|
|
pub struct OutputOnChain {
|
|
|
|
/// TODO
|
|
|
|
pub height: u64,
|
|
|
|
/// TODO
|
|
|
|
pub time_lock: Timelock,
|
|
|
|
/// TODO
|
|
|
|
pub key: Option<EdwardsPoint>,
|
|
|
|
/// TODO
|
|
|
|
pub commitment: EdwardsPoint,
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------- Tests
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
// use super::*;
|
|
|
|
}
|