Skip to content

Commit 74e94fc

Browse files
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into feat/expand-consensus-test-to-support-pre-nakamoto-epochs
2 parents 76edefd + 37ab0b2 commit 74e94fc

File tree

9 files changed

+258
-66
lines changed

9 files changed

+258
-66
lines changed

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1010
### Added
1111

1212
- Added support for new Clarity 4 builtin, `secp256r1-verify?` (not activated until epoch 3.3)
13-
14-
### Added
15-
13+
- Fixed an issue where `event.committed` was always equal to `true` in the block replay RPC endpoint
14+
- Added `result_hex` and `post_condition_aborted` to the block replay RPC endpoint
1615
- New `block_proposal_validation_timeout_secs` configuration option in the connection options section, allowing to set the maximum duration a node will spend validating a proposed block.
1716

1817
### Changed

build.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ fn current_git_hash() -> Option<String> {
2121
None
2222
}
2323

24-
fn current_git_branch() -> Option<String> {
25-
if option_env!("GIT_BRANCH") == None {
26-
let commit = Command::new("git")
27-
.arg("rev-parse")
28-
.arg("--abbrev-ref")
29-
.arg("HEAD")
30-
.output();
31-
if let Ok(commit) = commit {
32-
if let Ok(commit) = String::from_utf8(commit.stdout) {
33-
return Some(commit);
34-
}
35-
}
36-
} else {
37-
return option_env!("GIT_BRANCH").map(String::from);
38-
}
39-
40-
None
41-
}
42-
4324
fn is_working_tree_clean() -> bool {
4425
let status = Command::new("git")
4526
.arg("diff")

docs/rpc/components/examples/block-replay.example.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
}
9999
}
100100
},
101+
"result_hex": "0x0703",
102+
"post_condition_aborted": false,
101103
"stx_burned": 0,
102104
"tx_index": 0,
103105
"txid": "f14dd7dec56405fd7dac69c3080fb569fae4c49c591f9ad0e5cf5c797add9005"

docs/rpc/components/schemas/block-replay.schema.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ properties:
3636
state_index_root:
3737
type: string
3838
pattern: "^[0-9a-f]{64}$"
39-
description: block state index root computed from the MARF (got from the original block)
39+
description: block state index root computed from the MARF (got from the original block)
4040
timestamp:
4141
type: integer
4242
tx_merkle_root:
@@ -67,6 +67,12 @@ properties:
6767
result:
6868
type: object
6969
description: Clarity value representing the transaction result
70+
result_hex:
71+
type: string
72+
description: The transaction's result, encoded as a Clarity hex string
73+
post_condition_aborted:
74+
type: boolean
75+
description: Whether the transaction was aborted by a post-condition
7076
stx_burned:
7177
type: integer
7278
description: number of burned stx

stackslib/src/core/test_util.rs

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn sign_standard_single_sig_tx_anchor_mode_version(
104104
}
105105

