Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update StackStxOp to include signer key #4412

Merged
merged 36 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b978c02
Add initial placeholders for inclusion of signer key in StackStxOp
Feb 22, 2024
7c93f3b
Revert PreStxOp changes, make signer_key an optional for StackStxOp a…
Feb 22, 2024
1982435
Minor cleanup
Feb 22, 2024
197d281
Review comments + integration test
Feb 24, 2024
d20097e
Include fixed integ tests in CI
Feb 25, 2024
3d2043e
Cleanup
Feb 26, 2024
52d3c30
Remove option bit in stack-stx wire and infer signer-key from data le…
Mar 5, 2024
619fc3a
Fix broken unit test
Mar 5, 2024
3b05646
Add initial placeholders for inclusion of signer key in StackStxOp
Feb 22, 2024
9ea212e
Revert PreStxOp changes, make signer_key an optional for StackStxOp a…
Feb 22, 2024
a0f39c8
Minor cleanup
Feb 22, 2024
246b48f
Review comments + integration test
Feb 24, 2024
e0f1622
Include fixed integ tests in CI
Feb 25, 2024
43105b6
Cleanup
Feb 26, 2024
07ae770
Remove option bit in stack-stx wire and infer signer-key from data le…
Mar 5, 2024
88524fa
Fix broken unit test
Mar 5, 2024
e50f230
Merge branch 'feat/stacking-burnops-include-signer-key' of https://gi…
Mar 5, 2024
b171ed6
CRC: improve syntax + test stack-stx-op with signer_key as None
Mar 6, 2024
a0f5791
Set-signer-key-authorization before stack-stx Clarity call to fix rej…
Mar 8, 2024
14ce32e
Add StackStx Op with no signer key and more assertions to Nakamoto In…
Mar 10, 2024
5e13a45
Merge remote-tracking branch 'origin/next' into feat/stacking-burnops…
Mar 11, 2024
88dac0c
Merged with next, fixed compile error but not broken integ tests
Mar 11, 2024
be99b3d
Format
Mar 11, 2024
bb6b2a2
Add max_amount and auth_id to StackStxOp
Mar 12, 2024
3d27b2c
Add missing fields to StackStxOp tests
Mar 12, 2024
01b567a
Fix StackStx Json serialization
Mar 12, 2024
2305f35
fix: integration test timeout
hstove Mar 12, 2024
1385683
Merge remote-tracking branch 'origin/next' into feat/stacking-burnops…
hstove Mar 14, 2024
99347e5
fix: nakamoto integration test fix
hstove Mar 14, 2024
584ca20
feat: use u32 for auth_id
hstove Mar 14, 2024
77dcca4
fix: better handling of optional fields in `StackStxOp`
hstove Mar 19, 2024
7de2268
Merge remote-tracking branch 'origin/next' into feat/stacking-burnops…
hstove Mar 19, 2024
6405ba4
fix: remove `set-signer-key-auth` within stack-stx burn op
hstove Mar 19, 2024
7f3cf56
feat: update integration tests, verify success
hstove Mar 19, 2024
4d6c8f2
feat: cleanup handling of stacking ops
hstove Mar 19, 2024
cb136bf
Use PoxVersions enum for checking pox_contract version
Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ jobs:
- tests::neon_integrations::size_overflow_unconfirmed_stream_microblocks_integration_test
- tests::neon_integrations::stx_delegate_btc_integration_test
- tests::neon_integrations::stx_transfer_btc_integration_test
- tests::neon_integrations::stack_stx_burn_op_test
- tests::neon_integrations::test_chainwork_first_intervals
- tests::neon_integrations::test_chainwork_partial_interval
- tests::neon_integrations::test_flash_block_skip_tenure
Expand All @@ -83,6 +84,7 @@ jobs:
- tests::signer::stackerdb_block_proposal
- tests::signer::stackerdb_filter_bad_transactions
- tests::signer::stackerdb_mine_2_nakamoto_reward_cycles
- tests::nakamoto_integrations::stack_stx_burn_op_integration_test
steps:
## Setup test environment
- name: Setup Test Environment
Expand Down
30 changes: 29 additions & 1 deletion stackslib/src/chainstate/burn/db/sortdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,19 @@ impl FromRow<StackStxOp> for StackStxOp {
let stacked_ustx = u128::from_str_radix(&stacked_ustx_str, 10)
.expect("CORRUPTION: bad u128 written to sortdb");
let num_cycles = row.get_unwrap("num_cycles");
let signing_key_str_opt: Option<String> = row.get("signer_key")?;
let signer_key = match signing_key_str_opt {
Some(key_str) => serde_json::from_str(&key_str).ok(),
None => None,
};
let max_amount_str_opt: Option<String> = row.get("max_amount")?;
let max_amount = match max_amount_str_opt {
Some(max_amount_str) => u128::from_str_radix(&max_amount_str, 10)
.map_err(|_| db_error::ParseError)
.ok(),
None => None,
};
let auth_id = row.get("auth_id")?;

Ok(StackStxOp {
txid,
Expand All @@ -329,6 +342,9 @@ impl FromRow<StackStxOp> for StackStxOp {
reward_addr,
stacked_ustx,
num_cycles,
signer_key,
max_amount,
auth_id,
})
}
}
Expand Down Expand Up @@ -702,6 +718,9 @@ const SORTITION_DB_SCHEMA_8: &'static [&'static str] = &[
block_hash TEXT NOT NULL,
block_height INTEGER NOT NULL
);"#,
r#"ALTER TABLE stack_stx ADD signer_key TEXT DEFAULT NULL;"#,
r#"ALTER TABLE stack_stx ADD max_amount TEXT DEFAULT NULL;"#,
r#"ALTER TABLE stack_stx ADD auth_id INTEGER DEFAULT NULL;"#,
r#"
-- table definition for `vote-for-aggregate-key` burn op
CREATE TABLE vote_for_aggregate_key (
Expand Down Expand Up @@ -5372,9 +5391,12 @@ impl<'a> SortitionHandleTx<'a> {
&op.reward_addr.to_db_string(),
&op.stacked_ustx.to_string(),
&op.num_cycles,
&serde_json::to_string(&op.signer_key).unwrap(),
&serde_json::to_string(&op.max_amount).unwrap(),
&op.auth_id,
];

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)?;
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)?;

