Skip to content

Commit 843d8f9

Browse files
author
Aaron Blankstein
authored
Merge pull request #1973 from blockstack/next
Release `next`
2 parents b1a9b47 + ad32bd5 commit 843d8f9

File tree

29 files changed

+2365
-488
lines changed

29 files changed

+2365
-488
lines changed

.github/actions/docsgen/Dockerfile.docsgen

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ WORKDIR /src
44

55
COPY . .
66

7-
RUN apt-get update && apt-get install -y git
7+
RUN apt-get update && apt-get install -y git jq
88

99
RUN cargo build
1010

1111
RUN mkdir /out
1212

13-
RUN /src/target/debug/blockstack-core docgen > /out/clarity-reference.json
13+
RUN /src/target/debug/blockstack-core docgen | jq . > /out/clarity-reference.json
14+
RUN /src/target/debug/blockstack-core docgen_boot | jq . > /out/boot-contracts-reference.json
1415

1516
FROM scratch AS export-stage
1617
COPY --from=build /out/clarity-reference.json /
18+
COPY --from=build /out/boot-contracts-reference.json /

.github/workflows/docs-pr.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ jobs:
4343
id: push
4444
run: |
4545
cd docs.blockstack
46-
git config user.email "[email protected]"
46+
git config user.email "[email protected]"
4747
git config user.name "PR Robot"
4848
git fetch --unshallow
4949
git checkout -b $ROBOT_BRANCH
5050
cp ../docs-output/clarity-reference.json ./src/_data/clarity-reference.json
51-
if $(git diff --quiet --exit-code); then
52-
echo "No clarity-reference.json changes, stopping"
51+
cp ../docs-output/boot-contracts-reference.json ./src/_data/boot-contracts-reference.json
52+
git add src/_data/clarity-reference.json
53+
git add src/_data/boot-contracts-reference.json
54+
if $(git diff --staged --quiet --exit-code); then
55+
echo "No reference.json changes, stopping"
5356
echo "::set-output name=open_pr::0"
5457
else
5558
git remote add robot https://github.com/$ROBOT_OWNER/$ROBOT_REPO
56-
git add src/_data/clarity-reference.json
57-
git commit -m "auto: update clarity-reference.json from stacks-blockchain@${GITHUB_SHA}"
59+
git commit -m "auto: update Clarity references JSONs from stacks-blockchain@${GITHUB_SHA}"
5860
git push robot $ROBOT_BRANCH
5961
echo "::set-output name=open_pr::1"
6062
fi

src/burnchains/mod.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ pub struct PoxConstants {
280280
/// fraction of liquid STX that must vote to reject PoX for
281281
/// it to revert to PoB in the next reward cycle
282282
pub pox_rejection_fraction: u64,
283+
/// percentage of liquid STX that must participate for PoX
284+
/// to occur
285+
pub pox_participation_threshold_pct: u64,
283286
_shadow: PhantomData<()>,
284287
}
285288

@@ -289,6 +292,7 @@ impl PoxConstants {
289292
prepare_length: u32,
290293
anchor_threshold: u32,
291294
pox_rejection_fraction: u64,
295+
pox_participation_threshold_pct: u64,
292296
) -> PoxConstants {
293297
assert!(anchor_threshold > (prepare_length / 2));
294298

@@ -297,20 +301,35 @@ impl PoxConstants {
297301
prepare_length,
298302
anchor_threshold,
299303
pox_rejection_fraction,
304+
pox_participation_threshold_pct,
300305
_shadow: PhantomData,
301306
}
302307
}
303308
#[cfg(test)]
304309
pub fn test_default() -> PoxConstants {
305-
PoxConstants::new(10, 5, 3, 25)
310+
PoxConstants::new(10, 5, 3, 25, 5)
311+
}
312+
313+
pub fn reward_slots(&self) -> u32 {
314+
self.reward_cycle_length
315+
}
316+
317+
/// is participating_ustx enough to engage in PoX in the next reward cycle?
318+
pub fn enough_participation(&self, participating_ustx: u128, liquid_ustx: u128) -> bool {
319+
participating_ustx
320+
.checked_mul(100)
321+
.expect("OVERFLOW: uSTX overflowed u128")
322+
> liquid_ustx
323+
.checked_mul(self.pox_participation_threshold_pct as u128)
324+
.expect("OVERFLOW: uSTX overflowed u128")
306325
}
307326

308327
pub fn mainnet_default() -> PoxConstants {
309-
PoxConstants::new(1000, 240, 192, 25)
328+
PoxConstants::new(1000, 240, 192, 25, 5)
310329
}
311330

312331
pub fn testnet_default() -> PoxConstants {
313-
PoxConstants::new(120, 30, 20, 3333333333333333) // total liquid supply is 40000000000000000 µSTX
332+
PoxConstants::new(120, 30, 20, 3333333333333333, 5) // total liquid supply is 40000000000000000 µSTX
314333
}
315334
}
316335

