Skip to content
Open
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
7 changes: 5 additions & 2 deletions app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use plain_bitassets::{
miner::{self, Miner},
node::{self, Node},
types::{
self, Address, AmountOverflowError, BitcoinOutputContent, Body,
FilledOutput, OutPoint, Output, Transaction,
self, Address, AmountOverflowError, BLOCK_HEADER_VERSION,
BitcoinOutputContent, Body, FilledOutput, OutPoint, Output,
Transaction,
proto::mainchain::{
self,
generated::{validator_service_server, wallet_service_server},
Expand Down Expand Up @@ -439,6 +440,7 @@ impl App {
coinbase,
);
let header = types::Header {
version: BLOCK_HEADER_VERSION,
merkle_root,
prev_side_hash,
prev_main_hash,
Expand All @@ -456,6 +458,7 @@ impl App {
let merkle_root = Body::compute_merkle_root(&coinbase, &[]);
let body = Body::new(Vec::new(), coinbase);
let header = types::Header {
version: BLOCK_HEADER_VERSION,
merkle_root,
prev_side_hash,
prev_main_hash,
Expand Down
24 changes: 17 additions & 7 deletions lib/state/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use sneed::{RoTxn, RwTxn};
use crate::{
state::{Error, PrevalidatedBlock, State, amm, dutch_auction, error},
types::{
AmountOverflowError, Authorization, BitAssetId, Body, FilledOutput,
FilledOutputContent, GetAddress as _, GetBitcoinValue as _, Header,
InPoint, OutPoint, OutPointKey, OutputContent, SpentOutput, TxData,
Verify as _,
AmountOverflowError, Authorization, BLOCK_HEADER_VERSION, BitAssetId,
Body, FilledOutput, FilledOutputContent, GetAddress as _,
GetBitcoinValue as _, Header, InPoint, OutPoint, OutPointKey,
OutputContent, SpentOutput, TxData, Verify as _,
},
};

Expand Down Expand Up @@ -45,6 +45,8 @@ pub fn validate(
let err = Error::InvalidBody {
expected: header.merkle_root,
computed: merkle_root,
local_header_version: BLOCK_HEADER_VERSION,
block_header_version: header.version,
};
return Err(err);
}
Expand Down Expand Up @@ -124,6 +126,8 @@ pub fn prevalidate(
let err = Error::InvalidBody {
expected: header.merkle_root,
computed: computed_merkle_root,
local_header_version: BLOCK_HEADER_VERSION,
block_header_version: header.version,
};
return Err(err);
}
Expand Down Expand Up @@ -412,6 +416,8 @@ pub fn connect(
let err = Error::InvalidBody {
expected: merkle_root,
computed: header.merkle_root,
local_header_version: BLOCK_HEADER_VERSION,
block_header_version: header.version,
};
return Err(err);
}
Expand Down Expand Up @@ -574,6 +580,8 @@ pub fn disconnect_tip(
let err = Error::InvalidBody {
expected: header.merkle_root,
computed: merkle_root,
local_header_version: BLOCK_HEADER_VERSION,
block_header_version: header.version,
};
return Err(err);
}
Expand Down Expand Up @@ -726,14 +734,16 @@ mod test {
test::fresh_state,
},
types::{
BitAssetData, BitAssetDataUpdates, BitAssetId, BlockHash, Body,
FilledOutput, FilledOutputContent, Hash, Header, OutPoint,
OutPointKey, Output, OutputContent, Transaction, TxData, Update,
BLOCK_HEADER_VERSION, BitAssetData, BitAssetDataUpdates,
BitAssetId, BlockHash, Body, FilledOutput, FilledOutputContent,
Hash, Header, OutPoint, OutPointKey, Output, OutputContent,
Transaction, TxData, Update,
},
};

fn header(prev_side_hash: Option<BlockHash>, body: &Body) -> Header {
Header {
version: BLOCK_HEADER_VERSION,
merkle_root: Body::compute_merkle_root(
&body.coinbase,
&body.transactions,
Expand Down
4 changes: 3 additions & 1 deletion lib/state/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub mod dutch_auction {
#[error("Invalid tx; Final price cannot be greater than initial price")]
FinalPrice,
#[error(
"Invalid tx; For a single-block auction,
"Invalid tx; For a single-block auction,
final price must be exactly equal to initial price"
)]
PriceMismatch,
Expand Down Expand Up @@ -374,6 +374,8 @@ pub enum Error {
InvalidBody {
expected: MerkleRoot,
computed: MerkleRoot,
local_header_version: u8,
block_header_version: u8,
},
#[error("invalid header: {0}")]
InvalidHeader(InvalidHeader),
Expand Down
6 changes: 4 additions & 2 deletions lib/state/two_way_peg_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,8 @@ mod test {
},
},
types::{
Address, FilledOutput, FilledOutputContent, InPoint, M6id,
OutPoint, OutPointKey, Txid, WithdrawalBundle,
Address, BLOCK_HEADER_VERSION, FilledOutput, FilledOutputContent,
InPoint, M6id, OutPoint, OutPointKey, Txid, WithdrawalBundle,
WithdrawalBundleEvent, WithdrawalBundleEventStatus,
WithdrawalBundleStatus, WithdrawalOutputContent,
proto::mainchain::{BlockEvent, BlockInfo, Deposit, TwoWayPegData},
Expand Down Expand Up @@ -1269,6 +1269,7 @@ mod test {
let main1 = bitcoin::BlockHash::from_byte_array([11; 32]);

let genesis = Header {
version: BLOCK_HEADER_VERSION,
merkle_root,
prev_side_hash: None,
prev_main_hash: main0,
Expand All @@ -1284,6 +1285,7 @@ mod test {
}

let block1 = Header {
version: BLOCK_HEADER_VERSION,
merkle_root,
prev_side_hash: Some(genesis.hash()),
prev_main_hash: main1,
Expand Down
2 changes: 2 additions & 0 deletions lib/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub use transaction::{
};

pub const THIS_SIDECHAIN: u8 = 4;
pub const BLOCK_HEADER_VERSION: u8 = 0;

#[derive(Debug, Error)]
#[error("Bitcoin amount overflow")]
Expand Down Expand Up @@ -158,6 +159,7 @@ where
ToSchema,
)]
pub struct Header {
pub version: u8,
pub merkle_root: MerkleRoot,
pub prev_side_hash: Option<BlockHash>,
#[borsh(serialize_with = "borsh_serialize_bitcoin_block_hash")]
Expand Down