106106
#[allow(clippy::too_many_arguments)]
107-
pub fn sign_tx_anchor_mode_version(
107+
pub fn make_unsigned_tx(
108108
payload: TransactionPayload,
109109
sender: &StacksPrivateKey,
110110
payer: Option<&StacksPrivateKey>,
@@ -139,6 +139,32 @@ pub fn sign_tx_anchor_mode_version(
139139
unsigned_tx.anchor_mode = anchor_mode;
140140
unsigned_tx.post_condition_mode = TransactionPostConditionMode::Allow;
141141
unsigned_tx.chain_id = chain_id;
142+
unsigned_tx
143+
}
144+
145+
#[allow(clippy::too_many_arguments)]
146+
pub fn sign_tx_anchor_mode_version(
147+
payload: TransactionPayload,
148+
sender: &StacksPrivateKey,
149+
payer: Option<&StacksPrivateKey>,
150+
sender_nonce: u64,
151+
payer_nonce: Option<u64>,
152+
tx_fee: u64,
153+
chain_id: u32,
154+
anchor_mode: TransactionAnchorMode,
155+
version: TransactionVersion,
156+
) -> StacksTransaction {
157+
let unsigned_tx = make_unsigned_tx(
158+
payload,
159+
sender,
160+
payer,
161+
sender_nonce,
162+
payer_nonce,
163+
tx_fee,
164+
chain_id,
165+
anchor_mode,
166+
version,
167+
);
142168

143169
let mut tx_signer = StacksTransactionSigner::new(&unsigned_tx);
144170
tx_signer.sign_origin(sender).unwrap();
@@ -178,25 +204,43 @@ pub fn serialize_sign_tx_anchor_mode_version(
178204
buf
179205
}
180206

181-
pub fn make_contract_publish_versioned(
207+
pub fn make_contract_publish_tx(
182208
sender: &StacksPrivateKey,
183209
nonce: u64,
184210
tx_fee: u64,
185211
chain_id: u32,
186212
contract_name: &str,
187213
contract_content: &str,
188214
version: Option<ClarityVersion>,
189-
) -> Vec<u8> {
215+
) -> StacksTransaction {
190216
let name = ContractName::from(contract_name);
191217
let code_body = StacksString::from_string(&contract_content.to_string()).unwrap();
192218

193219
let payload =
194220
TransactionPayload::SmartContract(TransactionSmartContract { name, code_body }, version);
195221

196-
let tx = sign_standard_single_sig_tx(payload, sender, nonce, tx_fee, chain_id);
197-
let mut tx_bytes = vec![];
198-
tx.consensus_serialize(&mut tx_bytes).unwrap();
199-
tx_bytes
222+
sign_standard_single_sig_tx(payload, sender, nonce, tx_fee, chain_id)
223+
}
224+
225+
pub fn make_contract_publish_versioned(
226+
sender: &StacksPrivateKey,
227+
nonce: u64,
228+
tx_fee: u64,
229+
chain_id: u32,
230+
contract_name: &str,
231+
contract_content: &str,
232+
version: Option<ClarityVersion>,
233+
) -> Vec<u8> {
234+
make_contract_publish_tx(
235+
sender,
236+
nonce,
237+
tx_fee,
238+
chain_id,
239+
contract_name,
240+
contract_content,
241+
version,
242+
)
243+
.serialize_to_vec()
200244
}
201245

202246
pub fn make_contract_publish(
@@ -381,7 +425,7 @@ pub fn make_coinbase(sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, chain_i
381425
}
382426

383427
#[allow(clippy::too_many_arguments)]
384-
pub fn make_contract_call(
428+
pub fn make_contract_call_tx(
385429
sender: &StacksPrivateKey,
386430
nonce: u64,
387431
tx_fee: u64,
@@ -390,7 +434,7 @@ pub fn make_contract_call(
390434
contract_name: &str,
391435
function_name: &str,
392436
function_args: &[Value],
393-
) -> Vec<u8> {
437+
) -> StacksTransaction {
394438
let contract_name = ContractName::from(contract_name);
395439
let function_name = ClarityName::from(function_name);
396440

@@ -401,10 +445,31 @@ pub fn make_contract_call(
401445
function_args: function_args.to_vec(),
402446
};
403447

404-
let tx = sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee, chain_id);
405-
let mut tx_bytes = vec![];
406-
tx.consensus_serialize(&mut tx_bytes).unwrap();
407-
tx_bytes
448+
sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee, chain_id)
449+
}
450+
451+
#[allow(clippy::too_many_arguments)]
452+
pub fn make_contract_call(
453+
sender: &StacksPrivateKey,
454+
nonce: u64,
455+
tx_fee: u64,
456+
chain_id: u32,
457+
contract_addr: &StacksAddress,
458+
contract_name: &str,
459+
function_name: &str,
460+
function_args: &[Value],
461+
) -> Vec<u8> {
462+
make_contract_call_tx(
463+
sender,
464+
nonce,
465+
tx_fee,
466+
chain_id,
467+
contract_addr,
468+
contract_name,
469+
function_name,
470+
function_args,
471+
)
472+
.serialize_to_vec()
408473
}
409474

410475
#[allow(clippy::too_many_arguments)]

stackslib/src/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ extern crate stacks_common;
4444
#[macro_use]
4545
pub extern crate clarity;
4646

47-
use stacks_common::versions::{GIT_BRANCH, GIT_COMMIT, GIT_TREE_CLEAN, STACKS_NODE_VERSION};
47+
use std::env::consts::{ARCH, OS};
48+
49+
use stacks_common::versions::{GIT_COMMIT, GIT_TREE_CLEAN, STACKS_NODE_VERSION};
4850
pub use stacks_common::{address, codec, types, util};
4951

5052
#[macro_use]
@@ -82,19 +84,10 @@ const BUILD_TYPE: &str = "release";
8284

8385
pub fn version_string(pkg_name: &str, pkg_version: Option<&str>) -> String {
8486
let pkg_version = pkg_version.unwrap_or(STACKS_NODE_VERSION);
85-
let git_branch = GIT_BRANCH_ENV.unwrap_or_else(|| GIT_BRANCH.unwrap_or(""));
8687
let git_commit = GIT_COMMIT_ENV.unwrap_or_else(|| GIT_COMMIT.unwrap_or(""));
8788
let git_tree_clean = GIT_TREE_CLEAN_ENV.unwrap_or_else(|| GIT_TREE_CLEAN.unwrap_or(""));
8889

8990
format!(
90-
"{} {} ({}:{}{}, {} build, {} [{}])",
91-
pkg_name,
92-
pkg_version,
93-
git_branch,
94-
git_commit,
95-
git_tree_clean,
96-
BUILD_TYPE,
97-
std::env::consts::OS,
98-
std::env::consts::ARCH
91+
"{pkg_name} {pkg_version} ({git_commit}{git_tree_clean}, {BUILD_TYPE} build, {OS} [{ARCH}])"
9992
)
10093
}

stackslib/src/net/api/blockreplay.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use stacks_common::types::chainstate::{BlockHeaderHash, ConsensusHash, StacksBlo
2121
use stacks_common::types::net::PeerHost;
2222
use stacks_common::util::hash::Sha512Trunc256Sum;
2323
use stacks_common::util::secp256k1::MessageSignature;
24+
use stacks_common::util::serde_serializers::prefix_hex_codec;
2425

2526
use crate::burnchains::Txid;
2627
use crate::chainstate::burn::db::sortdb::SortitionDB;
@@ -215,12 +216,17 @@ pub struct RPCReplayedBlockTransaction {
215216
pub hex: String,
216217
/// result of transaction execution (clarity value)
217218
pub result: Value,
219+
/// result of the transaction execution (hex string)
220+
#[serde(with = "prefix_hex_codec")]
221+
pub result_hex: Value,
218222
/// amount of burned stx
219223
pub stx_burned: u128,
220224
/// execution cost infos
221225
pub execution_cost: ExecutionCost,
222226
/// generated events
223227
pub events: Vec<serde_json::Value>,
228+
/// Whether the tx was aborted by a post-condition
229+
pub post_condition_aborted: bool,
224230
/// optional vm error
225231
pub vm_error: Option<String>,
226232
}
@@ -233,7 +239,11 @@ impl RPCReplayedBlockTransaction {
233239
.enumerate()
234240
.map(|(event_index, event)| {
235241
event
236-
.json_serialize(event_index, &receipt.transaction.txid(), true)
242+
.json_serialize(
243+
event_index,
244+
&receipt.transaction.txid(),
245+
!receipt.post_condition_aborted,
246+
)
237247
.unwrap()
238248
})
239249
.collect();
@@ -251,9 +261,11 @@ impl RPCReplayedBlockTransaction {
251261
data: transaction_data,
252262
hex: receipt.transaction.serialize_to_dbstring(),
253263
result: receipt.result.clone(),
264+
result_hex: receipt.result.clone(),
254265
stx_burned: receipt.stx_burned,
255266
execution_cost: receipt.execution_cost.clone(),
256267
events,
268+
post_condition_aborted: receipt.post_condition_aborted,
257269
vm_error: receipt.vm_error.clone(),
258270
}
259271
}

0 commit comments

Comments
 (0)