Skip to content

Commit

Permalink
tests: removed test that tests old mining behavior where limit behavi…
Browse files Browse the repository at this point in the history
…or switches for TransactionTooLarge
  • Loading branch information
pavitthrap committed Feb 7, 2022
1 parent b2ee7ad commit 1b9441a
Showing 1 changed file with 0 additions and 253 deletions.
253 changes: 0 additions & 253 deletions src/chainstate/stacks/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10197,259 +10197,6 @@ pub mod test {
);
}

#[test]
fn test_mempool_mining_heuristics() {
let submitter_key_0 = StacksPrivateKey::new();
let submitter_key_1 = StacksPrivateKey::new();
let initial_balance_recipients: Vec<_> = vec![
StacksAddress {
version: C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
bytes: Hash160([1; 20]),
},
StacksAddress::from_public_keys(
C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
&AddressHashMode::SerializeP2PKH,
1,
&vec![StacksPublicKey::from_private(&submitter_key_0)],
)
.unwrap(),
StacksAddress {
version: C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
bytes: Hash160([2; 20]),
},
StacksAddress::from_public_keys(
C32_ADDRESS_VERSION_TESTNET_SINGLESIG,
&AddressHashMode::SerializeP2PKH,
1,
&vec![StacksPublicKey::from_private(&submitter_key_1)],
)
.unwrap(),
];

let initial_balances = initial_balance_recipients
.iter()
.map(|addr| (addr.clone(), 10_000_000_000))
.collect();
let chain_id = 8;
let mut chainstate = instantiate_and_exec(
false,
chain_id,
"test_mempool_mining_heuristics",
initial_balances,
Some(Box::new(|tx: &mut ClarityTx| {
tx.connection().as_transaction(|tx| {
let (ct_ast, ct_analysis) = tx
.analyze_smart_contract(&CONTRACT_IDENT, CONTRACT)
.unwrap();
tx.initialize_smart_contract(&CONTRACT_IDENT, &ct_ast, CONTRACT, |_, _| false)
.unwrap();
tx.save_analysis(&CONTRACT_IDENT, &ct_analysis).unwrap();
})
})),
);

let burndb = SortitionDB::connect(
"/tmp/test_mempool_mining_heuristics_sortdb",
0,
&BurnchainHeaderHash([1; 32]),
1,
&[StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: 0,
end_height: i64::MAX as u64,
block_limit: ExecutionCost {
write_length: 15_000_000, // roughly 15 mb
write_count: 500,
read_length: 100_000_000,
read_count: 7_750,
runtime: 5_000_000_000,
},
network_epoch: PEER_VERSION_EPOCH_2_0,
}],
true,
)
.unwrap();

let mut mempool = MemPoolDB::open_test(false, chain_id, &chainstate.root_path).unwrap();

let txs_to_push = vec![
StacksTransaction::new(
TransactionVersion::Testnet,
TransactionAuth::from_p2pkh(&submitter_key_0).unwrap(),
TransactionPayload::TokenTransfer(
initial_balance_recipients[2].clone().into(),
1000,
TokenTransferMemo([0; 34]),
),
),
StacksTransaction::new(
TransactionVersion::Testnet,
TransactionAuth::from_p2pkh(&submitter_key_0).unwrap(),
TransactionPayload::ContractCall(TransactionContractCall {
address: initial_balance_recipients[0].clone(),
contract_name: CONTRACT_IDENT.name.clone(),
function_name: "call-it".into(),
function_args: vec![Value::list_from(vec![
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
Value::Bool(true),
])
.unwrap()],
}),
),
];
let second_set_txs = vec![
StacksTransaction::new(
TransactionVersion::Testnet,
TransactionAuth::from_p2pkh(&submitter_key_1).unwrap(),
TransactionPayload::TokenTransfer(
initial_balance_recipients[2].clone().into(),
1000,
TokenTransferMemo([0; 34]),
),
),
StacksTransaction::new(
TransactionVersion::Testnet,
TransactionAuth::from_p2pkh(&submitter_key_1).unwrap(),
TransactionPayload::ContractCall(TransactionContractCall {
address: boot_code_addr(false),
contract_name: "pox".into(),
function_name: "stack-stx".into(),
function_args: vec![
Value::UInt(10),
Value::from(
TupleData::from_data(vec![
("version".into(), Value::buff_from_byte(0)),
("hashbytes".into(), Value::buff_from(vec![0; 20]).unwrap()),
])
.unwrap(),
),
Value::UInt(2),
Value::UInt(2),
],
}),
),
StacksTransaction::new(
TransactionVersion::Testnet,
TransactionAuth::from_p2pkh(&submitter_key_1).unwrap(),
TransactionPayload::ContractCall(TransactionContractCall {
address: initial_balance_recipients[0].clone(),
contract_name: CONTRACT_IDENT.name.clone(),
function_name: "call-it".into(),
function_args: vec![Value::list_from(vec![Value::Bool(true)]).unwrap()],
}),
),
];

