Skip to content

Commit 498b6c0

Browse files
authored
Merge pull request #4412 from stacks-network/feat/stacking-burnops-include-signer-key
Update StackStxOp to include signer key
2 parents c7e9dac + cb136bf commit 498b6c0

File tree

10 files changed

+1274
-30
lines changed

10 files changed

+1274
-30
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
- tests::neon_integrations::size_overflow_unconfirmed_stream_microblocks_integration_test
6060
- tests::neon_integrations::stx_delegate_btc_integration_test
6161
- tests::neon_integrations::stx_transfer_btc_integration_test
62+
- tests::neon_integrations::stack_stx_burn_op_test
6263
- tests::neon_integrations::test_chainwork_first_intervals
6364
- tests::neon_integrations::test_chainwork_partial_interval
6465
- tests::neon_integrations::test_flash_block_skip_tenure
@@ -83,6 +84,7 @@ jobs:
8384
- tests::signer::stackerdb_block_proposal
8485
- tests::signer::stackerdb_filter_bad_transactions
8586
- tests::signer::stackerdb_mine_2_nakamoto_reward_cycles
87+
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
8688
steps:
8789
## Setup test environment
8890
- name: Setup Test Environment

stackslib/src/chainstate/burn/db/sortdb.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ impl FromRow<StackStxOp> for StackStxOp {
319319
let stacked_ustx = u128::from_str_radix(&stacked_ustx_str, 10)
320320
.expect("CORRUPTION: bad u128 written to sortdb");
321321
let num_cycles = row.get_unwrap("num_cycles");
322+
let signing_key_str_opt: Option<String> = row.get("signer_key")?;
323+
let signer_key = match signing_key_str_opt {
324+
Some(key_str) => serde_json::from_str(&key_str).ok(),
325+
None => None,
326+
};
327+
let max_amount_str_opt: Option<String> = row.get("max_amount")?;
328+
let max_amount = match max_amount_str_opt {
329+
Some(max_amount_str) => u128::from_str_radix(&max_amount_str, 10)
330+
.map_err(|_| db_error::ParseError)
331+
.ok(),
332+
None => None,
333+
};
334+
let auth_id = row.get("auth_id")?;
322335

323336
Ok(StackStxOp {
324337
txid,
@@ -329,6 +342,9 @@ impl FromRow<StackStxOp> for StackStxOp {
329342
reward_addr,
330343
stacked_ustx,
331344
num_cycles,
345+
signer_key,
346+
max_amount,
347+
auth_id,
332348
})
333349
}
334350
}
@@ -702,6 +718,9 @@ const SORTITION_DB_SCHEMA_8: &'static [&'static str] = &[
702718
block_hash TEXT NOT NULL,
703719
block_height INTEGER NOT NULL
704720
);"#,
721+
r#"ALTER TABLE stack_stx ADD signer_key TEXT DEFAULT NULL;"#,
722+
r#"ALTER TABLE stack_stx ADD max_amount TEXT DEFAULT NULL;"#,
723+
r#"ALTER TABLE stack_stx ADD auth_id INTEGER DEFAULT NULL;"#,
705724
r#"
706725
-- table definition for `vote-for-aggregate-key` burn op
707726
CREATE TABLE vote_for_aggregate_key (
@@ -5372,9 +5391,12 @@ impl<'a> SortitionHandleTx<'a> {
53725391
&op.reward_addr.to_db_string(),
53735392
&op.stacked_ustx.to_string(),
53745393
&op.num_cycles,
5394+
&serde_json::to_string(&op.signer_key).unwrap(),
5395+
&serde_json::to_string(&op.max_amount).unwrap(),
5396+
&op.auth_id,
53755397
];
53765398

5377-
self.execute("REPLACE INTO stack_stx (txid, vtxindex, block_height, burn_header_hash, sender_addr, reward_addr, stacked_ustx, num_cycles) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)", args)?;
5399+
self.execute("REPLACE INTO stack_stx (txid, vtxindex, block_height, burn_header_hash, sender_addr, reward_addr, stacked_ustx, num_cycles, signer_key, max_amount, auth_id) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)", args)?;
53785400

53795401
Ok(())
53805402
}
@@ -10085,6 +10107,9 @@ pub mod tests {
1008510107
reward_addr: PoxAddress::Standard(StacksAddress::new(4, Hash160([4u8; 20])), None),
1008610108
stacked_ustx: 456,
1008710109
num_cycles: 6,
10110+
signer_key: Some(StacksPublicKeyBuffer([0x02; 33])),
10111+
max_amount: Some(u128::MAX),
10112+
auth_id: Some(0u32),
1008810113

1008910114
txid: Txid([0x02; 32]),
1009010115
vtxindex: 2,
@@ -10177,6 +10202,9 @@ pub mod tests {
1017710202
reward_addr: PoxAddress::Standard(StacksAddress::new(4, Hash160([4u8; 20])), None),
1017810203
stacked_ustx: 456,
1017910204
num_cycles: 6,
10205+
signer_key: None,
10206+
max_amount: None,
10207+
auth_id: None,
1018010208

1018110209
txid: Txid([0x02; 32]),
1018210210
vtxindex: 2,

stackslib/src/chainstate/burn/operations/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub enum Error {
8282
// stack stx related errors
8383
StackStxMustBePositive,
8484
StackStxInvalidCycles,
85+
StackStxInvalidKey,
8586

8687
// errors associated with delegate stx
8788
DelegateStxMustBePositive,
@@ -142,6 +143,7 @@ impl fmt::Display for Error {
142143
f,
143144
"Stack STX must set num cycles between 1 and max num cycles"
144145
),
146+
Error::StackStxInvalidKey => write!(f, "Signer key is invalid"),
145147
Error::DelegateStxMustBePositive => write!(f, "Delegate STX must be positive amount"),
146148
Error::VoteForAggregateKeyInvalidKey => {
147149
write!(f, "Aggregate key is invalid")
@@ -190,6 +192,9 @@ pub struct StackStxOp {
190192
/// how many ustx this transaction locks
191193
pub stacked_ustx: u128,
192194
pub num_cycles: u8,
195+
pub signer_key: Option<StacksPublicKeyBuffer>,
196+
pub max_amount: Option<u128>,
197+
pub auth_id: Option<u32>,
193198

194199
// common to all transactions
195200
pub txid: Txid, // transaction ID
@@ -478,6 +483,9 @@ impl BlockstackOperationType {
478483
"stacked_ustx": op.stacked_ustx,
479484
"burn_txid": op.txid,
480485
"vtxindex": op.vtxindex,
486+
"signer_key": op.signer_key.as_ref().map(|k| serde_json::Value::String(k.to_hex())).unwrap_or(serde_json::Value::Null),
487+
"max_amount": op.max_amount.map_or(serde_json::Value::Null, |amount| serde_json::Value::Number(serde_json::Number::from(amount))),
488+
"auth_id": op.auth_id.map_or(serde_json::Value::Null, |id| serde_json::Value::Number(serde_json::Number::from(id))),
481489
}
482490
})
483491
}

0 commit comments

Comments
 (0)