src/chainstate/coordinator/mod.rs

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use std::collections::VecDeque;
18-
use std::convert::TryInto;
18+
use std::convert::{TryFrom, TryInto};
1919
use std::time::Duration;
2020

2121
use burnchains::{
@@ -28,13 +28,18 @@ use chainstate::burn::{
2828
BlockHeaderHash, BlockSnapshot, ConsensusHash,
2929
};
3030
use chainstate::stacks::{
31+
boot::STACKS_BOOT_CODE_CONTRACT_ADDRESS,
3132
db::{ClarityTx, StacksChainState, StacksHeaderInfo},
3233
events::StacksTransactionReceipt,
3334
Error as ChainstateError, StacksAddress, StacksBlock, StacksBlockHeader, StacksBlockId,
3435
};
3536
use monitoring::increment_stx_blocks_processed_counter;
3637
use util::db::Error as DBError;
37-
use vm::{costs::ExecutionCost, types::PrincipalData};
38+
use vm::{
39+
costs::ExecutionCost,
40+
types::{PrincipalData, QualifiedContractIdentifier},
41+
Value,
42+
};
3843

3944
pub mod comm;
4045
use chainstate::stacks::index::MarfTrieId;
@@ -177,10 +182,35 @@ impl RewardSetProvider for OnChainRewardSetProvider {
177182
sortdb: &SortitionDB,
178183
block_id: &StacksBlockId,
179184
) -> Result<Vec<StacksAddress>, Error> {
180-
let res =
185+
let registered_addrs =
181186
chainstate.get_reward_addresses(burnchain, sortdb, current_burn_height, block_id)?;
182-
let addresses = res.iter().map(|a| a.0).collect::<Vec<StacksAddress>>();
183-
Ok(addresses)
187+
188+
let liquid_ustx = StacksChainState::get_stacks_block_header_info_by_index_block_hash(
189+
chainstate.headers_db(),
190+
block_id,
191+
)?
192+
.expect("CORRUPTION: Failed to look up block header info for PoX anchor block")
193+
.total_liquid_ustx;
194+
195+
let (threshold, participation) = StacksChainState::get_reward_threshold_and_participation(
196+
&burnchain.pox_constants,
197+
&registered_addrs,
198+
liquid_ustx,
199+
);
200+
201+
if !burnchain
202+
.pox_constants
203+
.enough_participation(participation, liquid_ustx)
204+
{
205+
info!("PoX reward cycle did not have enough participation. Defaulting to burn. participation={}, liquid_ustx={}, burn_height={}",
206+
participation, liquid_ustx, current_burn_height);
207+
return Ok(vec![]);
208+
}
209+
210+
Ok(StacksChainState::make_reward_set(
211+
threshold,
212+
registered_addrs,
213+
))
184214
}
185215
}
186216

@@ -212,7 +242,32 @@ impl<'a, T: BlockEventDispatcher>
212242
stacks_chain_id,
213243
chain_state_path,
214244
initial_balances,
215-
boot_block_exec,
245+
|clarity_tx| {
246+
let burnchain = burnchain.clone();
247+
let contract = QualifiedContractIdentifier::parse(&format!(
248+
"{}.pox",
249+
STACKS_BOOT_CODE_CONTRACT_ADDRESS
250+
))
251+
.expect("Failed to construct boot code contract address");
252+
let sender = PrincipalData::from(contract.clone());
253+
254+
clarity_tx.connection().as_transaction(|conn| {
255+
conn.run_contract_call(
256+
&sender,
257+
&contract,
258+
"set-burnchain-parameters",
259+
&[
260+
Value::UInt(burnchain.first_block_height as u128),
261+
Value::UInt(burnchain.pox_constants.prepare_length as u128),
262+
Value::UInt(burnchain.pox_constants.reward_cycle_length as u128),
263+
Value::UInt(burnchain.pox_constants.pox_rejection_fraction as u128),
264+
],
265+
|_, _| false,
266+
)
267+
.expect("Failed to set burnchain parameters in PoX contract");
268+
});
269+
boot_block_exec(clarity_tx)
270+
},
216271
block_limit,
217272
)
218273
.unwrap();

src/chainstate/coordinator/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn make_reward_set_coordinator<'a>(
268268

269269
pub fn get_burnchain(path: &str) -> Burnchain {
270270
let mut b = Burnchain::new(&format!("{}/burnchain/db/", path), "bitcoin", "regtest").unwrap();
271-
b.pox_constants = PoxConstants::new(5, 3, 3, 25);
271+
b.pox_constants = PoxConstants::new(5, 3, 3, 25, 5);
272272
b
273273
}
274274

0 commit comments

Comments
 (0)