let (parent_header_info, parent_consensus_hash) = (
StacksHeaderInfo::genesis(TrieHash([0u8; 32]), &BurnchainHeaderHash([1; 32]), 0, 1),
FIRST_BURNCHAIN_CONSENSUS_HASH,
);

for (ix, mut tx) in txs_to_push.into_iter().enumerate() {
tx.chain_id = chain_id;
tx.set_origin_nonce(ix as u64);
tx.set_tx_fee(1000);

let mut tx_signer = StacksTransactionSigner::new(&tx);
tx_signer.sign_origin(&submitter_key_0).unwrap();

let tx = tx_signer.get_tx().unwrap();

eprintln!("Mempool tx submitted {}", ix);

mempool
.submit(
&mut chainstate,
&parent_consensus_hash,
&parent_header_info.anchored_header.block_hash(),
&tx,
None,
&ExecutionCost::max_value(),
&StacksEpochId::Epoch20,
)
.unwrap()
}

for (ix, mut tx) in second_set_txs.into_iter().enumerate() {
tx.chain_id = chain_id;
tx.set_origin_nonce(ix as u64);
tx.set_tx_fee(1000);

let mut tx_signer = StacksTransactionSigner::new(&tx);
tx_signer.sign_origin(&submitter_key_1).unwrap();

let tx = tx_signer.get_tx().unwrap();

eprintln!("Mempool tx submitted {}", ix);

mempool
.submit(
&mut chainstate,
&parent_consensus_hash,
&parent_header_info.anchored_header.block_hash(),
&tx,
None,
&ExecutionCost::max_value(),
&StacksEpochId::Epoch20,
)
.unwrap()
}

mempool.dump_txs();

// in the first attempt to mine a block, we should mine *4* transactions:
// coinbase, a transfer, a stack-stx call, a transfer
// in the second attempt, because we've tossed out the large offender, *5*:
// coinbase, a transfer, a stack-stx call, a transfer, a contract call

for block_index in 0u8..2u8 {
let miner_key = StacksPrivateKey::new();
let mut tx = StacksTransaction::new(
TransactionVersion::Testnet,
TransactionAuth::from_p2pkh(&miner_key).unwrap(),
TransactionPayload::Coinbase(CoinbasePayload([0u8; 32])),
);
tx.chain_id = chain_id;
tx.anchor_mode = TransactionAnchorMode::OnChainOnly;
let mut tx_signer = StacksTransactionSigner::new(&tx);
tx_signer.sign_origin(&miner_key).unwrap();

let coinbase_tx = tx_signer.get_tx().unwrap();

let (block, _cost, _size) = StacksBlockBuilder::build_anchored_block(
&chainstate,
&burndb.index_conn(),
&mut mempool,
&parent_header_info,
block_index as u64,
VRFProof::empty(),
Hash160([block_index; 20]),
&coinbase_tx,
BlockBuilderSettings::limited(),
None,
)
.unwrap();

mempool.dump_txs();

eprintln!("BLOCK #{}, Tx Count: {}", block_index, block.txs.len());
if block_index == 0 {
assert_eq!(block.txs.len(), 4);
} else if block_index == 1 {
assert_eq!(block.txs.len(), 5);
}
}
}

// TODO: invalid block with duplicate microblock public key hash (okay between forks, but not
// within the same fork)
// TODO: (BLOCKED) build off of different points in the same microblock stream
Expand Down

0 comments on commit 1b9441a

Please sign in to comment.