Skip to content
Draft
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
45 changes: 45 additions & 0 deletions docs/rpc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2238,3 +2238,48 @@ paths:
$ref: "#/components/responses/NotFound"
"500":
$ref: "#/components/responses/InternalServerError"

/v3/blocks/simulate/{block_id}:
get:
summary: Simulate mining of a block with the specified transactions and returns its content
tags:
- Blocks
security:
- rpcAuth: []
operationId: blockSimulate
description: |
Simulate the mining of a block (no data is written in the MARF) with specified trnsactions and returns its content.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"trnsactions"

parameters:
- name: block_id
in: path
description: The block ID hash
required: true
schema:
type: string
pattern: "^[0-9a-f]{64}$"
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
type: string
description: SIP-003-encoded Transaction in hex format
responses:
"200":
description: Content of the simulated block
content:
application/json:
schema:
$ref: "#/components/schemas/BlockReplay"
example:
$ref: "./components/examples/block-replay.example.json"
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
"500":
$ref: "#/components/responses/InternalServerError"
4 changes: 4 additions & 0 deletions stackslib/src/chainstate/stacks/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,10 @@ impl<'a, 'b> ClarityTx<'a, 'b> {
})
.expect("FATAL: `ust-liquid-supply` overflowed");
}

pub fn disable_fees(&mut self) {
self.block.no_fees = true;
}
}

pub struct ChainstateTx<'a> {
Expand Down
14 changes: 11 additions & 3 deletions stackslib/src/chainstate/stacks/db/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ impl StacksChainState {
}

StacksChainState::account_debit(clarity_tx, &payer_account.principal, fee);

Ok(fee)
}

Expand Down Expand Up @@ -1568,6 +1569,8 @@ impl StacksChainState {
debug!("Process transaction {} ({})", tx.txid(), tx.payload.name());
let epoch = clarity_block.get_epoch();

let no_fees = clarity_block.block.no_fees;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but the purpose of this endpoint is to faithfully re-execute a block. The block will almost certainly contain transactions for transferring assets between accounts (including STX). Disabling fee payment along with the commensurate nonce increment would likely invalidate or otherwise alter the execution of transactions, leading to an unfaithful block re-execution.

Can you help me understand what purpose is served by this feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The block simulator allows you to execute "brand-new" transactions in a block (mainly as a quick-test mechanism). The (current) main usage is to run contract deploys and calls at specific heights (for example i am using it as the base for some integration tests for the python bindings). It happens sometime (especially when randomly generating keys) that having STXs is convoluted (in practice you are running your functions in the past). For this reason having the ability to run stuff "for free" is quite handy. Obviously if it does pose some risk it is definitely a feature that can be removed without harming the main goal of the patch.


StacksChainState::process_transaction_precheck(&clarity_block.config, tx, epoch)?;

// what version of Clarity did the transaction caller want? And, is it valid now?
Expand All @@ -1592,7 +1595,10 @@ impl StacksChainState {

let payer_address = payer_account.principal.clone();
let payer_nonce = payer_account.nonce;
StacksChainState::pay_transaction_fee(&mut transaction, fee, payer_account)?;

if !no_fees {
StacksChainState::pay_transaction_fee(&mut transaction, fee, payer_account)?;
}

// origin balance may have changed (e.g. if the origin paid the tx fee), so reload the account
let origin_account =
Expand Down Expand Up @@ -1633,8 +1639,10 @@ impl StacksChainState {
None,
)?;

let new_payer_account = StacksChainState::get_payer_account(&mut transaction, tx);
StacksChainState::pay_transaction_fee(&mut transaction, fee, new_payer_account)?;
if !no_fees {
let new_payer_account = StacksChainState::get_payer_account(&mut transaction, tx);
StacksChainState::pay_transaction_fee(&mut transaction, fee, new_payer_account)?;
}

// update the account nonces
StacksChainState::update_account_nonce(
Expand Down
8 changes: 8 additions & 0 deletions stackslib/src/clarity_vm/clarity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub struct ClarityBlockConnection<'a, 'b> {
mainnet: bool,
chain_id: u32,
epoch: StacksEpochId,
pub no_fees: bool,
}

///
Expand Down Expand Up @@ -318,6 +319,7 @@ impl ClarityBlockConnection<'_, '_> {
mainnet: false,
chain_id: CHAIN_ID_TESTNET,
epoch,
no_fees: false,
}
}

Expand Down Expand Up @@ -444,6 +446,7 @@ impl ClarityInstance {
mainnet: self.mainnet,
chain_id: self.chain_id,
epoch: epoch.epoch_id,
no_fees: false,
}
}

Expand All @@ -468,6 +471,7 @@ impl ClarityInstance {
mainnet: self.mainnet,
chain_id: self.chain_id,
epoch,
no_fees: false,
}
}

Expand All @@ -494,6 +498,7 @@ impl ClarityInstance {
mainnet: self.mainnet,
chain_id: self.chain_id,
epoch,
no_fees: false,
};

let use_mainnet = self.mainnet;
Expand Down Expand Up @@ -590,6 +595,7 @@ impl ClarityInstance {
mainnet: self.mainnet,
chain_id: self.chain_id,
epoch,
no_fees: false,
};

let use_mainnet = self.mainnet;
Expand Down Expand Up @@ -698,6 +704,7 @@ impl ClarityInstance {
mainnet: self.mainnet,
chain_id: self.chain_id,
epoch: epoch.epoch_id,
no_fees: false,
}
}

Expand Down Expand Up @@ -738,6 +745,7 @@ impl ClarityInstance {
mainnet: self.mainnet,
chain_id: self.chain_id,
epoch: epoch.epoch_id,
no_fees: false,
}
}

Expand Down
Loading
Loading