Skip to content

Commit

Permalink
fix: ignore anchor mode on a subnet
Browse files Browse the repository at this point in the history
All transactions are mined in microblocks, so the anchor mode is
useless.
  • Loading branch information
obycode committed Jun 21, 2023
1 parent b9fb9ad commit 0c7b9d7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 85 deletions.
73 changes: 0 additions & 73 deletions src/chainstate/stacks/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,6 @@ impl StacksMessageCodec for StacksBlock {
));
}

// all transactions must have anchor mode either OnChainOnly or Any
// (no OffChainOnly allowed)
if !StacksBlock::validate_anchor_mode(&txs, true) {
warn!("Invalid block: Found offchain-only transaction");
return Err(codec_error::DeserializeError(
"Invalid block: Found offchain-only transaction".to_string(),
));
}

// all transactions are unique
if !StacksBlock::validate_transactions_unique(&txs) {
warn!("Invalid block: Found duplicate transaction");
Expand Down Expand Up @@ -466,30 +457,6 @@ impl StacksBlock {
return true;
}

/// verify anchor modes
pub fn validate_anchor_mode(txs: &Vec<StacksTransaction>, anchored: bool) -> bool {
for tx in txs {
match (anchored, tx.anchor_mode) {
(true, TransactionAnchorMode::OffChainOnly) => {
warn!(
"Tx {} is off-chain-only; expected on-chain-only or any",
tx.txid()
);
return false;
}
(false, TransactionAnchorMode::OnChainOnly) => {
warn!(
"Tx {} is on-chain-only; expected off-chain-only or any",
tx.txid()
);
return false;
}
(_, _) => {}
}
}
return true;
}

/// verify that a coinbase is present and is on-chain only, or is absent
pub fn validate_coinbase(txs: &Vec<StacksTransaction>, check_present: bool) -> bool {
let mut found_coinbase = false;
Expand Down Expand Up @@ -552,9 +519,6 @@ impl StacksBlock {
if !StacksBlock::validate_transactions_chain_id(&self.txs, chain_id) {
return false;
}
if !StacksBlock::validate_anchor_mode(&self.txs, true) {
return false;
}
if !StacksBlock::validate_coinbase(&self.txs, true) {
return false;
}
Expand Down Expand Up @@ -774,13 +738,6 @@ impl StacksMessageCodec for StacksMicroblock {
));
}

if !StacksBlock::validate_anchor_mode(&txs, false) {
warn!("Invalid microblock: found on-chain-only transaction");
return Err(codec_error::DeserializeError(
"Invalid microblock: found on-chain-only transaction".to_string(),
));
}

// header and transactions must be consistent
let txid_vecs = txs.iter().map(|tx| tx.txid().as_bytes().to_vec()).collect();

Expand Down Expand Up @@ -869,9 +826,6 @@ impl StacksMicroblock {
if !StacksBlock::validate_transactions_chain_id(&self.txs, chain_id) {
return false;
}
if !StacksBlock::validate_anchor_mode(&self.txs, false) {
return false;
}
if !StacksBlock::validate_coinbase(&self.txs, false) {
return false;
}
Expand Down Expand Up @@ -1427,9 +1381,6 @@ mod test {
let mut block_header_invalid_coinbase = header.clone();
block_header_invalid_coinbase.tx_merkle_root = get_tx_root(&txs_bad_coinbase);

let mut block_header_invalid_anchor = header.clone();
block_header_invalid_anchor.tx_merkle_root = get_tx_root(&txs_bad_anchor);

let mut block_header_dup_tx = header.clone();
block_header_dup_tx.tx_merkle_root = get_tx_root(&txs_dup);

Expand All @@ -1451,13 +1402,6 @@ mod test {
},
"multiple coinbases found",
),
(
StacksBlock {
header: block_header_invalid_anchor,
txs: txs_bad_anchor,
},
"Found offchain-only transaction",
),
(
StacksBlock {
header: block_header_dup_tx,
Expand Down Expand Up @@ -1551,9 +1495,6 @@ mod test {
let mut block_header_offchain_coinbase = header.clone();
block_header_offchain_coinbase.tx_merkle_root = get_tx_root(&txs_coinbase);

let mut block_header_invalid_anchor = header.clone();
block_header_invalid_anchor.tx_merkle_root = get_tx_root(&txs_bad_anchor);

let mut block_header_dup_tx = header.clone();
block_header_dup_tx.tx_merkle_root = get_tx_root(&txs_dup);

Expand All @@ -1568,20 +1509,6 @@ mod test {
},
"invalid anchor mode for Coinbase",
),
(
StacksMicroblock {
header: block_header_coinbase,
txs: txs_coinbase,
},
"found on-chain-only transaction",
),
(
StacksMicroblock {
header: block_header_invalid_anchor,
txs: txs_bad_anchor,
},
"found on-chain-only transaction",
),
(
StacksMicroblock {
header: block_header_dup_tx,
Expand Down
12 changes: 0 additions & 12 deletions src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,18 +697,6 @@ impl<'a> StacksMicroblockBuilder<'a> {
bytes_so_far: u64,
limit_behavior: &BlockLimitFunction,
) -> Result<TransactionResult, Error> {
if tx.anchor_mode != TransactionAnchorMode::OffChainOnly
&& tx.anchor_mode != TransactionAnchorMode::Any
{
return Ok(TransactionResult::skipped_due_to_error(
&tx,
Error::InvalidStacksTransaction(
"Invalid transaction anchor mode for streamed data".to_string(),
false,
),
));
}

if bytes_so_far + tx_len >= MAX_EPOCH_SIZE.into() {
info!(
"Adding microblock tx {} would exceed epoch data size",
Expand Down

0 comments on commit 0c7b9d7

Please sign in to comment.