Ok(())
}
Expand Down Expand Up @@ -10085,6 +10107,9 @@ pub mod tests {
reward_addr: PoxAddress::Standard(StacksAddress::new(4, Hash160([4u8; 20])), None),
stacked_ustx: 456,
num_cycles: 6,
signer_key: Some(StacksPublicKeyBuffer([0x02; 33])),
max_amount: Some(u128::MAX),
auth_id: Some(0u32),

txid: Txid([0x02; 32]),
vtxindex: 2,
Expand Down Expand Up @@ -10177,6 +10202,9 @@ pub mod tests {
reward_addr: PoxAddress::Standard(StacksAddress::new(4, Hash160([4u8; 20])), None),
stacked_ustx: 456,
num_cycles: 6,
signer_key: None,
max_amount: None,
auth_id: None,

txid: Txid([0x02; 32]),
vtxindex: 2,
Expand Down
8 changes: 8 additions & 0 deletions stackslib/src/chainstate/burn/operations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub enum Error {
// stack stx related errors
StackStxMustBePositive,
StackStxInvalidCycles,
StackStxInvalidKey,

// errors associated with delegate stx
DelegateStxMustBePositive,
Expand Down Expand Up @@ -142,6 +143,7 @@ impl fmt::Display for Error {
f,
"Stack STX must set num cycles between 1 and max num cycles"
),
Error::StackStxInvalidKey => write!(f, "Signer key is invalid"),
Error::DelegateStxMustBePositive => write!(f, "Delegate STX must be positive amount"),
Error::VoteForAggregateKeyInvalidKey => {
write!(f, "Aggregate key is invalid")
Expand Down Expand Up @@ -190,6 +192,9 @@ pub struct StackStxOp {
/// how many ustx this transaction locks
pub stacked_ustx: u128,
pub num_cycles: u8,
pub signer_key: Option<StacksPublicKeyBuffer>,
pub max_amount: Option<u128>,
pub auth_id: Option<u32>,

// common to all transactions
pub txid: Txid, // transaction ID
Expand Down Expand Up @@ -478,6 +483,9 @@ impl BlockstackOperationType {
"stacked_ustx": op.stacked_ustx,
"burn_txid": op.txid,
"vtxindex": op.vtxindex,
"signer_key": op.signer_key.as_ref().map(|k| serde_json::Value::String(k.to_hex())).unwrap_or(serde_json::Value::Null),
"max_amount": op.max_amount.map_or(serde_json::Value::Null, |amount| serde_json::Value::Number(serde_json::Number::from(amount))),
"auth_id": op.auth_id.map_or(serde_json::Value::Null, |id| serde_json::Value::Number(serde_json::Number::from(id))),
}
})
}
Expand Down